gitlab-org--gitlab-foss/lib/gitlab/badge/coverage/report.rb
gfyoung e166e5747c Enable some frozen string in lib/gitlab
Enable frozen string for the following files:

* lib/gitlab/auth/**/*.rb
* lib/gitlab/badge/**/*.rb
* lib/gitlab/bare_repository_import/**/*.rb
* lib/gitlab/bitbucket_import/**/*.rb
* lib/gitlab/bitbucket_server_import/**/*.rb
* lib/gitlab/cache/**/*.rb
* lib/gitlab/checks/**/*.rb

Partially addresses #47424.
2018-10-13 02:31:31 -07:00

57 lines
1.1 KiB
Ruby

# frozen_string_literal: true
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
@pipeline = @project.pipelines.latest_successful_for(@ref)
end
def entity
'coverage'
end
def status
@coverage ||= raw_coverage
return unless @coverage
@coverage.to_f.round(2)
end
def metadata
@metadata ||= Coverage::Metadata.new(self)
end
def template
@template ||= Coverage::Template.new(self)
end
private
# rubocop: disable CodeReuse/ActiveRecord
def raw_coverage
return unless @pipeline
if @job.blank?
@pipeline.coverage
else
@pipeline.builds
.find_by(name: @job)
.try(:coverage)
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
end