-
Notifications
You must be signed in to change notification settings - Fork 14
80 lines (74 loc) · 2.53 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
70
71
72
73
74
75
76
77
78
79
80
name: "PR Merge on time v3"
on:
schedule:
- cron: '0,10 1 * * *'
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@v6"
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
labels(first: 10) {
nodes {
name
}
}
reviews(last: 1) {
nodes {
state
}
}
}
}
}
}
}`
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" || !node.labels.nodes.length) continue;
if (node.reviews.nodes.length && node.reviews.nodes[0].state === "CHANGES_REQUESTED") continue;
try {
if(node.mergeable === "CONFLICTING") {
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: node.number,
state: "closed"
})
} else {
await github.rest.pulls.merge({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: node.number,
merge_method: "merge"
})
}
} catch (e) {
console.log("error", e);
}
}