2018-10-11 20:12:21 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-01-27 03:08:58 +00:00
|
|
|
module Gitlab::Ci
|
2016-08-10 12:12:31 +00:00
|
|
|
module Badge
|
2017-07-19 11:08:47 +00:00
|
|
|
module Pipeline
|
2016-08-10 12:12:31 +00:00
|
|
|
##
|
2017-07-19 11:08:47 +00:00
|
|
|
# Pipeline status badge
|
2016-08-10 12:12:31 +00:00
|
|
|
#
|
|
|
|
class Status < Badge::Base
|
2020-05-29 21:08:35 +00:00
|
|
|
attr_reader :project, :ref, :customization
|
2016-08-10 12:12:31 +00:00
|
|
|
|
2020-05-29 21:08:35 +00:00
|
|
|
def initialize(project, ref, opts: {})
|
2016-08-10 12:12:31 +00:00
|
|
|
@project = project
|
|
|
|
@ref = ref
|
2020-08-24 12:10:17 +00:00
|
|
|
@ignore_skipped = Gitlab::Utils.to_boolean(opts[:ignore_skipped], default: false)
|
2020-05-29 21:08:35 +00:00
|
|
|
@customization = {
|
|
|
|
key_width: opts[:key_width].to_i,
|
|
|
|
key_text: opts[:key_text]
|
|
|
|
}
|
2016-08-11 09:16:14 +00:00
|
|
|
|
2016-08-10 12:12:31 +00:00
|
|
|
@sha = @project.commit(@ref).try(:sha)
|
|
|
|
end
|
|
|
|
|
2016-08-11 09:16:14 +00:00
|
|
|
def entity
|
2017-07-19 11:08:47 +00:00
|
|
|
'pipeline'
|
2016-08-11 09:16:14 +00:00
|
|
|
end
|
|
|
|
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-08-10 12:12:31 +00:00
|
|
|
def status
|
2020-08-24 12:10:17 +00:00
|
|
|
pipelines = @project.ci_pipelines
|
2016-11-24 09:00:37 +00:00
|
|
|
.where(sha: @sha)
|
2020-08-24 12:10:17 +00:00
|
|
|
|
|
|
|
relation = @ignore_skipped ? pipelines.without_statuses([:skipped]) : pipelines
|
|
|
|
relation.latest_status(@ref) || 'unknown'
|
2016-08-10 12:12:31 +00:00
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-08-10 12:12:31 +00:00
|
|
|
|
|
|
|
def metadata
|
2017-07-19 11:08:47 +00:00
|
|
|
@metadata ||= Pipeline::Metadata.new(self)
|
2016-08-10 12:12:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def template
|
2017-07-19 11:08:47 +00:00
|
|
|
@template ||= Pipeline::Template.new(self)
|
2016-08-10 12:12:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|