Commit 9bfa0a5f authored by Tiago Botelho's avatar Tiago Botelho

adds remaining messages

parent 7dd645e6
......@@ -17,6 +17,10 @@ module ChatMessage
raise NotImplementedError
end
def activity
raise NotImplementedError
end
private
def message
......
module ChatMessage
class IssueMessage < BaseMessage
attr_reader :user_name
attr_reader :user_avatar
attr_reader :title
attr_reader :project_name
attr_reader :project_url
......@@ -9,9 +10,11 @@ module ChatMessage
attr_reader :action
attr_reader :state
attr_reader :description
attr_reader :markdown_format
def initialize(params)
@user_name = params[:user][:username]
@user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name]
@project_url = params[:project_url]
......@@ -23,24 +26,29 @@ module ChatMessage
@action = obj_attr[:action]
@state = obj_attr[:state]
@description = obj_attr[:description] || ''
@markdown_format = params[:format]
end
def attachments
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
private
def message
case state
when "opened"
"[#{project_link}] Issue #{state} by #{user_name}"
else
"[#{project_link}] Issue #{issue_link} #{state} by #{user_name}"
end
end
def opened_issue?
action == "open"
......
module ChatMessage
class MergeMessage < BaseMessage
attr_reader :user_name
attr_reader :user_avatar
attr_reader :project_name
attr_reader :project_url
attr_reader :merge_request_id
......@@ -8,9 +9,11 @@ module ChatMessage
attr_reader :target_branch
attr_reader :state
attr_reader :title
attr_reader :markdown_format
def initialize(params)
@user_name = params[:user][:username]
@user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name]
@project_url = params[:project_url]
......@@ -21,10 +24,16 @@ module ChatMessage
@target_branch = obj_attr[:target_branch]
@state = obj_attr[:state]
@title = format_title(obj_attr[:title])
@markdown_format = params[:format]
end
def pretext
format(message)
def activity
{
title: "Merge Request #{state} by #{user_name}",
subtitle: "to: #{project_link}",
text: merge_request_link,
image: user_avatar
}
end
def attachments
......
module ChatMessage
class PipelineMessage < BaseMessage
attr_reader :ref_type, :ref, :status, :project_name, :project_url,
:user_name, :duration, :pipeline_id
attr_reader :ref_type
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)
pipeline_attributes = data[:object_attributes]
......@@ -14,6 +22,9 @@ module ChatMessage
@project_name = data[:project][:path_with_namespace]
@project_url = data[:project][:web_url]
@user_name = (data[:user] && data[:user][:name]) || 'API'
@user_avatar = data[:user][:avatar_url] || ''
@markdown_format = params[:format]
end
def pretext
......@@ -24,8 +35,17 @@ module ChatMessage
format(message)
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
[{ text: format(message), color: attachment_color }]
markdown_format ? message : [{ text: format(message), color: attachment_color }]
end
private
......@@ -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)}"
end
def format(string)
Slack::Notifier::LinkFormatter.format(string)
end
def humanized_status
case status
when 'success'
......
......@@ -7,9 +7,11 @@ module ChatMessage
attr_reader :wiki_page_url
attr_reader :action
attr_reader :description
attr_reader :markdown_format
def initialize(params)
@user_name = params[:user][:username]
@user_avatar = params[:user][:avatar_url]
@project_name = params[:project_name]
@project_url = params[:project_url]
......@@ -26,10 +28,21 @@ module ChatMessage
when "update"
"edited"
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
def attachments
description_message
markdown_format ? @description : description_message
end
private
......
......@@ -25,7 +25,10 @@ module MicrosoftTeams
'activityText' => options[:activity][:text],
'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
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