Skip to content

refactor: deduplicate search scope and author integrity in tool_rules.rs#3019

Merged
lpcox merged 1 commit intomainfrom
refactor/tool-rules-dedup-2986
Apr 1, 2026
Merged

refactor: deduplicate search scope and author integrity in tool_rules.rs#3019
lpcox merged 1 commit intomainfrom
refactor/tool-rules-dedup-2986

Conversation

@lpcox
Copy link
Copy Markdown
Collaborator

@lpcox lpcox commented Apr 1, 2026

Summary

Addresses both improvements from #2986 — deduplicating scope resolution and integrity elevation logic in the Rust guard's tool_rules.rs.

Changes

1. search_code → use resolve_search_scope (Improvement 1)

search_code bypassed the existing resolve_search_scope helper and hand-rolled the same repo-extraction logic with 3 mutable variables (~16 extra lines). Replaced with a call to resolve_search_scope, matching the pattern already used by search_issues and search_pull_requests.

2. Extract resolve_author_integrity helper (Improvement 2)

The issue_read and pull_request_read arms each contained ~45 nearly-identical lines for:

  1. Computing an integrity floor from author_association
  2. Elevating trusted bots/users to writer level
  3. Falling back to collaborator permission for org repos

Extracted into a single resolve_author_integrity function. Call sites reduced to 5 lines each.

Impact

  • Net reduction: 50 lines (79 added, 129 removed)
  • No behavior change: All existing labels, secrecy, and integrity logic preserved
  • All tests pass: Go unit + integration tests, Rust cargo check

Closes #2986

1. Replace search_code's hand-rolled scope resolution (~16 lines) with a
   call to resolve_search_scope, matching the pattern used by
   search_issues and search_pull_requests.

2. Extract resolve_author_integrity helper to consolidate the ~45-line
   author_association + trusted-bot + collaborator-permission elevation
   blocks duplicated in the issue_read and pull_request_read arms.

Net reduction: 50 lines. All existing behavior is preserved.

Closes #2986

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 1, 2026 21:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Rust guard labeling logic in tool_rules.rs to reduce duplication and keep scope/integrity handling consistent across tools, without intending to change labeling outcomes.

Changes:

  • Updated search_code to use the existing resolve_search_scope helper (matching search_issues / search_pull_requests).
  • Extracted duplicated issue/PR author-integrity elevation logic into a shared resolve_author_integrity helper and reused it at both call sites.

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

@lpcox lpcox merged commit 543c3f9 into main Apr 1, 2026
14 checks passed
@lpcox lpcox deleted the refactor/tool-rules-dedup-2986 branch April 1, 2026 21:56
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.

[rust-guard] Rust Guard: Deduplicate search scope resolution and trusted-author integrity elevation in tool_rules.rs

2 participants