|
1 | 1 | name: Close issue/PR on adding invalid label |
2 | 2 |
|
3 | 3 | # Closes public issues and PRs when the invalid label is added. |
| 4 | +# Re-closes invalid PRs that someone without write access reopens. |
4 | 5 |
|
5 | 6 | on: |
6 | 7 | issues: |
7 | 8 | types: [labeled] |
8 | | - # pull_request_target lets the workflow close forked PRs after the invalid label is added. |
| 9 | + # pull_request_target lets the workflow close forked PRs when they're labeled invalid or reopened. |
9 | 10 | pull_request_target: |
10 | | - types: [labeled] |
| 11 | + types: [labeled, reopened] |
11 | 12 |
|
12 | 13 | permissions: |
13 | 14 | contents: read |
14 | | - issues: write |
15 | | - pull-requests: write |
16 | 15 |
|
17 | 16 | jobs: |
18 | 17 | close-on-adding-invalid-label: |
19 | 18 | if: github.repository == 'github/docs' && github.event.label.name == 'invalid' |
20 | 19 | runs-on: ubuntu-latest |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + issues: write |
| 23 | + pull-requests: write |
21 | 24 |
|
22 | 25 | steps: |
23 | 26 | - name: Close issue |
|
42 | 45 | if: ${{ failure() && github.event_name != 'pull_request_target' }} |
43 | 46 | with: |
44 | 47 | slack_token: ${{ secrets.SLACK_DOCS_BOT_TOKEN }} |
| 48 | + |
| 49 | + # Authors can reopen PRs they closed themselves, even after the invalid label is added. |
| 50 | + reclose-reopened-invalid-pr: |
| 51 | + if: > |
| 52 | + github.repository == 'github/docs' && github.event_name == 'pull_request_target' && |
| 53 | + github.event.action == 'reopened' && |
| 54 | + contains(github.event.pull_request.labels.*.name, 'invalid') |
| 55 | + runs-on: ubuntu-latest |
| 56 | + permissions: |
| 57 | + pull-requests: write |
| 58 | + steps: |
| 59 | + - name: Re-close PR unless reopened by someone with write access |
| 60 | + env: |
| 61 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 63 | + SENDER: ${{ github.event.sender.login }} |
| 64 | + run: | |
| 65 | + if ! permission=$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$SENDER/permission" --jq '.permission'); then |
| 66 | + echo "::warning::Couldn't look up permission for $SENDER, so treating them as read-only." |
| 67 | + permission=none |
| 68 | + fi |
| 69 | + if [[ "$permission" == "admin" || "$permission" == "write" ]]; then |
| 70 | + echo "$SENDER has $permission access, so leaving the PR open." |
| 71 | + exit 0 |
| 72 | + fi |
| 73 | + gh pr close "$PR_URL" --comment 'This pull request is labeled `invalid`, so only maintainers can reopen it. If you think this is incorrect, please mention this in a corresponding issue.' |
0 commit comments