BigW Consortium Gitlab

template.rb 1 KB
Newer Older
1 2
module Gitlab
  module Badge
3
    module Pipeline
4
      ##
5
      # Class that represents a pipeline badge template.
6 7 8
      #
      # Template object will be passed to badge.svg.erb template.
      #
9
      class Template < Badge::Template
10
        STATUS_RENAME = { 'success' => 'passed' }.freeze
11 12 13 14 15 16 17 18
        STATUS_COLOR = {
          success: '#4c1',
          failed: '#e05d44',
          running: '#dfb317',
          pending: '#dfb317',
          canceled: '#9f9f9f',
          skipped: '#9f9f9f',
          unknown: '#9f9f9f'
19
        }.freeze
20

21 22 23
        def initialize(badge)
          @entity = badge.entity
          @status = badge.status
24 25 26
        end

        def key_text
27
          @entity.to_s
28 29 30
        end

        def value_text
31
          STATUS_RENAME[@status.to_s] || @status.to_s
32 33 34
        end

        def key_width
35
          62
36 37 38 39 40 41 42
        end

        def value_width
          54
        end

        def value_color
43
          STATUS_COLOR[@status.to_sym] || STATUS_COLOR[:unknown]
44 45 46 47 48
        end
      end
    end
  end
end