-
Notifications
You must be signed in to change notification settings - Fork 172
819 lines (729 loc) · 30.9 KB
/
Copy pathpr-labeler.yml
File metadata and controls
819 lines (729 loc) · 30.9 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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
name: PR Labeler
on:
pull_request_target:
types: [opened, synchronize, reopened, ready_for_review, closed, labeled]
pull_request_review:
types: [submitted, edited, dismissed]
issue_comment:
types: [created]
permissions: {}
jobs:
# ── PR Validation (opened, synchronize, reopened, ready_for_review) ──────────
pr-validation:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
if: |
github.event_name == 'pull_request_target' &&
(
github.event.action == 'opened' ||
github.event.action == 'synchronize' ||
github.event.action == 'reopened' ||
github.event.action == 'ready_for_review'
)
outputs:
valid: ${{ steps.assignment.outputs.valid }}
steps:
- name: Welcome New PR Contributors (First Interaction)
if: github.event.action == 'opened'
uses: actions/first-interaction@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
pr-message: |
Hello there! 🎉 Thank you so much for your first pull request to DoubtDesk!
We really appreciate your contribution. A maintainer will review your code soon. If you are participating in GSSoC, ensure your PR is linked to an open issue. Please make sure you have followed all rules in our [Contributing Guidelines](https://github.com/knoxiboy/DoubtDesk/blob/main/CONTRIBUTING.md). Happy coding!
- name: Verify PR author is assigned to linked issue
id: assignment
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prAuthor = context.payload.pull_request.user.login;
const prBody = context.payload.pull_request.body || '';
const prNumber = context.payload.pull_request.number;
// Skip check for repo owner/maintainers
try {
const { data: perm } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: prAuthor,
});
if (['admin', 'write'].includes(perm.permission)) {
console.log(`${prAuthor} is a maintainer — skipping assignment check.`);
core.setOutput('valid', 'true');
return;
}
} catch (e) {
console.log('Could not check permission:', e.message);
}
// Extract linked issue numbers from PR body
const bodyMatches = prBody.matchAll(
/(?:closes?|fixes?|resolves?)\s+#(\d+)/gi
);
const linkedIssuesSet = new Set(
[...bodyMatches].map(m => parseInt(m[1]))
);
// Check branch name for leading numbers
const prBranch = context.payload.pull_request.head.ref || '';
const branchMatch = prBranch.match(/(?:^|\/|-)(\d+)(?:-|$)/);
if (branchMatch) {
const num = parseInt(branchMatch[1], 10);
if (num > 0 && num < 10000) {
linkedIssuesSet.add(num);
}
}
const linkedIssues = Array.from(linkedIssuesSet);
if (linkedIssues.length === 0) {
console.log('No linked issues found. Closing PR.');
core.setOutput('valid', 'false');
const comment = "We are closing this pr as it has no linking issue to it. If your is actually related to a isssue assigned to u then create a new pr and link the issue in discription.";
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment,
});
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['invalid'],
});
} catch (e) {
console.log(`Failed to add invalid label: ${e.message}`);
}
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
state: 'closed',
});
return;
}
console.log(`PR #${prNumber} by @${prAuthor} links to issues: ${linkedIssues.join(', ')}`);
const violations = [];
for (const issueNumber of linkedIssues) {
let issue;
try {
const { data } = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
});
issue = data;
} catch (e) {
console.log(`Could not fetch issue #${issueNumber}: ${e.message} — skipping.`);
continue;
}
const assignees = issue.assignees.map(a => a.login.toLowerCase());
const isAssigned = assignees.includes(prAuthor.toLowerCase());
console.log(`Issue #${issueNumber} assignees: [${assignees.join(', ')}] — @${prAuthor} assigned: ${isAssigned}`);
if (!isAssigned) {
violations.push({
issueNumber,
assignees: issue.assignees.map(a => a.login),
reason: assignees.length === 0
? `Issue #${issueNumber} has no assignees. Please request assignment before submitting a PR.`
: `Issue #${issueNumber} is assigned to @${issue.assignees.map(a => a.login).join(', @')} — not to @${prAuthor}.`,
});
}
}
if (violations.length === 0) {
console.log(`✅ @${prAuthor} is assigned to all linked issues.`);
core.setOutput('valid', 'true');
return;
}
core.setOutput('valid', 'false');
const marker = '<!-- pr-assignment-check -->';
const violationLines = violations
.map(v => `- **#${v.issueNumber}**: ${v.reason}`)
.join('\n');
const comment = [
marker,
`## ❌ PR Rejected — Issue Assignment Check Failed`,
``,
`Hi @${prAuthor}! This PR has been **closed** because you are not assigned to the issue(s) it references:`,
``,
violationLines,
``,
`**What to do:**`,
`1. Comment \`/assign\` on the issue to request assignment from a maintainer.`,
`2. Wait until you are officially assigned.`,
`3. Then re-open or re-submit your PR.`,
``,
`> PRs that fix issues not assigned to the author cannot be accepted — this ensures fair contribution tracking.`,
].join('\n');
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: comment,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: comment,
});
}
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['invalid'],
});
} catch (e) {
console.log(`Failed to add invalid label: ${e.message}`);
}
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
state: 'closed',
});
console.log(`❌ Closed PR #${prNumber} — @${prAuthor} not assigned.`);
- name: Verify author has starred repo and assign reviewers
if: |
steps.assignment.outputs.valid == 'true' &&
github.event.action != 'synchronize'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const author = context.payload.pull_request.user.login;
const prNumber = context.payload.pull_request.number;
// 1. Verify Star status
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});
const existingStarReview = reviews.find(
r => r.user.login === 'github-actions[bot]' &&
r.body && r.body.includes('Please star the DoubtDesk repository')
);
let hasStarred = false;
try {
let page = 1;
const perPage = 100;
let found = false;
while (page <= 100) {
const { data: stargazers } = await github.rest.activity.listStargazersForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: perPage,
page: page,
});
if (stargazers.length === 0) break;
if (stargazers.some(s => s.login.toLowerCase() === author.toLowerCase())) {
found = true;
break;
}
if (stargazers.length < perPage) break;
page++;
}
hasStarred = found;
} catch (e) {
console.error('Error checking stargazers:', e.message);
hasStarred = true; // Fallback
}
if (hasStarred) {
console.log(`✅ @${author} has starred the repository.`);
if (existingStarReview && existingStarReview.state === 'CHANGES_REQUESTED') {
try {
await github.rest.pulls.dismissReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
review_id: existingStarReview.id,
message: 'Star verified ✅',
});
} catch (e) {
console.log('Could not dismiss old star review:', e.message);
}
}
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
labels: ['review-needed'],
});
} catch (e) {
console.log('Could not add review-needed label:', e.message);
}
} else {
if (!existingStarReview) {
await github.rest.pulls.createReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
body: `### ⭐ Star Required\n\nHi @${author}! Thank you for your contribution to DoubtDesk.\n\nBefore we can complete the review and merge this pull request, please **star the DoubtDesk repository**.\n\nOnce you have starred the repository, please drop a comment here saying "done" and we will proceed with reviewing your PR. Thank you!`,
event: 'REQUEST_CHANGES',
});
console.log(`⭐ Requested @${author} to star the repo.`);
}
}
// 2. Assign Author and Reviewers
const maintainers = ['knoxiboy'];
try {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
assignees: [author],
});
} catch (e) {
console.log('Could not assign author:', e.message);
}
const reviewers = maintainers.filter(m => m !== author);
if (reviewers.length > 0) {
try {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
reviewers,
});
console.log(`Requested review from: ${reviewers.join(', ')}`);
} catch (e) {
console.log('Could not assign human reviewers:', e.message);
}
}
try {
await github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
reviewers: ['copilot'],
});
console.log('Requested review from GitHub Copilot');
} catch (e) {
console.log('Could not request Copilot review:', e.message);
}
const rabbitMarker = '<!-- coderabbit-trigger -->';
const { data: prComments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const hasCodeRabbitComment = prComments.some(
c => c.body && (c.body.includes(rabbitMarker) || c.body.includes('@coderabbitai review'))
);
if (!hasCodeRabbitComment) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `${rabbitMarker}\n@coderabbitai review\n@codeantai review`,
});
console.log('Requested CodeRabbit and CodeAntAI review');
}
# ── Size Labeling (only on PR creation, update, or labeling) ──────────────────
size-labeling:
runs-on: ubuntu-latest
needs: pr-validation
permissions:
issues: write
pull-requests: write
if: |
always() &&
(
github.event_name == 'pull_request_target' &&
(
github.event.action == 'opened' ||
github.event.action == 'synchronize' ||
github.event.action == 'reopened' ||
github.event.action == 'labeled'
)
) &&
(needs.pr-validation.result == 'success' || needs.pr-validation.result == 'skipped')
steps:
- name: Calculate and apply size label
if: github.event.action != 'labeled'
uses: pascalgn/size-label-action@v0.5.0
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
with:
sizes: >
{
"0": "xs",
"20": "s",
"50": "m",
"200": "l",
"800": "xl",
"2000": "xxl"
}
- name: Handle exclusive size labels and normalization
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const number = context.payload.pull_request.number;
const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
});
const currentLabelNames = currentLabels.map(l => l.name);
if (context.payload.action === 'labeled') {
const addedLabel = context.payload.label.name.toLowerCase();
if (!addedLabel.startsWith('size/') && !addedLabel.startsWith('size:')) {
return;
}
}
const sizeMapping = {
'size:xs': 'size/xs', 'size:s': 'size/s', 'size:m': 'size/m',
'size:l': 'size/l', 'size:xl': 'size/xl', 'size:xxl': 'size/xxl',
};
for (const labelName of currentLabelNames) {
const lower = labelName.toLowerCase();
if (sizeMapping[lower] && sizeMapping[lower] !== labelName) {
const mapped = sizeMapping[lower];
console.log(`Normalizing "${labelName}" to "${mapped}"`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
labels: [mapped],
});
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
name: labelName,
});
} catch (e) {
console.log(`Could not remove "${labelName}": ${e.message}`);
}
}
}
const { data: updatedLabels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
});
const standardSizes = new Set([
'size/xs', 'size/s', 'size/m', 'size/l', 'size/xl', 'size/xxl'
]);
const appliedSizes = updatedLabels.filter(
l => standardSizes.has(l.name.toLowerCase())
);
if (appliedSizes.length <= 1) return;
let keepLabel = appliedSizes[appliedSizes.length - 1].name;
if (context.payload.action === 'labeled') {
const addedLabelName = context.payload.label.name;
const normalizedAdded = sizeMapping[addedLabelName.toLowerCase()] || addedLabelName;
const match = appliedSizes.find(l => l.name.toLowerCase() === normalizedAdded.toLowerCase());
if (match) keepLabel = match.name;
}
for (const label of appliedSizes) {
if (label.name !== keepLabel) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
name: label.name,
});
console.log(`Removed conflicting size label "${label.name}" (kept "${keepLabel}")`);
} catch (e) {
console.log(`Could not remove "${label.name}": ${e.message}`);
}
}
}
# ── PR Status Checks and Lifecycle ────────────────────────────────────────────
pr-status-and-lifecycle:
runs-on: ubuntu-latest
needs: pr-validation
permissions:
issues: write
pull-requests: write
if: |
always() &&
(needs.pr-validation.result == 'success' || needs.pr-validation.result == 'skipped') &&
github.event.action != 'closed'
steps:
- name: PR-specific labeling and lifecycle logic
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const payload = context.payload;
const isComment = context.eventName === 'issue_comment';
const isReview = context.eventName === 'pull_request_review';
const isPR = !!payload.pull_request || (isComment && !!payload.issue.pull_request);
if (!isPR) {
console.log('Not a pull request context — skipping.');
return;
}
let number;
if (isComment) {
number = payload.issue.number;
} else if (isReview) {
number = payload.pull_request.number;
} else {
number = payload.pull_request.number;
}
// ── B. Fetch current labels and PR details ────────────────────
let prDetails = null;
try {
const { data } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: number,
});
prDetails = data;
} catch (e) {
console.log(`Error fetching PR details: ${e.message}`);
return;
}
if (prDetails.state === 'closed') {
console.log('PR is closed. Skipping dynamic label updates.');
return;
}
let currentLabels = [];
try {
const { data } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
});
currentLabels = data;
} catch (e) {
console.log(`Error listing labels: ${e.message}`);
}
const currentLabelNames = currentLabels.map(l => l.name);
const labelsToAdd = [];
// ── C. Merge Conflict Check ───────────────────────────────────
let mergeable = prDetails.mergeable;
let attempt = 0;
while (mergeable === null && attempt < 5) {
console.log(`PR #${number} mergeable status is null. Retrying in 10s...`);
await new Promise(r => setTimeout(r, 10000));
try {
const { data: prRetry } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: number,
});
mergeable = prRetry.mergeable;
} catch (e) {
console.log(`Retry error: ${e.message}`);
}
attempt++;
}
if (mergeable === false) {
labelsToAdd.push('merge-conflict');
} else if (mergeable === true) {
if (currentLabelNames.includes('merge-conflict')) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
name: 'merge-conflict',
});
console.log('Removed "merge-conflict" label.');
} catch (e) {
console.log(`Could not remove "merge-conflict": ${e.message}`);
}
}
}
// ── D. Review Quality Check (quality : needs-work) ────────────
try {
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: number,
});
const latestReviews = {};
for (const review of reviews) {
if (!review.user || review.state === 'PENDING') continue;
latestReviews[review.user.login] = review.state;
}
const hasChangesRequested = Object.values(latestReviews).includes('CHANGES_REQUESTED');
if (hasChangesRequested) {
labelsToAdd.push('quality : needs-work');
} else {
if (currentLabelNames.includes('quality : needs-work')) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
name: 'quality : needs-work',
});
console.log('Removed "quality : needs-work" label.');
} catch (e) {
console.log(`Could not remove "quality : needs-work": ${e.message}`);
}
}
}
} catch (e) {
console.log(`Error checking reviews: ${e.message}`);
}
// ── E. Star Verification Check (need-star) ────────────────────
const author = prDetails.user.login;
let hasStarred = false;
try {
let page = 1;
const perPage = 100;
let found = false;
while (page <= 100) {
const { data: stargazers } = await github.rest.activity.listStargazersForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: perPage,
page: page,
});
if (stargazers.length === 0) break;
if (stargazers.some(s => s.login.toLowerCase() === author.toLowerCase())) {
found = true;
break;
}
if (stargazers.length < perPage) break;
page++;
}
hasStarred = found;
} catch (e) {
console.log(`Error checking star status for @${author}: ${e.message}`);
hasStarred = true; // Fallback
}
if (!hasStarred) {
labelsToAdd.push('need-star');
} else {
if (currentLabelNames.includes('need-star')) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
name: 'need-star',
});
console.log('Removed "need-star" label.');
} catch (e) {
console.log(`Could not remove "need-star": ${e.message}`);
}
}
try {
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: number,
});
const starReview = reviews.find(
r => r.user.login === 'github-actions[bot]' &&
r.state === 'CHANGES_REQUESTED' &&
r.body && r.body.includes('Please star the DoubtDesk repository')
);
if (starReview) {
await github.rest.pulls.dismissReview({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: number,
review_id: starReview.id,
message: 'Star verified ✅',
});
console.log('Dismissed star-check review.');
}
} catch (e) {
console.log(`Could not dismiss star review: ${e.message}`);
}
}
// ── F. Apply Labels ───────────────────────────────────────────
const uniqueLabels = [...new Set(labelsToAdd)];
if (uniqueLabels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
labels: uniqueLabels,
});
console.log(`Applied PR status labels: ${uniqueLabels.join(', ')}`);
}
# ── PR Closed & Merged Cleanup ────────────────────────────────────────────────
pr-closed-cleanup:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
if: |
github.event_name == 'pull_request_target' &&
github.event.action == 'closed'
steps:
- name: Clean labels on PR close
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const payload = context.payload;
const number = payload.pull_request.number;
const merged = payload.pull_request.merged;
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
});
if (merged === true) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
labels: ['gssoc:approved', 'quality:clean'],
});
console.log(`PR #${number} merged — added approval labels.`);
const transientLabels = [
'review-needed',
'needs-maintainer-approval',
'quality : needs-work',
'quality:needs-work',
'merge-conflict',
'need-star'
];
for (const label of labels) {
const shouldRemove =
label.name.startsWith('size/') ||
transientLabels.includes(label.name);
if (!shouldRemove) continue;
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
name: label.name,
});
console.log(`Removed transient label: ${label.name}`);
} catch (e) {
console.log(`Failed to remove ${label.name}: ${e.message}`);
}
}
} else {
const keepLabels = ['duplicate', 'invalid', 'already-implemented'];
for (const label of labels) {
if (keepLabels.includes(label.name)) continue;
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: number,
name: label.name,
});
console.log(`Removed label from unmerged PR: ${label.name}`);
} catch (e) {
console.log(`Failed to remove ${label.name}: ${e.message}`);
}
}
}