-
Notifications
You must be signed in to change notification settings - Fork 1
89 lines (78 loc) Β· 2.99 KB
/
review-status-labeling.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
81
82
83
84
85
86
87
88
89
name: 'Review Status Labeling'
on:
pull_request:
types: [opened, edited, reopened, ready_for_review]
pull_request_review:
types: [submitted, edited]
jobs:
labeler:
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2
- name: Count Approvals
id: count_approvals
uses: actions/github-script@v6
with:
github-token: ${{ secrets.ACTIONS_TOKEN }}
script: |
const reviewsResponse = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const approvedReviews = reviewsResponse.data.filter(review => review.state === 'APPROVED');
return approvedReviews.length;
- name: Get Labels
id: get_labels
uses: actions/github-script@v6
with:
github-token: ${{ secrets.ACTIONS_TOKEN }}
script: |
const labelsResponse = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
return labelsResponse.data.map(label => label.name);
- name: Apply Labels
uses: actions/github-script@v6
with:
github-token: ${{ secrets.ACTIONS_TOKEN }}
script: |
const labelNameList = ${{ steps.get_labels.outputs.result }};
if (${{ steps.count_approvals.outputs.result }} === 0) {
if (labelNameList.includes('Approved π') === true) {
await github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Approved π'
});
}
if (labelNameList.length === 0 || labelNameList.includes('Review Plzπ') === false) {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Review Plzπ']
});
}
} else {
if (labelNameList.includes('Review Plzπ') === true) {
await github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'Review Plzπ'
});
}
if (labelNameList.includes('Approved π') === false) {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['Approved π']
});
}
}