Skip to content

Commit bb4ef32

Browse files
fix(workflow): skip every stacked-label mutation on a self-match
A self-match means the open-PR map still lists this PR own previous head, which is not evidence that a current stacked relationship is stale. Returning before any mutation keeps an existing label untouched instead of letting the removal branch delete it. Tests: an existing stacked label survives a self-match run, and a valid stacked label survives review-state reconciliation. Workflow suite 236 passed.
1 parent 2589454 commit bb4ef32

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎.github/workflows/label-pr-review-state.yml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,11 @@ jobs:
499499
? openPrHeads.get(String(parents[0].sha).toLowerCase())
500500
: undefined;
501501
// The open-PR map can predate a push to this PR: its own previous (or now
502-
// base) head is not a parent PR, so a self-match must not label it stacked.
503-
const parentPr = matchedPr === pr.number ? undefined : matchedPr;
502+
// base) head resolves back to this PR. That is not a parent PR, and it is
503+
// also not evidence that an existing stacked label is stale - leave every
504+
// stacked-label mutation untouched for this ambiguous self-match.
505+
if (matchedPr === pr.number) return;
506+
const parentPr = matchedPr;
504507
const hasLabel = pr.labels.some(label => label.name === stackedLabel);
505508
if (hasLabel && parentPr === undefined) {
506509
await github.rest.issues.removeLabel({ owner, repo, issue_number: pr.number, name: stackedLabel });

‎src/services/__tests__/pr-review-state-workflow.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,44 @@ describe("PR review-state workflow", () => {
750750
expect(result.removeLabel).not.toHaveBeenCalledWith(expect.objectContaining({ name: "stacked" }))
751751
})
752752

753+
it("leaves an existing stacked label untouched on a self-match", async () => {
754+
// A valid label must survive a run whose open-PR map still contains this PR's own
755+
// previous head: a self-match is not evidence that the relationship is stale.
756+
const result = await runWorkflow({
757+
labels: ["stacked"],
758+
commitParents: [OLD_SHA],
759+
openPrHeads: [{ number: 1437, sha: OLD_SHA }],
760+
})
761+
762+
expect(result.removeLabel).not.toHaveBeenCalledWith(expect.objectContaining({ name: "stacked" }))
763+
expect(result.addLabels).not.toHaveBeenCalledWith(expect.objectContaining({ labels: ["stacked"] }))
764+
const labels = ((await result.getPullRequest()).data.labels || []).map((label: { name: string }) => label.name)
765+
expect(labels).toContain("stacked")
766+
})
767+
768+
it("keeps a valid stacked label through review-state reconciliation", async () => {
769+
const result = await runWorkflow({
770+
labels: ["stacked", "awaiting-maintainer"],
771+
commitParents: [OLD_SHA],
772+
openPrHeads: [{ number: 1436, sha: OLD_SHA }],
773+
permissions: { maintainer: "write" },
774+
reviews: [
775+
{
776+
login: "maintainer",
777+
type: "User",
778+
state: "APPROVED",
779+
submittedAt: REVIEWED_AT,
780+
},
781+
],
782+
})
783+
784+
// The reconcileLabels turn may replace review-state labels; the orthogonal stacked
785+
// label must be neither removed nor re-added.
786+
expect(result.removeLabel).not.toHaveBeenCalledWith(expect.objectContaining({ name: "stacked" }))
787+
const labels = ((await result.getPullRequest()).data.labels || []).map((label: { name: string }) => label.name)
788+
expect(labels).toContain("stacked")
789+
})
790+
753791
it("removes a stale stacked label when the parent is not another open PR head", async () => {
754792
const result = await runWorkflow({
755793
labels: ["stacked"],

0 commit comments

Comments
 (0)