Skip to content

Commit 03c1a76

Browse files
akash3444juliusmarmingeclaude
authored
fix(pull-request): prioritize failed checks (pingdotgg#12274)
Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 449e317 commit 03c1a76

10 files changed

Lines changed: 107 additions & 33 deletions

File tree

‎packages/source-control-bitbucket/src/server/BitbucketPullRequestApi.test.ts‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,18 +568,39 @@ layer("BitbucketPullRequestApi.layer", (it) => {
568568
const next = "https://api.bitbucket.org/2.0/statuses?page=2";
569569
mockedRequest
570570
.mockReturnValueOnce(
571-
Effect.succeed(response(valuePage([{ name: "Build", state: "SUCCESSFUL" }], next))),
571+
Effect.succeed(
572+
response(
573+
valuePage(
574+
[
575+
{ name: "Build", state: "SUCCESSFUL" },
576+
{ name: "Tests", state: "STOPPED" },
577+
],
578+
next,
579+
),
580+
),
581+
),
572582
)
573583
.mockReturnValueOnce(
574-
Effect.succeed(response(valuePage([{ name: "Lint", state: "FAILED" }]))),
584+
Effect.succeed(
585+
response(
586+
valuePage([
587+
{ name: "Lint", state: "FAILED" },
588+
{ name: "Deploy", state: "INPROGRESS" },
589+
{ name: "Audit", state: "FAILED" },
590+
]),
591+
),
592+
),
575593
);
576594
const api = yield* BitbucketPullRequestApi.BitbucketPullRequestApi;
577595

578596
const checks = yield* api.listChecks({ repository: "acme/web", number: 7 });
579597

580598
expect(checks.map((check) => [check.name, check.status])).toEqual([
581-
["Build", "success"],
599+
["Tests", "cancelled"],
582600
["Lint", "failure"],
601+
["Audit", "failure"],
602+
["Build", "success"],
603+
["Deploy", "pending"],
583604
]);
584605
expect(callAt(1).url).toBe(next);
585606
}),

‎packages/source-control-bitbucket/src/server/BitbucketPullRequestApi.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323

2424
import * as BitbucketApi from "./BitbucketApi.ts";
2525
import { parseDiffFileRevisions } from "@t3tools/source-control-core/server/diffFileRevisions";
26+
import { sortChecks } from "@t3tools/source-control-core/server/pullRequestChecks";
2627
import {
2728
buildReviewThreads,
2829
decodeCommentsJson,
@@ -671,7 +672,7 @@ export const make = Effect.gen(function* () {
671672
decode: decodeStatusesJson,
672673
items: [],
673674
prepend: false,
674-
}),
675+
}).pipe(Effect.map(sortChecks)),
675676
),
676677

677678
listReviewerCandidates: (input) =>

‎packages/source-control-bitbucket/src/server/bitbucketPullRequestJson.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ describe("decodeStatusesJson", () => {
350350
);
351351

352352
expect(decoded.items.map((check) => [check.name, check.status])).toEqual([
353-
["build / Pipeline", "success"],
354353
["deploy / Pipeline", "failure"],
354+
["build / Pipeline", "success"],
355355
]);
356356
});
357357
});

‎packages/source-control-core/src/server/pullRequestChecks.test.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,25 @@ describe("dedupeChecks", () => {
133133
]);
134134
});
135135

136+
it("puts failed and cancelled checks first, preserving each group's order after reruns", () => {
137+
const checks = dedupeChecks([
138+
entry("lint", "failure", { at: "2026-08-11T16:00:00Z" }),
139+
entry("integration", "cancelled"),
140+
entry("types", "pending"),
141+
entry("unit", "failure"),
142+
entry("format", "success"),
143+
entry("lint", "success", { at: "2026-08-11T18:00:00Z" }),
144+
]);
145+
146+
expect(checks.map((check) => [check.name, check.status])).toEqual([
147+
["integration", "cancelled"],
148+
["unit", "failure"],
149+
["lint", "success"],
150+
["types", "pending"],
151+
["format", "success"],
152+
]);
153+
});
154+
136155
it("keeps distinct workflow and check pairs even when their names join to the same text", () => {
137156
const checks = dedupeChecks([
138157
entry("Linux tests", "success", {
@@ -181,8 +200,8 @@ describe("dedupeChecks", () => {
181200
]);
182201

183202
expect(checks.map((check) => [check.name, check.status])).toEqual([
184-
["CI / build", "success"],
185203
["Release / build", "failure"],
204+
["CI / build", "success"],
186205
]);
187206
});
188207

@@ -193,6 +212,6 @@ describe("dedupeChecks", () => {
193212
entry("build", "failure", { workflowName: "CI", at: "2026-08-11T16:00:00Z" }),
194213
]);
195214

196-
expect(checks.map((check) => check.name)).toEqual(["build", "CI / build"]);
215+
expect(checks.map((check) => check.name)).toEqual(["CI / build", "build"]);
197216
});
198217
});

‎packages/source-control-core/src/server/pullRequestChecks.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ function isAtLeastAsNew(candidate: string | null, kept: string | null): boolean
3636
);
3737
}
3838

