Skip to content

ci(action): enforces an upper limit of 5 open PRs by a single user #2

ci(action): enforces an upper limit of 5 open PRs by a single user

ci(action): enforces an upper limit of 5 open PRs by a single user #2

Workflow file for this run

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);
}