Commit 50a4098
Autolabel bot: optional draft field for path-based labeler.yml rules (#8020)
## Summary
Extends repo `labeler.yml` so each label rule can opt out of (or limit
to) draft pull requests. Path-based labels can stay on the legacy
list-of-globs form; new behavior uses a small object with `globs` and
optional `draft`.
When a PR's draft state changes, the bot also **removes** draft-gated
labels that no longer apply (e.g. `draft: false` labels when converted
to draft, `draft: true` labels when marked ready for review). Removal is
limited to labels the bot previously applied, so manually added labels
are left alone.
Logic lives in `labelerConfigUtils.ts`; `autoLabelBot.ts` imports it and
re-exports `getLabelsFromLabelerConfig` so existing imports keep
working.
## Motivation
torchtitan CI uses
[`labeler.yml`](https://github.com/pytorch/torchtitan/blob/main/.github/labeler.yml)
to apply labels that trigger CI on PRs. We want to avoid adding those
labels automatically on draft PRs to limit CI workloads, and remove them
if a PR is converted back to draft.
---
## `labeler.yml` schema
**Legacy (unchanged):**
```yaml
"module: dynamo":
- torch/_dynamo/**
```
**Extended:**
```yaml
"ciflow/inductor":
globs:
- torch/_inductor/**
draft: false
```
| `draft` | Behavior |
| -------- | -------- |
| (omitted) | Same as today: apply when paths match (draft or not). |
| `false` | Apply only when the PR is not a draft. |
| `true` | Apply only when the PR is a draft. |
## Code changes
| Area | Change |
| -------- | -------- |
| `torchci/lib/bot/labelerConfigUtils.ts` | New module: parsing,
`getLabelsFromLabelerConfig`, and `getDraftGatedLabelsToRemove`. |
| `torchci/lib/bot/autoLabelBot.ts` | Pass `pull_request.draft`; handle
`ready_for_review` and `converted_to_draft`; remove bot-applied
draft-gated labels on draft transitions; skip required-label comments on
`ready_for_review`. |
| `torchci/lib/bot/utils.ts` | No changes on this branch. |
## Tests added / updated
- `torchci/test/labelerConfigUtils.test.ts` — unit tests for parsing,
draft gating, and label removal helpers.
- `torchci/test/autoLabelBot.test.ts` — integration tests for adding
labels on draft vs non-draft PRs, removing labels on
`converted_to_draft` / `ready_for_review`, and no duplicate
required-label comments on `ready_for_review`.
## Test plan
- [x] From `torchci`, run: `jest test/labelerConfigUtils.test.ts`
- [x] Run path-based labeler integration tests: `jest
test/autoLabelBot.test.ts -t "labeler.yml config"`
- [x] (Recommended) full auto-label suite: `jest
test/autoLabelBot.test.ts`
Authored with assistance from Cursor
---------
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent a6fa78f commit 50a4098
5 files changed
Lines changed: 682 additions & 30 deletions
File tree
- torchci
- lib/bot
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
4 | 11 | | |
5 | 12 | | |
6 | 13 | | |
| |||
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
| 23 | + | |
| 24 | + | |
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
| |||
140 | 149 | | |
141 | 150 | | |
142 | 151 | | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | 152 | | |
165 | 153 | | |
166 | 154 | | |
| |||
357 | 345 | | |
358 | 346 | | |
359 | 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 | + | |
360 | 381 | | |
361 | 382 | | |
362 | 383 | | |
| |||
504 | 525 | | |
505 | 526 | | |
506 | 527 | | |
507 | | - | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
508 | 535 | | |
509 | 536 | | |
510 | 537 | | |
| |||
547 | 574 | | |
548 | 575 | | |
549 | 576 | | |
| 577 | + | |
| 578 | + | |
550 | 579 | | |
551 | 580 | | |
552 | 581 | | |
553 | | - | |
| 582 | + | |
| 583 | + | |
554 | 584 | | |
555 | 585 | | |
556 | 586 | | |
| |||
579 | 609 | | |
580 | 610 | | |
581 | 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 | + | |
582 | 639 | | |
583 | 640 | | |
584 | 641 | | |
585 | | - | |
| 642 | + | |
| 643 | + | |
586 | 644 | | |
587 | 645 | | |
588 | 646 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments