-
-
Notifications
You must be signed in to change notification settings - Fork 579
135 lines (121 loc) · 5.1 KB
/
labeler.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
#/
# @license Apache-2.0
#
# Copyright (c) 2024 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/
# Workflow name:
name: labeler
# Workflow triggers:
on:
pull_request_target:
types:
- opened
- synchronize
- reopened
- edited
- review_requested
- review_request_removed
- ready_for_review
- converted_to_draft
- labeled
# Workflow jobs:
jobs:
# Define a job which automatically labels pull requests based on the contents of the pull request:
labeler:
# Define job name:
name: 'Labeler'
# Only run this job if the pull request did not have label `automated-pr`:
if: contains(github.event.pull_request.labels.*.name, 'automated-pr') == false
# Define job permissions:
permissions:
contents: read
pull-requests: write
# Define the type of virtual host machine:
runs-on: ubuntu-latest
# Define the sequence of job steps:
steps:
# Automatically label pull requests:
- name: 'Automatically label pull requests'
# Pin action to full length commit SHA
uses: actions/labeler@8558fd74291d67161a8a78ce36a881fa63b766a9 # v5.0.0
with:
configuration-path: .github/labeler.yml
repo-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
# Add "Needs Review" label when PR is opened and not a draft:
- name: 'Add "Needs Review" label if PR is opened and not draft'
if: ${{ github.event.action == 'opened' && github.event.pull_request.draft == false }}
# Pin action to full length commit SHA
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
script: |
await github.rest.issues.addLabels({
'owner': context.repo.owner,
'repo': context.repo.repo,
'issue_number': context.payload.pull_request.number,
'labels': [ 'Needs Review' ]
})
# Add "Needs Review" label when PR is marked ready for review or review is requested:
- name: 'Add "Needs Review" label if PR is ready for review or review is requested'
if: ${{ github.event.action == 'ready_for_review' || github.event.action == 'review_requested' }}
# Pin action to full length commit SHA
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
script: |
await github.rest.issues.addLabels({
'owner': context.repo.owner,
'repo': context.repo.repo,
'issue_number': context.payload.pull_request.number,
'labels': [ 'Needs Review' ]
})
# Remove "Needs Review" label when PR is converted to draft or closed:
- name: 'Remove "Needs Review" label if PR is converted to draft or closed'
if: ${{ github.event.action == 'converted_to_draft' || github.event.action == 'closed' }}
# Pin action to full length commit SHA
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
'owner': context.repo.owner,
'repo': context.repo.repo,
'issue_number': context.payload.pull_request.number,
'name': 'Needs Review'
})
} catch ( error ) {
console.log( 'Error removing label: %s', error.message );
}
# Remove "Needs Review" and "Needs Changes" labels when "Ready To Merge" is assigned:
- name: 'Remove "Needs Review" and "Needs Changes" labels when "Ready To Merge" is assigned'
if: ${{ github.event.action == 'labeled' && github.event.label.name == 'Ready To Merge' }}
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
script: |
const labelsToRemove = [ 'Needs Review', 'Needs Changes' ];
for ( const label of labelsToRemove ) {
try {
await github.rest.issues.removeLabel({
'owner': context.repo.owner,
'repo': context.repo.repo,
'issue_number': context.payload.pull_request.number,
'name': label
})
} catch ( error ) {
console.log( 'Error removing label %s: %s', label, error.message );
}
}