Skip to content

Instantly share code, notes, and snippets.

@dmzoneill
Created March 8, 2024 10:17
Show Gist options
  • Save dmzoneill/f234183850275c36dd43564e81126338 to your computer and use it in GitHub Desktop.
Save dmzoneill/f234183850275c36dd43564e81126338 to your computer and use it in GitHub Desktop.
fail ci with approvers
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/github-script@0.10.0
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