[Repo Assist] refactor(rust-guard): add MinIntegrity::from_policy_str to unify duplicate parsers#7377
Merged
lpcox merged 2 commits intoJun 11, 2026
Conversation
…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>
Contributor
There was a problem hiding this comment.
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) intoMinIntegrity. - Refactored
integrity_level_rankandintegrity_for_levelto usefrom_policy_str()instead of duplicated if/else chains. - Added new unit tests for
from_policy_strand forextract_repo_from_itemrepository 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
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot stopped work on behalf of
lpcox due to an error
June 11, 2026 18:12
This was referenced Jun 12, 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 PR was created by Repo Assist, an automated AI assistant.
Summary
Closes #7369
MinIntegrityalready hadas_str()to serialize an enum variant to a string, but had no reverse operation. As a result,integrity_level_rankandintegrity_for_levelboth 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.rsAdd
MinIntegrity::from_policy_str(level: &str) -> Option<Self>— parses a policy integrity level string case-insensitively; returnsNonefor unrecognised values. This completes theMinIntegritytype as a proper bidirectional mapping.Refactor
integrity_level_rank— replace the 4-branch if/else chain with amatchonfrom_policy_str().Refactor
integrity_for_level— same: replace the 4-branch if/else chain with amatchonfrom_policy_str().Add 14 new tests:
from_policy_str: known values, case-insensitivity, whitespace trimming, unknown inputs, and roundtrip (from_policy_str(as_str()) == Some(level))extract_repo_from_item: all 5 lookup strategies (directfull_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 itemWhy This Matters
from_policy_str; the exhaustive match at each call site will fail to compile until updated.MinIntegritybecomes a complete, bidirectional type: serialize withas_str(), deserialize withfrom_policy_str().test_integrity_level_rank_*andtest_integrity_for_level_*) continue to pass, confirming behavior is unchanged.Test Status
cargo test --lib)proxy.golang.orgis 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.orgSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run