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 ...@@ -44,19 +44,13 @@ module Gitlab
@pipeline ||= @project.ci_pipelines.latest_successful_for_ref(@ref) @pipeline ||= @project.ci_pipelines.latest_successful_for_ref(@ref)
end end
# rubocop: disable CodeReuse/ActiveRecord
def raw_coverage def raw_coverage
return unless pipeline if @job.present?
@project.builds.latest.success.for_ref(@ref).by_name(@job).order_id_desc.first&.coverage
if @job.blank?
pipeline.coverage
else else
pipeline.builds @project.ci_pipelines.latest_successful_for_ref(@ref)&.coverage
.find_by(name: @job)
.try(:coverage)
end end
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
end end
end end
......
...@@ -45,8 +45,8 @@ RSpec.describe Gitlab::Badge::Coverage::Report do ...@@ -45,8 +45,8 @@ RSpec.describe Gitlab::Badge::Coverage::Report do
context 'with no pipeline' do context 'with no pipeline' do
let(:pipeline) { nil } let(:pipeline) { nil }
it 'returns nil' do it 'returns coverage from that job' do
expect(badge.status).to be_nil expect(badge.status).to eq(40)
end end
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