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
This commit is contained in:
17
.github/workflows/require-issue-link.yml
vendored
17
.github/workflows/require-issue-link.yml
vendored
@@ -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.');
|
||||
|
||||
Reference in New Issue
Block a user