Skip to content

rust-guard: add MinIntegrity::from_policy_str to unify integrity parsers + extract_repo_from_item tests#7386

Merged
lpcox merged 3 commits into
mainfrom
copilot/rust-guard-add-minintegrity-from-policy-str
Jun 11, 2026
Merged

rust-guard: add MinIntegrity::from_policy_str to unify integrity parsers + extract_repo_from_item tests#7386
lpcox merged 3 commits into
mainfrom
copilot/rust-guard-add-minintegrity-from-policy-str

Conversation

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

integrity_level_rank and integrity_for_level both 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 of as_str(). Trims whitespace, case-insensitive match, returns None for unrecognised values.
impl MinIntegrity {
    pub(crate) fn from_policy_str(level: &str) -> Option<Self> { ... }
}
  • integrity_level_rank / integrity_for_level refactored — both now delegate to match 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_str unit tests — known levels, case insensitivity, whitespace trimming, unknown input (None), and roundtrip with as_str().

  • extract_repo_from_item unit tests — previously untested despite driving repo attribution for every labeled item. New tests cover all five lookup strategies (direct full_name, repository.full_name, base.repo.full_name, head.repo.full_name, URL parsing fallback) plus priority ordering and the empty fallback.

GitHub Advanced Security started work on behalf of lpcox June 11, 2026 18:08 View session
GitHub Advanced Security finished work on behalf of lpcox June 11, 2026 18:09
…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
Copilot finished work on behalf of lpcox June 11, 2026 18:12
Copilot AI requested a review from lpcox June 11, 2026 18:12
GitHub Advanced Security started work on behalf of lpcox June 11, 2026 18:13 View session
GitHub Advanced Security finished work on behalf of lpcox June 11, 2026 18:15
@lpcox lpcox marked this pull request as ready for review June 11, 2026 18:20
Copilot AI review requested due to automatic review settings June 11, 2026 18:20

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 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_rank and integrity_for_level to delegate parsing to MinIntegrity::from_policy_str, keeping default behaviors intact.
  • Added unit tests covering MinIntegrity::from_policy_str parsing behavior and extract_repo_from_item’s primary lookup strategies and precedence.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/helpers.rs Centralizes integrity parsing in MinIntegrity::from_policy_str, updates rank/label helpers to use it, and adds unit tests for integrity parsing + repo extraction.

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

@lpcox

lpcox commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Copilot AI commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/27367774755/job/80873393067?pr=7386

Fixed in 7a0c1ef. The main branch already had extract_repo_from_item tests, so my commit introduced duplicate function names. I've removed the duplicate block — the MinIntegrity::from_policy_str tests are retained and all 471 tests pass.

Copilot finished work on behalf of lpcox June 11, 2026 18:30
GitHub Advanced Security started work on behalf of lpcox June 11, 2026 18:30 View session
GitHub Advanced Security finished work on behalf of lpcox June 11, 2026 18:31
@lpcox lpcox merged commit 5c2434d into main Jun 11, 2026
27 checks passed
@lpcox lpcox deleted the copilot/rust-guard-add-minintegrity-from-policy-str branch June 11, 2026 18:39
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.

3 participants