Skip to content

Commit 50e455f

Browse files
committed
fix: translate keys for frontend
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent 8fe8ad0 commit 50e455f

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

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

Lines changed: 2 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,7 @@ 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(r.lastActivityContent ?? null, r.lastActivityType, r.lastActivityMetadata),
8384
at: r.lastActivityAt.toISOString(),
8485
}
8586
: 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: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ export async function listStewardshipActivity(
383383
actorUserId: row.actorUserId,
384384
actorType: row.actorType,
385385
activityType: row.activityType,
386-
content: translateActivityContent(row.content),
386+
content: translateActivityContent(row.content, row.activityType, row.metadata as Record<string, unknown> | null),
387387
metadata: row.metadata as Record<string, unknown> | null,
388388
stewardshipStatus: row.stewardshipStatus,
389389
createdAt: toIso(row.createdAt),
@@ -424,7 +424,7 @@ export async function listPackageHistory(
424424
actorUserId: r.actorUserId ? String(r.actorUserId) : null,
425425
actorType: String(r.actorType),
426426
activityType: String(r.activityType),
427-
content: translateActivityContent(r.content ? String(r.content) : null),
427+
content: translateActivityContent(r.content ? String(r.content) : null, String(r.activityType), r.metadata as Record<string, unknown> | null),
428428
metadata: r.metadata as Record<string, unknown> | null,
429429
createdAt: toIso(r.createdAt),
430430
}))
@@ -450,8 +450,16 @@ export const ESCALATION_RESOLUTION_PATH_LABELS: Record<EscalationResolutionPath,
450450
namespace_takeover: 'Namespace Takeover',
451451
}
452452

453-
function translateActivityContent(content: string | null): string | null {
453+
export function translateActivityContent(
454+
content: string | null,
455+
activityType?: string | null,
456+
metadata?: Record<string, unknown> | null,
457+
): string | null {
454458
if (!content) return content
459+
if (activityType === 'escalation' && metadata?.resolutionPath) {
460+
const label = ESCALATION_RESOLUTION_PATH_LABELS[metadata.resolutionPath as EscalationResolutionPath]
461+
if (label) return `Escalated with resolution path: ${label}`
462+
}
455463
return content.replace(/^(Escalated with resolution path: )(\S+)$/, (_, prefix, key) => {
456464
const label = ESCALATION_RESOLUTION_PATH_LABELS[key as EscalationResolutionPath]
457465
return label ? `${prefix}${label}` : content

0 commit comments

Comments
 (0)