refactor(rust-guard): replace `reaction_kind: &str` with `ReactionKind` enum; collapse `issue_dependency_read` double guard by Copilot · Pull Request #8279 · github/gh-aw-mcpg · GitHub
Skip to content

refactor(rust-guard): replace reaction_kind: &str with ReactionKind enum; collapse issue_dependency_read double guard#8279

Merged
lpcox merged 3 commits into
mainfrom
copilot/rust-guard-replace-reaction-kind
Jun 29, 2026
Merged

refactor(rust-guard): replace reaction_kind: &str with ReactionKind enum; collapse issue_dependency_read double guard#8279
lpcox merged 3 commits into
mainfrom
copilot/rust-guard-replace-reaction-kind

Conversation

Copilot AI commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Two type-safety and duplication improvements to the Rust Guard.

ReactionKind enum (helpers.rs)

has_maintainer_reaction_with_callback previously accepted reaction_kind: &str constrained only by a comment, leaving a dead _ => false arm that would silently swallow any typo at a future call site.

Before:

let already_warned = match reaction_kind {
    "endorsement" => ENDORSEMENT_GATEWAY_WARNING_EMITTED.swap(true, Ordering::Relaxed),
    "disapproval"  => DISAPPROVAL_GATEWAY_WARNING_EMITTED.swap(true, Ordering::Relaxed),
    _ => false,  // dead arm
};

After:

enum ReactionKind { Endorsement, Disapproval }

impl ReactionKind {
    fn as_str(self) -> &'static str { ... }
    fn warning_emitted(self) -> &'static AtomicBool { ... }
}

// In has_maintainer_reaction_with_callback:
let already_warned = reaction_kind.warning_emitted().swap(true, Ordering::Relaxed);

All 18 call sites updated (has_maintainer_endorsement, has_maintainer_disapproval, and 16 test sites).

Collapse double guard in issue_dependency_read (tool_rules.rs)

The arm checked !owner.is_empty() && !repo.is_empty() and called extract_number_as_string twice. The second block is now nested inside the first, removing the redundant guard and allocation.

GitHub Advanced Security started work on behalf of lpcox June 29, 2026 13:56 View session
GitHub Advanced Security finished work on behalf of lpcox June 29, 2026 13:57
…um; collapse issue_dependency_read double guard

- Add ReactionKind enum with as_str() and warning_emitted() methods
- Update has_maintainer_reaction_with_callback to accept ReactionKind
- Replace dead-arm string match with reaction_kind.warning_emitted() dispatch
- Update has_maintainer_endorsement/disapproval callers to use enum variants
- Update all 18 test call sites from string literals to enum variants
- Collapse double guard + double extraction in issue_dependency_read arm

Closes #8276
GitHub Advanced Security started work on behalf of lpcox June 29, 2026 14:02 View session
Copilot AI changed the title [WIP] Replace reaction_kind: &str with ReactionKind enum refactor(rust-guard): replace reaction_kind: &str with ReactionKind enum; collapse issue_dependency_read double guard Jun 29, 2026
Copilot finished work on behalf of lpcox June 29, 2026 14:02
Copilot AI requested a review from lpcox June 29, 2026 14:02
GitHub Advanced Security finished work on behalf of lpcox June 29, 2026 14:02
@lpcox lpcox marked this pull request as ready for review June 29, 2026 14:33
Copilot AI review requested due to automatic review settings June 29, 2026 14:33

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 improves the Rust GitHub Guard’s labeling/helpers code by (1) making maintainer-reaction evaluation type-safe via a ReactionKind enum and (2) simplifying issue_dependency_read labeling logic to remove redundant guards and duplicate extraction.

Changes:

  • Introduce ReactionKind enum and refactor has_maintainer_reaction_with_callback to use it instead of &str.
  • Update endorsement/disapproval call sites (including tests) to pass ReactionKind variants.
  • Collapse the double guard in issue_dependency_read and reuse a single extracted issue number for both desc and author integrity enrichment.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/helpers.rs Adds ReactionKind and updates reaction evaluation + call sites for stronger type safety.
guards/github-guard/rust-guard/src/labels/tool_rules.rs Refactors issue_dependency_read to avoid redundant checks/extractions and set desc during enrichment.

Review details

Tip

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

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

Comment thread guards/github-guard/rust-guard/src/labels/tool_rules.rs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
GitHub Advanced Security started work on behalf of lpcox June 29, 2026 15:25 View session
GitHub Advanced Security finished work on behalf of lpcox June 29, 2026 15:26
@lpcox lpcox merged commit d64e882 into main Jun 29, 2026
27 checks passed
@lpcox lpcox deleted the copilot/rust-guard-replace-reaction-kind branch June 29, 2026 15:29
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