Skip to content

Commit 2589454

Browse files
fix(workflow): do not label a PR stacked on its own previous head
The open-PR head map can predate a push to the PR being reconciled, so a parent sha can resolve to the PR itself. A self-match is not a parent PR: the label is left untouched instead of marking the PR stacked on its own old head. Adds the regression test the review suggested.
1 parent e689ebd commit 2589454

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,12 @@ jobs:
495495
try {
496496
const { data: commit } = await github.rest.git.getCommit({ owner, repo, commit_sha: pr.head.sha });
497497
const parents = Array.isArray(commit.parents) ? commit.parents : [];
498-
const parentPr = parents.length === 1
498+
const matchedPr = parents.length === 1
499499
? openPrHeads.get(String(parents[0].sha).toLowerCase())
500500
: undefined;
501+
// 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;
501504
const hasLabel = pr.labels.some(label => label.name === stackedLabel);
502505
if (hasLabel && parentPr === undefined) {
503506
await github.rest.issues.removeLabel({ owner, repo, issue_number: pr.number, name: stackedLabel });

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,17 @@ describe("PR review-state workflow", () => {
739739
expect(result.warning).not.toHaveBeenCalled()
740740
})
741741

742+
it("does not label a PR stacked when the matched open head is its own", async () => {
743+
const result = await runWorkflow({
744+
commitParents: [OLD_SHA],
745+
// The open-PR map predates this PR's latest push: its own previous head is listed.
746+
openPrHeads: [{ number: 1437, sha: OLD_SHA }],
747+
})
748+
749+
expect(result.addLabels).not.toHaveBeenCalledWith(expect.objectContaining({ labels: ["stacked"] }))
750+
expect(result.removeLabel).not.toHaveBeenCalledWith(expect.objectContaining({ name: "stacked" }))
751+
})
752+
742753
it("removes a stale stacked label when the parent is not another open PR head", async () => {
743754
const result = await runWorkflow({
744755
labels: ["stacked"],

0 commit comments

Comments
 (0)