Skip to content

Commit 01f5fee

Browse files
committed
fix: review comments
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 689cf2a commit 01f5fee

7 files changed

Lines changed: 65 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export async function getPackage(req: Request, res: Response): Promise<void> {
9090
},
9191
},
9292
stewardship: {
93+
id: pkg.stewardshipId ?? null,
9394
status: (pkg.stewardshipStatus ?? 'unassigned') as StewardshipStatus,
9495
stewards: stewardshipSummary?.stewards ?? null,
9596
lastActivityAt: stewardshipSummary?.lastActivityAt ?? null,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export async function listPackages(req: Request, res: Response): Promise<void> {
8787
lifecycle: null,
8888
maintainerBusFactor: r.maintainerCount,
8989
openVulns: r.openVulns,
90+
stewardshipId: r.stewardshipId ?? null,
9091
stewardship: (r.stewardshipStatus ?? 'unassigned') as StewardshipStatus,
9192
stewards: null,
9293
}))

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ components:
194194
oneOf:
195195
- $ref: '#/components/schemas/OpenVulns'
196196
- type: 'null'
197+
stewardshipId:
198+
type:
199+
- string
200+
- 'null'
201+
description: Stewardship ID. Required to call mutation endpoints (assign/escalate/status). Null if no stewardship row exists.
202+
example: '42'
197203
stewardship:
198204
$ref: '#/components/schemas/StewardshipStatus'
199205
stewards:
@@ -420,6 +426,12 @@ components:
420426
type: object
421427
description: Stewardship state. In v1 always unassigned with no stewards or activity.
422428
properties:
429+
id:
430+
type:
431+
- string
432+
- 'null'
433+
description: Stewardship ID. Required to call mutation endpoints (assign/escalate/status).
434+
example: '42'
423435
status:
424436
$ref: '#/components/schemas/StewardshipStatus'
425437
stewards:

backend/src/api/public/v1/stewardships/assignSteward.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,20 @@ const paramsSchema = z.object({
1515
const bodySchema = z.object({
1616
userId: z.string().trim().min(1),
1717
role: z.enum(['lead', 'co_steward']),
18+
moveToAssessing: z.boolean().optional().default(false),
1819
})
1920

2021
export async function assignStewardHandler(req: Request, res: Response): Promise<void> {
2122
const { id } = validateOrThrow(paramsSchema, req.params)
22-
const { userId, role } = validateOrThrow(bodySchema, req.body)
23+
const { userId, role, moveToAssessing } = validateOrThrow(bodySchema, req.body)
2324

2425
const qx = await getPackagesQx()
25-
const result = await assignSteward(qx, id, { userId, role, assignedBy: req.actor.id })
26+
const result = await assignSteward(qx, id, {
27+
userId,
28+
role,
29+
assignedBy: req.actor.id,
30+
moveToAssessing,
31+
})
2632

2733
if (!result) {
2834
throw new NotFoundError(`Stewardship not found: ${id}`)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,17 @@ paths:
250250
role:
251251
type: string
252252
enum: [lead, co_steward]
253+
moveToAssessing:
254+
type: boolean
255+
default: false
256+
description: >
257+
If true, atomically transitions the stewardship status to `assessing`
258+
in the same transaction as the assignment. Use for the "Assign & move to
259+
Assessing" action to avoid a second round-trip.
253260
example:
254261
userId: abc123
255262
role: lead
263+
moveToAssessing: true
256264
responses:
257265
'200':
258266
description: Steward assigned.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface PackageListRow {
5454
name: string
5555
ecosystem: string
5656
criticalityScore: number | null
57+
stewardshipId: string | null
5758
stewardshipStatus: string | null
5859
openVulns: number
5960
maintainerCount: number
@@ -226,6 +227,7 @@ export async function listPackagesForApi(
226227
p.name,
227228
p.ecosystem,
228229
p.impact AS "criticalityScore",
230+
s.id::text AS "stewardshipId",
229231
s.status AS "stewardshipStatus",
230232
COALESCE(ap_counts.cnt, 0) AS "openVulns",
231233
pm_counts.cnt AS "maintainerCount",

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export async function openStewardshipByPurl(
180180
export async function assignSteward(
181181
qx: QueryExecutor,
182182
stewardshipId: number,
183-
data: { userId: string; role: 'lead' | 'co_steward'; assignedBy: string },
183+
data: { userId: string; role: 'lead' | 'co_steward'; assignedBy: string; moveToAssessing?: boolean },
184184
): Promise<{ stewardship: StewardshipRecord; stewards: StewardshipStewardRecord[] } | null> {
185185
return qx.tx(async (tx) => {
186186
const stewardship = await getStewardshipById(tx, stewardshipId)
@@ -213,6 +213,37 @@ export async function assignSteward(
213213
},
214214
)
215215

216+
let finalStewardship = stewardship
217+
218+
if (data.moveToAssessing) {
219+
const updated: Record<string, unknown> | null = await tx.selectOneOrNone(
220+
`
221+
WITH upd AS (
222+
UPDATE stewardships
223+
SET status = 'assessing',
224+
last_status_at = NOW(),
225+
resolution_path = NULL,
226+
status_note = NULL,
227+
updated_at = NOW()
228+
WHERE id = $(stewardshipId)
229+
AND status IN ('unassigned', 'open')
230+
RETURNING id, package_id, status, origin, version, opened_at,
231+
last_status_at, inactive_reason, resolution_path, status_note, created_at, updated_at
232+
),
233+
_log AS (
234+
INSERT INTO stewardship_activity
235+
(stewardship_id, actor_user_id, actor_type, activity_type, content, metadata)
236+
SELECT id, $(actorUserId), 'user', 'state_changed',
237+
'Status updated to assessing', $(metadata)::jsonb
238+
FROM upd
239+
)
240+
SELECT * FROM upd
241+
`,
242+
{ stewardshipId, actorUserId: data.assignedBy, metadata: JSON.stringify({ status: 'assessing' }) },
243+
)
244+
if (updated) finalStewardship = mapStewardshipRow(updated)
245+
}
246+
216247
const stewards: Array<Record<string, unknown>> = await tx.select(
217248
`SELECT id, stewardship_id, user_id, role, assigned_at, assigned_by
218249
FROM stewardship_stewards
@@ -223,7 +254,7 @@ export async function assignSteward(
223254
)
224255

225256
return {
226-
stewardship,
257+
stewardship: finalStewardship,
227258
stewards: stewards.map(mapStewardStewardRow),
228259
}
229260
})

0 commit comments

Comments
 (0)