Skip to content

Commit b0599e8

Browse files
authored
feat: add ecosystem filter (CM-1236) (#4237)
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent ee124fc commit b0599e8

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

backend/src/api/public/v1/ossprey/packageScatter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ function normalizeToArray(v: unknown): unknown[] | undefined {
2424

2525
const scatterQuerySchema = z.object({
2626
status: z.preprocess(normalizeToArray, z.array(statusEnum).min(1)).optional(),
27+
ecosystem: z.string().min(1).optional(),
2728
})
2829

2930
export async function packageScatterHandler(req: Request, res: Response): Promise<void> {
30-
const { status } = validateOrThrow(scatterQuerySchema, req.query)
31+
const { status, ecosystem } = validateOrThrow(scatterQuerySchema, req.query)
3132
const qx = await getPackagesQx()
32-
const points = await listPackagesForScatter(qx, { status })
33+
const points = await listPackagesForScatter(qx, { status, ecosystem })
3334
ok(res, { points, total: points.length })
3435
}

services/libs/data-access-layer/src/osspckgs/api.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,9 @@ export interface ScatterPoint {
667667

668668
export async function listPackagesForScatter(
669669
qx: QueryExecutor,
670-
options: { status?: string[] } = {},
670+
options: { status?: string[]; ecosystem?: string } = {},
671671
): Promise<ScatterPoint[]> {
672-
const { status } = options
672+
const { status, ecosystem } = options
673673

674674
// 'unassigned' covers packages with no stewardship row (s.id IS NULL) in addition
675675
// to rows explicitly marked unassigned. All other statuses filter via s.status = ANY(...).
@@ -678,6 +678,7 @@ export async function listPackagesForScatter(
678678
const statusFilter = status?.length
679679
? `AND (s.status = ANY($(status)::text[])${includesUnassigned ? ' OR s.id IS NULL' : ''})`
680680
: ''
681+
const ecosystemFilter = ecosystem ? `AND p.ecosystem = $(ecosystem)` : ''
681682

682683
const rows: Array<{
683684
purl: string
@@ -714,10 +715,11 @@ export async function listPackagesForScatter(
714715
) r_sc ON true
715716
WHERE p.is_critical = true
716717
${statusFilter}
718+
${ecosystemFilter}
717719
ORDER BY p.impact DESC NULLS LAST, p.purl ASC
718720
LIMIT 2000
719721
`,
720-
{ status },
722+
{ status, ecosystem },
721723
)
722724

723725
return rows.map((r) => ({

0 commit comments

Comments
 (0)