Welcome to mirror list, hosted at ThFree Co, Russian Federation.

template.rb « pipeline « badge « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8430b01fc9a172075658211e7fd496b5aaf167a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true

module Gitlab::Ci
  module Badge
    module Pipeline
      ##
      # Class that represents a pipeline badge template.
      #
      # Template object will be passed to badge.svg.erb template.
      #
      class Template < Badge::Template
        STATUS_RENAME = { 'success' => 'passed' }.freeze
        STATUS_COLOR = {
          success: '#4c1',
          failed: '#e05d44',
          running: '#dfb317',
          pending: '#dfb317',
          preparing: '#a7a7a7',
          canceled: '#9f9f9f',
          skipped: '#9f9f9f',
          unknown: '#9f9f9f'
        }.freeze

        def initialize(badge)
          @entity = badge.entity
          @status = badge.status
          @key_text = badge.customization.dig(:key_text)
          @key_width = badge.customization.dig(:key_width)
        end

        def key_text
          if @key_text && @key_text.size <= MAX_KEY_TEXT_SIZE
            @key_text
          else
            @entity.to_s
          end
        end

        def value_text
          STATUS_RENAME[@status.to_s] || @status.to_s
        end

        def key_width
          if @key_width && @key_width.between?(1, MAX_KEY_WIDTH)
            @key_width
          else
            62
          end
        end

        def value_width
          54
        end

        def value_color
          STATUS_COLOR[@status.to_sym] || STATUS_COLOR[:unknown]
        end
      end
    end
  end
end