forked from apache/helix
-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (64 loc) · 2.65 KB
/
Helix-PR-Premerge-Check.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
# Verify if the PR meets all the requirements for merging on PR review event.
name: PR Pre-merge Check
on:
pull_request_target:
types: [opened, synchronize, reopened, edited]
jobs:
validate_PR:
runs-on: ubuntu-latest
steps:
- name: Label PR if ready to be merged.
uses: actions/github-script@v3
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const approvalLabel = 'CheckedAndApproved'
const reviews = await github.pulls.listReviews({
pull_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo
})
// Check if any recent APPROVED or CHANGES_REQUESTED reviews.
var approved = false
for (const review_info of reviews.data) {
if (review_info.author_association == 'NONE' || review_info.author_association == 'FIRST_TIMER' || review_info.author_association == 'FIRST_TIME_CONTRIBUTOR') {
continue
}
if (review_info.state == 'APPROVED') {
approved = true
} else if (review_info.state == 'CHANGES_REQUESTED') {
approved = false
}
}
if (approved) {
console.log("This PR has been approved.")
github.issues.addLabels({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [approvalLabel]
})
} else {
console.log("This PR has not been approved.")
const labels_info = await github.issues.listLabelsOnIssue({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo
})
var approvalLabelExist = false
for (const label of labels_info.data) {
if (label.name == approvalLabel) {
approvalLabelExist = true
break
}
}
if (approvalLabelExist) {
github.issues.removeLabel({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: approvalLabel
})
}
}
if: ${{ (!contains(github.event.pull_request.body, '[ ]') || contains(github.event.pull_request.labels.*.name, 'CheckedAndApproved')) && (github.event.pull_request.state == 'open') }}