Skip to content

Add community PR limit workflow#6229

Merged
moonbox3 merged 2 commits into
microsoft:mainfrom
moonbox3:limit-num-prs-action
Jun 1, 2026
Merged

Add community PR limit workflow#6229
moonbox3 merged 2 commits into
microsoft:mainfrom
moonbox3:limit-num-prs-action

Conversation

@moonbox3
Copy link
Copy Markdown
Contributor

@moonbox3 moonbox3 commented Jun 1, 2026

Motivation and Context

Limit community contributors to 10 open pull requests at a time.

This helps keep the review queue manageable and prevents a single community author from opening a large number of concurrent PRs. Team members are excluded from this limit.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@moonbox3 moonbox3 self-assigned this Jun 1, 2026
Copilot AI review requested due to automatic review settings June 1, 2026 03:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an automated workflow that caps community contributors at 10 concurrent open pull requests. On PR open/reopen, a team-membership check skips enforcement for maintainers; otherwise the contributor's open-PR count is queried via the search API, and if the limit is exceeded the PR is labeled (too-many-prs), commented on, and closed. The enforcement logic lives in a new shared JS module with unit tests.

Changes:

  • New workflow .github/workflows/limit-community-prs.yml with team-check and limit-enforcement jobs gated on pull_request_target.
  • New helper .github/scripts/pr_limit_moderation.js implementing label-ensure, comment, and close logic against the Octokit REST surface.
  • New Node test suite .github/tests/test_pr_limit_moderation.js covering at-limit, search-not-indexed, missing-label, and message-body cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
.github/workflows/limit-community-prs.yml New workflow wiring team-check + enforcement jobs.
.github/scripts/pr_limit_moderation.js New helper that counts open PRs and closes/labels/comments when over limit.
.github/tests/test_pr_limit_moderation.js Unit tests for the enforcement helper.

Comment thread .github/workflows/limit-community-prs.yml
Comment thread .github/scripts/pr_limit_moderation.js
Comment thread .github/workflows/limit-community-prs.yml
Comment thread .github/workflows/limit-community-prs.yml Outdated
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 92%

✓ Correctness

The PR adds a clean, well-tested workflow for limiting community PRs. The core logic in getOpenPrCount correctly handles the GitHub search indexing race condition by checking whether the current PR number appears in search results. Error handling in ensureLabel properly handles both 404 (label doesn't exist) and 422 (race condition on creation). The workflow correctly uses pull_request_target for secret access and a custom token for team membership checks. All previously flaged issues (reopened trigger loop, env redundancy, >100 PRs edge case, team_check failure mode) are marked resolved. No new correctness issues found.

✓ Security Reliability

The PR implements a community PR limit workflow using pull_request_target with appropriate security controls: scripts are checked out from the base branch (not the PR head), action versions are pinned to SHA, input validation exists for the payload structure, concurrency control prevents race conditions, and the label creation handles 404/422 races correctly. No new security or reliability issues found beyond those already discussed and resolved in the review thread.

✓ Test Coverage

The test file covers the main happy paths (at-limit, over-limit, label creation, message content) but mises several explicitly-coded error-handling paths in the production code. Most notably, the 422 race-condition guard in ensureLabel and the getPullRequest validation throw are untested. The tests also never assert on core.info log output, leaving observability behavior unverified.

✓ Design Approach

I found two design issues that can disable or contradict the intended moderation flow. First, the workflow still runs on reopened, but the moderation script always recloses over-limit PRs and even tells authors a maintainer can reopen them, so deliberate maintainer reopens will loop back into auto-close. Second, if the team-membership lookup errors, the helper throws and the downstream if only runs on an explicit 'false' output, so enforcement is silently skipped for that PR instead of failing closed or continuing with the limit check.


Automated review by moonbox3's agents

Comment thread .github/tests/test_pr_limit_moderation.js
Comment thread .github/workflows/limit-community-prs.yml
@moonbox3 moonbox3 merged commit 8b0db48 into microsoft:main Jun 1, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants