Created
March 8, 2024 10:17
-
-
Save dmzoneill/f234183850275c36dd43564e81126338 to your computer and use it in GitHub Desktop.
fail ci with approvers
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
name: PR Approval Check | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- review_requested | |
- review_request_removed | |
jobs: | |
pr-approval-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check for PR approval | |
uses: actions/[email protected] | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const pr = await github.pulls.get({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number | |
}); | |
const reviews = await github.pulls.listReviews({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.payload.pull_request.number | |
}); | |
const approvedReviewers = reviews.data | |
.filter(review => review.state === 'APPROVED') | |
.map(review => review.user.login); | |
if (approvedReviewers.length > 0) { | |
console.log(`PR approved by: ${approvedReviewers.join(', ')}`); | |
core.setOutput('approved', 'true'); | |
} else { | |
console.log('PR not approved by any reviewer.'); | |
core.setOutput('approved', 'false'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment