Skip to content

Add PRIVATE_BASE constant and deduplicate GraphQL traversal in rust-guard#3233

Merged
lpcox merged 2 commits intomainfrom
copilot/rust-guard-add-private-base-constant
Apr 6, 2026
Merged

Add PRIVATE_BASE constant and deduplicate GraphQL traversal in rust-guard#3233
lpcox merged 2 commits intomainfrom
copilot/rust-guard-add-private-base-constant

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 5, 2026

Two small deduplication improvements in the Rust guard, as described in the original issue.

Improvement 1: Add PRIVATE_BASE constant to label_constants

The bare "private" string was used as a secrecy label value in 4 places across three files, but label_constants had no constant for it — despite already defining BLOCKED_BASE, READER_BASE, WRITER_BASE, and MERGED_BASE.

  • Added PRIVATE_BASE = "private" to constants.rs
  • Replaced all 4 raw literals in helpers.rs, response_items.rs, and response_paths.rs

Improvement 2: Eliminate GraphQL traversal duplication

extract_items_array and extract_graphql_nodes both contained an identical ~12-line GraphQL node traversal loop. Extracted a shared find_graphql_nodes_with_path helper:

  • extract_items_array now delegates its GraphQL branch to the helper
  • extract_graphql_nodes becomes a one-liner: find_graphql_nodes_with_path(response).map(|(arr, _)| arr)
  • Adding a new collection field now requires only a one-line change in GRAPHQL_COLLECTION_FIELDS

Verification

  • All 251 Rust guard tests pass (cargo test)
  • make agent-finished passes (Go build + lint + all tests)

Copilot AI requested a review from lpcox April 5, 2026 23:12
@lpcox lpcox changed the title [WIP] Add PRIVATE_BASE constant to label_constants Add PRIVATE_BASE constant and deduplicate GraphQL traversal in rust-guard Apr 6, 2026
@lpcox lpcox marked this pull request as ready for review April 6, 2026 01:32
Copilot AI review requested due to automatic review settings April 6, 2026 01:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 consistency and maintainability in the GitHub rust-guard labeling code by introducing a shared "private" secrecy constant and deduplicating repeated GraphQL node traversal logic. It also includes a small proxy-side behavior change to URL-escape the REST search_repositories query string.

Changes:

  • Add PRIVATE_BASE = "private" to label_constants and replace hard-coded "private" label literals.
  • Deduplicate GraphQL collection traversal via a shared find_graphql_nodes_with_path helper.
  • URL-escape the REST proxy search_repositories q parameter.
Show a summary per file
File Description
internal/proxy/proxy.go URL-escapes REST search_repositories query when building the upstream GitHub API path
guards/github-guard/rust-guard/src/labels/constants.rs Adds PRIVATE_BASE to centralized label constants
guards/github-guard/rust-guard/src/labels/helpers.rs Replaces raw "private" label usage; factors out GraphQL node traversal helper
guards/github-guard/rust-guard/src/labels/response_items.rs Uses label_constants::PRIVATE_BASE instead of raw "private" label
guards/github-guard/rust-guard/src/labels/response_paths.rs Uses label_constants::PRIVATE_BASE instead of raw "private" label

Copilot's findings

Tip

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

  • Files reviewed: 5/5 changed files
  • Comments generated: 1

Comment on lines +323 to +327
@@ -324,7 +324,7 @@ func (r *restBackendCaller) CallTool(ctx context.Context, toolName string, args
if pp, ok := argsMap["perPage"].(float64); ok {
perPage = fmt.Sprintf("%d", int(pp))
}
apiPath = fmt.Sprintf("/search/repositories?q=%s&per_page=%s", query, perPage)
apiPath = fmt.Sprintf("/search/repositories?q=%s&per_page=%s", url.QueryEscape(query), perPage)
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description/title focuses on rust-guard label/constants + GraphQL traversal deduplication, but this hunk also changes REST proxy behavior (URL-escaping the search query). Please either (a) mention this Go change in the PR description or (b) split it into a separate PR so reviewers can track the behavioral change explicitly.

Copilot uses AI. Check for mistakes.
Improvement 1: Add PRIVATE_BASE constant to label_constants
- Add `PRIVATE_BASE = "private"` constant alongside existing BLOCKED_BASE,
  READER_BASE, WRITER_BASE, MERGED_BASE constants
- Replace 4 bare "private" string literals across helpers.rs,
  response_items.rs, and response_paths.rs with
  label_constants::PRIVATE_BASE

Improvement 2: Eliminate GraphQL traversal duplication
- Extract shared `find_graphql_nodes_with_path` helper that returns both
  the nodes array and its JSON Pointer path
- Simplify `extract_items_array` GraphQL branch to a one-liner delegation
- Rewrite `extract_graphql_nodes` to delegate entirely to the shared helper
- Removes ~12 lines of verbatim-duplicated traversal logic

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox force-pushed the copilot/rust-guard-add-private-base-constant branch from 5fa1874 to 2dca269 Compare April 6, 2026 01:36
@lpcox lpcox merged commit be02957 into main Apr 6, 2026
3 checks passed
@lpcox lpcox deleted the copilot/rust-guard-add-private-base-constant branch April 6, 2026 01:43
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: Two small deduplication opportunities in helpers.rs and constants.rs

3 participants