{{ message }}
rust-guard: add MinIntegrity::from_policy_str to unify integrity parsers + extract_repo_from_item tests#7386
Merged
Conversation
…from_item tests - Add MinIntegrity::from_policy_str(level: &str) -> Option<Self> to unify the duplicate case-insensitive if/else chains in integrity_level_rank and integrity_for_level - Refactor integrity_level_rank to use match on from_policy_str - Refactor integrity_for_level to use match on from_policy_str - Add unit tests for from_policy_str (known levels, case insensitivity, whitespace trimming, unknown input, roundtrip with as_str) - Add unit tests for extract_repo_from_item covering all five lookup strategies plus priority ordering and empty fallback Closes #7369
Copilot
AI
changed the title
[WIP] Add MinIntegrity::from_policy_str to unify integrity-level parsers
rust-guard: add MinIntegrity::from_policy_str to unify integrity parsers + extract_repo_from_item tests
Jun 11, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR reduces duplication in the rust-guard policy integrity parsing by centralizing string-to-MinIntegrity conversion, and it adds missing unit test coverage for extract_repo_from_item, which influences repo attribution for labeled items.
Changes:
- Added
MinIntegrity::from_policy_str(&str) -> Option<MinIntegrity>to provide a single canonical, trimmed, case-insensitive parser for policy integrity tokens. - Refactored
integrity_level_rankandintegrity_for_levelto delegate parsing toMinIntegrity::from_policy_str, keeping default behaviors intact. - Added unit tests covering
MinIntegrity::from_policy_strparsing behavior andextract_repo_from_item’s primary lookup strategies and precedence.
Show a summary per file
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
Collaborator
Contributor
Author
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.

integrity_level_rankandintegrity_for_levelboth contained an identical 4-way case-insensitive if/else chain parsing integrity level strings. Adding a new level required updating both in sync with no compiler enforcement.Changes
MinIntegrity::from_policy_str(level: &str) -> Option<Self>— adds the reverse direction ofas_str(). Trims whitespace, case-insensitive match, returnsNonefor unrecognised values.integrity_level_rank/integrity_for_levelrefactored — both now delegate tomatch MinIntegrity::from_policy_str(level). The parsing logic lives in exactly one place; exhaustive match means the compiler will flag any missed case site when a new variant is added.MinIntegrity::from_policy_strunit tests — known levels, case insensitivity, whitespace trimming, unknown input (None), and roundtrip withas_str().extract_repo_from_itemunit tests — previously untested despite driving repo attribution for every labeled item. New tests cover all five lookup strategies (directfull_name,repository.full_name,base.repo.full_name,head.repo.full_name, URL parsing fallback) plus priority ordering and the empty fallback.