Skip to content
Snippets Groups Projects
Commit 2b9013ee authored by Mehmet Emin Inaç's avatar Mehmet Emin Inaç
Browse files

Merge branch 'bwill/fix-missing-counts-on-group-sbom-occurrences' into 'master'

Fix broken dependency list aggregation

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/139014



Merged-by: default avatarMehmet Emin INAC <minac@gitlab.com>
Approved-by: default avatarmo khan <mo@mokhan.ca>
Approved-by: default avatarMehmet Emin INAC <minac@gitlab.com>
Reviewed-by: default avatarmo khan <mo@mokhan.ca>
Co-authored-by: default avatarBrian Williams <bwilliams@gitlab.com>
parents a0ea0ea4 49ff243a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -891,9 +891,12 @@ def sbom_occurrences(with_totals: true)
.order(component_version_id: :desc, project_count: :desc, id: :desc)
)
 
select_values = Sbom::Occurrence.column_names + %w[occurrence_count project_count]
Sbom::Occurrence
.with(our_occurrences.to_arel)
.from(our_occurrences.alias_to(Sbom::Occurrence.arel_table))
.select(*select_values)
end
 
def sbom_licenses(limit:)
Loading
Loading
Loading
Loading
@@ -3191,7 +3191,9 @@ def webhook_headers
end
 
describe '#sbom_occurrences' do
subject { group.sbom_occurrences(with_totals: true) }
let(:with_totals) { true }
subject { group.sbom_occurrences(with_totals: with_totals) }
 
it { is_expected.to be_empty }
 
Loading
Loading
@@ -3204,9 +3206,23 @@ def webhook_headers
let!(:sbom_occurrence) { create(:sbom_occurrence, project: project) }
 
it 'returns occurrences with aggregated ids' do
expect(subject).to eq([sbom_occurrence])
expect(subject.pluck(:project_count)).to eq([1])
expect(subject.pluck(:occurrence_count)).to eq([1])
occurrence = subject.first
expect(occurrence).to eq(sbom_occurrence)
expect(occurrence.project_count).to eq(1)
expect(occurrence.occurrence_count).to eq(1)
end
context 'without totals' do
let(:with_totals) { false }
it 'does not have counts' do
occurrence = subject.first
expect(occurrence).to eq(sbom_occurrence)
expect(occurrence).not_to respond_to(:project_count)
expect(occurrence).not_to respond_to(:occurrence_count)
end
end
end
end
Loading
Loading
@@ -3230,14 +3246,14 @@ def webhook_headers
let_it_be(:another_webpack_npm_project) { create(:sbom_occurrence, :npm, project: npm_project, component: webpack, component_version: webpack_v4) }
 
it 'returns the project count for each component' do
expect(subject.pluck(:component_name, :component_version_id, :project_count)).to match_array([
[webpack.name, webpack_v4.id, 3]
expect(subject).to match_array([
an_object_having_attributes(component_name: webpack.name, component_version_id: webpack_v4.id, project_count: 3)
])
end
 
it 'returns the occurrence count for each component' do
expect(subject.pluck(:component_name, :component_version_id, :occurrence_count)).to match_array([
[webpack.name, webpack_v4.id, 5]
expect(subject).to match_array([
an_object_having_attributes(component_name: webpack.name, component_version_id: webpack_v4.id, occurrence_count: 5)
])
end
end
Loading
Loading
@@ -3278,20 +3294,20 @@ def webhook_headers
end
 
it 'returns the project count for each component' do
expect(subject.pluck(:component_name, :component_version_id, :project_count)).to match_array([
[bundler.name, bundler_v1.id, 2],
[bundler.name, bundler_v2.id, 1],
[caddy.name, caddy_v1.id, 1],
[webpack.name, webpack_v4.id, 1]
expect(subject).to match_array([
an_object_having_attributes(component_name: bundler.name, component_version_id: bundler_v1.id, project_count: 2),
an_object_having_attributes(component_name: bundler.name, component_version_id: bundler_v2.id, project_count: 1),
an_object_having_attributes(component_name: caddy.name, component_version_id: caddy_v1.id, project_count: 1),
an_object_having_attributes(component_name: webpack.name, component_version_id: webpack_v4.id, project_count: 1)
])
end
 
it 'returns the occurrence count for each component' do
expect(subject.pluck(:component_name, :component_version_id, :occurrence_count)).to match_array([
[bundler.name, bundler_v1.id, 3],
[bundler.name, bundler_v2.id, 1],
[caddy.name, caddy_v1.id, 1],
[webpack.name, webpack_v4.id, 1]
expect(subject).to match_array([
an_object_having_attributes(component_name: bundler.name, component_version_id: bundler_v1.id, occurrence_count: 3),
an_object_having_attributes(component_name: bundler.name, component_version_id: bundler_v2.id, occurrence_count: 1),
an_object_having_attributes(component_name: caddy.name, component_version_id: caddy_v1.id, occurrence_count: 1),
an_object_having_attributes(component_name: webpack.name, component_version_id: webpack_v4.id, occurrence_count: 1)
])
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment