2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module ChatMessage
|
2015-04-26 12:48:37 +05:30
|
|
|
class MergeMessage < BaseMessage
|
2019-12-04 20:38:33 +05:30
|
|
|
prepend_if_ee('::EE::ChatMessage::MergeMessage') # rubocop: disable Cop/InjectEnterpriseEditionModule
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
attr_reader :merge_request_iid
|
2015-04-26 12:48:37 +05:30
|
|
|
attr_reader :source_branch
|
|
|
|
attr_reader :target_branch
|
|
|
|
attr_reader :state
|
|
|
|
attr_reader :title
|
|
|
|
|
|
|
|
def initialize(params)
|
2017-08-17 22:00:37 +05:30
|
|
|
super
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
obj_attr = params[:object_attributes]
|
|
|
|
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
2017-08-17 22:00:37 +05:30
|
|
|
@merge_request_iid = obj_attr[:iid]
|
2015-04-26 12:48:37 +05:30
|
|
|
@source_branch = obj_attr[:source_branch]
|
|
|
|
@target_branch = obj_attr[:target_branch]
|
|
|
|
@state = obj_attr[:state]
|
|
|
|
@title = format_title(obj_attr[:title])
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def activity
|
|
|
|
{
|
2018-12-05 23:21:45 +05:30
|
|
|
title: "Merge Request #{state_or_action_text} by #{user_combined_name}",
|
2017-08-17 22:00:37 +05:30
|
|
|
subtitle: "in #{project_link}",
|
|
|
|
text: merge_request_link,
|
|
|
|
image: user_avatar
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def format_title(title)
|
|
|
|
'*' + title.lines.first.chomp + '*'
|
|
|
|
end
|
|
|
|
|
|
|
|
def message
|
|
|
|
merge_request_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_link
|
2017-08-17 22:00:37 +05:30
|
|
|
link(project_name, project_url)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_message
|
2018-12-05 23:21:45 +05:30
|
|
|
"#{user_combined_name} #{state_or_action_text} #{merge_request_link} in #{project_link}"
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_link
|
2017-08-17 22:00:37 +05:30
|
|
|
link(merge_request_title, merge_request_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_title
|
|
|
|
"#{MergeRequest.reference_prefix}#{merge_request_iid} #{title}"
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_url
|
2020-03-09 13:42:32 +05:30
|
|
|
"#{project_url}/-/merge_requests/#{merge_request_iid}"
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
|
|
|
|
# overridden in EE
|
|
|
|
def state_or_action_text
|
|
|
|
state
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|