debian-mirror-gitlab/lib/gitlab/badge/pipeline/status.rb

42 lines
839 B
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
module Gitlab
module Badge
2017-09-10 17:25:29 +05:30
module Pipeline
2016-09-13 17:45:13 +05:30
##
2017-09-10 17:25:29 +05:30
# Pipeline status badge
2016-09-13 17:45:13 +05:30
#
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
2017-09-10 17:25:29 +05:30
'pipeline'
2016-09-13 17:45:13 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2016-09-13 17:45:13 +05:30
def status
2019-02-15 15:39:39 +05:30
@project.ci_pipelines
2017-08-17 22:00:37 +05:30
.where(sha: @sha)
.latest_status(@ref) || 'unknown'
2016-09-13 17:45:13 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2016-09-13 17:45:13 +05:30
def metadata
2017-09-10 17:25:29 +05:30
@metadata ||= Pipeline::Metadata.new(self)
2016-09-13 17:45:13 +05:30
end
def template
2017-09-10 17:25:29 +05:30
@template ||= Pipeline::Template.new(self)
2016-09-13 17:45:13 +05:30
end
end
end
end
end