rust-guard: extract first_matching_label helper and add label-check unit tests#8047
Merged
lpcox merged 2 commits intoJun 24, 2026
Merged
Conversation
Copilot
AI
changed the title
[WIP] Extract shared
rust-guard: extract Jun 24, 2026
first_matching_label helper and add label-check testsfirst_matching_label helper and add label-check unit tests
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the rust-guard label-matching logic by extracting duplicated approval/refusal label search into a shared helper, and adds targeted unit tests for the label-check helpers to validate behavior like case-insensitive matching and “feature disabled” defaults.
Changes:
- Extracted a shared
first_matching_labelhelper used by bothfirst_matching_approval_labelandfirst_matching_refusal_label. - Added unit tests for
has_approval_label,has_refusal_label,has_promotion_label, andhas_demotion_labelcovering key edge cases (case-insensitivity, disabled config, missing labels).
Show a summary per file
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/labels/helpers.rs | Deduplicates approval/refusal label matching via a shared helper and adds direct unit tests for label-checking helpers. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
first_matching_approval_labelandfirst_matching_refusal_labelwere near-identical — differing only in whichPolicyContextfield they accessed. Adds a shared private helper and direct unit tests for all four label-check functions.Refactor: extract
first_matching_labelReplaces the duplicated body in both functions with a single helper that takes the label list directly:
Tests: direct unit tests for label-check helpers in
helpers.rsAdds 10 tests covering
has_approval_label,has_refusal_label,has_promotion_label, andhas_demotion_label:false)labelsfield on the item →false