Skip to content

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

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 #4

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: Get open PRs for user
id: get_prs
uses: octokit/request-action@v2.x
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
route: GET /repos/:repository/pulls
repository: ${{ github.repository }}
author: ${{ github.event.pull_request.user.login }}
state: open
- name: Fail if too many open PRs
if: ${{ steps.get_prs.outputs.data.length > 5 }}
uses: actions/github-script@v6
with:
script: |
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 (!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);
}