Skip to content

Commit

Permalink
ci(action): enforces an upper limit of 5 open PRs by a single user
Browse files Browse the repository at this point in the history
  • Loading branch information
edm00se authored Oct 19, 2023
1 parent 50e9440 commit 24f571b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/limit-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Limit Open PRs

on:
pull_request:
types: [opened, reopened, synchronize, labeled, unlabeled]

jobs:
limit_prs:
if: ${{ !contains(github.event.pull_request.labels.*.name, 'approved') }}
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Check open pull requests
uses: actions/github-script@v6
with:
script: |
const openPRs = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
author: context.payload.sender.login,
});
const hasHacktoberfestAcceptedLabel = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
}).then(response => response.data.some(label => label.name === 'hacktoberfest-accepted'));
if (openPRs.data.length > 5 && !hasHacktoberfestAcceptedLabel) {
const message = `You already have ${openPRs.data.length-1} other open pull requests. Please focus on completing those before opening new ones. Do not open additional PRs until those are resolved.`;
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
core.setFailed(message);
}

0 comments on commit 24f571b

Please sign in to comment.