Commit 8374665e authored by Stan Hu's avatar Stan Hu

Merge branch '208723-load-licenses-sooner' into 'master'

Load license scan data as soon as it is available

See merge request gitlab-org/gitlab!44194
parents 3ac2ec5c 473553fc
...@@ -165,6 +165,10 @@ module EE ...@@ -165,6 +165,10 @@ module EE
.select(&:failed?) .select(&:failed?)
end end
def license_scan_completed?
builds.latest.with_reports(::Ci::JobArtifact.license_scanning_reports).exists?
end
private private
def project_has_subscriptions? def project_has_subscriptions?
......
...@@ -223,7 +223,7 @@ module EE ...@@ -223,7 +223,7 @@ module EE
end end
def compare_license_scanning_reports(current_user) def compare_license_scanning_reports(current_user)
return missing_report_error("license scanning") unless has_license_scanning_reports? return missing_report_error("license scanning") unless actual_head_pipeline&.license_scan_completed?
compare_reports(::Ci::CompareLicenseScanningReportsService, current_user) compare_reports(::Ci::CompareLicenseScanningReportsService, current_user)
end end
......
---
title: Load license scan data as soon as it is available
merge_request: 44194
author:
type: fixed
...@@ -512,4 +512,36 @@ RSpec.describe Ci::Pipeline do ...@@ -512,4 +512,36 @@ RSpec.describe Ci::Pipeline do
it { is_expected.to match_array(expected_builds) } it { is_expected.to match_array(expected_builds) }
end end
describe "#license_scan_completed?" do
where(:pipeline_status, :build_types, :expected_status) do
[
[:blocked, [:container_scanning], false],
[:blocked, [:license_scan_v2_1, :container_scanning], true],
[:blocked, [:license_scan_v2_1], true],
[:blocked, [], false],
[:failed, [:container_scanning], false],
[:failed, [:license_scan_v2_1, :container_scanning], true],
[:failed, [:license_scan_v2_1], true],
[:failed, [], false],
[:running, [:container_scanning], false],
[:running, [:license_scan_v2_1, :container_scanning], true],
[:running, [:license_scan_v2_1], true],
[:running, [], false],
[:success, [:container_scanning], false],
[:success, [:license_scan_v2_1, :container_scanning], true],
[:success, [:license_scan_v2_1], true],
[:success, [], false]
]
end
with_them do
subject { pipeline.license_scan_completed? }
let(:pipeline) { create(:ci_pipeline, pipeline_status, builds: builds) }
let(:builds) { build_types.map { |build_type| create(:ee_ci_build, build_type) } }
specify { expect(subject).to eq(expected_status) }
end
end
end end
...@@ -728,6 +728,40 @@ RSpec.describe MergeRequest do ...@@ -728,6 +728,40 @@ RSpec.describe MergeRequest do
expect(subject[:status_reason]).to eq('This merge request does not have license scanning reports') expect(subject[:status_reason]).to eq('This merge request does not have license scanning reports')
end end
end end
context "when a license scan report is produced from the head pipeline" do
where(:pipeline_status, :build_types, :expected_status) do
[
[:blocked, [:license_scan_v2_1], :parsed],
[:blocked, [:container_scanning], :error],
[:blocked, [:license_scan_v2_1, :container_scanning], :parsed],
[:blocked, [], :error],
[:failed, [:container_scanning], :error],
[:failed, [:license_scan_v2_1], :parsed],
[:failed, [:license_scan_v2_1, :container_scanning], :parsed],
[:failed, [], :error],
[:running, [:container_scanning], :error],
[:running, [:license_scan_v2_1], :parsed],
[:running, [:license_scan_v2_1, :container_scanning], :parsed],
[:running, [], :error],
[:success, [:container_scanning], :error],
[:success, [:license_scan_v2_1], :parsed],
[:success, [:license_scan_v2_1, :container_scanning], :parsed],
[:success, [], :error]
]
end
with_them do
let!(:head_pipeline) { create(:ci_pipeline, pipeline_status, project: project, ref: merge_request.source_branch, sha: merge_request.diff_head_sha, builds: builds) }
let(:builds) { build_types.map { |build_type| create(:ee_ci_build, build_type) } }
before do
synchronous_reactive_cache(merge_request)
end
specify { expect(subject[:status]).to eq(expected_status) }
end
end
end end
describe '#compare_metrics_reports' do describe '#compare_metrics_reports' do
......
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