[Repo Assist] refactor(rust-guard): extract extract_items_slice and is_pr_merged helpers#8417
Merged
lpcox merged 1 commit intoJul 1, 2026
Conversation
…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>
This was referenced Jul 1, 2026
Contributor
There was a problem hiding this comment.
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_slicehelper to centralize multi-shape response item extraction for both PR and issue labeling paths. - Added a shared
is_pr_mergedhelper (using existingfield_namesconstants) and updated bothpr_integrityand 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
This was referenced Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 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 →itemsenvelope → 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_integrityinhelpers.rsandget_pull_request_facts_with_callbackinbackend.rsboth duplicated the samemerged_at/mergedboolean check.backend.rsadditionally used raw string literals instead of thefield_namesconstants used everywhere else, creating a drift risk.Fix
response_items.rs: Extract a privateextract_items_slice<'a>(response, list_field)helper. Each call site collapses from 26 lines to one:helpers.rs: Addpub(crate) fn is_pr_merged(item: &Value) -> boolusing thefield_namesconstants. Updatepr_integrityto delegate to it.backend.rs: Import and useis_pr_merged. Removes the raw"merged_at"/"merged"string literals.Impact
field_namesconstants throughoutTest Status
All 556 Rust unit tests pass (
cargo testgreen). Go tests skipped due to sandbox network restrictions (infrastructure-only, not caused by these changes).Add this agentic workflow to your repo
To install this agentic workflow, run