-
Notifications
You must be signed in to change notification settings - Fork 5
60 lines (54 loc) · 2.02 KB
/
tag-merge-conflicts.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
name: Tag Merge Conflicts
on:
push:
branches: ['develop']
pull_request:
branches: ['develop']
jobs:
merge-conflicts:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v6
with:
script: |
const pullRequests = (await github.rest.pulls.list({
...context.repo
})).data
const addMergeConflictTag = async (pullRequests) => {
const promises = pullRequests.map(pr => {
const { number } = pr
return github.rest.pulls.get({
...context.repo,
pull_number: number
})
})
const prs = await Promise.allSettled(promises)
const prsAwaitingCheck = []
prs.forEach(pr => {
const data = pr.value.data
if (data.mergeable === false) {
github.rest.issues.addLabels({
...context.repo,
issue_number: data.number,
labels: ["merge conflict"]
})
} else if (data.mergeable === true
&& data.labels.some(label => label.name === "merge conflict")) {
github.rest.issues.removeLabel({
...context.repo,
issue_number: data.number,
name: "merge conflict"
})
} else if (data.mergeable === null) {
prsAwaitingCheck.push({...data})
}
})
if (prsAwaitingCheck.length) {
console.log("Some PRs are still waiting to calculate status...")
await new Promise(resolve => setTimeout(resolve, 5000))
addMergeConflictTag(prsAwaitingCheck)
}
}
await addMergeConflictTag(pullRequests)