Skip to content

Commit 193a8d5

Browse files
authored
fix: translate keys (#4229)
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 77fcdcb commit 193a8d5

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
computeHealthBand,
66
getPackageStatusCounts,
77
listPackagesForApi,
8+
translateActivityContent,
89
} from '@crowd/data-access-layer'
910

1011
import { getPackagesQx } from '@/db/packagesDb'
@@ -79,7 +80,11 @@ export async function packageListHandler(req: Request, res: Response): Promise<v
7980
lastActivity: r.lastActivityAt
8081
? {
8182
type: r.lastActivityType,
82-
content: r.lastActivityContent,
83+
content: translateActivityContent(
84+
r.lastActivityContent ?? null,
85+
r.lastActivityType,
86+
r.lastActivityMetadata,
87+
),
8388
at: r.lastActivityAt.toISOString(),
8489
}
8590
: null,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export interface PackageListRow {
126126
latestReleaseAt: Date | null
127127
lastActivityType?: string | null
128128
lastActivityContent?: string | null
129+
lastActivityMetadata?: Record<string, unknown> | null
129130
lastActivityAt?: Date | null
130131
stewards?: StewardEntry[]
131132
total: string
@@ -470,7 +471,7 @@ export async function listPackagesForApi(
470471
opts.includeLastActivity === true
471472
? `
472473
LEFT JOIN LATERAL (
473-
SELECT sa.activity_type, sa.content, sa.created_at
474+
SELECT sa.activity_type, sa.content, sa.metadata, sa.created_at
474475
FROM stewardship_activity sa
475476
WHERE sa.stewardship_id = s.id
476477
ORDER BY sa.created_at DESC
@@ -502,7 +503,7 @@ export async function listPackagesForApi(
502503
pm_counts.cnt AS "maintainerCount",
503504
r_sc.scorecard_score AS "scorecardScore",
504505
p.latest_release_at AS "latestReleaseAt",
505-
${opts.includeLastActivity === true ? `last_act.activity_type AS "lastActivityType", last_act.content AS "lastActivityContent", last_act.created_at AS "lastActivityAt",` : ''}
506+
${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",` : ''}
506507
${opts.includeStewards === true ? "COALESCE(ss_agg.stewards, '[]'::json) AS stewards," : ''}
507508
COUNT(*) OVER() AS total
508509
FROM packages p

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,11 @@ export async function listStewardshipActivity(
383383
actorUserId: row.actorUserId,
384384
actorType: row.actorType,
385385
activityType: row.activityType,
386-
content: row.content,
386+
content: translateActivityContent(
387+
row.content,
388+
row.activityType,
389+
row.metadata as Record<string, unknown> | null,
390+
),
387391
metadata: row.metadata as Record<string, unknown> | null,
388392
stewardshipStatus: row.stewardshipStatus,
389393
createdAt: toIso(row.createdAt),
@@ -424,7 +428,11 @@ export async function listPackageHistory(
424428
actorUserId: r.actorUserId ? String(r.actorUserId) : null,
425429
actorType: String(r.actorType),
426430
activityType: String(r.activityType),
427-
content: r.content ? String(r.content) : null,
431+
content: translateActivityContent(
432+
r.content ? String(r.content) : null,
433+
String(r.activityType),
434+
r.metadata as Record<string, unknown> | null,
435+
),
428436
metadata: r.metadata as Record<string, unknown> | null,
429437
createdAt: toIso(r.createdAt),
430438
}))
@@ -441,6 +449,32 @@ export const ESCALATION_RESOLUTION_PATHS = [
441449

442450
export type EscalationResolutionPath = (typeof ESCALATION_RESOLUTION_PATHS)[number]
443451

452+
export const ESCALATION_RESOLUTION_PATH_LABELS: Record<EscalationResolutionPath, string> = {
453+
right_of_first_refusal: 'Right of First Refusal',
454+
replace_the_dependency: 'Replace the Dependency',
455+
find_vendor_for_lts: 'Find Vendor for LTS',
456+
consortium_adopts_maintainership: 'Consortium Adopts Maintainership',
457+
compensating_controls_monitor: 'Compensating Controls / Monitor',
458+
namespace_takeover: 'Namespace Takeover',
459+
}
460+
461+
export function translateActivityContent(
462+
content: string | null,
463+
activityType?: string | null,
464+
metadata?: Record<string, unknown> | null,
465+
): string | null {
466+
if (!content) return content
467+
if (activityType === 'escalation' && metadata?.resolutionPath) {
468+
const label =
469+
ESCALATION_RESOLUTION_PATH_LABELS[metadata.resolutionPath as EscalationResolutionPath]
470+
if (label) return `Escalated with resolution path: ${label}`
471+
}
472+
return content.replace(/^(Escalated with resolution path: )(\S+)$/, (_, prefix, key) => {
473+
const label = ESCALATION_RESOLUTION_PATH_LABELS[key as EscalationResolutionPath]
474+
return label ? `${prefix}${label}` : content
475+
})
476+
}
477+
444478
/**
445479
* Escalates a stewardship. Updates status to 'escalated' and logs the
446480
* chosen resolution path in stewardship_activity metadata.

0 commit comments

Comments
 (0)