Skip to content

refactor(rust-guard): eliminate duplicated author_association lookup and raw field-name literals in backend.rs - #9535

Merged
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-eliminate-duplicate-lookup
Jul 18, 2026
Merged

refactor(rust-guard): eliminate duplicated author_association lookup and raw field-name literals in backend.rs#9535
lpcox merged 2 commits into
mainfrom
copilot/rust-guard-eliminate-duplicate-lookup

Conversation

Copilot AI commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

backend.rs had two inline copies of the author_association/authorAssociation dual-alias extraction pattern, despite helpers.rs already owning a helper for exactly this. It also used raw "full_name" and "login" string literals in five production-code sites while the field_names constants module (already imported in the test block of the same file) exists as the single source of truth for those names.

Changes

helpers.rs

  • get_author_association: fnpub(crate) fn (minimal visibility bump to expose within crate)

backend.rs — imports

// before
use super::constants::{MEDIUM_BUFFER_SIZE, SMALL_BUFFER_SIZE};
use super::helpers::is_pr_merged;

// after
use super::constants::{field_names, MEDIUM_BUFFER_SIZE, SMALL_BUFFER_SIZE};
use super::helpers::{get_author_association, is_pr_merged};

backend.rs — deduplicate author_association extraction (2 sites)

// before (repeated verbatim in both get_pull_request_facts_with_callback and get_issue_author_info_with_callback)
let author_association = item
    .get("author_association")
    .or_else(|| item.get("authorAssociation"))
    .and_then(|v| v.as_str())
    .map(String::from);

// after
let author_association = get_author_association(&item).map(String::from);

backend.rs — replace raw field-name literals with constants (5 sites)

  • "full_name"field_names::FULL_NAME (base and head repo in get_pull_request_facts_with_callback)
  • "login"field_names::LOGIN (PR author, issue author, collaborator #[cfg(test)] path)

…and raw field-name literals in backend.rs

- Make `get_author_association` in helpers.rs `pub(crate)` so backend.rs can use it
- Import `get_author_association` and `field_names` in backend.rs
- Replace two inline author_association extraction blocks with `get_author_association()`
- Replace raw `"full_name"` literals with `field_names::FULL_NAME` (2 sites)
- Replace raw `"login"` literals with `field_names::LOGIN` (3 sites)

Closes #9512
Copilot AI changed the title [WIP] Eliminate duplicated author_association lookup in backend.rs refactor(rust-guard): eliminate duplicated author_association lookup and raw field-name literals in backend.rs Jul 17, 2026
Copilot finished work on behalf of lpcox July 17, 2026 17:01
Copilot AI requested a review from lpcox July 17, 2026 17:01
@lpcox
lpcox marked this pull request as ready for review July 18, 2026 04:32
Copilot AI review requested due to automatic review settings July 18, 2026 04:32

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

Centralizes GitHub response-field extraction in the Rust guard.

Changes:

  • Exposes the existing author-association helper within the crate.
  • Reuses shared extraction helpers and field-name constants in backend logic.
Show a summary per file
File Description
helpers.rs Makes get_author_association crate-visible.
backend.rs Removes duplicate extraction logic and raw field-name literals.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Medium

@lpcox
lpcox merged commit b04fef5 into main Jul 18, 2026
37 checks passed
@lpcox
lpcox deleted the copilot/rust-guard-eliminate-duplicate-lookup branch July 18, 2026 04:36
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: Eliminate duplicated author_association lookup in backend.rs

3 participants