From f9d12831d467d0eac603e84e42667ed063d09aa0 Mon Sep 17 00:00:00 2001 From: cheyang Date: Wed, 28 Jan 2026 21:35:34 +0800 Subject: [PATCH 1/5] Add PR quota limit workflow to enforce max 3 open PRs per user Signed-off-by: cheyang --- .github/workflows/pr-quota-limit.yml | 103 +++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 .github/workflows/pr-quota-limit.yml diff --git a/.github/workflows/pr-quota-limit.yml b/.github/workflows/pr-quota-limit.yml new file mode 100644 index 00000000000..52420140112 --- /dev/null +++ b/.github/workflows/pr-quota-limit.yml @@ -0,0 +1,103 @@ +name: PR Quota Limit + +on: + pull_request: + types: [opened, reopened] + +permissions: + pull-requests: write + issues: write + +jobs: + check-pr-quota: + runs-on: ubuntu-latest + steps: + - name: Check PR quota + uses: actions/github-script@v7 + with: + script: | + try { + const prAuthor = context.payload.pull_request.user.login; + const currentPRNumber = context.payload.pull_request.number; + + console.log(`Checking PR quota for user: ${prAuthor}`); + console.log(`Current PR number: ${currentPRNumber}`); + + // Get all open PRs with pagination support + let allPRs = []; + let page = 1; + let hasMorePages = true; + + while (hasMorePages) { + const { data: prs } = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open', + per_page: 100, + page: page + }); + + allPRs = allPRs.concat(prs); + + // If we got less than 100 PRs, we've reached the last page + if (prs.length < 100) { + hasMorePages = false; + } else { + page++; + } + } + + console.log(`Total open PRs in repository: ${allPRs.length}`); + + // Filter PRs by the same author + const userPRs = allPRs.filter(pr => pr.user.login === prAuthor); + const openCount = userPRs.length; + + console.log(`User ${prAuthor} has ${openCount} open PR(s)`); + + // Check if exceeds quota (10 PRs max) + const maxPRs = 10; + if (openCount > maxPRs) { + const availableSlots = 0; + const currentStatus = `${availableSlots}/${maxPRs}`; + + const message = `This pull request will be temporarily closed (Current status: ${currentStatus} open slots available). We encourage you to submit a new PR once the quota policy permits future contributions.`; + + console.log(`Quota exceeded! Closing PR #${currentPRNumber}`); + console.log(`User has ${openCount} open PRs, which exceeds the limit of ${maxPRs}`); + console.log(`Message: ${message}`); + + // Add comment to the PR + try { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: currentPRNumber, + body: message + }); + console.log('Comment added successfully'); + } catch (commentError) { + console.error('Failed to add comment:', commentError.message); + } + + // Close the PR + try { + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: currentPRNumber, + state: 'closed' + }); + console.log(`PR #${currentPRNumber} has been closed due to quota limit.`); + } catch (closeError) { + console.error('Failed to close PR:', closeError.message); + throw closeError; // Re-throw to fail the workflow + } + } else { + const availableSlots = maxPRs - openCount; + console.log(`Quota check passed. User has ${availableSlots} slot(s) available.`); + } + } catch (error) { + console.error('Error in PR quota check:', error.message); + throw error; // Re-throw to fail the workflow + } \ No newline at end of file From 498cb91d7285fe93c257d404ca24a48dfa7c76ca Mon Sep 17 00:00:00 2001 From: cheyang Date: Wed, 28 Jan 2026 21:36:06 +0800 Subject: [PATCH 2/5] Add PR quota limit workflow to enforce max 3 open PRs per user Signed-off-by: cheyang --- .github/workflows/pr-quota-limit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-quota-limit.yml b/.github/workflows/pr-quota-limit.yml index 52420140112..8b32d084b70 100644 --- a/.github/workflows/pr-quota-limit.yml +++ b/.github/workflows/pr-quota-limit.yml @@ -55,8 +55,8 @@ jobs: console.log(`User ${prAuthor} has ${openCount} open PR(s)`); - // Check if exceeds quota (10 PRs max) - const maxPRs = 10; + // Check if exceeds quota (2 PRs max) + const maxPRs = 2; if (openCount > maxPRs) { const availableSlots = 0; const currentStatus = `${availableSlots}/${maxPRs}`; From fe12a46a6240a94472b224c8f7b71f552fac2503 Mon Sep 17 00:00:00 2001 From: cheyang Date: Wed, 28 Jan 2026 21:39:18 +0800 Subject: [PATCH 3/5] Add PR quota limit workflow to enforce max 3 open PRs per user Signed-off-by: cheyang --- .github/workflows/pr-quota-limit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-quota-limit.yml b/.github/workflows/pr-quota-limit.yml index 8b32d084b70..56eb56f804f 100644 --- a/.github/workflows/pr-quota-limit.yml +++ b/.github/workflows/pr-quota-limit.yml @@ -59,7 +59,7 @@ jobs: const maxPRs = 2; if (openCount > maxPRs) { const availableSlots = 0; - const currentStatus = `${availableSlots}/${maxPRs}`; + const currentStatus = `${openCount}/${maxPRs}`; const message = `This pull request will be temporarily closed (Current status: ${currentStatus} open slots available). We encourage you to submit a new PR once the quota policy permits future contributions.`; From 67b3ed86ac20c858ef497efc02ed6328482484e8 Mon Sep 17 00:00:00 2001 From: cheyang Date: Wed, 28 Jan 2026 21:50:16 +0800 Subject: [PATCH 4/5] Add PR quota limit workflow to enforce max 3 open PRs per user Signed-off-by: cheyang --- .github/workflows/pr-quota-limit.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-quota-limit.yml b/.github/workflows/pr-quota-limit.yml index 56eb56f804f..0430ccb83c1 100644 --- a/.github/workflows/pr-quota-limit.yml +++ b/.github/workflows/pr-quota-limit.yml @@ -61,7 +61,7 @@ jobs: const availableSlots = 0; const currentStatus = `${openCount}/${maxPRs}`; - const message = `This pull request will be temporarily closed (Current status: ${currentStatus} open slots available). We encourage you to submit a new PR once the quota policy permits future contributions.`; + const message = `Hi, @${prAuthor}, Thanks for your contribution! To ensure quality reviews, we limit how many concurrent open PRs contributors can open. This pull request will be temporarily closed (Current status: ${currentStatus} open). We encourage you to submit a new PR once the quota policy permits future contributions.`; console.log(`Quota exceeded! Closing PR #${currentPRNumber}`); console.log(`User has ${openCount} open PRs, which exceeds the limit of ${maxPRs}`); From d641947d39b9de2ed04ba15beb7706ed65eb042c Mon Sep 17 00:00:00 2001 From: cheyang Date: Thu, 29 Jan 2026 09:59:30 +0800 Subject: [PATCH 5/5] Add PR quota limit workflow to enforce max 3 open PRs per user Signed-off-by: cheyang --- .github/workflows/pr-quota-limit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-quota-limit.yml b/.github/workflows/pr-quota-limit.yml index 0430ccb83c1..4f21a942cc7 100644 --- a/.github/workflows/pr-quota-limit.yml +++ b/.github/workflows/pr-quota-limit.yml @@ -55,8 +55,8 @@ jobs: console.log(`User ${prAuthor} has ${openCount} open PR(s)`); - // Check if exceeds quota (2 PRs max) - const maxPRs = 2; + // Check if exceeds quota (15 PRs max) + const maxPRs = 15; if (openCount > maxPRs) { const availableSlots = 0; const currentStatus = `${openCount}/${maxPRs}`;