-
Notifications
You must be signed in to change notification settings - Fork 88
45 lines (42 loc) · 1.32 KB
/
auto-merge-pr.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
name: Automerge Batches
on:
schedule:
- cron: '*/5 * * * *' # Run every 5 minutes
jobs:
batch-merge:
runs-on: ubuntu-latest
steps:
- name: List Pull Requests Ready for Merge
id: pr_list
uses: actions/github-script@v6
with:
script: |
const { data: pullRequests } = await github.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'updated',
direction: 'desc',
});
const prNumbers = pullRequests
.filter(pr => pr.labels.some(label => label.name === 'automerge'))
.map(pr => pr.number);
if (prNumbers.length > 0) {
return prNumbers.join(',');
} else {
return '';
}
- name: Merge PRs
if: steps.pr_list.outputs.result != ''
uses: actions/github-script@v6
with:
script: |
const prNumbers = ${{ steps.pr_list.outputs.result }}.split(',');
for (const pr of prNumbers) {
await github.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr,
merge_method: 'squash',
});
}