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

49 lines
1.2 KiB
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
2020-06-23 00:09:42 +05:30
attr_reader :project, :ref, :customization
2016-09-13 17:45:13 +05:30
2020-06-23 00:09:42 +05:30
def initialize(project, ref, opts: {})
2016-09-13 17:45:13 +05:30
@project = project
@ref = ref
2020-11-24 15:15:51 +05:30
@ignore_skipped = Gitlab::Utils.to_boolean(opts[:ignore_skipped], default: false)
2020-06-23 00:09:42 +05:30
@customization = {
key_width: opts[:key_width].to_i,
key_text: opts[:key_text]
}
2016-09-13 17:45:13 +05:30
@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
2020-11-24 15:15:51 +05:30
pipelines = @project.ci_pipelines
2017-08-17 22:00:37 +05:30
.where(sha: @sha)
2020-11-24 15:15:51 +05:30
relation = @ignore_skipped ? pipelines.without_statuses([:skipped]) : pipelines
relation.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