summaryrefslogtreecommitdiff
path: root/lib/gitlab/badge/build/status.rb
blob: b762d85b6e5378b56a1693bc03c0f229f2ec7b7e (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
module Gitlab
  module Badge
    module Build
      ##
      # Build status badge
      #
      class Status < Badge::Base
        attr_reader :project, :ref

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

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

        def entity
          'build'
        end

        def status
          @project.pipelines
            .where(sha: @sha)
            .latest_status(@ref) || 'unknown'
        end

        def metadata
          @metadata ||= Build::Metadata.new(self)
        end

        def template
          @template ||= Build::Template.new(self)
        end
      end
    end
  end
end