Skip to content

Pull request approval checks #3804

Pull request approval checks

Pull request approval checks #3804

# Checks the number of a approvals for any pull requests from bump_version->main where the PR title starts with release
# This should be setup as a protection rule on the main branch. PRs coming from other branches will be exempt from this rule
name: Pull request approval checks
on:
pull_request_review:
branches:
- main
jobs:
count_approvals:
runs-on: ubuntu-latest
# This restricts which PRs this workflow applies to.
if: ${{ github.event_name == 'pull_request_review'
&& github.event.pull_request.head.ref == 'bump_version'
&& startsWith(github.event.pull_request.title, 'release:')
}}
steps:
- uses: actions/github-script@ffc2c79a5b2490bd33e0a41c1de74b877714d736 # v3
id: get_approval_count
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const reviews = await github.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
const approvals = reviews.data.filter(review => review.state==='APPROVED').length;
if (approvals < 2) {
core.setFailed('Not enough approvals yet :(');
}