debian-mirror-gitlab/app/models/project_services/chat_message/merge_message.rb

82 lines
1.8 KiB
Ruby
Raw Normal View History

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
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
2020-11-24 15:15:51 +05:30
attr_reader :action
2015-04-26 12:48:37 +05:30
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]
2020-11-24 15:15:51 +05:30
@action = obj_attr[:action]
2015-04-26 12:48:37 +05:30
@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
2020-06-23 00:09:42 +05:30
"#{user_combined_name} #{state_or_action_text} merge request #{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-13 15:44:24 +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
def state_or_action_text
2020-11-24 15:15:51 +05:30
case action
when 'approved', 'unapproved'
action
when 'approval'
'added their approval to'
when 'unapproval'
'removed their approval from'
else
state
end
2018-12-05 23:21:45 +05:30
end
2015-04-26 12:48:37 +05:30
end
end