2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
module Gitlab
|
|
|
|
module Badge
|
|
|
|
module Coverage
|
|
|
|
##
|
|
|
|
# Class that represents a coverage badge template.
|
|
|
|
#
|
|
|
|
# Template object will be passed to badge.svg.erb template.
|
|
|
|
#
|
|
|
|
class Template < Badge::Template
|
|
|
|
STATUS_COLOR = {
|
|
|
|
good: '#4c1',
|
|
|
|
acceptable: '#a3c51c',
|
|
|
|
medium: '#dfb317',
|
|
|
|
low: '#e05d44',
|
|
|
|
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
|
2018-03-17 18:26:18 +05:30
|
|
|
@status ? ("%.2f%%" % @status) : 'unknown'
|
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
|
2018-03-17 18:26:18 +05:30
|
|
|
@status ? 54 : 58
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def value_color
|
|
|
|
case @status
|
|
|
|
when 95..100 then STATUS_COLOR[:good]
|
|
|
|
when 90..95 then STATUS_COLOR[:acceptable]
|
|
|
|
when 75..90 then STATUS_COLOR[:medium]
|
|
|
|
when 0..75 then STATUS_COLOR[:low]
|
|
|
|
else
|
|
|
|
STATUS_COLOR[:unknown]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|