2016-08-10 08:12:31 -04:00
|
|
|
module Gitlab
|
|
|
|
module Badge
|
|
|
|
module Coverage
|
|
|
|
##
|
|
|
|
# Test coverage report badge
|
|
|
|
#
|
|
|
|
class Report < Badge::Base
|
2016-08-11 06:38:03 -04:00
|
|
|
attr_reader :project, :ref, :job
|
|
|
|
|
2016-08-10 08:12:31 -04:00
|
|
|
def initialize(project, ref, job = nil)
|
|
|
|
@project = project
|
|
|
|
@ref = ref
|
|
|
|
@job = job
|
2016-08-11 06:38:03 -04:00
|
|
|
|
2016-08-26 03:40:12 -04:00
|
|
|
@pipeline = @project.pipelines.latest_successful_for(@ref)
|
2016-08-10 08:12:31 -04:00
|
|
|
end
|
|
|
|
|
2016-08-11 06:38:03 -04:00
|
|
|
def entity
|
|
|
|
'coverage'
|
|
|
|
end
|
|
|
|
|
|
|
|
def status
|
|
|
|
@coverage ||= raw_coverage
|
|
|
|
return unless @coverage
|
|
|
|
|
2017-03-20 09:34:47 -04:00
|
|
|
@coverage.to_f.round(2)
|
2016-08-11 06:38:03 -04:00
|
|
|
end
|
|
|
|
|
2016-08-11 09:04:37 -04:00
|
|
|
def metadata
|
|
|
|
@metadata ||= Coverage::Metadata.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def template
|
|
|
|
@template ||= Coverage::Template.new(self)
|
|
|
|
end
|
|
|
|
|
2016-08-11 06:38:03 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def raw_coverage
|
|
|
|
return unless @pipeline
|
|
|
|
|
|
|
|
if @job.blank?
|
|
|
|
@pipeline.coverage
|
|
|
|
else
|
|
|
|
@pipeline.builds
|
|
|
|
.find_by(name: @job)
|
|
|
|
.try(:coverage)
|
|
|
|
end
|
2016-08-10 08:12:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|