39+
export function sortChecks(
40+
checks: ReadonlyArray<PullRequestCheck>,
41+
): ReadonlyArray<PullRequestCheck> {
42+
return checks.toSorted(
43+
(a, b) =>
44+
Number(b.status === "failure" || b.status === "cancelled") -
45+
Number(a.status === "failure" || a.status === "cancelled"),
46+
);
47+
}
48+
3949
/**
4050
* A host's rollup is a list of runs, not a list of checks: while a workflow is being re-run — or
4151
* while a second run of it is already live — the same check arrives twice, and both copies reach
@@ -61,10 +71,12 @@ export function dedupeChecks(
6171
for (const entry of survivors) {
6272
countsByName.set(entry.check.name, (countsByName.get(entry.check.name) ?? 0) + 1);
6373
}
64-
return survivors.map((entry) => {
65-
const workflowName = entry.workflowName ?? "";
66-
return workflowName.length > 0 && (countsByName.get(entry.check.name) ?? 0) > 1
67-
? { ...entry.check, name: `${workflowName} / ${entry.check.name}` }
68-
: entry.check;
69-
});
74+
return sortChecks(
75+
survivors.map((entry) => {
76+
const workflowName = entry.workflowName ?? "";
77+
return workflowName.length > 0 && (countsByName.get(entry.check.name) ?? 0) > 1
78+
? { ...entry.check, name: `${workflowName} / ${entry.check.name}` }
79+
: entry.check;
80+
}),
81+
);
7082
}

‎packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,17 @@ it.effect.each([
240240
for (const checks of [summary.checks, detail.checks]) {
241241
assert.deepStrictEqual(
242242
checks.map((check) => [check.name, check.status, check.required]),
243-
[
244-
["ci/required-build", "success", supported ? true : undefined],
245-
["ci/optional-lint", supported ? "failure" : "success", undefined],
246-
[missing, "pending", supported ? true : undefined],
247-
],
243+
supported
244+
? [
245+
["ci/optional-lint", "failure", undefined],
246+
["ci/required-build", "success", true],
247+
[missing, "pending", true],
248+
]
249+
: [
250+
["ci/required-build", "success", undefined],
251+
["ci/optional-lint", "success", undefined],
252+
[missing, "pending", undefined],
253+
],
248254
);
249255
if (!supported) {
250256
assert.strictEqual(
@@ -298,8 +304,8 @@ it.effect.each([
298304
assert.deepStrictEqual(
299305
checks.map((check) => [check.name, check.status, check.required]),
300306
[
301-
["ci/required-build", "success", undefined],
302307
["ci/optional-lint", "failure", undefined],
308+
["ci/required-build", "success", undefined],
303309
],
304310
);
305311
}

‎packages/source-control-gitcafe/src/server/GitCafePullRequestProvider.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ describe("GitCafePullRequestProvider", () => {
646646
});
647647
assert.deepStrictEqual(
648648
detail.checks.map((check) => check.name),
649-
["early", "late"],
649+
["late", "early"],
650650
);
651651
assert.deepStrictEqual(
652652
detail.reviewers.map((reviewer) => reviewer.login),

‎packages/source-control-gitcafe/src/server/gitCafePullRequestJson.test.ts‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,12 @@ describe("toDiff", () => {
494494

495495
describe("toChecks", () => {
496496
it("maps GitCafe's status and conclusion onto the shared check states", () => {
497-
const check = (status: string, conclusion: string | null) => ({
498-
name: `${status}-${conclusion}`,
497+
const check = (
498+
status: string,
499+
conclusion: string | null,
500+
name = `${status}-${conclusion}`,
501+
) => ({
502+
name,
499503
status,
500504
conclusion,
501505
summary: null,
@@ -506,16 +510,24 @@ describe("toChecks", () => {
506510
items: [
507511
check("queued", null),
508512
check("in_progress", null),
509-
check("completed", "success"),
513+
check("completed", "success", "Build"),
514+
check("completed", "cancelled"),
510515
check("completed", "action_required"),
511-
check("completed", "timed_out"),
516+
check("completed", "timed_out", "Build"),
512517
],
513518
next: null,
514519
}),
515520
);
516521
assert.deepStrictEqual(
517-
checks.map((item) => item.status),
518-
["pending", "pending", "success", "action-required", "failure"],
522+
checks.map((item) => [item.name, item.status]),
523+
[
524+
["completed-cancelled", "cancelled"],
525+
["Build", "failure"],
526+
["queued-null", "pending"],
527+
["in_progress-null", "pending"],
528+
["Build", "success"],
529+
["completed-action_required", "action-required"],
530+
],
519531
);
520532
});
521533
});

‎packages/source-control-gitcafe/src/server/gitCafePullRequestJson.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { quoteGitPatchPath } from "@t3tools/shared/gitPatchPath";
2+
import { sortChecks } from "@t3tools/source-control-core/server/pullRequestChecks";
23
import * as DateTime from "effect/DateTime";
34
import * as Schema from "effect/Schema";
45
import {
@@ -549,10 +550,12 @@ function checkStatus(check: (typeof GitCafeChecks.Type.items)[number]): PullRequ
549550
}
550551

551552
export function toChecks(checks: typeof GitCafeChecks.Type): ReadonlyArray<PullRequestCheck> {
552-
return checks.items.map((check) => ({
553-
name: check.name,
554-
status: checkStatus(check),
555-
description: check.summary,
556-
url: check.detailsUrl,
557-
}));
553+
return sortChecks(
554+
checks.items.map((check) => ({
555+
name: check.name,
556+
status: checkStatus(check),
557+
description: check.summary,
558+
url: check.detailsUrl,
559+
})),
560+
);
558561
}

‎packages/source-control-github/src/server/gitHubPullRequestJson.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,8 @@ describe("pull request detail decoding", () => {
623623
check({ __typename: "StatusContext", context: "ci/legacy", state: "SUCCESS" }),
624624
]);
625625
expect(detail.checks.map((check) => [check.name, check.status])).toEqual([
626-
["build", "pending"],
627626
["test", "failure"],
627+
["build", "pending"],
628628
["ci/legacy", "success"],
629629
]);
630630
});

0 commit comments

Comments
 (0)