BigW Consortium Gitlab

Commit 9bfa0a5f by Tiago Botelho

adds remaining messages

parent 7dd645e6
...@@ -17,6 +17,10 @@ module ChatMessage ...@@ -17,6 +17,10 @@ module ChatMessage
raise NotImplementedError raise NotImplementedError
end end
def activity
raise NotImplementedError
end
private private
def message def message
......
module ChatMessage module ChatMessage
class IssueMessage < BaseMessage class IssueMessage < BaseMessage
attr_reader :user_name attr_reader :user_name
attr_reader :user_avatar
attr_reader :title attr_reader :title
attr_reader :project_name attr_reader :project_name
attr_reader :project_url attr_reader :project_url
...@@ -9,9 +10,11 @@ module ChatMessage ...@@ -9,9 +10,11 @@ module ChatMessage
attr_reader :action attr_reader :action
attr_reader :state attr_reader :state
attr_reader :description attr_reader :description
attr_reader :markdown_format
def initialize(params) def initialize(params)
@user_name = params[:user][:username] @user_name = params[:user][:username]
@user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name] @project_name = params[:project_name]
@project_url = params[:project_url] @project_url = params[:project_url]
...@@ -23,23 +26,28 @@ module ChatMessage ...@@ -23,23 +26,28 @@ module ChatMessage
@action = obj_attr[:action] @action = obj_attr[:action]
@state = obj_attr[:state] @state = obj_attr[:state]
@description = obj_attr[:description] || '' @description = obj_attr[:description] || ''
@markdown_format = params[:format]
end end
def attachments def attachments
return [] unless opened_issue? return [] unless opened_issue?
description_message markdown_format ? description : description_message
end
def activity
{
title: "Issue #{state} by #{user_name}",
subtitle: "to: #{project_link}",
text: issue_link,
image: user_avatar
}
end end
private private
def message def message
case state "[#{project_link}] Issue #{issue_link} #{state} by #{user_name}"
when "opened"
"[#{project_link}] Issue #{state} by #{user_name}"
else
"[#{project_link}] Issue #{issue_link} #{state} by #{user_name}"
end
end end
def opened_issue? def opened_issue?
...@@ -52,7 +60,7 @@ module ChatMessage ...@@ -52,7 +60,7 @@ module ChatMessage
title_link: issue_url, title_link: issue_url,
text: format(description), text: format(description),
color: "#C95823" color: "#C95823"
}] }]
end end
def project_link def project_link
......
module ChatMessage module ChatMessage
class MergeMessage < BaseMessage class MergeMessage < BaseMessage
attr_reader :user_name attr_reader :user_name
attr_reader :user_avatar
attr_reader :project_name attr_reader :project_name
attr_reader :project_url attr_reader :project_url
attr_reader :merge_request_id attr_reader :merge_request_id
...@@ -8,9 +9,11 @@ module ChatMessage ...@@ -8,9 +9,11 @@ module ChatMessage
attr_reader :target_branch attr_reader :target_branch
attr_reader :state attr_reader :state
attr_reader :title attr_reader :title
attr_reader :markdown_format
def initialize(params) def initialize(params)
@user_name = params[:user][:username] @user_name = params[:user][:username]
@user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name] @project_name = params[:project_name]
@project_url = params[:project_url] @project_url = params[:project_url]
...@@ -21,10 +24,16 @@ module ChatMessage ...@@ -21,10 +24,16 @@ module ChatMessage
@target_branch = obj_attr[:target_branch] @target_branch = obj_attr[:target_branch]
@state = obj_attr[:state] @state = obj_attr[:state]
@title = format_title(obj_attr[:title]) @title = format_title(obj_attr[:title])
@markdown_format = params[:format]
end end
def pretext def activity
format(message) {
title: "Merge Request #{state} by #{user_name}",
subtitle: "to: #{project_link}",
text: merge_request_link,
image: user_avatar
}
end end
def attachments def attachments
......
module ChatMessage module ChatMessage
class PipelineMessage < BaseMessage class PipelineMessage < BaseMessage
attr_reader :ref_type, :ref, :status, :project_name, :project_url, attr_reader :ref_type
:user_name, :duration, :pipeline_id attr_reader :ref
attr_reader :status
attr_reader :project_name
attr_reader :project_url
attr_reader :user_name
attr_reader :duration
attr_reader :pipeline_id
attr_reader :user_avatar
attr_reader :markdown_format
def initialize(data) def initialize(data)
pipeline_attributes = data[:object_attributes] pipeline_attributes = data[:object_attributes]
...@@ -14,6 +22,9 @@ module ChatMessage ...@@ -14,6 +22,9 @@ module ChatMessage
@project_name = data[:project][:path_with_namespace] @project_name = data[:project][:path_with_namespace]
@project_url = data[:project][:web_url] @project_url = data[:project][:web_url]
@user_name = (data[:user] && data[:user][:name]) || 'API' @user_name = (data[:user] && data[:user][:name]) || 'API'
@user_avatar = data[:user][:avatar_url] || ''
@markdown_format = params[:format]
end end
def pretext def pretext
...@@ -24,8 +35,17 @@ module ChatMessage ...@@ -24,8 +35,17 @@ module ChatMessage
format(message) format(message)
end end
def activity
{
title: "Pipeline #{pipeline_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status}",
subtitle: "to: #{project_link}",
text: "in #{duration} #{'second'.pluralize(duration)}",
image: user_avatar
}
end
def attachments def attachments
[{ text: format(message), color: attachment_color }] markdown_format ? message : [{ text: format(message), color: attachment_color }]
end end
private private
...@@ -34,10 +54,6 @@ module ChatMessage ...@@ -34,10 +54,6 @@ module ChatMessage
"#{project_link}: Pipeline #{pipeline_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status} in #{duration} #{'second'.pluralize(duration)}" "#{project_link}: Pipeline #{pipeline_link} of #{branch_link} #{ref_type} by #{user_name} #{humanized_status} in #{duration} #{'second'.pluralize(duration)}"
end end
def format(string)
Slack::Notifier::LinkFormatter.format(string)
end
def humanized_status def humanized_status
case status case status
when 'success' when 'success'
......
...@@ -7,9 +7,11 @@ module ChatMessage ...@@ -7,9 +7,11 @@ module ChatMessage
attr_reader :wiki_page_url attr_reader :wiki_page_url
attr_reader :action attr_reader :action
attr_reader :description attr_reader :description
attr_reader :markdown_format
def initialize(params) def initialize(params)
@user_name = params[:user][:username] @user_name = params[:user][:username]
@user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name] @project_name = params[:project_name]
@project_url = params[:project_url] @project_url = params[:project_url]
...@@ -26,10 +28,21 @@ module ChatMessage ...@@ -26,10 +28,21 @@ module ChatMessage
when "update" when "update"
"edited" "edited"
end end
@markdown_format = params[:format]
end
def activity
{
title: "#{user_name} #{action} #{wiki_page_link}",
subtitle: "in: #{project_link}",
text: title,
image: user_avatar
}
end end
def attachments def attachments
description_message markdown_format ? @description : description_message
end end
private private
......
...@@ -25,7 +25,10 @@ module MicrosoftTeams ...@@ -25,7 +25,10 @@ module MicrosoftTeams
'activityText' => options[:activity][:text], 'activityText' => options[:activity][:text],
'activityImage' => options[:activity][:image] 'activityImage' => options[:activity][:image]
} }
result['sections'] << { 'title' => 'Details', 'facts' => attachments(options[:attachments]) } if options[:attachments]
if options[:attachments].present? && !options[:attachments].empty?
result['sections'] << { 'title' => 'Details', 'facts' => attachments(options[:attachments]) }
end
result.to_json result.to_json
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment