Merge pull request #1371 from getagentseal/ci/pr-gate

ci: pull request gate for empty descriptions and large first-time changes
This commit is contained in:
Resham Joshi 2026-09-14 13:11:55 +03:00 • committed by GitHub
commit dca2db65f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 15 deletions

View file

@ -1,9 +1,14 @@
name: Limit open PRs per contributor
name: Pull request gate
# A contributor may have at most five pull requests open at once. The sixth 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.
# Three checks when a pull request is opened or reopened, all skipped for
# repository admins and bots. Each closes the PR with a note; reopening after
# the fix is the intended path. Runs on pull_request_target so it can act on
# PRs from forks; it never checks out or runs the PR's code.
#
# 1. The description must say what the change is: an untouched template closes.
# 2. A first-time contributor's PR over 300 changed lines must reference an
# issue, so large work is discussed before it is written.
# 3. A contributor may have at most five pull requests open at once.
on:
pull_request_target:
@ -13,28 +18,51 @@ permissions:
pull-requests: write
jobs:
limit:
gate:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const max = 5
const maxOpen = 5
const bigChange = 300
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 close = async (body) => {
await github.rest.issues.createComment({ owner, repo, issue_number: pr.number, body })
await github.rest.pulls.update({ owner, repo, pull_number: pr.number, state: 'closed' })
}
// 1. Description filled in. The template's Summary section, minus its
// HTML comments, must contain something.
const body = pr.body ?? ''
const summary = (body.split(/^## Testing/m)[0] ?? '').replace(/^## Summary/m, '').replace(/<!--[\s\S]*?-->/g, '').trim()
if (summary.length < 20) {
await close('Closing for now: the description is still the template. Fill in what this change does and why under "Summary", then reopen. A couple of sentences is enough.')
return
}
// 2. Large first-time PRs need an issue behind them.
const firstTimer = ['FIRST_TIME_CONTRIBUTOR', 'FIRST_TIMER', 'NONE'].includes(pr.author_association)
const size = (pr.additions ?? 0) + (pr.deletions ?? 0)
const linksIssue = /(#\d+)|(github\.com\/[^\s]+\/issues\/\d+)/.test(body)
if (firstTimer && size > bigChange && !linksIssue) {
await close(`Closing for now: this is your first pull request here and it changes ${size} lines with no issue behind it. Open an issue describing the change first so we can agree on the shape before the work is written, then reopen this with the issue number in the description. Small fixes do not need this.`)
return
}
// 3. Open-PR cap.
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' })
if (others.length >= maxOpen) {
const list = others.map(i => `#${i.number}`).join(', ')
await close(`Closing for now: you already have ${others.length} pull requests open (${list}), and we review at most ${maxOpen} per contributor at a time. Reopen this one when one of them is merged or closed. Issues are always welcome.`)
}

View file

@ -129,7 +129,9 @@ PRs that add a provider based solely on online documentation or AI-generated cod
3. The `firstlook` workflow will auto-assess the PR. The `semgrep` CI workflow runs the hot-path bracket-assign guard. The `block-claude-coauthor` workflow scans commits.
4. A maintainer reviews. For non-trivial changes, expect requests for tests.
5. Squash-merge is the default. Keep the PR title short and accurate; the description carries the context.
6. Keep at most five pull requests open at a time. A sixth is closed automatically with a note and can be reopened once one of the others lands or closes. If you have more ideas than open slots, file an issue for each so the work is visible and can be discussed before it is written.
6. Fill in the description. A PR whose "Summary" is still the template is closed automatically; write what the change does and why, then reopen.
7. If this is your first contribution and the change is over about 300 lines, open an issue first and reference it in the PR. Large work gets discussed before it is written; small fixes do not need this.
8. Keep at most five pull requests open at a time. A sixth is closed automatically with a note and can be reopened once one of the others lands or closes. If you have more ideas than open slots, file an issue for each so the work is visible and can be discussed before it is written.
## Reporting Bugs