Skip to content

[Repo Assist] refactor(rust-guard): add MinIntegrity::from_policy_str to unify duplicate parsers#7377

Merged
lpcox merged 2 commits into
mainfrom
repo-assist/improve-rust-guard-min-integrity-7369-e21640261f0871c1
Jun 11, 2026
Merged

[Repo Assist] refactor(rust-guard): add MinIntegrity::from_policy_str to unify duplicate parsers#7377
lpcox merged 2 commits into
mainfrom
repo-assist/improve-rust-guard-min-integrity-7369-e21640261f0871c1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

Closes #7369

MinIntegrity already had as_str() to serialize an enum variant to a string, but had no reverse operation. As a result, integrity_level_rank and integrity_for_level both contained an identical 4-way case-insensitive if/else chain to parse a policy integrity level string. If a fifth integrity level is ever added, both places must be updated in sync with no compiler enforcement.

Changes

guards/github-guard/rust-guard/src/labels/helpers.rs

  1. Add MinIntegrity::from_policy_str(level: &str) -> Option<Self> — parses a policy integrity level string case-insensitively; returns None for unrecognised values. This completes the MinIntegrity type as a proper bidirectional mapping.

  2. Refactor integrity_level_rank — replace the 4-branch if/else chain with a match on from_policy_str().

  3. Refactor integrity_for_level — same: replace the 4-branch if/else chain with a match on from_policy_str().

  4. Add 14 new tests:

    • 6 tests for from_policy_str: known values, case-insensitivity, whitespace trimming, unknown inputs, and roundtrip (from_policy_str(as_str()) == Some(level))
    • 8 tests for extract_repo_from_item: all 5 lookup strategies (direct full_name, repository.full_name, base.repo.full_name, head.repo.full_name, URL fallback), plus empty case and priority ordering — this function previously had zero direct tests despite being called for every labelled item

Why This Matters

  • The parsing logic is now defined once — adding a new integrity level requires only updating from_policy_str; the exhaustive match at each call site will fail to compile until updated.
  • MinIntegrity becomes a complete, bidirectional type: serialize with as_str(), deserialize with from_policy_str().
  • All existing tests (test_integrity_level_rank_* and test_integrity_for_level_*) continue to pass, confirming behavior is unchanged.

Test Status

  • ✅ Rust tests: 479 passed, 0 failed (cargo test --lib)
  • ⚠️ Go build/tests: skipped — proxy.golang.org is blocked in this environment (infrastructure constraint, not related to this change)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by Repo Assist · 831.2 AIC · ⊞ 50K ·
Comment /repo-assist to run again

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

…icate parsers

Add a bidirectional MinIntegrity type by introducing from_policy_str(),
the natural complement to as_str(). Refactor integrity_level_rank and
integrity_for_level to use the new method, eliminating two identical
4-way case-insensitive if/else chains.

Also add 14 new tests: 6 covering from_policy_str (known values,
case-insensitivity, whitespace trimming, unknown inputs, roundtrip) and
8 covering extract_repo_from_item (all 5 lookup strategies + empty case
+ priority check), which previously had zero direct tests.

Closes #7369

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review June 11, 2026 18:05
Copilot AI review requested due to automatic review settings June 11, 2026 18:05

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 refactors the Rust guard’s policy-integrity parsing by adding a single MinIntegrity::from_policy_str(&str) -> Option<Self> deserializer and reusing it in existing helpers, reducing duplicated parsing logic and improving maintainability.

Changes:

  • Added MinIntegrity::from_policy_str() to parse policy integrity levels case-insensitively (with trimming) into MinIntegrity.
  • Refactored integrity_level_rank and integrity_for_level to use from_policy_str() instead of duplicated if/else chains.
  • Added new unit tests for from_policy_str and for extract_repo_from_item repository extraction strategies.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/helpers.rs Introduces MinIntegrity::from_policy_str, refactors integrity helpers to use it, and adds unit tests (including new coverage for extract_repo_from_item).

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: 1

Comment thread guards/github-guard/rust-guard/src/labels/helpers.rs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpcox lpcox merged commit b82ba1d into main Jun 11, 2026
26 checks passed
@lpcox lpcox deleted the repo-assist/improve-rust-guard-min-integrity-7369-e21640261f0871c1 branch June 11, 2026 18:11
Copilot stopped work on behalf of lpcox due to an error June 11, 2026 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rust-guard] Rust Guard: Add MinIntegrity::from_policy_str to unify duplicate integrity-level parsers

2 participants