Skip to content

[Repo Assist] refactor(rust-guard): extract extract_items_slice and is_pr_merged helpers#8417

Merged
lpcox merged 1 commit into
mainfrom
repo-assist/refactor-rust-guard-extract-helpers-8409-a3a77527dfc6f16f
Jul 1, 2026
Merged

[Repo Assist] refactor(rust-guard): extract extract_items_slice and is_pr_merged helpers#8417
lpcox merged 1 commit into
mainfrom
repo-assist/refactor-rust-guard-extract-helpers-8409-a3a77527dfc6f16f

Conversation

@github-actions

@github-actions github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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

Closes #8409

Problem

Issue #8409 identified two duplication patterns in the Rust guard:

1. 26-line duplicate item-extraction block (response_items.rs)

The PR arm and issue arm both contained identical logic to build a &[Value] slice from a response, trying root array → items envelope → type-specific envelope → GraphQL nodes → GraphQL single object → bare REST singleton. The only difference was the fallback field name ("pull_requests" vs "issues"). Any future change to the extraction logic required a two-place update.

2. 4-line duplicate merged-status check (helpers.rs + backend.rs)

pr_integrity in helpers.rs and get_pull_request_facts_with_callback in backend.rs both duplicated the same merged_at/merged boolean check. backend.rs additionally used raw string literals instead of the field_names constants used everywhere else, creating a drift risk.

Fix

response_items.rs: Extract a private extract_items_slice<'a>(response, list_field) helper. Each call site collapses from 26 lines to one:

// PR arm:
let items = extract_items_slice(&actual_response, "pull_requests");

// Issue arm:
let items = extract_items_slice(&actual_response, "issues");

helpers.rs: Add pub(crate) fn is_pr_merged(item: &Value) -> bool using the field_names constants. Update pr_integrity to delegate to it.

backend.rs: Import and use is_pr_merged. Removes the raw "merged_at"/"merged" string literals.

Impact

  • Net -20 lines of code
  • Single authoritative extraction path for all multi-shape PR/issue responses
  • Single authoritative merged-status check using field_names constants throughout
  • No behaviour change — same extraction logic, same field ordering

Test Status

All 556 Rust unit tests pass (cargo test green). Go tests skipped due to sandbox network restrictions (infrastructure-only, not caused by these changes).

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

Add this agentic workflow to your repo

To install this agentic workflow, run

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

…lpers

Resolves two duplication patterns identified in #8409:

**1. extract_items_slice (response_items.rs)**

The PR arm (lines 122-148) and issue arm (lines 245-268) contained
byte-for-byte identical 26-line blocks that built a `&[Value]` slice
from the response, differing only in the fallback field name
(`pull_requests` vs `issues`). Extract to a private module helper:

    fn extract_items_slice<'a>(response: &'a Value, list_field: &str) -> &'a [Value]

Each call site becomes a single line:

    let items = extract_items_slice(&actual_response, "pull_requests");
    let items = extract_items_slice(&actual_response, "issues");

**2. is_pr_merged (helpers.rs → backend.rs)**

The `pr_integrity` function in helpers.rs and
`get_pull_request_facts_with_callback` in backend.rs both duplicated
the same 4-line merged-status check. backend.rs additionally used raw
string literals (`"merged_at"`, `"merged"`) instead of the
`field_names` constants used everywhere else. Extract to:

    pub(crate) fn is_pr_merged(item: &Value) -> bool

Both callers updated. The raw string literals in backend.rs are removed.

Net: -20 lines, two single-maintenance-point helpers.

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

This PR refactors the Rust GitHub guard labeling code to remove duplicated logic when (1) extracting item slices from varied response shapes and (2) determining whether a pull request is merged, aligning with the duplication report in #8409.

Changes:

  • Extracted a shared extract_items_slice helper to centralize multi-shape response item extraction for both PR and issue labeling paths.
  • Added a shared is_pr_merged helper (using existing field_names constants) and updated both pr_integrity and the backend PR-facts fetcher to use it.
  • Removed duplicated inlined extraction/merged-check logic from call sites, reducing drift risk.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/response_items.rs Replaces duplicated item-slice extraction logic in PR/issue arms with a single extract_items_slice helper.
guards/github-guard/rust-guard/src/labels/helpers.rs Introduces is_pr_merged helper and updates pr_integrity to delegate to it.
guards/github-guard/rust-guard/src/labels/backend.rs Uses the shared is_pr_merged helper instead of duplicated merged-status checks with raw string keys.

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 38a96a9 into main Jul 1, 2026
23 checks passed
@lpcox lpcox deleted the repo-assist/refactor-rust-guard-extract-helpers-8409-a3a77527dfc6f16f branch July 1, 2026 15:26
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: Extract extract_items_slice helper to eliminate duplicated item-extraction block

2 participants