Skip to content

rust-guard: deduplicate repo fallback resolution and private-flag field checks#7988

Merged
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-extract-default-repo-helper
Jun 23, 2026
Merged

rust-guard: deduplicate repo fallback resolution and private-flag field checks#7988
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-extract-default-repo-helper

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

response_paths.rs duplicated the same default-repo fallback logic across four tool handlers, and backend.rs repeated equivalent private field probing logic in three separate blocks. This PR consolidates both patterns into single reusable paths while preserving behavior.

  • response_paths.rs: extract shared default repo resolver

    • Added default_repo_for_items(arg_repo_full: String, items: &[Value]) -> String.
    • Replaced 4 duplicated call-site blocks in:
      • list_pull_requests
      • list_issues
      • list_commits
      • list_releases
  • backend.rs: collapse repeated private-field probes

    • Updated private_flag_from_repo_object to iterate candidate field names in order:
      • "private", "is_private", "isPrivate"
    • Kept existing visibility fallback logic unchanged.
  • Resulting code shape (representative)

    fn default_repo_for_items(arg_repo_full: String, items: &[Value]) -> String {
        if !arg_repo_full.is_empty() {
            return arg_repo_full;
        }
        items.first().map(extract_repo_from_item).unwrap_or_default()
    }
    
    fn private_flag_from_repo_object(item: &Value) -> Option<bool> {
        for field in &["private", "is_private", "isPrivate"] {
            if let Some(is_private) = item.get(*field).and_then(|v| v.as_bool()) {
                return Some(is_private);
            }
        }
        // existing visibility fallback remains
        ...
    }

GitHub Advanced Security started work on behalf of lpcox June 23, 2026 18:26 View session
GitHub Advanced Security finished work on behalf of lpcox June 23, 2026 18:27
Copilot AI changed the title [WIP] Extract default_repo_for_items helper to reduce code duplication rust-guard: deduplicate repo fallback resolution and private-flag field checks Jun 23, 2026
GitHub Advanced Security started work on behalf of lpcox June 23, 2026 18:43 View session
Copilot AI requested a review from lpcox June 23, 2026 18:43
Copilot finished work on behalf of lpcox June 23, 2026 18:43
GitHub Advanced Security finished work on behalf of lpcox June 23, 2026 18:43
@lpcox lpcox marked this pull request as ready for review June 23, 2026 20:00
Copilot AI review requested due to automatic review settings June 23, 2026 20:00

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 “default repo” fallback logic in path-based response labeling, and to consolidate repeated “private” field probing in repo objects—keeping behavior consistent while reducing maintenance overhead.

Changes:

  • Extracted default_repo_for_items(...) and reused it across the collection labelers that previously reimplemented the same fallback logic.
  • Simplified private_flag_from_repo_object(...) to iterate through the known candidate boolean fields (private, is_private, isPrivate) before falling back to visibility handling.
  • Updated the affected tool handler branches to use the shared helpers without changing labeling semantics.
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/response_paths.rs Deduplicates default-repo fallback resolution used by multiple collection labeling paths.
guards/github-guard/rust-guard/src/labels/backend.rs Consolidates private-flag detection by probing candidate field names in a single loop.

Copilot's findings

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@lpcox lpcox merged commit b6ac903 into main Jun 23, 2026
40 checks passed
@lpcox lpcox deleted the copilot/rust-guard-extract-default-repo-helper branch June 23, 2026 21:40
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.

3 participants