Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion backend/src/api/public/v1/ossprey/packageList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
computeHealthBand,
getPackageStatusCounts,
listPackagesForApi,
translateActivityContent,
} from '@crowd/data-access-layer'

import { getPackagesQx } from '@/db/packagesDb'
Expand Down Expand Up @@ -79,7 +80,11 @@ export async function packageListHandler(req: Request, res: Response): Promise<v
lastActivity: r.lastActivityAt
? {
type: r.lastActivityType,
content: r.lastActivityContent,
content: translateActivityContent(
r.lastActivityContent ?? null,
r.lastActivityType,
r.lastActivityMetadata,
),
at: r.lastActivityAt.toISOString(),
}
: null,
Expand Down
5 changes: 3 additions & 2 deletions services/libs/data-access-layer/src/osspckgs/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export interface PackageListRow {
latestReleaseAt: Date | null
lastActivityType?: string | null
lastActivityContent?: string | null
lastActivityMetadata?: Record<string, unknown> | null
lastActivityAt?: Date | null
stewards?: StewardEntry[]
total: string
Expand Down Expand Up @@ -470,7 +471,7 @@ export async function listPackagesForApi(
opts.includeLastActivity === true
? `
LEFT JOIN LATERAL (
SELECT sa.activity_type, sa.content, sa.created_at
SELECT sa.activity_type, sa.content, sa.metadata, sa.created_at
FROM stewardship_activity sa
WHERE sa.stewardship_id = s.id
ORDER BY sa.created_at DESC
Expand Down Expand Up @@ -502,7 +503,7 @@ export async function listPackagesForApi(
pm_counts.cnt AS "maintainerCount",
r_sc.scorecard_score AS "scorecardScore",
p.latest_release_at AS "latestReleaseAt",
${opts.includeLastActivity === true ? `last_act.activity_type AS "lastActivityType", last_act.content AS "lastActivityContent", last_act.created_at AS "lastActivityAt",` : ''}
${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",` : ''}
${opts.includeStewards === true ? "COALESCE(ss_agg.stewards, '[]'::json) AS stewards," : ''}
COUNT(*) OVER() AS total
FROM packages p
Expand Down
38 changes: 36 additions & 2 deletions services/libs/data-access-layer/src/osspckgs/stewardships.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,11 @@ export async function listStewardshipActivity(
actorUserId: row.actorUserId,
actorType: row.actorType,
activityType: row.activityType,
content: row.content,
content: translateActivityContent(
row.content,
row.activityType,
row.metadata as Record<string, unknown> | null,
),
metadata: row.metadata as Record<string, unknown> | null,
stewardshipStatus: row.stewardshipStatus,
createdAt: toIso(row.createdAt),
Expand Down Expand Up @@ -424,7 +428,11 @@ export async function listPackageHistory(
actorUserId: r.actorUserId ? String(r.actorUserId) : null,
actorType: String(r.actorType),
activityType: String(r.activityType),
content: r.content ? String(r.content) : null,
content: translateActivityContent(
r.content ? String(r.content) : null,
String(r.activityType),
r.metadata as Record<string, unknown> | null,
),
metadata: r.metadata as Record<string, unknown> | null,
createdAt: toIso(r.createdAt),
}))
Expand All @@ -441,6 +449,32 @@ export const ESCALATION_RESOLUTION_PATHS = [

export type EscalationResolutionPath = (typeof ESCALATION_RESOLUTION_PATHS)[number]

export const ESCALATION_RESOLUTION_PATH_LABELS: Record<EscalationResolutionPath, string> = {
right_of_first_refusal: 'Right of First Refusal',
replace_the_dependency: 'Replace the Dependency',
find_vendor_for_lts: 'Find Vendor for LTS',
consortium_adopts_maintainership: 'Consortium Adopts Maintainership',
compensating_controls_monitor: 'Compensating Controls / Monitor',
namespace_takeover: 'Namespace Takeover',
}

export function translateActivityContent(
content: string | null,
activityType?: string | null,
metadata?: Record<string, unknown> | null,
): string | null {
Comment thread
ulemons marked this conversation as resolved.
if (!content) return content
if (activityType === 'escalation' && metadata?.resolutionPath) {
const label =
ESCALATION_RESOLUTION_PATH_LABELS[metadata.resolutionPath as EscalationResolutionPath]
if (label) return `Escalated with resolution path: ${label}`
}
Comment thread
ulemons marked this conversation as resolved.
return content.replace(/^(Escalated with resolution path: )(\S+)$/, (_, prefix, key) => {
const label = ESCALATION_RESOLUTION_PATH_LABELS[key as EscalationResolutionPath]
return label ? `${prefix}${label}` : content
})
Comment thread
ulemons marked this conversation as resolved.
}

/**
* Escalates a stewardship. Updates status to 'escalated' and logs the
* chosen resolution path in stewardship_activity metadata.
Expand Down
Loading