Skip to content

Commit d8debe4

Browse files
committed
fix: unmock stewardship
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 4832260 commit d8debe4

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

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

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

44
import { NotFoundError } from '@crowd/common'
5-
import { getAdvisoriesByPackageId, getPackageDetailByPurl } from '@crowd/data-access-layer'
5+
import {
6+
getAdvisoriesByPackageId,
7+
getPackageDetailByPurl,
8+
getStewardshipSummary,
9+
} from '@crowd/data-access-layer'
610

711
import { getPackagesQx } from '@/db/packagesDb'
812
import { ok } from '@/utils/api'
@@ -30,7 +34,10 @@ export async function getPackage(req: Request, res: Response): Promise<void> {
3034
throw new NotFoundError()
3135
}
3236

33-
const advisories = await getAdvisoriesByPackageId(qx, pkg.id)
37+
const [advisories, stewardshipSummary] = await Promise.all([
38+
getAdvisoriesByPackageId(qx, pkg.id),
39+
pkg.stewardshipId ? getStewardshipSummary(qx, pkg.stewardshipId) : null,
40+
])
3441

3542
ok(res, {
3643
purl: pkg.purl,
@@ -84,8 +91,8 @@ export async function getPackage(req: Request, res: Response): Promise<void> {
8491
},
8592
stewardship: {
8693
status: (pkg.stewardshipStatus ?? 'unassigned') as StewardshipStatus,
87-
stewards: null,
88-
lastActivityAt: null,
94+
stewards: stewardshipSummary?.stewards ?? null,
95+
lastActivityAt: stewardshipSummary?.lastActivityAt ?? null,
8996
},
9097
history: {},
9198
})

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ export interface PackageDetailRow {
273273
declaredRepositoryUrl: string | null
274274
repositoryUrl: string | null
275275
hasCriticalVulnerability: boolean
276+
stewardshipId: string | null
276277
stewardshipStatus: string | null
277278
stewardshipLastStatusAt: Date | null
278279
// from package_repos + repos
@@ -315,6 +316,7 @@ export async function getPackageDetailByPurl(
315316
p.declared_repository_url AS "declaredRepositoryUrl",
316317
p.repository_url AS "repositoryUrl",
317318
p.has_critical_vulnerability AS "hasCriticalVulnerability",
319+
s.id::text AS "stewardshipId",
318320
s.status AS "stewardshipStatus",
319321
s.last_status_at AS "stewardshipLastStatusAt",
320322
-- best repo link (highest confidence, prefer declared)

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,45 @@ export async function assignSteward(
225225
})
226226
}
227227

228+
export interface StewardshipSummary {
229+
stewards: StewardshipStewardRecord[]
230+
lastActivityAt: string | null
231+
}
232+
233+
export async function getStewardshipSummary(
234+
qx: QueryExecutor,
235+
stewardshipId: string,
236+
): Promise<StewardshipSummary> {
237+
const [stewards, activityRow] = await Promise.all([
238+
qx.select(
239+
`SELECT id, stewardship_id, user_id, role, assigned_at, assigned_by
240+
FROM stewardship_stewards
241+
WHERE stewardship_id = $(stewardshipId)
242+
AND deleted_at IS NULL
243+
ORDER BY assigned_at ASC`,
244+
{ stewardshipId },
245+
) as Promise<Array<Record<string, unknown>>>,
246+
qx.selectOneOrNone(
247+
`SELECT MAX(created_at) AS last_activity_at
248+
FROM stewardship_activity
249+
WHERE stewardship_id = $(stewardshipId)`,
250+
{ stewardshipId },
251+
) as Promise<Record<string, unknown> | null>,
252+
])
253+
254+
return {
255+
stewards: stewards.map((s) => ({
256+
id: String(s.id),
257+
stewardshipId: String(s.stewardship_id),
258+
userId: String(s.user_id),
259+
role: String(s.role),
260+
assignedAt: toIso(s.assigned_at),
261+
assignedBy: s.assigned_by ? String(s.assigned_by) : null,
262+
})),
263+
lastActivityAt: activityRow?.last_activity_at ? toIso(activityRow.last_activity_at) : null,
264+
}
265+
}
266+
228267
export const ESCALATION_RESOLUTION_PATHS = [
229268
'lf_staff_review',
230269
'community_outreach',

0 commit comments

Comments
 (0)