BigW Consortium Gitlab

status.rb 691 Bytes
Newer Older
1 2 3 4 5 6 7
module Gitlab
  module Badge
    module Build
      ##
      # Build status badge
      #
      class Status < Badge::Base
8
        attr_reader :project, :ref
9 10 11 12

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

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

17 18 19 20
        def entity
          'build'
        end

21 22
        def status
          @project.pipelines
23
            .where(sha: @sha)
24
            .latest_status(@ref) || 'unknown'
25 26 27
        end

        def metadata
28
          @metadata ||= Build::Metadata.new(self)
29 30 31
        end

        def template
32
          @template ||= Build::Template.new(self)
33 34 35 36 37
        end
      end
    end
  end
end