0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/util/vulnerability/utils.ts
2023-11-07 15:50:29 +00:00

29 lines
723 B
TypeScript

const severityOrder: Record<string, number> = {
LOW: 1,
MEDIUM: 2,
MODERATE: 2,
HIGH: 3,
CRITICAL: 4,
UNKNOWN: 5,
};
export function getHighestVulnerabilitySeverity<
T extends Record<string, any>,
TChild extends Record<string, any> | undefined,
>(parent: T, child: TChild): string {
const parentVulSeverity = parent.vulnerabilitySeverity?.toUpperCase();
const childVulSeverity = child?.vulnerabilitySeverity?.toUpperCase();
if (childVulSeverity === undefined) {
return parentVulSeverity;
}
if (parentVulSeverity === undefined) {
return childVulSeverity;
}
return severityOrder[parentVulSeverity] >= severityOrder[childVulSeverity]
? parentVulSeverity
: childVulSeverity;
}