Skip to content

rust-guard: extract item_has_config_label helper + simplify get_string_field#7207

Merged
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-extract-helper
Jun 8, 2026
Merged

rust-guard: extract item_has_config_label helper + simplify get_string_field#7207
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-extract-helper

Conversation

Copilot AI commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Two small refactors in guards/github-guard/rust-guard/src/labels/helpers.rs to eliminate duplicated extraction logic with no behaviour change.

Changes

  • Extract item_has_config_label private helperhas_promotion_label and has_demotion_label shared an identical three-step body (empty-guard → extract labels → case-insensitive match). Both now delegate to a single private helper; any future change to matching semantics is a one-site edit.
fn item_has_config_label(item: &Value, config_label: &str) -> bool {
    if config_label.is_empty() { return false; }
    extract_github_label_names(item)
        .iter()
        .any(|name| config_label.eq_ignore_ascii_case(name))
}

pub fn has_promotion_label(item: &Value, ctx: &PolicyContext) -> bool {
    item_has_config_label(item, &ctx.promotion_label)
}
pub fn has_demotion_label(item: &Value, ctx: &PolicyContext) -> bool {
    item_has_config_label(item, &ctx.demotion_label)
}
  • Simplify get_string_field — body reduced to a single delegation to the already-present get_str_or, giving the extraction chain one authoritative implementation.
pub fn get_string_field(value: &Value, field: &str) -> String {
    get_str_or(value, field, "").to_string()
}

Copilot AI changed the title [WIP] Extract item_has_config_label helper and simplify get_string_field rust-guard: extract item_has_config_label helper + simplify get_string_field Jun 8, 2026
Copilot AI requested a review from lpcox June 8, 2026 14:03
Copilot finished work on behalf of lpcox June 8, 2026 14:04
@lpcox lpcox marked this pull request as ready for review June 8, 2026 14:35
Copilot AI review requested due to automatic review settings June 8, 2026 14:35

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 performs two small internal refactors in guards/github-guard/rust-guard/src/labels/helpers.rs to reduce duplicated JSON/label extraction logic while preserving existing behavior in the GitHub guard label helpers.

Changes:

  • Extracted a private item_has_config_label helper to centralize case-insensitive matching for promotion/demotion label checks (including the “empty config disables feature” behavior).
  • Simplified get_string_field to delegate to the existing get_str_or helper for a single authoritative string-extraction implementation.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/helpers.rs Deduplicates configured-label matching logic and simplifies string field extraction via existing helper.

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 merged commit c4d2875 into main Jun 8, 2026
29 checks passed
@lpcox lpcox deleted the copilot/rust-guard-extract-helper branch June 8, 2026 15:45
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 item_has_config_label helper + simplify get_string_field

3 participants