feat: add metrics in packages api (CM-1285) - #4259
Conversation
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
There was a problem hiding this comment.
Pull request overview
This PR extends the public packages list API (GET /v1/packages) to expose already-computed package metrics: impact, lifecycle, and health (now shaped as { score, label }). It updates the DAL list query to select the additional columns and updates the OpenAPI schema/example accordingly.
Changes:
- Extend
listPackagesForApiSELECT +PackageListRowtyping to includepackages.health_labelandpackages.lifecycle_label. - Change list response
healthfrominteger | nullto{ score, label }, withlabelcoming from Tinybird-enrichedhealth_labelor falling back tocomputeHealthBand(scorecardScore). - Update OpenAPI
PackageListItem.healthschema and the batch-stewardship example.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
services/libs/data-access-layer/src/osspckgs/api.ts |
Adds healthLabel/lifecycleLabel fields to PackageListRow and selects p.health_label/p.lifecycle_label in listPackagesForApi. |
backend/src/api/public/v1/packages/listPackages.ts |
Reshapes health into { score, label } and returns lifecycle from the DB label. |
backend/src/api/public/v1/packages/openapi.yaml |
Updates PackageListItem.health to an object schema and adjusts an example payload. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6b4b120. Configure here.
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Comments suppressed due to low confidence (1)
services/libs/data-access-layer/src/osspckgs/api.ts:154
HealthBandnow includes'excellent', butbuildHealthBandConditioncan only build conditions for scorecard-derived bands. As written, passing'excellent'would fall through to the “critical” branch, which is incorrect and makes the helper’s contract unsafe now that the type includes'excellent'. Narrow the helper’sbandparameter to exclude'excellent'(or introduce a separate scorecard-only band type) so TypeScript prevents accidental misuse.
export type HealthBand = 'excellent' | 'healthy' | 'fair' | 'concerning' | 'critical'
export type VulnSeverityFilter = 'any' | 'high' | 'critical' | 'none'
export function computeHealthBand(scorecardScore: number | null): HealthBand {
if (scorecardScore === null || scorecardScore < 3.0) return 'critical'

Summary
Adds
impact,lifecycle, andhealth: { score, label }to the/v1/packageslist API response. These fields were already computed and stored in thepackagestable but not exposed in the list endpoint. No new JOINs or queries are added — it's a pure SELECT extension on an already-touched table.health.labeluses the Tinybird-enrichedhealth_labelwhen available, falling back tocomputeHealthBand(scorecardScore)— consistent with the detail endpoint behaviour.Changes
listPackages.ts—healthreshaped fromnumber | nullto{ score, label };lifecyclenow populated fromp.lifecycle_labelinstead of hardcodednull;health.labeluses Tinybird field with scorecard fallbackapi.ts(DAL) —PackageListRowinterface gainslifecycleLabelandhealthLabel;listPackagesForApiSELECT extended withp.lifecycle_labelandp.health_labelopenapi.yaml—PackageListItem.healthschema updated frominteger | nullto{ score, label }object; inline example updatedType of change
CM-1285
Note
Medium Risk
Breaking JSON shape for
/v1/packageslisthealth(integer → object) and OSSPREYhealthBand→health; clients must update. Filter semantics for lifecycle andexcellenthealth band change query results.Overview
Package list responses now surface Tinybird-enriched
health_score,health_label, andlifecycle_labelfrom thepackagestable (SELECT-only in the DAL), with OpenAPI aligned for both OSSPREY and/v1/packages.healthis no longer a bare integer or top-levelhealthBand: list rows return{ score, label }, preferring stored Tinybird values and falling back to Scorecard × 10 andcomputeHealthBand.impactis added as a 0–100 display field;lifecycleis populated when the label is in the allowed set (now includingarchived). DetailgetPackageapplies the same label validation forhealthBandandriskSignals.lifecycle.Query validation and filtering share
HEALTH_BAND_VALUES/LIFECYCLE_VALUES;healthBand=excellentfilters onp.health_label, and lifecycle filters onp.lifecycle_labelinstead of the previousp.status IS NOT NULLplaceholder.Reviewed by Cursor Bugbot for commit 3079df4. Bugbot is set up for automated code reviews on this repo. Configure here.