2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module ChatMessage
|
2016-09-29 09:46:39 +05:30
|
|
|
class PipelineMessage < BaseMessage
|
2017-08-17 22:00:37 +05:30
|
|
|
attr_reader :ref_type
|
|
|
|
attr_reader :ref
|
|
|
|
attr_reader :status
|
|
|
|
attr_reader :duration
|
|
|
|
attr_reader :pipeline_id
|
2016-09-29 09:46:39 +05:30
|
|
|
|
|
|
|
def initialize(data)
|
2017-08-17 22:00:37 +05:30
|
|
|
super
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@user_name = data.dig(:user, :username) || 'API'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
pipeline_attributes = data[:object_attributes]
|
|
|
|
@ref_type = pipeline_attributes[:tag] ? 'tag' : 'branch'
|
|
|
|
@ref = pipeline_attributes[:ref]
|
|
|
|
@status = pipeline_attributes[:status]
|
2017-08-17 22:00:37 +05:30
|
|
|
@duration = pipeline_attributes[:duration].to_i
|
2016-09-29 09:46:39 +05:30
|
|
|
@pipeline_id = pipeline_attributes[:id]
|
|
|
|
end
|
|
|
|
|
|
|
|
def pretext
|
|
|
|
''
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachments
|
2017-08-17 22:00:37 +05:30
|
|
|
return message if markdown
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
[{ text: format(message), color: attachment_color }]
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def activity
|
|
|
|
{
|
2018-03-17 18:26:18 +05:30
|
|
|
title: "Pipeline #{pipeline_link} of #{ref_type} #{branch_link} by #{user_combined_name} #{humanized_status}",
|
2017-08-17 22:00:37 +05:30
|
|
|
subtitle: "in #{project_link}",
|
|
|
|
text: "in #{pretty_duration(duration)}",
|
|
|
|
image: user_avatar || ''
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def message
|
2018-03-17 18:26:18 +05:30
|
|
|
"#{project_link}: Pipeline #{pipeline_link} of #{ref_type} #{branch_link} by #{user_combined_name} #{humanized_status} in #{pretty_duration(duration)}"
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def humanized_status
|
|
|
|
case status
|
|
|
|
when 'success'
|
|
|
|
'passed'
|
|
|
|
else
|
|
|
|
status
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def attachment_color
|
|
|
|
if status == 'success'
|
|
|
|
'good'
|
|
|
|
else
|
|
|
|
'danger'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch_url
|
|
|
|
"#{project_url}/commits/#{ref}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def branch_link
|
|
|
|
"[#{ref}](#{branch_url})"
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_link
|
|
|
|
"[#{project_name}](#{project_url})"
|
|
|
|
end
|
|
|
|
|
|
|
|
def pipeline_url
|
|
|
|
"#{project_url}/pipelines/#{pipeline_id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def pipeline_link
|
2017-08-17 22:00:37 +05:30
|
|
|
"[##{pipeline_id}](#{pipeline_url})"
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|