2015-02-20 10:05:40 -05:00
|
|
|
class SlackService
|
2015-02-20 08:49:26 -05:00
|
|
|
class MergeMessage < BaseMessage
|
2015-03-06 11:31:49 -05:00
|
|
|
attr_reader :user_name
|
2015-02-19 00:02:57 -05:00
|
|
|
attr_reader :project_name
|
|
|
|
attr_reader :project_url
|
|
|
|
attr_reader :merge_request_id
|
|
|
|
attr_reader :source_branch
|
|
|
|
attr_reader :target_branch
|
|
|
|
attr_reader :state
|
2015-03-06 11:31:49 -05:00
|
|
|
attr_reader :title
|
2015-02-19 00:02:57 -05:00
|
|
|
|
|
|
|
def initialize(params)
|
2015-03-06 11:31:49 -05:00
|
|
|
@user_name = params[:user][:name]
|
2015-02-19 00:02:57 -05:00
|
|
|
@project_name = params[:project_name]
|
|
|
|
@project_url = params[:project_url]
|
|
|
|
|
|
|
|
obj_attr = params[:object_attributes]
|
|
|
|
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
|
|
|
@merge_request_id = obj_attr[:iid]
|
|
|
|
@source_branch = obj_attr[:source_branch]
|
|
|
|
@target_branch = obj_attr[:target_branch]
|
|
|
|
@state = obj_attr[:state]
|
2015-03-06 11:31:49 -05:00
|
|
|
@title = format_title(obj_attr[:title])
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def pretext
|
|
|
|
format(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-03-06 11:31:49 -05:00
|
|
|
def format_title(title)
|
|
|
|
'*' + title.lines.first.chomp + '*'
|
|
|
|
end
|
|
|
|
|
2015-02-19 00:02:57 -05:00
|
|
|
def message
|
|
|
|
merge_request_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_link
|
|
|
|
"[#{project_name}](#{project_url})"
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_message
|
2015-03-06 11:31:49 -05:00
|
|
|
"#{user_name} #{state} #{merge_request_link} in #{project_link}: #{title}"
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_link
|
2016-04-19 02:32:02 -04:00
|
|
|
"[merge request !#{merge_request_id}](#{merge_request_url})"
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_url
|
|
|
|
"#{project_url}/merge_requests/#{merge_request_id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|