[rust-guard] Deduplicate owner/repo parsing paths in labels backend#5548
Merged
Conversation
Copilot
AI
changed the title
[WIP] Refactor backend.rs to deduplicate identical loop bodies
[rust-guard] Deduplicate owner/repo parsing paths in labels backend
May 12, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors repo owner/org parsing in the Rust guard labels backend to reduce duplicated logic when extracting owner.type from search results and when deriving repo IDs from repo objects.
Changes:
- Introduces a shared
find_org_in_items(items, repo_id)helper and reuses it for both{ "items": [...] }and plain-array response shapes. - Deduplicates repo ID extraction by looping over
["full_name", "fullName"]in priority order. - Adds regression tests for plain-array owner/org extraction and
fullNamerepo ID extraction.
Show a summary per file
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/labels/backend.rs | Deduplicates owner/org lookup and repo-id field parsing; adds tests for the new paths. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
Comment on lines
+1386
to
+1394
| fn find_org_in_items(items: &[Value], repo_id: &str) -> Option<bool> { | ||
| items.iter().find_map(|item| { | ||
| let item_repo_id = repo_id_from_repo_object(item)?; | ||
| if item_repo_id.eq_ignore_ascii_case(repo_id) { | ||
| owner_type_from_repo_object(item) | ||
| } else { | ||
| None | ||
| } | ||
| }) |
Comment on lines
+1257
to
+1262
| #[test] | ||
| fn test_repo_id_from_repo_object_full_name_camel_case() { | ||
| let item = serde_json::json!({ | ||
| "fullName": "myorg/myrepo", | ||
| "owner": { "login": "myorg", "type": "Organization" } | ||
| }); |
Collaborator
|
@copilot merge main and address review feedback |
Contributor
Author
Merged
|
This was referenced May 12, 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.
✨ Enhancement
This change removes two duplication hotspots in
guards/github-guard/rust-guard/src/labels/backend.rswithout altering behavior: repeated item-scan logic in owner-type extraction and repeatedfull_name/fullNamelookup logic in repo ID extraction. The result is a smaller, more maintainable parsing path with unchanged field precedence and fallback behavior.What does this improve?
find_org_in_items(items, repo_id)and reuses it for both response shapes:{ "items": [...] }[...]ifblocks for"full_name"and"fullName"with a single ordered loop.fullNamerepo ID extraction pathWhy is this valuable?
Implementation approach:
owner_is_org_from_itemsto delegate both array shapes to the helper.repo_id_from_repo_objectto iterate["full_name", "fullName"]in priority order, preserving existing behavior.