diff --git a/src/shared/pr-check-severity-order.ts b/src/shared/pr-check-severity-order.ts index db0230d37dd..b6a430586e2 100644 --- a/src/shared/pr-check-severity-order.ts +++ b/src/shared/pr-check-severity-order.ts @@ -25,12 +25,11 @@ export function getCheckSeverityRank(conclusion: string | null | undefined): num export function sortChecksBySeverity>( checks: readonly T[] ): T[] { + if (checks.length < 2) { + return checks.slice() + } return checks - .map((check, index) => ({ check, index })) - .sort( - (a, b) => - getCheckSeverityRank(a.check.conclusion) - getCheckSeverityRank(b.check.conclusion) || - a.index - b.index - ) + .map((check, index) => ({ check, index, rank: getCheckSeverityRank(check.conclusion) })) + .sort((a, b) => a.rank - b.rank || a.index - b.index) .map(({ check }) => check) }