2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
module Gitlab
|
|
|
|
module Badge
|
|
|
|
module Coverage
|
|
|
|
##
|
|
|
|
# Test coverage report badge
|
|
|
|
#
|
|
|
|
class Report < Badge::Base
|
|
|
|
attr_reader :project, :ref, :job
|
|
|
|
|
|
|
|
def initialize(project, ref, job = nil)
|
|
|
|
@project = project
|
|
|
|
@ref = ref
|
|
|
|
@job = job
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
@pipeline = @project.pipelines.latest_successful_for(@ref)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def entity
|
|
|
|
'coverage'
|
|
|
|
end
|
|
|
|
|
|
|
|
def status
|
|
|
|
@coverage ||= raw_coverage
|
|
|
|
return unless @coverage
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
@coverage.to_f.round(2)
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def metadata
|
|
|
|
@metadata ||= Coverage::Metadata.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def template
|
|
|
|
@template ||= Coverage::Template.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2016-09-13 17:45:13 +05:30
|
|
|
def raw_coverage
|
|
|
|
return unless @pipeline
|
|
|
|
|
|
|
|
if @job.blank?
|
|
|
|
@pipeline.coverage
|
|
|
|
else
|
|
|
|
@pipeline.builds
|
|
|
|
.find_by(name: @job)
|
|
|
|
.try(:coverage)
|
|
|
|
end
|
|
|
|
end
|
2018-12-05 23:21:45 +05:30
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|