Skip to content

rust-guard: flatten commit integrity branch logic and expand trusted bot variant coverage - #8842

Merged
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-simplify-commit-arm
Jul 7, 2026
Merged

rust-guard: flatten commit integrity branch logic and expand trusted bot variant coverage#8842
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-simplify-commit-arm

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This updates Rust guard labeling in two low-risk areas: it removes duplicated branching in get_commit/list_commits integrity selection, and adds explicit coverage for all trusted first-party bot username variants (including app/ forms and merge queue bot).

  • Commit integrity rule clarity (tool_rules.rs)

    • Replaced a double-nested conditional with an equivalent 3-way branch.
    • Behavior remains the same, but the policy is now explicit: default refs always map to merged_integrity; non-default refs in private repos map to writer_integrity; otherwise empty integrity.
  • Trusted bot coverage completeness (helpers.rs)

    • Added a focused unit test for is_trusted_first_party_bot covering all canonical entries in TRUSTED_FIRST_PARTY_BOTS.
    • Includes case-insensitivity checks and negative assertions for non-trusted usernames.
  • Illustrative snippet (logic simplification)

integrity = if is_default_ref {
    merged_integrity(repo_id, ctx)
} else if repo_private_effective {
    writer_integrity(repo_id, ctx)
} else {
    vec![]
};

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
Copilot finished work on behalf of lpcox July 7, 2026 12:42
Copilot AI requested a review from lpcox July 7, 2026 12:42
@lpcox
lpcox marked this pull request as ready for review July 7, 2026 12:48
Copilot AI review requested due to automatic review settings July 7, 2026 12:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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_commits integrity 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"
);
}
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.

[rust-guard] Rust Guard: Simplify commit arm double-nested if in tool_rules.rs

3 participants