Skip to content

Autolabel bot: optional draft field for path-based labeler.yml rules#8020

Draft
jithunnair-amd wants to merge 4 commits into
mainfrom
feat/labeler-draft-pr-flag
Draft

Autolabel bot: optional draft field for path-based labeler.yml rules#8020
jithunnair-amd wants to merge 4 commits into
mainfrom
feat/labeler-draft-pr-flag

Conversation

@jithunnair-amd
Copy link
Copy Markdown
Collaborator

@jithunnair-amd jithunnair-amd commented Apr 28, 2026

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.

Also registers pull_request.ready_for_review so when a draft PR is marked ready, the bot re-runs the same auto-label path (needed for rules with draft: false).

Logic lives in a new module labelerConfigUtils.ts; autoLabelBot.ts imports it and re-exports getLabelsFromLabelerConfig so existing imports keep working.

Motivation:

torchtitan CI uses labeler.yml to apply labels that trigger CI on PRs. However, we would like to avoid adding that label automatically on draft PRs to limit CI workloads.


labeler.yml schema

Legacy (unchanged):

"module: dynamo":
  - torch/_dynamo/**

** Extended:**

  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: helpers + getLabelsFromLabelerConfig(context, tracker, changed_files, isDraft).
torchci/lib/bot/autoLabelBot.ts Use labelerConfigUtils; pass context.payload.pull_request.draft; handle pull_request.ready_for_review; export { getLabelsFromLabelerConfig }.
torchci/lib/bot/utils.ts No changes on this branch (see dependency note below).

Tests added / updated

  • torchci/test/labelerConfigUtils.test.ts — unit tests for parsing and draft gating.
  • torchci/test/autoLabelBot.test.ts — integration tests under “labeler.yml config” for mixed legacy rules + draft: false on draft vs non-draft PRs.

Test plan

  • From torchci, run:
    jest test/labelerConfigUtils.test.ts
  • Run path-based labeler integration tests:
    jest test/autoLabelBot.test.ts -t "labeler.yml config"
  • (Recommended) full auto-label suite:
    jest test/autoLabelBot.test.ts

- Add labelerConfigUtils with legacy glob arrays and extended { globs, draft } rules
- draft: false skips the label while the PR is draft; draft: true limits to drafts only
- Pass pull_request.draft into getLabelsFromLabelerConfig; listen for ready_for_review
- Await context.config when loading labeler and label-to-label configs (fix stale promises)
- Add unit and integration tests

Made-with: Cursor
Labeler config loading fix lives on fix/await-labeler-config-cache; merge
that PR before or rebase this branch onto main after it lands.

Made-with: Cursor
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
torchci Ready Ready Preview May 5, 2026 4:58pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the auto-label bot’s labeler.yml path-based labeling to optionally gate individual label rules on whether a pull request is a draft, and ensures labels can be applied when a PR transitions from draft to ready-for-review.

Changes:

  • Added torchci/lib/bot/labelerConfigUtils.ts to normalize labeler.yml rules and apply optional draft constraints during path matching.
  • Updated autoLabelBot.ts to use the new helper, pass pull_request.draft, and handle pull_request.ready_for_review.
  • Added unit + integration tests covering rule normalization and draft: false behavior for draft vs non-draft PRs.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
torchci/lib/bot/labelerConfigUtils.ts New utility module for parsing/normalizing labeler rules and enforcing optional draft constraints during glob matching.
torchci/lib/bot/autoLabelBot.ts Switches labeler logic to the new module, passes draft state, and re-runs labeling on ready_for_review.
torchci/test/labelerConfigUtils.test.ts Unit tests for rule normalization and draft gating behavior.
torchci/test/autoLabelBot.test.ts Integration tests for mixed legacy + draft:false rules on draft vs non-draft PRs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +25 to +30
const r = rule as { globs: string[]; draft?: unknown };
const out: { globs: string[]; draft?: boolean } = { globs: r.globs };
if (typeof r.draft === "boolean") {
out.draft = r.draft;
}
return out;
context: Context,
labelerConfigTracker: CachedLabelerConfigTracker,
changed_files: string[],
isDraft: boolean
Comment on lines 452 to +458
app.on(
["pull_request.opened", "pull_request.edited", "pull_request.synchronize"],
[
"pull_request.opened",
"pull_request.edited",
"pull_request.synchronize",
"pull_request.ready_for_review",
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants