Auto Merge Approved PRs #7
Workflow file for this run
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: "Auto Merge Approved PRs" | |
on: | |
pull_request_review: | |
types: [submitted] | |
jobs: | |
auto_merge: | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Check Approvals" | |
id: check | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
result-encoding: string | |
script: | | |
const pull_number = context.payload.pull_request.number; | |
const reviews = await github.rest.pulls.listReviews({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pull_number, | |
}); | |
const approvals = reviews.data.filter(review => review.state === 'APPROVED'); | |
return approvals.length >= 2; | |
- name: "Merge PR" | |
if: ${{ steps.check.outputs.result == 'true' }} | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const pull_number = context.payload.pull_request.number; | |
await github.rest.pulls.merge({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: pull_number, | |
}); |