Read about our upcoming Code of Conduct on this issue

status.rb 839 Bytes
Newer Older
1
2
# frozen_string_literal: true

3
4
module Gitlab
  module Badge
5
    module Pipeline
6
      ##
7
      # Pipeline status badge
8
9
      #
      class Status < Badge::Base
10
        attr_reader :project, :ref
11
12
13
14

        def initialize(project, ref)
          @project = project
          @ref = ref
15

16
17
18
          @sha = @project.commit(@ref).try(:sha)
        end

19
        def entity
20
          'pipeline'
21
22
        end

23
        # rubocop: disable CodeReuse/ActiveRecord
24
        def status
25
          @project.ci_pipelines
26
            .where(sha: @sha)
27
            .latest_status(@ref) || 'unknown'
28
        end
29
        # rubocop: enable CodeReuse/ActiveRecord
30
31

        def metadata
32
          @metadata ||= Pipeline::Metadata.new(self)
33
34
35
        end

        def template
36
          @template ||= Pipeline::Template.new(self)
37
38
39
40
41
        end
      end
    end
  end
end