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

未关闭 适合新手
#16,697 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
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 分钟
30 天内合并 PR
177

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

github/gh-aw-mcpg 的其他 Issue

查看 github/gh-aw-mcpg 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。