2015-02-20 15:05:40 +00:00
|
|
|
class SlackService
|
2015-02-20 13:49:26 +00:00
|
|
|
class MergeMessage < BaseMessage
|
2015-03-06 16:31:49 +00:00
|
|
|
attr_reader :user_name
|
2015-02-19 05:02:57 +00: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 16:31:49 +00:00
|
|
|
attr_reader :title
|
2015-02-19 05:02:57 +00:00
|
|
|
|
|
|
|
def initialize(params)
|
2016-09-30 21:03:30 +00:00
|
|
|
@user_name = params[:user][:username]
|
2015-02-19 05:02:57 +00: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 16:31:49 +00:00
|
|
|
@title = format_title(obj_attr[:title])
|
2015-02-19 05:02:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def pretext
|
|
|
|
format(message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2015-03-06 16:31:49 +00:00
|
|
|
def format_title(title)
|
|
|
|
'*' + title.lines.first.chomp + '*'
|
|
|
|
end
|
|
|
|
|
2015-02-19 05:02:57 +00:00
|
|
|
def message
|
|
|
|
merge_request_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_link
|
|
|
|
"[#{project_name}](#{project_url})"
|
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_message
|
2015-03-06 16:31:49 +00:00
|
|
|
"#{user_name} #{state} #{merge_request_link} in #{project_link}: #{title}"
|
2015-02-19 05:02:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_link
|
2016-04-19 06:32:02 +00:00
|
|
|
"[merge request !#{merge_request_id}](#{merge_request_url})"
|
2015-02-19 05:02:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def merge_request_url
|
|
|
|
"#{project_url}/merge_requests/#{merge_request_id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|