Skip to content

Auto Merge Approved PRs #1

Auto Merge Approved PRs

Auto Merge Approved PRs #1

name: "Auto Merge Approved PRs"
on:
pull_request_review:
types: [submitted]
jobs:
auto_merge:
runs-on: ubuntu-latest
steps:
- name: "Get Pull Request"
id: pr
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const { data: pr } = await github.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
return JSON.stringify(pr);
- name: "Check Approvals"
id: check
uses: actions/github-script@v6
with:
script: |
const pr = JSON.parse(steps.pr.outputs.result);
const reviews = await github.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.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:
script: |
await github.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});