-
-
Notifications
You must be signed in to change notification settings - Fork 625
100 lines (87 loc) · 3 KB
/
bot-automerge.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: 'Z-Wave Bot: Auto-Merge PR'
on:
issue_comment:
types: [created] # edited, deleted
pull_request:
types: [synchronize, reopened]
jobs:
# #########################################################################
# Approves and enables automerge on a PR when authorized person comments
# @zwave-js-bot automerge
bot-automerge:
if: |
contains(github.event.issue.html_url, '/pull/') &&
contains(github.event.comment.body, '@zwave-js-bot automerge') &&
github.event.comment.user.login == 'AlCalzone'
runs-on: [ubuntu-latest]
steps:
- uses: actions/github-script@v7
with:
github-token: ${{secrets.BOT_TOKEN}}
script: |
const options = {
owner: context.repo.owner,
repo: context.repo.repo,
};
await github.rest.pulls.createReview({
...options,
pull_number: context.payload.issue.number,
event: "APPROVE"
});
- name: Auto-merge PR
env:
PR_URL: ${{github.event.issue.html_url}}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
gh pr merge --auto --squash "$PR_URL"
bot-reenable-automerge:
# Don't run in forks, don't run for drafts
if: |
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository &&
github.event.pull_request.user.login != 'dependabot[bot]' &&
github.event.pull_request.draft == false
runs-on: [ubuntu-latest]
steps:
- name: Check if auto-merging should be enabled
id: should-automerge
uses: actions/github-script@v7
with:
github-token: ${{secrets.BOT_TOKEN}}
result-encoding: string
script: |
const options = {
owner: context.repo.owner,
repo: context.repo.repo,
};
const { data: comments } = await github.rest.issues.listComments({
...options,
issue_number: context.issue.number,
});
return comments.some(
(c) =>
c.user.login === "AlCalzone" &&
c.body === "@zwave-js-bot automerge",
);
- name: Approve PR
if: ${{ steps.should-automerge.outputs.result == 'true' }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.BOT_TOKEN }}
script: |
const options = {
owner: context.repo.owner,
repo: context.repo.repo,
};
await github.rest.pulls.createReview({
...options,
pull_number: context.issue.number,
event: "APPROVE"
});
- name: Auto-merge PR
if: ${{ steps.should-automerge.outputs.result == 'true' }}
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
run: |
gh pr merge --auto --squash "$PR_URL"