-
Notifications
You must be signed in to change notification settings - Fork 2
69 lines (61 loc) ยท 2.44 KB
/
auto-merge.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
});
core.setOutput('prResult', JSON.stringify(pr));
- name: 'Check Approvals and Labels'
id: check
uses: actions/github-script@v6
with:
script: |
const pr = JSON.parse(process.env.PR_RESULT);
const reviews = await github.rest.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 === 'ํ์ธ ์์ฒญ');
// ๋ฉ์ธ ๋ธ๋์น๋ก ํฅํ๋ PR์ธ ๊ฒฝ์ฐ ๋ฆฌ๋ทฐ์ด 3๋ช
, ๋ค๋ฅธ ๋ธ๋์น์ธ ๊ฒฝ์ฐ 2๋ช
ํ์
const requiredApprovals = pr.base.ref === 'main' ? 3 : 2;
// Check ์กฐ๊ฑด ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅ์ ์ค์
core.setOutput('result', approvals.length >= requiredApprovals && 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.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
merge_method: 'merge', // 'squash' ๋๋ 'rebase'๋ก๋ ์ค์ ๊ฐ๋ฅ
commit_title: `์๋ ๋จธ์ง: PR #${context.payload.pull_request.number}`
});