Skip to content

labeler: parse yes/no template fields, keep legacy checkbox fallback#5

Merged
bryanbeverly merged 2 commits into
mainfrom
labeler-yesno-template-fields
Apr 21, 2026
Merged

labeler: parse yes/no template fields, keep legacy checkbox fallback#5
bryanbeverly merged 2 commits into
mainfrom
labeler-yesno-template-fields

Conversation

@bryanbeverly
Copy link
Copy Markdown
Contributor

@bryanbeverly bryanbeverly commented Apr 21, 2026

Summary

The PR template's Review guidance section is switching from checkbox syntax (- [ ] **Urgent** ...) to a yes/no value (- **Urgent** (needs same-day review): no). GitHub treats every - [ ] line as a task and rolls them into the "X of Y tasks" indicator on the PR list view, which makes the indicator misleading -- a normal PR could never read 100% complete unless the bug happened to be both Urgent and High complexity.

This is the labeler half of the rollout. The companion template changes ship in trufflesecurity/.github-private and trufflesecurity/thog.

What changed

pr_labeler.py:

  • New field_state(body, *, yesno, checkbox) helper. Tries the new yes/no regex first; falls back to the legacy checkbox regex.
  • New yesno_regex(keyword) matches - **Urgent** (...): yes|no (case-insensitive, with word-boundary guards so values like nothing don't get parsed as no).
  • Existing checkbox_regex(keyword) is retained so in-flight PRs opened before the template change still get labeled correctly.
  • Reconcile loop pairs both regexes per label.

test_pr_labeler.py:

  • New TestFieldStateYesNo class with parametrized yes/no variants, value validation, and parenthetical-hint edge cases.
  • Existing TestCheckboxState cases are preserved as TestFieldStateLegacyCheckbox.
  • New TestFieldStatePrecedence class confirms yes/no wins when both formats appear in the same body.
  • Reconcile-level coverage for both formats.

54 total tests pass (was 22).

Review guidance

  • Urgent (needs same-day review): no
  • High complexity (non-obvious logic, careful review): no
  • Estimated review time: 5-10 min
  • Key files to focus on: .github/scripts/pr_labeler.py (regex + field_state)
  • Areas you're unsure about: None

Testing

Verified locally with pytest .github/scripts/test_pr_labeler.py -v -- 54 passed. ruff check and ruff format --check both clean.

Deployment notes

None. Pure script + tests change; reusable workflow caller signature is unchanged. The legacy regex stays in for ~2 weeks; a follow-up will drop it once the open-PR queue rolls over.


Note

Medium Risk
Changes PR labeling behavior by switching parsing from checkbox-only to yes/no template fields, which could cause incorrect review/urgent/complexity/high labels if the new regex misses edge cases. Scope is limited to a GitHub Actions helper script and expanded unit tests.

Overview
Updates the PR labeler to derive review/urgent and complexity/high from the new PR template format - **Field**: yes|no, while retaining legacy checkbox parsing as a fallback for older PRs.

Introduces a new field_state helper and anchored yes/no regexes with defensive handling to avoid mis-parsing : yes/no text inside legacy checkbox descriptions, and expands the test suite to cover yes/no variants, legacy behavior, and precedence/edge cases.

Reviewed by Cursor Bugbot for commit b648472. Bugbot is set up for automated code reviews on this repo. Configure here.

The Urgent and High complexity rows in the PR template are switching from
`- [ ] **Urgent** ...` to `- **Urgent** (...): yes|no`. GitHub treats every
`- [ ]` line as a task and rolls them into the "X of Y tasks" indicator on
the PR list, which made the indicator misleading: a normal PR could never
read 100% complete unless the bug was both Urgent and High complexity.

This change teaches `pr_labeler.py` to parse both formats so labels keep
flowing during the rollout:

  - New `field_state(body, yesno=..., checkbox=...)` tries the yes/no regex
    first and falls back to the legacy checkbox regex.
  - The legacy `checkbox_regex` and tests are preserved so in-flight PRs
    opened before the template change still get labeled correctly.
  - A follow-up will drop the legacy regex once the open-PR queue rolls
    over (~2 weeks).

Test coverage goes from 22 to 54 cases, including parametrized yes/no
variants, value validation (must be `yes` or `no`, with word-boundary
guards against words like `nothing`), parenthetical hint handling, and
precedence (yes/no wins when both formats appear in the same body).

This PR is the labeler half of the rollout. The companion template
changes ship in trufflesecurity/.github-private and trufflesecurity/thog.

Made-with: Cursor
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 3f53db2. Configure here.

Comment thread .github/scripts/pr_labeler.py
The yesno regex `[-*]\s*[*_`+'`'+`]*\s*<keyword>...` could treat the `*`
of an inline `**Urgent**` as a list bullet, so on a legacy line like
`- [x] **Urgent**: no further action` it captured `no` from the
description and `field_state` returned immediately, flipping a checked
box from `on` to `off`.

Anchor the yesno regex to the start of a line (`^\s*[-*]`, MULTILINE) so
inline bold can't impersonate a bullet, and harden `field_state` to
discard any yes/no match whose enclosing line is itself a checkbox line
so a future regression in the regex can't reintroduce the same flip.

Made-with: Cursor
@bryanbeverly
Copy link
Copy Markdown
Contributor Author

If you are the lucky person reviewing this, could you please also check these? They are all related to this one issue. The .github-private PR and the thog PR 6133 both update the actual PR template referred to in this PR. The final thog PR 6134 provides extra clarity for future agents in the project-wide rules.

@bryanbeverly bryanbeverly requested review from a team April 21, 2026 19:25
@bryanbeverly bryanbeverly merged commit 5bc9199 into main Apr 21, 2026
4 checks passed
@bryanbeverly bryanbeverly deleted the labeler-yesno-template-fields branch April 21, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants