From f6a6e4322688945100bff5817b494f5bf67dbe34 Mon Sep 17 00:00:00 2001 From: Tom Boucher Date: Wed, 29 Apr 2026 17:40:18 -0400 Subject: [PATCH] fix(#2872): auto-close PRs that omit the issue-link keyword (#2873) The Require Issue Link workflow was posting a comment and failing the status check, but never transitioning the PR to closed. PR templates promise auto-close behavior; PR #2863 demonstrated the gap (opened without a Closes #N, sat open until manually closed). Adds a `pulls.update({state: 'closed'})` call after the existing comment, updates the comment heading to 'PR auto-closed', and tells the author how to reopen after fixing the body. Closes #2872 --- .github/workflows/require-issue-link.yml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/.github/workflows/require-issue-link.yml b/.github/workflows/require-issue-link.yml index c76168ca5..ad7cddda4 100644 --- a/.github/workflows/require-issue-link.yml +++ b/.github/workflows/require-issue-link.yml @@ -24,19 +24,20 @@ jobs: echo "found=false" >> "$GITHUB_OUTPUT" fi - - name: Comment and fail if no issue link + - name: Comment, close, and fail if no issue link if: steps.check.outputs.found == 'false' uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: # Uses GitHub API SDK — no shell string interpolation of untrusted input script: | const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; + const prNumber = context.payload.pull_request.number; await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: context.payload.pull_request.number, + issue_number: prNumber, body: [ - '## Missing issue link', + '## Missing issue link — PR auto-closed', '', 'This PR does not reference an issue. **All PRs must link to an open issue** using a closing keyword in the PR body:', '', @@ -46,7 +47,13 @@ jobs: '', `If no issue exists for this change, [open one first](${repoUrl}/issues/new/choose), then update this PR body with the reference.`, '', - 'This PR will remain blocked until a valid `Closes #NNN`, `Fixes #NNN`, or `Resolves #NNN` line is present in the description.', + 'To resume work after fixing the body: edit the PR description to add a valid `Closes #NNN`, `Fixes #NNN`, or `Resolves #NNN` line, then click **Reopen pull request**. The workflow will re-evaluate on reopen.', ].join('\n') }); - core.setFailed('PR body must contain a closing issue reference (e.g. "Closes #123")'); + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + state: 'closed', + }); + core.setFailed('PR body must contain a closing issue reference (e.g. "Closes #123") — PR closed.');