2016-08-10 12:12:31 +00:00
|
|
|
module Gitlab
|
|
|
|
module Badge
|
|
|
|
module Coverage
|
|
|
|
##
|
|
|
|
# Test coverage report badge
|
|
|
|
#
|
|
|
|
class Report < Badge::Base
|
2016-08-11 10:38:03 +00:00
|
|
|
attr_reader :project, :ref, :job
|
|
|
|
|
2016-08-10 12:12:31 +00:00
|
|
|
def initialize(project, ref, job = nil)
|
|
|
|
@project = project
|
|
|
|
@ref = ref
|
|
|
|
@job = job
|
2016-08-11 10:38:03 +00:00
|
|
|
|
2016-08-26 07:40:12 +00:00
|
|
|
@pipeline = @project.pipelines.latest_successful_for(@ref)
|
2016-08-10 12:12:31 +00:00
|
|
|
end
|
|
|
|
|
2016-08-11 10:38:03 +00:00
|
|
|
def entity
|
|
|
|
'coverage'
|
|
|
|
end
|
|
|
|
|
|
|
|
def status
|
|
|
|
@coverage ||= raw_coverage
|
|
|
|
return unless @coverage
|
|
|
|
|
|
|
|
@coverage.to_i
|
|
|
|
end
|
|
|
|
|
2016-08-11 13:04:37 +00:00
|
|
|
def metadata
|
|
|
|
@metadata ||= Coverage::Metadata.new(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def template
|
|
|
|
@template ||= Coverage::Template.new(self)
|
|
|
|
end
|
|
|
|
|
2016-08-11 10:38:03 +00: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 12:12:31 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|