{{ message }}
Refactor Rust guard response item extraction and PR merged detection#8422
Merged
Conversation
Copilot
AI
changed the title
[WIP] Extract extract_items_slice helper to eliminate duplicated item-extraction block
Refactor Rust guard response item extraction and PR merged detection
Jul 1, 2026
Collaborator
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Rust GitHub guard’s response-shape handling and PR merged-state detection to remove duplicated logic while preserving existing extraction behavior, and fixes the merged_at: null case so it correctly falls back to merged: true.
Changes:
- Consolidates response item extraction into a shared helper (
extract_items_slice) and reuses it across PR and issue labeling paths. - Centralizes PR merged detection via
is_pr_mergedand reuses it in both integrity calculation and backend fact extraction. - Adds targeted Rust tests to cover type-specific envelopes, REST singleton promotion, and merged boolean fallback behavior.
Show a summary per file
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/labels/response_items.rs | Introduces extract_items_slice to unify REST/search/GraphQL item extraction and adds focused extraction tests. |
| guards/github-guard/rust-guard/src/labels/helpers.rs | Adds is_pr_merged helper and updates PR integrity logic + tests to use it. |
| guards/github-guard/rust-guard/src/labels/backend.rs | Removes inline merged detection in PR fact extraction, reusing is_pr_merged, and adds a regression test for boolean fallback. |
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: 1
- Review effort level: Low
Comment on lines
1790
to
+1791
| // Check if PR is merged (either merged_at field exists or merged boolean is true) | ||
| let mut is_merged = item | ||
| .get(field_names::MERGED_AT) | ||
| .map(|v| !v.is_null()) | ||
| .or_else(|| item.get(field_names::MERGED).and_then(|v| v.as_bool())) | ||
| .unwrap_or(false); | ||
| let mut is_merged = is_pr_merged(item); |
Contributor
Author
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.

The Rust guard had two duplicated response-shape extraction blocks in
response_items.rsand duplicated PR merged-state detection in bothhelpers.rsandbackend.rs. This change consolidates both paths and preserves the existing response-shape handling while fixing themerged_at: null→merged: truefallback case.Consolidate response item extraction
extract_items_slice(response, list_field)inlabels/response_items.rsitemspull_requests/issues)nodesCentralize PR merged-state detection
is_pr_merged(item)inlabels/helpers.rspr_integrity(...)get_pull_request_facts_with_callback(...)"merged_at"/"merged"handling frombackend.rsBehavioral cleanup
merged_atis present butnull, so the logic now falls back tomerged: trueas intendedTargeted coverage
is_pr_mergedtimestamp and boolean fallback behaviormergedboolean fallback