2021-05-17 11:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Integrations
|
|
|
|
module ChatMessage
|
|
|
|
class MergeMessage < BaseMessage
|
|
|
|
attr_reader :merge_request_iid
|
|
|
|
attr_reader :source_branch
|
|
|
|
attr_reader :target_branch
|
|
|
|
attr_reader :action
|
|
|
|
attr_reader :state
|
|
|
|
attr_reader :title
|
|
|
|
|
|
|
|
def initialize(params)
|
|
|
|
super
|
|
|
|
|
|
|
|
obj_attr = params[:object_attributes]
|
|
|
|
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
|
|
|
@merge_request_iid = obj_attr[:iid]
|
|
|
|
@source_branch = obj_attr[:source_branch]
|
|
|
|
@target_branch = obj_attr[:target_branch]
|
|
|
|
@action = obj_attr[:action]
|
|
|
|
@state = obj_attr[:state]
|
|
|
|
@title = format_title(obj_attr[:title])
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
def activity
|
|
|
|
{
|
2022-01-11 19:16:35 -05:00
|
|
|
title: "Merge request #{state_or_action_text} by #{strip_markup(user_combined_name)}",
|
2021-05-17 11:10:15 -04:00
|
|
|
subtitle: "in #{project_link}",
|
|
|
|
text: merge_request_link,
|
|
|
|
image: user_avatar
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def format_title(title)
|
2022-01-11 19:16:35 -05:00
|
|
|
'*' + strip_markup(title.lines.first.chomp) + '*'
|
2021-05-17 11:10:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
merge_request_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_link
|
|
|
|
link(project_name, project_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_message
|
2022-01-11 19:16:35 -05:00
|
|
|
"#{strip_markup(user_combined_name)} #{state_or_action_text} merge request #{merge_request_link} in #{project_link}"
|
2021-05-17 11:10:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_link
|
|
|
|
link(merge_request_title, merge_request_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_title
|
2022-01-11 19:16:35 -05:00
|
|
|
"#{MergeRequest.reference_prefix}#{merge_request_iid} #{strip_markup(title)}"
|
2021-05-17 11:10:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_url
|
|
|
|
"#{project_url}/-/merge_requests/#{merge_request_iid}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def state_or_action_text
|
|
|
|
case action
|
|
|
|
when 'approved', 'unapproved'
|
|
|
|
action
|
|
|
|
when 'approval'
|
|
|
|
'added their approval to'
|
|
|
|
when 'unapproval'
|
|
|
|
'removed their approval from'
|
|
|
|
else
|
|
|
|
state
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|