-
Notifications
You must be signed in to change notification settings - Fork 317
107 lines (90 loc) · 3.31 KB
/
force-merge.yml
File metadata and controls
107 lines (90 loc) · 3.31 KB
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
101
102
103
104
105
106
name: "Force merge automation"
description: Merge a pull request when N committers post a comment with the command /force-merge
on:
issue_comment:
types: [created, edited]
permissions:
contents: write
pull-requests: write
issues: read
env:
quorum: 3
jobs:
force_merge:
runs-on: ubuntu-latest
steps:
- name: Check pull request
id: should-run
uses: actions/github-script@v7
with:
script: |
const issue = await github.rest.issues.get({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
const isPR = issue.data.pull_request != null
const isClosed = issue.data.closed_at != null
const isDraft = issue.data.draft
return isPR && !isClosed && !isDraft
- name: Count votes
id: count-votes
if: ${{ steps.should-run.outputs.result == 'true' }}
uses: actions/github-script@v7
with:
script: |
const comments = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
const votes = new Map();
for(const comment of comments.data) {
const hasVotingRights = comment.author_association === 'MEMBER' || comment.author_association === 'OWNER'
const hasCastedVote = comment.body === '/force-merge'
if(hasVotingRights && hasCastedVote) {
votes.set(comment.user.login, comment.author_association);
}
}
// Display voters and role
console.table(votes)
return votes.size
- name: Set lables
if: ${{ steps.should-run.outputs.result == 'true' }}
uses: actions/github-script@v7
with:
script: |
const labels = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
const labelsToAdd = []
for(const label of labels.data) {
if(!label.name.startsWith('force-merge-votes-')) {
labelsToAdd.push(label.name)
}
}
const votes = ${{ steps.count-votes.outputs.result }}
if(votes >= 1 && votes < ${{env.quorum}}) {
labelsToAdd.push("force-merge-votes-" + votes)
}
console.log(labelsToAdd) // Debug
const result = github.rest.issues.setLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: labelsToAdd
})
- name: Perform merge
if: ${{ (steps.should-run.outputs.result == 'true') && (steps.count-votes.outputs.result >= env.quorum) }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.KURA_BOT_GITHUB_TOKEN }}
script: |
await github.rest.pulls.merge({
pull_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
merge_method: "squash"
});