Auto Merge Approved PRs #17
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
# Reviewer 2๋ช ์ด ๋ฆฌ๋ทฐ๋ฅผ ๋จ๊ธฐ๊ณ ์น์ธํ ๋ค, ๋ผ๋ฒจ์ด "์์ ์๋ฃ"๋ก ๋ณ๊ฒฝ๋๊ณ ์๋์ผ๋ก ํน์ ๋ธ๋์น์ Mergeํ๊ธฐ | |
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 and Labels' | |
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'); | |
const hasLabel = pr.labels.some(label => label.name === 'ํ์ธ ์์ฒญ'); | |
return approvals.length >= 2 && hasLabel; | |
- name: 'Change Label to ์์ ์๋ฃ' | |
if: steps.check.outputs.result == 'true' | |
uses: actions-ecosystem/action-add-labels@v1 | |
with: | |
labels: '์์ ์๋ฃ' | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: 'Remove Label ํ์ธ ์์ฒญ' | |
if: steps.check.outputs.result == 'true' | |
uses: actions-ecosystem/action-remove-labels@v1 | |
with: | |
labels: 'ํ์ธ ์์ฒญ' | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- 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, | |
}); |