Skip to content

Commit bb59ba7

Browse files
committed
fix(ci): strip WRONG BRANCH prefix when base is corrected
1 parent 7584bf7 commit bb59ba7

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

.github/scripts/enforce-pr-target.test.cjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,16 @@ describe("enforce-pr-target workflow", () => {
6060
assert.match(workflow, /pr-quality\.cjs/);
6161
assert.match(workflow, /collectPrQualityFailures/);
6262
});
63+
64+
it("strips stale WRONG BRANCH prefix on failure when base is corrected", () => {
65+
const failureBlock = workflow.match(
66+
/if \(failures\.length > 0\) \{([\s\S]*?)core\.setFailed\(/,
67+
);
68+
assert.ok(failureBlock, "workflow must have a failure path");
69+
const failurePath = failureBlock[1];
70+
assert.match(failurePath, /shouldStripTitlePrefix/);
71+
assert.match(failurePath, /!hasWrongBase/);
72+
assert.match(failurePath, /titlePrefixedByBot = false/);
73+
assert.match(failurePath, /pr\.title\.slice\(TITLE_PREFIX\.length\)/);
74+
});
6375
});

.github/workflows/enforce-pr-target.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,15 @@ jobs:
332332
failure => failure.code === "bad_description"
333333
);
334334
335+
const shouldStripTitlePrefix =
336+
!hasWrongBase &&
337+
state.titlePrefixedByBot &&
338+
pr.title.startsWith(TITLE_PREFIX);
339+
335340
if (willPrefixTitle) {
336341
state.titlePrefixedByBot = true;
342+
} else if (shouldStripTitlePrefix) {
343+
state.titlePrefixedByBot = false;
337344
}
338345
339346
let draftConversionFailed = false;
@@ -357,6 +364,13 @@ jobs:
357364
pull_number,
358365
title: `${TITLE_PREFIX}${pr.title}`
359366
});
367+
} else if (shouldStripTitlePrefix) {
368+
await github.rest.pulls.update({
369+
owner,
370+
repo,
371+
pull_number,
372+
title: pr.title.slice(TITLE_PREFIX.length)
373+
});
360374
}
361375
362376
if (!pr.draft) {

0 commit comments

Comments
 (0)