2018-08-10 02:45:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-25 14:36:37 -05:00
|
|
|
module ChatMessage
|
2015-02-20 08:49:26 -05:00
|
|
|
class IssueMessage < BaseMessage
|
2015-02-19 00:02:57 -05:00
|
|
|
attr_reader :title
|
|
|
|
attr_reader :issue_iid
|
|
|
|
attr_reader :issue_url
|
|
|
|
attr_reader :action
|
|
|
|
attr_reader :state
|
|
|
|
attr_reader :description
|
|
|
|
|
|
|
|
def initialize(params)
|
2017-04-04 11:10:21 -04:00
|
|
|
super
|
2015-02-19 00:02:57 -05:00
|
|
|
|
|
|
|
obj_attr = params[:object_attributes]
|
|
|
|
obj_attr = HashWithIndifferentAccess.new(obj_attr)
|
|
|
|
@title = obj_attr[:title]
|
|
|
|
@issue_iid = obj_attr[:iid]
|
|
|
|
@issue_url = obj_attr[:url]
|
|
|
|
@action = obj_attr[:action]
|
|
|
|
@state = obj_attr[:state]
|
2016-03-28 07:15:41 -04:00
|
|
|
@description = obj_attr[:description] || ''
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
|
|
|
return [] unless opened_issue?
|
2017-04-04 11:10:21 -04:00
|
|
|
return description if markdown
|
2015-02-19 00:02:57 -05:00
|
|
|
|
2017-04-04 11:10:21 -04:00
|
|
|
description_message
|
2017-04-03 13:16:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def activity
|
2017-04-04 11:10:21 -04:00
|
|
|
{
|
2017-10-06 16:00:50 -04:00
|
|
|
title: "Issue #{state} by #{user_combined_name}",
|
2017-04-04 11:10:21 -04:00
|
|
|
subtitle: "in #{project_link}",
|
|
|
|
text: issue_link,
|
|
|
|
image: user_avatar
|
|
|
|
}
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def message
|
2017-11-06 08:48:34 -05:00
|
|
|
if opened_issue?
|
2017-10-06 16:00:50 -04:00
|
|
|
"[#{project_link}] Issue #{state} by #{user_combined_name}"
|
2017-04-04 11:10:21 -04:00
|
|
|
else
|
2017-10-06 16:00:50 -04:00
|
|
|
"[#{project_link}] Issue #{issue_link} #{state} by #{user_combined_name}"
|
2017-04-04 11:10:21 -04:00
|
|
|
end
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def opened_issue?
|
|
|
|
action == "open"
|
|
|
|
end
|
|
|
|
|
|
|
|
def description_message
|
2015-09-16 07:19:46 -04:00
|
|
|
[{
|
|
|
|
title: issue_title,
|
|
|
|
title_link: issue_url,
|
|
|
|
text: format(description),
|
2017-02-22 12:44:44 -05:00
|
|
|
color: "#C95823"
|
2017-04-04 05:16:24 -04:00
|
|
|
}]
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_link
|
2017-01-18 05:38:59 -05:00
|
|
|
link(project_name, project_url)
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def issue_link
|
2017-01-18 05:38:59 -05:00
|
|
|
link(issue_title, issue_url)
|
2015-09-16 07:19:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def issue_title
|
2017-04-04 11:10:21 -04:00
|
|
|
"#{Issue.reference_prefix}#{issue_iid} #{title}"
|
2015-02-19 00:02:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|