-
Notifications
You must be signed in to change notification settings - Fork 331
143 lines (130 loc) · 6.07 KB
/
add_label_from_review.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Add "ready-to-merge" and "delegated" label from PR review
on:
pull_request_review:
types: [submitted]
jobs:
add_ready_to_merge_label:
name: Add ready-to-merge label
if: (startsWith(github.event.review.body, 'bors r+') || contains(toJSON(github.event.review.body), '\r\nbors r+') || startsWith(github.event.review.body, 'bors merge') || contains(toJSON(github.event.review.body), '\r\nbors merge'))
runs-on: ubuntu-latest
steps:
- uses: octokit/[email protected]
name: Get PR head
id: get_pr_head
with:
route: GET /repos/:repository/pulls/:pull_number
repository: ${{ github.repository }}
pull_number: ${{ github.event.pull_request.number }}
env:
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }}
# Parse steps.get_pr_head.outputs.data, since it is a string
- id: parse_pr_head
name: Parse PR head
uses: gr2m/[email protected]
with:
json: ${{ steps.get_pr_head.outputs.data }}
head_user: 'head.user.login'
# we skip the rest if this PR is from a fork,
# since the GITHUB_TOKEN doesn't have write perms
- if: steps.parse_pr_head.outputs.head_user == 'leanprover-community'
uses: octokit/[email protected]
name: Get comment author
id: get_user
with:
route: GET /repos/:repository/collaborators/:username/permission
repository: ${{ github.repository }}
username: ${{ github.event.review.user.login }}
env:
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }}
# Parse steps.get_user.outputs.data, since it is a string
- if: steps.parse_pr_head.outputs.head_user == 'leanprover-community'
id: parse_user
name: Parse comment author permission
uses: gr2m/[email protected]
with:
json: ${{ steps.get_user.outputs.data }}
permission: 'permission'
- if: (steps.parse_pr_head.outputs.head_user == 'leanprover-community') && (steps.parse_user.outputs.permission == 'admin')
uses: octokit/[email protected]
id: add_label
name: Add label
with:
route: POST /repos/:repository/issues/:issue_number/labels
repository: ${{ github.repository }}
issue_number: ${{ github.event.pull_request.number }}
labels: '["ready-to-merge"]'
env:
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }}
- if: (steps.parse_pr_head.outputs.head_user == 'leanprover-community') && (steps.parse_user.outputs.permission == 'admin')
id: remove_labels
name: Remove "awaiting-review" and "awaiting-author"
# we use curl rather than octokit/request-action so that the job won't fail
# (and send an annoying email) if the labels don't exist
run: |
curl --request DELETE \
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/awaiting-review \
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}'
curl --request DELETE \
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/awaiting-author \
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}'
add_delegated_label:
name: Add delegated label
if: (startsWith(github.event.review.body, 'bors d') || contains(toJSON(github.event.review.body), '\r\nbors d'))
runs-on: ubuntu-latest
steps:
- uses: octokit/[email protected]
name: Get PR head
id: get_pr_head
with:
route: GET /repos/:repository/pulls/:pull_number
repository: ${{ github.repository }}
pull_number: ${{ github.event.pull_request.number }}
env:
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }}
# Parse steps.get_pr_head.outputs.data, since it is a string
- id: parse_pr_head
name: Parse PR head
uses: gr2m/[email protected]
with:
json: ${{ steps.get_pr_head.outputs.data }}
head_user: 'head.user.login'
# we skip the rest if this PR is from a fork,
# since the GITHUB_TOKEN doesn't have write perms
- if: steps.parse_pr_head.outputs.head_user == 'leanprover-community'
uses: octokit/[email protected]
name: Get comment author
id: get_user
with:
route: GET /repos/:repository/collaborators/:username/permission
repository: ${{ github.repository }}
username: ${{ github.event.review.user.login }}
env:
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }}
# Parse steps.get_user.outputs.data, since it is a string
- if: steps.parse_pr_head.outputs.head_user == 'leanprover-community'
id: parse_user
name: Parse comment author permission
uses: gr2m/[email protected]
with:
json: ${{ steps.get_user.outputs.data }}
permission: 'permission'
- if: (steps.parse_pr_head.outputs.head_user == 'leanprover-community') && (steps.parse_user.outputs.permission == 'admin')
uses: octokit/[email protected]
id: add_label
name: Add label
with:
route: POST /repos/:repository/issues/:issue_number/labels
repository: ${{ github.repository }}
issue_number: ${{ github.event.pull_request.number }}
labels: '["delegated"]'
env:
GITHUB_TOKEN: ${{ secrets.TRIAGE_TOKEN }}
- if: (steps.parse_pr_head.outputs.head_user == 'leanprover-community') && (steps.parse_user.outputs.permission == 'admin')
id: remove_labels
name: Remove "awaiting-review"
# we use curl rather than octokit/request-action so that the job won't fail
# (and send an annoying email) if the labels don't exist
run: |
curl --request DELETE \
--url https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/awaiting-review \
--header 'authorization: Bearer ${{ secrets.TRIAGE_TOKEN }}'