[Repo Assist] refactor(rust-guard): remove PathLabelEntry, use PathLabel directly; simplify secrecy conditions by github-actions[bot] · Pull Request #8139 · github/gh-aw-mcpg · GitHub
Skip to content

[Repo Assist] refactor(rust-guard): remove PathLabelEntry, use PathLabel directly; simplify secrecy conditions#8139

Merged
lpcox merged 1 commit into
mainfrom
repo-assist/refactor-rust-guard-pathlabel-secrecy-8131-8c926732a925db46
Jun 26, 2026
Merged

[Repo Assist] refactor(rust-guard): remove PathLabelEntry, use PathLabel directly; simplify secrecy conditions#8139
lpcox merged 1 commit into
mainfrom
repo-assist/refactor-rust-guard-pathlabel-secrecy-8131-8c926732a925db46

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Closes #8131

Problem

response_paths.rs defined PathLabelEntry — a struct structurally identical to the PathLabel type already defined in lib.rs (both carry path: String and labels: ResourceLabels). Because they were separate types, label_resource in lib.rs had to pay a needless allocation + copy loop to rename the type:

// lib.rs — pointless identity conversion (8 lines, allocates a new Vec)
let labeled_paths: Vec<PathLabel> = path_result
    .labeled_paths
    .into_iter()
    .map(|entry| PathLabel { path: entry.path, labels: entry.labels })
    .collect();

Additionally, the secrecy conditions in response_items.rs for PRs and issues used 3-way positive match arms that enumerated every tool except the search variant, while response_paths.rs already used the simpler negative check pattern (tool_name != "search_*").

Changes

labels/response_paths.rs

  • Removed PathLabelEntry struct definition (it was identical to crate::PathLabel)
  • Changed PathLabelResult.labeled_paths from Vec<PathLabelEntry> to Vec<crate::PathLabel>
  • Updated all 9 push sites: PathLabelEntry { ... }crate::PathLabel { ... }

lib.rs

  • Removed the 8-line conversion loop; path_result.labeled_paths is now a zero-cost move into PathLabeledOutput
  • Net: -12 lines of pure noise

labels/response_items.rs

  • PRs arm secrecy: tool_name == "list_pull_requests" || tool_name == "pull_request_read" || tool_name == "get_pull_request"tool_name != "search_pull_requests" (mirrors response_paths.rs pattern; future tool names automatically included)
  • Issues arm secrecy: tool_name == "list_issues" || tool_name == "get_issue" || tool_name == "issue_read"tool_name != "search_issues" (same motivation)
  • Added clarifying comments at each site

Why This Matters

Performance (Task 8): Eliminates one Vec heap allocation and copy per label_resource response — the loop iterated every labeled path and cloned field values into a new Vec<PathLabel>. The new code is a single zero-cost ownership transfer.

Correctness/Maintainability (Task 3): The 3-way positive conditions were inconsistent with the already-established negative-check pattern in response_paths.rs. More importantly, adding a new tool name to the outer match arm (e.g., get_pull_request_v2) would silently fall through to vec![] secrecy — the negative-check pattern fixes this by defaulting to shared-repo secrecy for any non-search tool.

Test Status

  • cargo test — all 534 Rust unit tests pass
  • ⚠️ Go unit tests blocked (network access to proxy.golang.org forbidden in sandbox — infrastructure limitation, unrelated to these changes which are Rust-only)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by Repo Assist · 186.4 AIC · ⊞ 12.2K ·
Comment /repo-assist to run again

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

…simplify secrecy conditions

Closes #8131

- Remove PathLabelEntry struct from response_paths.rs (was identical to
  crate::PathLabel) and update PathLabelResult.labeled_paths to use
  Vec<crate::PathLabel> directly. This eliminates the allocation+copy
  loop in lib.rs that converted between the two identical types.
- Remove the 8-line conversion loop from label_resource in lib.rs;
  path_result.labeled_paths is now a zero-cost move into PathLabeledOutput.
- Replace 3-way positive secrecy conditions in response_items.rs with
  single negative checks: 'tool_name != search_pull_requests' and
  'tool_name != search_issues'. Mirrors the pattern already used in
  response_paths.rs and makes the intent explicit: all tools in each
  match arm use shared repo secrecy except the search variants.
  Adds a clarifying comment at each site.

All 534 Rust unit tests pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

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

Refactors the Rust GitHub guard’s response-labeling pipeline to remove a redundant path-label wrapper type and to simplify secrecy selection logic, reducing unnecessary allocations and making tool handling more future-proof.

Changes:

  • Removed the redundant PathLabelEntry type and switched PathLabelResult.labeled_paths to use the canonical crate::PathLabel directly.
  • Eliminated the Vec<PathLabel> “identity conversion” in label_response by moving path_result.labeled_paths into the output struct.
  • Simplified PR/issue shared-repo secrecy conditions in response_items.rs using a negative check (!= search_*) consistent with existing patterns.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/lib.rs Removes the allocation/copy conversion loop by moving labeled_paths directly into PathLabeledOutput.
guards/github-guard/rust-guard/src/labels/response_paths.rs Drops PathLabelEntry and emits crate::PathLabel at all push sites.
guards/github-guard/rust-guard/src/labels/response_items.rs Replaces positive-list secrecy checks with tool_name != "search_*" for PRs and issues.

Review details

Tip

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

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

@lpcox lpcox merged commit 1fb7389 into main Jun 26, 2026
24 checks passed
@lpcox lpcox deleted the repo-assist/refactor-rust-guard-pathlabel-secrecy-8131-8c926732a925db46 branch June 26, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rust-guard] Rust Guard: Remove redundant PathLabelEntry struct and simplify secrecy conditions in response_items.rs

2 participants