-
Notifications
You must be signed in to change notification settings - Fork 13
68 lines (63 loc) · 2.09 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
name: "PR Merge on time v2"
on:
schedule:
- cron: '*/10 * * * *'
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
merge:
name: "Auto Merge on time"
runs-on: "ubuntu-latest"
steps:
- name: "Merge pull request"
uses: "actions/github-script@v3"
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const query = `query($owner:String!, $name:String!) {
repository(owner: $owner, name: $name) {
pullRequests(last: 100, states: OPEN) {
edges {
node {
number
headRefName
baseRefName
author {
login
}
repository {
name
}
mergeable
}
}
}
}
}`
const variables = {
owner: context.repo.owner,
name: context.repo.repo,
}
const {repository:{pullRequests:{edges: list}}} = await github.graphql(query, variables)
for( let {node} of list) {
if(node.baseRefName === "main") continue;
try {
if(node.mergeable === "CONFLICTING") {
await github.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: node.number,
state: "closed"
})
} else {
await github.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: node.number,
merge_method: "squash"
})
}
} catch (e) {
console.log("error", e);
}
}