refactor(rust-guard): extract `resolve_integrity_level` helper + add promotion/demotion label tests by Copilot · Pull Request #8506 · github/gh-aw-mcpg · GitHub
Skip to content

refactor(rust-guard): extract resolve_integrity_level helper + add promotion/demotion label tests#8506

Merged
lpcox merged 3 commits into
mainfrom
copilot/rust-guard-extract-resolve-integrity-level
Jul 2, 2026
Merged

refactor(rust-guard): extract resolve_integrity_level helper + add promotion/demotion label tests#8506
lpcox merged 3 commits into
mainfrom
copilot/rust-guard-extract-resolve-integrity-level

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

effective_disapproval_integrity and effective_endorser_min_integrity duplicated an identical 14-line parse-and-warn body. The promotion/demotion label pipeline (apply_post_integrity_adjustments) also lacked end-to-end test coverage, meaning accidental removal of either adjustment step would go undetected.

Changes

  • Extract resolve_integrity_level helper — consolidates the shared "empty → default, unrecognised → warn + default" pattern into a single function; both callers now delegate in one line each:
fn resolve_integrity_level(value: &str, default: MinIntegrity, caller: &str) -> &'static str {
    let v = value.trim();
    if v.is_empty() {
        default.as_str()
    } else {
        MinIntegrity::from_policy_str(v)
            .unwrap_or_else(|| {
                crate::log_warn(&format!("{}: unrecognised level {:?}, defaulting to '{}'",
                    caller, v, default.as_str()));
                default
            })
            .as_str()
    }
}

fn effective_disapproval_integrity(ctx: &PolicyContext) -> &'static str {
    resolve_integrity_level(&ctx.disapproval_integrity, MinIntegrity::None, "effective_disapproval_integrity")
}
  • Add 4 promotion/demotion label integration tests — exercise the full issue_integrity / pr_integrity pipeline to verify:
    • promotion_label raises a NONE-association issue to writer (rank 3)
    • demotion_label caps an OWNER-association issue to none (rank 1)
    • promotion_label raises a forked PR from reader (rank 2) to writer (rank 3)
    • demotion_label caps a merged PR from merged (rank 4) to none (rank 1)

…omotion/demotion label tests

- Extract shared parse-and-warn logic into resolve_integrity_level()
  so effective_disapproval_integrity and effective_endorser_min_integrity
  delegate to a single helper instead of duplicating 14 lines each.
- Add four tests covering promotion_label and demotion_label flow
  through issue_integrity and pr_integrity.

Closes #8485
GitHub Advanced Security started work on behalf of lpcox July 2, 2026 22:43 View session
GitHub Advanced Security finished work on behalf of lpcox July 2, 2026 22:43
Copilot AI changed the title [WIP] Extract resolve_integrity_level helper and add tests refactor(rust-guard): extract resolve_integrity_level helper + add promotion/demotion label tests Jul 2, 2026
Copilot finished work on behalf of lpcox July 2, 2026 22:44
Copilot AI requested a review from lpcox July 2, 2026 22:44
@lpcox lpcox marked this pull request as ready for review July 2, 2026 22:47
Copilot AI review requested due to automatic review settings July 2, 2026 22:47

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 GitHub guard label/integrity logic by extracting a shared integrity-level parsing helper, and adds end-to-end tests to lock in the promotion/demotion label adjustment behavior within the issue_integrity / pr_integrity pipelines.

Changes:

  • Extracts resolve_integrity_level to centralize “empty → default” and “unrecognized → warn + default” parsing for policy integrity strings.
  • Refactors effective_disapproval_integrity and effective_endorser_min_integrity to delegate to the new helper.
  • Adds four integration-style unit tests validating built-in promotion_label and demotion_label effects for issues and PRs (including forked and merged PR scenarios).
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/helpers.rs Adds resolve_integrity_level helper and new tests covering promotion/demotion label post-adjustment behavior for issues and PRs.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Low

The import is already brought into scope locally inside the functions
that need it, making the module-level import redundant. Rust 1.96
correctly flags it as unused with -D warnings.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox July 2, 2026 23:04 View session
GitHub Advanced Security finished work on behalf of lpcox July 2, 2026 23:04
@lpcox lpcox merged commit 6a8b060 into main Jul 2, 2026
23 checks passed
@lpcox lpcox deleted the copilot/rust-guard-extract-resolve-integrity-level branch July 2, 2026 23:06
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: Extract resolve_integrity_level helper + add promotion/demotion label tests

3 participants