Sort dependencies by license
-
Review changes -
-
Download -
Patches
-
Plain diff
What does this MR do and why?
This change is gated by the group_level_licenses
feature flag. This change adds an option to sort dependencies, on the group dependency list, by SPDX identifier. The sbom_occurrences.licenses
column is a jsonb
column with a schema that resembles the following:
[
{
"url": "https://spdx.org/licenses/Apache-2.0.html",
"name": "Apache 2.0",
"spdx_identifier": "Apache-2.0"
},
{
"url": "https://spdx.org/licenses/Artistic-2.0.html",
"name": "Artistic-2.0",
"spdx_identifier": "Artistic-2.0"
},
{
"url": "https://spdx.org/licenses/BSD-3-Clause.html",
"name": "New BSD",
"spdx_identifier": "BSD-3-Clause"
},
{
"url": "https://spdx.org/licenses/GPL-3.0.html",
"name": "GPLv3",
"spdx_identifier": "GPL-3.0"
}
]
The change in this MR attempts to add support for sorting Sbom::Occurence
records by licenses. The # of elements in the sbom_occurrences.licenses
column can be between 0-N with no upper bound at this time.
The change in this MR attempts to sort records by the first detected license then by the second detected license.
Related to:
- Add `&sort_by=license` query string parameter t... (#422086 - closed) • mo khan • 16.4 • At risk
- Add sort-by-license to group-level dependencies... (!130280 - merged) • David Pisek • 16.4
Sort by licenses ascending:
SELECT
sbom_occurrences.*,
agg_occurrences.occurrence_count,
agg_occurrences.project_count
FROM
sbom_occurrences
INNER JOIN (
SELECT
component_id,
COUNT(DISTINCT id) AS occurrence_count,
COUNT(DISTINCT project_id) AS project_count
FROM
sbom_occurrences
WHERE
project_id IN (
SELECT
"projects"."id"
FROM
"projects"
WHERE
"projects"."namespace_id" IN (
SELECT
namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)] AS id
FROM
"namespaces"
WHERE
"namespaces"."type" = 'Group'
AND (traversal_ids @> ('{9970}'))))
GROUP BY
component_id) agg_occurrences ON sbom_occurrences.component_id = agg_occurrences.component_id
WHERE
"sbom_occurrences"."project_id" IN (
SELECT
"projects"."id"
FROM
"projects"
WHERE
"projects"."namespace_id" IN (
SELECT
namespaces.traversal_ids[array_length(namespaces.traversal_ids, 1)] AS id
FROM
"namespaces"
WHERE
"namespaces"."type" = 'Group'
AND (traversal_ids @> ('{9970}'))))
ORDER BY
licenses #> '{0,spdx_identifier}' ASC,
licenses #> '{1,spdx_identifier}' ASC
LIMIT 20 OFFSET 0
https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/21933/commands/71064
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Merge request reports
- version 303482582f
- version 290c0f3a7d
- version 283dcde825
- version 274d1dee87
- version 264d1dee87
- version 25cdf5461b
- version 246fa2c925
- version 23ba978aba
- version 22efb49be0
- version 216212f734
- version 201759ec4a
- version 196ccd6331
- version 183df06f05
- version 175ac0b32d
- version 16742a57e8
- version 1514384604
- version 14df4fb429
- version 1376f4ca58
- version 12e0129d84
- version 112ca8cddc
- version 1058808906
- version 97a9db081
- version 8f85a10a0
- version 79a8ae9e0
- version 69dd16f76
- version 59e7148d5
- version 4d2c12e1e
- version 3d6e93d37
- version 247ba7c80
- version 1a9da6201
- master (base)
- latest version66f402cd32 commits,
- version 303482582f31 commits,
- version 290c0f3a7d30 commits,
- version 283dcde82529 commits,
- version 274d1dee8729 commits,
- version 264d1dee8729 commits,
- version 25cdf5461b28 commits,
- version 246fa2c92527 commits,
- version 23ba978aba26 commits,
- version 22efb49be025 commits,
- version 216212f73425 commits,
- version 201759ec4a25 commits,
- version 196ccd633124 commits,
- version 183df06f0523 commits,
- version 175ac0b32d21 commits,
- version 16742a57e820 commits,
- version 151438460419 commits,
- version 14df4fb42918 commits,
- version 1376f4ca5817 commits,
- version 12e0129d8416 commits,
- version 112ca8cddc15 commits,
- version 105880890614 commits,
- version 97a9db08112 commits,
- version 8f85a10a011 commits,
- version 79a8ae9e010 commits,
- version 69dd16f769 commits,
- version 59e7148d58 commits,
- version 4d2c12e1e7 commits,
- version 3d6e93d376 commits,
- version 247ba7c805 commits,
- version 1a9da62014 commits,
- Side-by-side
- Inline
There are no changes yet
No changes between version 11 and version 11