Skip to content

Commit 5bbe8b5

Browse files
committed
ci: add manual gate-close workflow for missed PRs
The PR Gate only fires on `pull_request_target` `opened`, so PRs that were opened while the gate was misconfigured (e.g. #1281) cannot be retroactively auto-closed. Add a `workflow_dispatch` workflow that closes a given PR number with the same contribution-gate message, attributed to github-actions[bot] like the gate itself.
1 parent 4254918 commit 5bbe8b5

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Gate Close PR
2+
3+
# Manually close a PR that the PR Gate did not auto-close (for example a PR
4+
# opened while the gate was misconfigured). Runs from a workflow_dispatch so the
5+
# comment and close are attributed to github-actions[bot], matching the gate.
6+
# It posts the same message as .github/workflows/pr-gate.yaml.
7+
8+
on:
9+
workflow_dispatch:
10+
inputs:
11+
pr_number:
12+
description: PR number to close
13+
required: true
14+
type: number
15+
16+
jobs:
17+
close:
18+
runs-on: ubuntu-slim
19+
permissions:
20+
contents: read
21+
issues: write
22+
pull-requests: write
23+
steps:
24+
- name: Close PR with the contribution-gate message
25+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
26+
with:
27+
script: |
28+
const prNumber = Number(context.payload.inputs.pr_number);
29+
const defaultBranch = context.payload.repository.default_branch;
30+
31+
const message = [
32+
'This PR was auto-closed. Only contributors approved with `lgtm` can open PRs. Open an issue first.',
33+
'',
34+
`Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in [CONTRIBUTING.md](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/${defaultBranch}/CONTRIBUTING.md) may not be reopened or receive a reply.`,
35+
'',
36+
'If a maintainer replies `lgtmi`, your future issues will stay open. If a maintainer replies `lgtm`, your future issues and PRs will stay open.',
37+
'',
38+
`See [CONTRIBUTING.md](https://github.com/${context.repo.owner}/${context.repo.repo}/blob/${defaultBranch}/CONTRIBUTING.md).`,
39+
].join('\n');
40+
41+
await github.rest.issues.createComment({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
issue_number: prNumber,
45+
body: message,
46+
});
47+
48+
await github.rest.pulls.update({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
pull_number: prNumber,
52+
state: 'closed',
53+
});

0 commit comments

Comments
 (0)