rust-guard: flatten commit integrity branch logic and expand trusted bot variant coverage - #8842
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Simplify double-nested if in tool_rules.rs
rust-guard: flatten commit integrity branch logic and expand trusted bot variant coverage
Jul 7, 2026
lpcox
marked this pull request as ready for review
July 7, 2026 12:48
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the GitHub Rust guard’s labeling logic to make commit-integrity selection clearer while keeping behavior unchanged, and adds unit test coverage to ensure trusted first-party bot username variants are recognized consistently.
Changes:
- Simplified the
get_commit/list_commitsintegrity selection into an explicit 3-way branch (default ref → merged integrity; private non-default → writer integrity; otherwise empty integrity). - Added a unit test exercising trusted first-party bot username variants (including
app/forms) and case-insensitivity.
Show a summary per file
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/labels/tool_rules.rs | Refactors integrity-branching logic for commit-related tools into a clearer equivalent conditional structure. |
| guards/github-guard/rust-guard/src/labels/helpers.rs | Adds a targeted unit test for trusted first-party bot username variant recognition. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Low
Comment on lines
+2226
to
+2247
| let trusted = [ | ||
| "dependabot[bot]", | ||
| "github-actions[bot]", | ||
| "github-actions", | ||
| "app/github-actions", | ||
| "github-merge-queue[bot]", | ||
| "copilot", | ||
| "copilot-swe-agent[bot]", | ||
| "copilot-swe-agent", | ||
| "app/copilot-swe-agent", | ||
| ]; | ||
|
|
||
| for username in trusted { | ||
| assert!( | ||
| is_trusted_first_party_bot(username), | ||
| "{username} must be recognized as a trusted first-party bot" | ||
| ); | ||
| assert!( | ||
| is_trusted_first_party_bot(&username.to_uppercase()), | ||
| "{username} (uppercase) must also be recognized" | ||
| ); | ||
| } |
This was referenced Jul 7, 2026
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.
This updates Rust guard labeling in two low-risk areas: it removes duplicated branching in
get_commit/list_commitsintegrity selection, and adds explicit coverage for all trusted first-party bot username variants (includingapp/forms and merge queue bot).Commit integrity rule clarity (
tool_rules.rs)merged_integrity; non-default refs in private repos map towriter_integrity; otherwise empty integrity.Trusted bot coverage completeness (
helpers.rs)is_trusted_first_party_botcovering all canonical entries inTRUSTED_FIRST_PARTY_BOTS.Illustrative snippet (logic simplification)