2016-08-11 08:46:47 -04:00
|
|
|
module Gitlab
|
|
|
|
module Badge
|
|
|
|
module Coverage
|
|
|
|
##
|
|
|
|
# Class that represents a coverage badge template.
|
|
|
|
#
|
|
|
|
# Template object will be passed to badge.svg.erb template.
|
|
|
|
#
|
2016-08-11 09:01:14 -04:00
|
|
|
class Template < Badge::Template
|
2016-08-11 08:46:47 -04:00
|
|
|
STATUS_COLOR = {
|
|
|
|
good: '#4c1',
|
2016-08-12 09:26:55 -04:00
|
|
|
acceptable: '#a3c51c',
|
2016-08-11 08:46:47 -04:00
|
|
|
medium: '#dfb317',
|
|
|
|
low: '#e05d44',
|
|
|
|
unknown: '#9f9f9f'
|
2017-02-21 18:32:18 -05:00
|
|
|
}.freeze
|
2016-08-11 08:46:47 -04:00
|
|
|
|
|
|
|
def initialize(badge)
|
|
|
|
@entity = badge.entity
|
|
|
|
@status = badge.status
|
|
|
|
end
|
|
|
|
|
|
|
|
def key_text
|
|
|
|
@entity.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def value_text
|
2017-03-20 09:34:47 -04:00
|
|
|
@status ? ("%.2f%%" % @status) : 'unknown'
|
2016-08-11 08:46:47 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def key_width
|
|
|
|
62
|
|
|
|
end
|
|
|
|
|
|
|
|
def value_width
|
2017-03-20 09:34:47 -04:00
|
|
|
@status ? 54 : 58
|
2016-08-11 08:46:47 -04:00
|
|
|
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
|