diff --git a/.github/scripts/pr-open-limit.js b/.github/scripts/pr-open-limit.js index dd1650b0d6..46f770074f 100644 --- a/.github/scripts/pr-open-limit.js +++ b/.github/scripts/pr-open-limit.js @@ -1,7 +1,8 @@ // Warns when a repository member has too many open pull requests. // // Review capacity is the bottleneck, so authors are expected to land or close -// existing work before opening more. Drafts count: they still occupy attention. +// existing work before opening more. Drafts are not counted and never warned +// about: they are not asking for review yet. // This is advisory only — it never closes a pull request or fails the job. import { appendFileSync } from "node:fs"; @@ -47,7 +48,7 @@ async function isTeamMember(octokit, owner, repo, username) { function buildComment(author, total, limit, openPrs) { const listed = openPrs .slice(0, MAX_LISTED_PRS) - .map((pr) => `- #${pr.number} ${pr.title}${pr.draft ? " _(draft)_" : ""}`); + .map((pr) => `- #${pr.number} ${pr.title}`); const hidden = openPrs.length - listed.length; const list = hidden > 0 ? `${listed.join("\n")}\n- ...and ${hidden} more` : listed.join("\n"); @@ -99,6 +100,11 @@ async function upsertComment(octokit, params, body) { return; } + if (process.env.PR_IS_DRAFT === "true") { + summary(`Skipping #${prNumber}: draft.`); + return; + } + const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }); if (!(await isTeamMember(octokit, owner, repo, author))) { @@ -117,7 +123,7 @@ async function upsertComment(octokit, params, body) { // The pull request that triggered this run is already open, so exclude it and // report the total separately. const others = allOpen.filter( - (pr) => pr.user?.login === author && pr.number !== prNumber + (pr) => pr.user?.login === author && pr.number !== prNumber && !pr.draft ); const total = others.length + 1; diff --git a/.github/workflows/pr-open-limit.yml b/.github/workflows/pr-open-limit.yml index de5b723cb2..081454cb00 100644 --- a/.github/workflows/pr-open-limit.yml +++ b/.github/workflows/pr-open-limit.yml @@ -5,15 +5,15 @@ on: types: - opened - reopened + - ready_for_review concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number }} cancel-in-progress: true -# The warning comment goes through the issues API, hence `issues: write`. permissions: contents: read - pull-requests: read + pull-requests: write issues: write jobs: @@ -44,4 +44,5 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_NUMBER: ${{ github.event.pull_request.number }} PR_AUTHOR: ${{ github.event.pull_request.user.login }} + PR_IS_DRAFT: ${{ github.event.pull_request.draft }} MAX_OPEN_PRS: ${{ vars.MAX_OPEN_PRS_PER_AUTHOR || 5 }}