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

オープン 初心者向け
#16,697 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
65/100
issue の種類
リファクタリング
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust

調査の方向性

guards/github-guard/rust-guard/src/labels/tool_rules.rsを読み、特にresolve_author_integrity、issueとPRからの呼び出し箇所、および指定された行付近の単体テストを確認してください。名前付きリソース構造体を導入し、呼び出し箇所とテストを更新してそれを使うようにしてください。crateのcargo testとcargo clippy --all-targetsを実行してください。テストが成功し、Clippyが新たな警告を報告しなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
Go
スター
188
フォーク
60
平均マージ
6時間 50分
マージ済み PR(30日)
177

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

github/gh-aw-mcpg のほかの issue

github/gh-aw-mcpg の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。