From 4f0583fe3e8f88c5690e669131946d0a6e10b02e Mon Sep 17 00:00:00 2001 From: iamtoruk Date: Mon, 14 Sep 2026 02:50:41 -0700 Subject: [PATCH] ci: close a contributor's fourth open pull request --- .github/workflows/pr-limit.yml | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/pr-limit.yml diff --git a/.github/workflows/pr-limit.yml b/.github/workflows/pr-limit.yml new file mode 100644 index 00000000..ec903f7f --- /dev/null +++ b/.github/workflows/pr-limit.yml @@ -0,0 +1,40 @@ +name: Limit open PRs per contributor + +# A contributor may have at most three pull requests open at once. The fourth is +# closed with a note and can be reopened when one of the others lands or closes. +# Repository admins are exempt. Runs on pull_request_target so it can act on PRs +# from forks; it never checks out or runs the PR's code. + +on: + pull_request_target: + types: [opened, reopened] + +permissions: + pull-requests: write + +jobs: + limit: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v7 + with: + script: | + const max = 3 + const { owner, repo } = context.repo + const pr = context.payload.pull_request + const author = pr.user.login + if (pr.user.type === 'Bot') return + const { data: perm } = await github.rest.repos.getCollaboratorPermissionLevel({ owner, repo, username: author }) + if (perm.permission === 'admin') return + const { data: open } = await github.rest.search.issuesAndPullRequests({ + q: `repo:${owner}/${repo} is:pr is:open author:${author}`, + per_page: 100, + }) + const others = open.items.filter(i => i.number !== pr.number).sort((a, b) => a.number - b.number) + if (others.length < max) return + const list = others.map(i => `#${i.number}`).join(', ') + await github.rest.issues.createComment({ + owner, repo, issue_number: pr.number, + body: `Closing for now: you already have ${others.length} pull requests open (${list}), and we review at most ${max} per contributor at a time. Reopen this one when one of them is merged or closed. Issues are always welcome.`, + }) + await github.rest.pulls.update({ owner, repo, pull_number: pr.number, state: 'closed' })