debian-mirror-gitlab/lib/gitlab/badge/pipeline/template.rb

62 lines
1.4 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module Gitlab
module Badge
2017-09-10 17:25:29 +05:30
module Pipeline
2016-09-13 17:45:13 +05:30
##
2017-09-10 17:25:29 +05:30
# Class that represents a pipeline badge template.
2016-09-13 17:45:13 +05:30
#
# Template object will be passed to badge.svg.erb template.
#
class Template < Badge::Template
2017-09-10 17:25:29 +05:30
STATUS_RENAME = { 'success' => 'passed' }.freeze
2016-09-13 17:45:13 +05:30
STATUS_COLOR = {
success: '#4c1',
failed: '#e05d44',
running: '#dfb317',
pending: '#dfb317',
2019-12-21 20:55:43 +05:30
preparing: '#a7a7a7',
2016-09-13 17:45:13 +05:30
canceled: '#9f9f9f',
skipped: '#9f9f9f',
unknown: '#9f9f9f'
2017-08-17 22:00:37 +05:30
}.freeze
2016-09-13 17:45:13 +05:30
def initialize(badge)
@entity = badge.entity
@status = badge.status
2020-06-23 00:09:42 +05:30
@key_text = badge.customization.dig(:key_text)
@key_width = badge.customization.dig(:key_width)
2016-09-13 17:45:13 +05:30
end
def key_text
2020-06-23 00:09:42 +05:30
if @key_text && @key_text.size <= MAX_KEY_SIZE
@key_text
else
@entity.to_s
end
2016-09-13 17:45:13 +05:30
end
def value_text
2017-09-10 17:25:29 +05:30
STATUS_RENAME[@status.to_s] || @status.to_s
2016-09-13 17:45:13 +05:30
end
def key_width
2020-06-23 00:09:42 +05:30
if @key_width && @key_width.between?(1, MAX_KEY_SIZE)
@key_width
else
62
end
2016-09-13 17:45:13 +05:30
end
def value_width
54
end
def value_color
STATUS_COLOR[@status.to_sym] || STATUS_COLOR[:unknown]
end
end
end
end
end