Skip to content

Commit 8beb4f8

Browse files
korthoutclaude
andcommitted
fix(summary): distinguish total vs partial failure in intro
formatIntroduction previously only branched on `error` (pre-loop failure) and `pendingTargets` (in-progress). Once the loop completed with no pending targets, it always rendered "backported this pull request" regardless of per-target outcomes, so a run where every target failed read identically to a run where every target succeeded. Branch by severity using the results array: - all results failed -> "failed to backport this pull request" (reuses the existing pre-loop-error wording; consistent for users scanning to see whether anything succeeded) - any failed but not all -> "completed backporting this pull request with failures" - otherwise -> "backported" (unchanged) success_with_conflicts is intentionally not treated as a failure for intro wording: the PR was created and the table cell already flags the conflicts. When conflict_resolution is "fail", conflicts surface as status: "failed" via CherryPickError, so they trigger the new wording through the normal path. Tests cover all-failed, mixed success/failure, failure-plus-skip, and success_with_conflicts. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent a188ef8 commit 8beb4f8

2 files changed

Lines changed: 84 additions & 1 deletion

File tree

‎src/comments.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function formatRunComment(
5757
}
5858

5959
function formatIntroduction(
60-
_results: TargetResult[],
60+
results: TargetResult[],
6161
pendingTargets: string[],
6262
context: CommentContext,
6363
error?: string,
@@ -69,6 +69,13 @@ function formatIntroduction(
6969
if (pendingTargets.length > 0) {
7070
return `${ACTION_LINK} is backporting this pull request in ${runLink}.`;
7171
}
72+
const failedCount = results.filter((r) => r.status === "failed").length;
73+
if (failedCount > 0 && failedCount === results.length) {
74+
return `${ACTION_LINK} failed to backport this pull request in ${runLink}.`;
75+
}
76+
if (failedCount > 0) {
77+
return `${ACTION_LINK} completed backporting this pull request with failures in ${runLink}.`;
78+
}
7279
return `${ACTION_LINK} backported this pull request in ${runLink}.`;
7380
}
7481

‎src/test/comments.test.ts‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,82 @@ describe("formatRunComment", () => {
160160
);
161161
});
162162

163+
it("all targets failed: intro is 'failed to backport'", () => {
164+
const results: TargetResult[] = [
165+
failed(
166+
"stable/8.0",
167+
new CherryPickError("cp", "backport-42-to-8.0", ["abc"]),
168+
),
169+
failed(
170+
"stable/7.8",
171+
new GitPushError("push", "backport-42-to-7.8", "origin", 128),
172+
),
173+
];
174+
const out = formatRunComment(results, [], context);
175+
176+
expect(out).toContain("failed to backport this pull request");
177+
expect(out).not.toContain("completed backporting");
178+
expect(out).not.toContain("is backporting");
179+
});
180+
181+
it("mixed success and failure: intro reports completion with failures", () => {
182+
const results: TargetResult[] = [
183+
{
184+
status: "success",
185+
targetBranch: "main",
186+
newPrNumber: 100,
187+
branchname: "b1",
188+
},
189+
failed(
190+
"stable/8.0",
191+
new CherryPickError("cp", "backport-42-to-8.0", ["abc"]),
192+
),
193+
];
194+
const out = formatRunComment(results, [], context);
195+
196+
expect(out).toContain(
197+
"completed backporting this pull request with failures",
198+
);
199+
expect(out).not.toContain("failed to backport");
200+
});
201+
202+
it("failure mixed with skip: intro reports completion with failures", () => {
203+
const results: TargetResult[] = [
204+
failed(
205+
"stable/8.0",
206+
new CherryPickError("cp", "backport-42-to-8.0", ["abc"]),
207+
),
208+
{
209+
status: "skipped",
210+
targetBranch: "stable/7.9",
211+
reason: "PR already exists",
212+
},
213+
];
214+
const out = formatRunComment(results, [], context);
215+
216+
expect(out).toContain(
217+
"completed backporting this pull request with failures",
218+
);
219+
expect(out).not.toContain("failed to backport");
220+
});
221+
222+
it("success_with_conflicts is not a failure for intro wording", () => {
223+
const results: TargetResult[] = [
224+
{
225+
status: "success_with_conflicts",
226+
targetBranch: "main",
227+
newPrNumber: 200,
228+
branchname: "b1",
229+
uncommittedShas: ["abc"],
230+
},
231+
];
232+
const out = formatRunComment(results, [], context);
233+
234+
expect(out).toContain("backported this pull request");
235+
expect(out).not.toContain("with failures");
236+
expect(out).not.toContain("failed to backport");
237+
});
238+
163239
it("mix of statuses: only failures get details blocks", () => {
164240
const results: TargetResult[] = [
165241
{

0 commit comments

Comments
 (0)