Skip to content

Commit bfc0aa0

Browse files
committed
feat: add metrics in packages api
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent e67136b commit bfc0aa0

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

backend/src/api/public/v1/packages/listPackages.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import type { Request, Response } from 'express'
22
import { z } from 'zod'
33

4-
import { getPackageStatusCounts, listPackagesForApi } from '@crowd/data-access-layer'
4+
import {
5+
computeHealthBand,
6+
getPackageStatusCounts,
7+
listPackagesForApi,
8+
} from '@crowd/data-access-layer'
59

610
import { getPackagesQx } from '@/db/packagesDb'
711
import { ok } from '@/utils/api'
@@ -84,9 +88,12 @@ export async function listPackages(req: Request, res: Response): Promise<void> {
8488
purl: r.purl,
8589
name: r.name,
8690
ecosystem: r.ecosystem,
87-
health: r.scorecardScore != null ? Math.round(Number(r.scorecardScore) * 10) : null,
91+
health: {
92+
score: r.scorecardScore != null ? Math.round(Number(r.scorecardScore) * 10) : null,
93+
label: r.healthLabel ?? computeHealthBand(r.scorecardScore),
94+
},
8895
impact: r.criticalityScore != null ? Math.round(Number(r.criticalityScore) * 100) : null,
89-
lifecycle: null,
96+
lifecycle: r.lifecycleLabel,
9097
maintainerBusFactor: r.maintainerCount,
9198
openVulns: r.openVulns,
9299
stewardshipId: r.stewardshipId ?? null,

backend/src/api/public/v1/packages/openapi.yaml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,20 @@ components:
180180
type: string
181181
example: npm
182182
health:
183-
type:
184-
- integer
185-
- 'null'
186-
example: 18
183+
type: object
184+
required: [score, label]
185+
properties:
186+
score:
187+
type:
188+
- integer
189+
- 'null'
190+
description: Health score (0–100) derived from OpenSSF Scorecard. Null if no repo is linked.
191+
example: 18
192+
label:
193+
type: string
194+
enum: [healthy, fair, concerning, critical]
195+
description: 'Derived from score: healthy ≥70, fair 50–69, concerning 30–49, critical <30 or null.'
196+
example: critical
187197
impact:
188198
type:
189199
- integer
@@ -814,7 +824,9 @@ paths:
814824
name: lodash
815825
ecosystem: npm
816826
lifecycle: declining
817-
health: 18
827+
health:
828+
score: 18
829+
label: critical
818830
impact: 71
819831
openVulns:
820832
low: 0

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ export interface PackageListRow {
135135
maxVulnSeverity: 'critical' | 'high' | 'medium' | 'low' | null
136136
maintainerCount: number
137137
scorecardScore: number | null
138+
healthLabel: string | null
138139
latestReleaseAt: Date | null
140+
lifecycleLabel: string | null
139141
lastActivityType?: string | null
140142
lastActivityContent?: string | null
141143
lastActivityMetadata?: Record<string, unknown> | null
@@ -551,7 +553,9 @@ export async function listPackagesForApi(
551553
END AS "maxVulnSeverity",
552554
pm_counts.cnt AS "maintainerCount",
553555
r_sc.scorecard_score AS "scorecardScore",
556+
p.health_label AS "healthLabel",
554557
p.latest_release_at AS "latestReleaseAt",
558+
p.lifecycle_label AS "lifecycleLabel",
555559
${opts.includeLastActivity === true ? `last_act.activity_type AS "lastActivityType", last_act.content AS "lastActivityContent", last_act.metadata AS "lastActivityMetadata", last_act.created_at AS "lastActivityAt",` : ''}
556560
${opts.includeStewards === true ? 'ss_agg.stewards AS stewards,' : ''}
557561
COUNT(*) OVER() AS total

0 commit comments

Comments
 (0)