Skip to content

Auto Merge Approved PRs #7

Auto Merge Approved PRs

Auto Merge Approved PRs #7

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,
});