|
| 1 | +name: "Auto-Close External PRs" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + types: [opened] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + close-on-open: |
| 10 | + if: github.event_name == 'pull_request_target' && github.event.pull_request.user.login != github.repository_owner |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + pull-requests: write |
| 14 | + issues: write |
| 15 | + steps: |
| 16 | + - uses: actions/github-script@v7 |
| 17 | + with: |
| 18 | + script: | |
| 19 | + const pr = context.issue.number; |
| 20 | + await github.rest.issues.createComment({ |
| 21 | + owner: context.repo.owner, |
| 22 | + repo: context.repo.repo, |
| 23 | + issue_number: pr, |
| 24 | + body: "Thanks for the interest! This repository isn't currently accepting external contributions as I am actively experimenting with different approaches and want to avoid merge conflicts. Therefore, this PR is being closed automatically by Github Bot." |
| 25 | + }); |
| 26 | + await github.rest.pulls.update({ |
| 27 | + owner: context.repo.owner, |
| 28 | + repo: context.repo.repo, |
| 29 | + pull_number: pr, |
| 30 | + state: "closed" |
| 31 | + }); |
| 32 | +
|
| 33 | + sweep-existing: |
| 34 | + if: github.event_name == 'workflow_dispatch' |
| 35 | + runs-on: ubuntu-latest |
| 36 | + permissions: |
| 37 | + pull-requests: write |
| 38 | + issues: write |
| 39 | + steps: |
| 40 | + - uses: actions/github-script@v7 |
| 41 | + with: |
| 42 | + script: | |
| 43 | + const owner = context.repo.owner; |
| 44 | + const repo = context.repo.repo; |
| 45 | + const prs = await github.paginate(github.rest.pulls.list, { |
| 46 | + owner, repo, state: 'open', per_page: 100 |
| 47 | + }); |
| 48 | + for (const pr of prs) { |
| 49 | + if (pr.user.login === owner) continue; |
| 50 | + core.info(`Closing PR #${pr.number} by ${pr.user.login}`); |
| 51 | + await github.rest.issues.createComment({ |
| 52 | + owner, repo, issue_number: pr.number, |
| 53 | + body: "Thanks for the interest! This repository isn't currently accepting external contributions as I am actively experimenting with different approaches and want to avoid merge conflicts. Therefore, this PR is being closed automatically by Github Bot." |
| 54 | + }); |
| 55 | + await github.rest.pulls.update({ |
| 56 | + owner, repo, pull_number: pr.number, state: "closed" |
| 57 | + }); |
| 58 | + } |
0 commit comments