-
-
Notifications
You must be signed in to change notification settings - Fork 23
392 lines (356 loc) · 14.3 KB
/
pr-labeler.yml
File metadata and controls
392 lines (356 loc) · 14.3 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
name: PR Labeler
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft, edited]
pull_request_review_comment:
types: [created]
issue_comment:
types: [created]
schedule:
# Run every day at 00:00 UTC to check for stale PRs
- cron: '0 0 * * *'
permissions: {}
jobs:
label-by-files:
name: Label by Changed Files
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
if: github.event_name == 'pull_request'
steps:
- name: Label based on changed files
uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6.0.1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
configuration-path: .github/labeler.yml
sync-labels: false
label-by-size:
name: Label by PR Size
runs-on: ubuntu-latest
permissions:
pull-requests: write
if: github.event_name == 'pull_request'
steps:
- name: Label PR by size
uses: codelytv/pr-size-labeler@4ec67706cd878fbc1c8db0a5dcd28b6bb412e85a # v1.10.3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
xs_label: 'size/XS'
xs_max_size: '10'
s_label: 'size/S'
s_max_size: '100'
m_label: 'size/M'
m_max_size: '500'
l_label: 'size/L'
l_max_size: '1000'
xl_label: 'size/XL'
fail_if_xl: 'false'
message_if_xl: >
This PR is very large. Consider splitting it into smaller PRs for easier review.
files_to_ignore: |
*.lock
*.md
uv.lock
label-pr-status:
name: Label PR Status
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
if: github.event_name == 'pull_request'
steps:
- name: Check for merge conflicts
uses: eps1lon/actions-label-merge-conflict@1df065ebe6e3310545d4f4c4e862e43bdca146f0 # v3.0.3
with:
dirtyLabel: 'status/conflicts'
repoToken: ${{ secrets.GITHUB_TOKEN }}
- name: Label draft PRs
if: github.event.pull_request.draft == true
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['status/draft']
});
- name: Remove draft label when ready
if: github.event.pull_request.draft == false && github.event.action == 'ready_for_review'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'status/draft'
});
} catch (error) {
// Label might not exist, ignore error
console.log('Draft label not found or already removed');
}
label-stale-prs:
name: Label Stale PRs
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
if: github.event_name == 'schedule'
steps:
- name: Mark stale PRs
uses: actions/stale@997185467fa4f803885201cee163a9f38240193d # v10.1.1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: |
This pull request has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs within the next 7 days.
Please comment if this PR is still relevant and should remain open.
stale-pr-label: 'status/stale'
days-before-stale: 30
days-before-close: 7
exempt-pr-labels: 'status/on-hold,status/blocked,priority/critical'
exempt-draft-pr: true
operations-per-run: 100
remove-stale-when-updated: true
close-pr-message: |
This pull request has been automatically closed due to inactivity.
If you would like to continue working on this, please reopen the PR or create a new one.
check-blocked-status:
name: Check for Blocked Status
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
if: github.event_name == 'pull_request' || github.event_name == 'issue_comment' || github.event_name == 'pull_request_review_comment'
steps:
- name: Check for blocked keywords in comments
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const blockedKeywords = [
'blocked',
'blocking',
'waiting for',
'depends on',
'blocked by',
'do not merge',
'dnm'
];
const onHoldKeywords = [
'on hold',
'place on hold',
'waiting for decision',
'needs discussion',
'awaiting decision'
];
let pullNumber;
// Get the PR number depending on the event type
if (context.eventName === 'pull_request') {
pullNumber = context.payload.pull_request.number;
} else if (context.eventName === 'issue_comment' && context.payload.issue.pull_request) {
pullNumber = context.payload.issue.number;
} else if (context.eventName === 'pull_request_review_comment') {
pullNumber = context.payload.pull_request.number;
} else {
console.log('Not a pull request event, skipping');
return;
}
// Get all comments on the PR (issue comments) with pagination
let allComments = [];
let page = 1;
let hasMore = true;
while (hasMore) {
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullNumber,
per_page: 100,
page: page
});
allComments = allComments.concat(comments.data);
hasMore = comments.data.length === 100;
page++;
}
// Get review comments with pagination
let allReviewComments = [];
page = 1;
hasMore = true;
while (hasMore) {
const reviewComments = await github.rest.pulls.listReviewComments({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullNumber,
per_page: 100,
page: page
});
allReviewComments = allReviewComments.concat(reviewComments.data);
hasMore = reviewComments.data.length === 100;
page++;
}
// Get PR details for body and title
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullNumber
});
// Check title, body, issue comments, and review comments for blocked keywords
const allText = [
pr.data.title.toLowerCase(),
pr.data.body?.toLowerCase() || '',
...allComments.map(c => c.body?.toLowerCase() || ''),
...allReviewComments.map(c => c.body?.toLowerCase() || '')
].join(' ');
// Helper function to escape regex special characters
function escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
// Check with word boundaries to avoid false positives
const isBlocked = blockedKeywords.some(keyword => {
const pattern = new RegExp(`\\b${escapeRegExp(keyword)}\\b`, 'i');
return pattern.test(allText);
});
const isOnHold = onHoldKeywords.some(keyword => {
const pattern = new RegExp(`\\b${escapeRegExp(keyword)}\\b`, 'i');
return pattern.test(allText);
});
// Get current labels
const currentLabels = pr.data.labels.map(l => l.name);
// Add blocked label if detected
if (isBlocked && !currentLabels.includes('status/blocked')) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullNumber,
labels: ['status/blocked']
});
console.log('Added status/blocked label');
}
// Add on-hold label if detected
if (isOnHold && !currentLabels.includes('status/on-hold')) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullNumber,
labels: ['status/on-hold']
});
console.log('Added status/on-hold label');
}
// Remove blocked label if no longer blocked
if (!isBlocked && currentLabels.includes('status/blocked')) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullNumber,
name: 'status/blocked'
});
console.log('Removed status/blocked label');
} catch (error) {
console.log('Failed to remove status/blocked label');
}
}
// Remove on-hold label if no longer on hold
if (!isOnHold && currentLabels.includes('status/on-hold')) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pullNumber,
name: 'status/on-hold'
});
console.log('Removed status/on-hold label');
} catch (error) {
console.log('Failed to remove status/on-hold label');
}
}
check-needs-review:
name: Check Needs Review Status
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
if: github.event_name == 'pull_request'
steps:
- name: Label PRs needing review
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const pr = context.payload.pull_request;
// Skip draft PRs
if (pr.draft) {
console.log('PR is draft, skipping review check');
return;
}
// Get reviews
const reviews = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pr.number
});
// Get the latest review per reviewer, excluding dismissed reviews
const latestReviewsByUser = {};
const activeReviews = reviews.data.filter(review => review.state !== 'DISMISSED');
for (const review of activeReviews) {
const userId = review.user.id;
if (!latestReviewsByUser[userId] ||
new Date(review.submitted_at) > new Date(latestReviewsByUser[userId].submitted_at)) {
latestReviewsByUser[userId] = review;
}
}
const latestReviews = Object.values(latestReviewsByUser);
// Check latest review states
const hasApproval = latestReviews.some(review => review.state === 'APPROVED');
const hasChangesRequested = latestReviews.some(review => review.state === 'CHANGES_REQUESTED');
// Get current labels
const currentLabels = pr.labels.map(l => l.name);
// Add needs-review if no reviews and not already labeled
if (latestReviews.length === 0 && !currentLabels.includes('status/needs-review')) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: ['status/needs-review']
});
console.log('Added status/needs-review label');
}
// Add changes-requested if changes were requested
if (hasChangesRequested && !currentLabels.includes('status/changes-requested')) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: ['status/changes-requested']
});
console.log('Added status/changes-requested label');
}
// Remove needs-review if there are reviews
if (latestReviews.length > 0 && currentLabels.includes('status/needs-review')) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
name: 'status/needs-review'
});
console.log('Removed status/needs-review label');
} catch (error) {
console.log('Failed to remove status/needs-review label');
}
}
// Remove changes-requested if approved or changes addressed
if (hasApproval && currentLabels.includes('status/changes-requested')) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
name: 'status/changes-requested'
});
console.log('Removed status/changes-requested label');
} catch (error) {
console.log('Failed to remove status/changes-requested label');
}
}