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

46 lines
990 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
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-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
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