gitlab-org--gitlab-foss/app/models/project_services/chat_message/base_message.rb
Z.J. van de Weg 5d4183e58d Convert seconds to minutes and hours on chat notifations
In the pipeline message, the duration of the pipeline was shown as:

> gitlab-org/gitlab-ee: Pipeline #8002259 of master branch by Douwe Maan
failed in 8612 seconds

But this many seconds only gave me a clue how long the pipeline took,
so now this will be shown as something like: 02:20:12 which gives a much
better measure of time.
2017-05-04 08:39:06 +02:00

65 lines
1.3 KiB
Ruby

require 'slack-notifier'
module ChatMessage
class BaseMessage
attr_reader :markdown
attr_reader :user_name
attr_reader :user_avatar
attr_reader :project_name
attr_reader :project_url
def initialize(params)
@markdown = params[:markdown] || false
@project_name = params.dig(:project, :path_with_namespace) || params[:project_name]
@project_url = params.dig(:project, :web_url) || params[:project_url]
@user_name = params.dig(:user, :username) || params[:user_name]
@user_avatar = params.dig(:user, :avatar_url) || params[:user_avatar]
end
def pretext
return message if markdown
format(message)
end
def fallback
end
def attachments
raise NotImplementedError
end
def activity
raise NotImplementedError
end
private
def message
raise NotImplementedError
end
def format(string)
Slack::Notifier::LinkFormatter.format(string)
end
def attachment_color
'#345'
end
def link(text, url)
"[#{text}](#{url})"
end
def pretty_duration(seconds)
parse_string =
if duration < 1.hour
'%M:%S'
else
'%H:%M:%S'
end
Time.at(seconds).utc.strftime(parse_string)
end
end
end