[rust-guard] Group resource identifiers in resolve_author_integrity to drop a too_many_arguments allow

Aperta Adatta ai principianti
#16,697 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
65/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Leggi guards/github-guard/rust-guard/src/labels/tool_rules.rs, in particolare resolve_author_integrity, i relativi punti di chiamata per issue e PR e il test unitario intorno alle righe indicate. Introduci la struct della risorsa con nome e aggiorna i punti di chiamata e il test affinché la utilizzino. Esegui cargo test e cargo clippy --all-targets del crate; il lavoro è completato quando i test passano e Clippy non segnala nuovi avvisi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

refactor rust-guard

Improvement 1: Bundle resource identifiers into AuthoredResource

Category: API Surface / Type Safety
File(s): guards/github-guard/rust-guard/src/labels/tool_rules.rs (lines ~185, ~256, ~436, ~3281)
Effort: Small (< 15 min)
Risk: Low

Problem

resolve_author_integrity takes 9 positional arguments and carries #[allow(clippy::too_many_arguments)]. Four of them (owner, repo, repo_id, and resource_label/resource_num) all describe the same issue or PR. Because they are plain &str positional arguments, the compiler cannot catch a transposed pair such as owner/repo. The two call sites (issue read at ~line 251, PR read at ~line 430) and the unit test at ~line 3269 pass them in the same order, so a swap would be silent.

Suggested Change

Add a small borrowed struct that names the resource, and pass it as one argument. Remove the #[allow]. This drops the function to 5 arguments, below clippy's threshold.

Before
#[allow(clippy::too_many_arguments)]
fn resolve_author_integrity(
    owner: &str,
    repo: &str,
    repo_id: &str,
    author_login: Option<&str>,
    author_association: Option<&str>,
    resource_label: &str,
    resource_num: &str,
    base_integrity: &[String],
    ctx: &PolicyContext,
) -> Vec<String> { /* ... */ }

// call site
integrity = resolve_author_integrity(
    owner, repo, repo_id,
    info.author_login.as_deref(),
    info.author_association.as_deref(),
    tool_names::ISSUE_READ, &issue_num,
    &integrity, ctx,
);
After
/// Identifies the issue or PR whose author integrity is being resolved.
struct AuthoredResource<'a> {
    owner: &'a str,
    repo: &'a str,
    repo_id: &'a str,
    /// Tool name used as the resource kind in debug logs.
    label: &'a str,
    number: &'a str,
}

fn resolve_author_integrity(
    resource: &AuthoredResource<'_>,
    author_login: Option<&str>,
    author_association: Option<&str>,
    base_integrity: &[String],
    ctx: &PolicyContext,
) -> Vec<String> {
    let repo_id = resource.repo_id;
    // ... body unchanged, except resource_id uses resource.owner/repo/number
    // and elevate_via_collaborator_permission receives resource.label
}

// call site
integrity = resolve_author_integrity(
    &AuthoredResource {
        owner, repo, repo_id,
        label: tool_names::ISSUE_READ,
        number: &issue_num,
    },
    info.author_login.as_deref(),
    info.author_association.as_deref(),
    &integrity,
    ctx,
);

The full change is attached as proposal.diff (touches only tool_rules.rs, 3 call sites plus the test).

Verification

Run on a scratch copy of the crate, with the repository left untouched:

  • cargo test: 724 passed, 0 failed before and after the change.
  • cargo clippy --all-targets: warning count unchanged (90 needless_borrow and 1 field_reassign_with_default, both already tracked in earlier suggestions). No new warnings.
  • rustfmt --check src/labels/tool_rules.rs: clean.
  • The WASM target (wasm32-wasip1) is not installed in this environment, so the WASM build was not run. The change is type-level only, with no FFI or ABI surface touched, so no codegen difference is expected.
Why This Matters
  • Named fields make the call sites self-describing and remove the risk of silently swapping owner/repo or label/number.
  • Removes one of the three too_many_arguments allows. The remaining two (apply_governance_labels and apply_issue_read_enrichment, both 8 arguments) are natural follow-ups using the same pattern.

Generated by Rust Guard Improver • Run: 44053257234

Generated by Rust Guard Improver · copilot · routed: haiku55 xhigh · ~5 AIC · ⊞ 5K · ◷

  • expires on Nov 24, 2026, 9:17 AM UTC
Lingua principale
Go
Stelle
188
Fork
60
Merge medio
6h 50m
PR unite (30g)
177

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di github/gh-aw-mcpg

Tutte le issue di github/gh-aw-mcpg

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.