-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(action): enforces an upper limit of 5 open PRs by a single user
- Loading branch information
Showing
1 changed file
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |