Commit 9b55c1fa authored by drew cimino's avatar drew cimino

Expand scope of coverage query

If job name is specified, allow for a successful execution of that
job to represent coverage even if it belongs to a failed pipeline.
If no job name is passed, we default back to the existing pipeline
coverage implementation.
parent 60e145b1
---
title: Expand scope of coverage badge query to all successful builds
merge_request: 45321
author:
type: changed
......@@ -44,19 +44,13 @@ module Gitlab
@pipeline ||= @project.ci_pipelines.latest_successful_for_ref(@ref)
end
# rubocop: disable CodeReuse/ActiveRecord
def raw_coverage
return unless pipeline
if @job.blank?
pipeline.coverage
if @job.present?
@project.builds.latest.success.for_ref(@ref).by_name(@job).order_id_desc.first&.coverage
else
pipeline.builds
.find_by(name: @job)
.try(:coverage)
@project.ci_pipelines.latest_successful_for_ref(@ref)&.coverage
end
end
# rubocop: enable CodeReuse/ActiveRecord
end
end
end
......
......@@ -45,8 +45,8 @@ RSpec.describe Gitlab::Badge::Coverage::Report do
context 'with no pipeline' do
let(:pipeline) { nil }
it 'returns nil' do
expect(badge.status).to be_nil
it 'returns coverage from that job' do
expect(badge.status).to eq(40)
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment