-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
96 lines (87 loc) · 3.6 KB
/
update-labels.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
name: Check labels to update
on:
pull_request_target:
types:
[
review_requested,
ready_for_review,
review_request_removed,
converted_to_draft,
synchronize,
edited,
]
pull_request_review:
types: [submitted, edited, dismissed]
pull_request_review_comment:
types: [created, edited]
issue_comment:
types: [created, edited]
jobs:
update-labels:
runs-on: ubuntu-latest
env:
PR_NUM: ${{ github.event.pull_request.number || github.event.issue.number }}
steps:
- name: Set up varibles
run: |
echo "REVIEW=0" >> $GITHUB_ENV
echo "UPDATE=0" >> $GITHUB_ENV
- name: Add 'waiting for review' label
# when a review is requested or if the PR is converted from a draft
if: |
github.event_name == 'pull_request_target' &&
contains(fromJSON('["review_requested", "ready_for_review"]'), github.event.action)
run: echo "REVIEW=1" >> $GITHUB_ENV
- name: Remove 'waiting for review' label
# when a review request is removed or if the PR is converted to a draft
# or when the PR is reviewed by the owner, a member or a collaborator
if: |
(
github.event_name == 'pull_request_target' &&
contains(fromJSON('["review_request_removed", "converted_to_draft"]'), github.event.action)
) ||
(
github.event_name == 'pull_request_review' &&
contains(fromJSON('["submitted", "edited"]'), github.event.action) &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.review.author_association)
)
run: echo "REVIEW=-1" >> $GITHUB_ENV
- name: Add 'waiting for update' label
# when a review by one of {owner, member, collaborator} requests changes
if: |
github.event_name == 'pull_request_review' &&
github.event.review.state == 'changes_requested' &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.review.author_association)
run: echo "UPDATE=1" >> $GITHUB_ENV
- name: Remove 'waiting for update' label from PR/issue
# when PR is commited to or if the PR is edited or if a review is requested or dismissed
# or when a comment is added by the author to the review or to the main PR thread
if: |
(
github.event_name == 'pull_request_target' &&
contains(fromJSON('["synchronize", "edited", "review_requested"]'), github.event.action)
) ||
(
github.event_name == 'pull_request_review' &&
github.event.action == 'dismissed'
) ||
(
github.event_name == 'pull_request_review_comment' &&
contains(fromJSON('["created", "edited"]'), github.event.action) &&
github.event.comment.user.id == github.event.pull_request.user.id
) ||
(
github.event_name == 'issue_comment' &&
contains(fromJSON('["created", "edited"]'), github.event.action) &&
github.event.comment.user.id == github.event.issue.user.id
)
run: echo "UPDATE=-1" >> $GITHUB_ENV
- name: Save result in a JSON file
env:
LABELS_JSON: ${{ format('{{"waiting_for_review"{0} "{1}", "waiting_for_update"{0} "{2}", "pr_num"{0} "{3}"}}', ':', env.REVIEW, env.UPDATE, env.PR_NUM) }}
run: echo $LABELS_JSON > write-labels.json
- name: Upload the JSON file
uses: actions/upload-artifact@v4
with:
name: labels
path: ./write-labels.json