Skip to content

[Repo Assist] refactor(rust-guard): extract short_sha helper to fix 5-site duplication and 7-vs-8 inconsistency#7316

Merged
lpcox merged 3 commits into
mainfrom
repo-assist/refactor-rust-guard-short-sha-7308-11e5da8e97e38d2f
Jun 10, 2026
Merged

[Repo Assist] refactor(rust-guard): extract short_sha helper to fix 5-site duplication and 7-vs-8 inconsistency#7316
lpcox merged 3 commits into
mainfrom
repo-assist/refactor-rust-guard-short-sha-7308-11e5da8e97e38d2f

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Closes #7308

Root Cause

The SHA truncation idiom (if sha.len() > 8 { &sha[..8] } else { sha }) was copy-pasted across 5 locations in 4 files, and silently diverged in length:

  • 4 sites used 8 characters (helpers.rs ×2, tool_rules.rs, response_items.rs)
  • 1 site used 7 characters (response_paths.rs) — the Git-canonical short SHA length

This means commit descriptions and log messages were inconsistent depending on the code path that produced them.

Fix

Added a single canonical helper in labels/helpers.rs:

/// Truncate a SHA to the standard 7-character short form used by GitHub's UI
/// and `git log --abbrev`. Returns the full string unchanged when it is already
/// shorter than 7 characters.
#[inline]
pub(crate) fn short_sha(sha: &str) -> &str {
    &sha[..sha.len().min(7)]
}

All 5 inline expressions replaced with short_sha(sha) / short_sha(&commit_sha). The 4 "8-char" sites now produce the same 7-char prefix as response_paths.rs, matching GitHub's UI and git log --abbrev.

Changes

File Change
labels/helpers.rs Added short_sha() helper + 3 unit tests; replaced 2 inline expressions
labels/tool_rules.rs Added short_sha to imports; replaced 1 inline expression
labels/response_items.rs Replaced 1 inline expression (uses helpers::* glob)
labels/response_paths.rs Replaced 1 inline expression (uses helpers::* glob)

Test Status

Rust guard tests: All 461 tests pass, including 3 new short_sha unit tests:

  • short_sha_truncates_full_sha_to_7
  • short_sha_leaves_short_shas_intact
  • short_sha_handles_empty_string

⚠️ Go tests: Build failed due to infrastructure — proxy.golang.org is blocked in this environment and Go module cache is incomplete. This is a pre-existing constraint unrelated to these Rust-only changes. The Go code is unchanged.

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

Generated by Repo Assist · sonnet46 6.3M ·

Add this agentic workflows to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@851905c06e905bf362a9f6cc54f912e3df747d55

…ion and 7-vs-8 inconsistency

Closes #7308

All 5 inline SHA truncation expressions are replaced with a single
canonical helper:

    pub(crate) fn short_sha(sha: &str) -> &str { &sha[..sha.len().min(7)] }

Sites updated:
- labels/helpers.rs:  2 inline expressions (both used 8 chars)
- labels/tool_rules.rs: 1 inline expression (used 8 chars)
- labels/response_items.rs: 1 inline expression (used 8 chars)
- labels/response_paths.rs: 1 inline expression (used 7 chars correctly)

All 4 "8-char" sites now match the canonical 7-char standard used by
response_paths.rs, GitHub's UI, and git log --abbrev output.

Added 3 unit tests: truncate full SHA to 7, leave short SHAs intact,
handle empty string.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review June 10, 2026 15:26
Copilot AI review requested due to automatic review settings June 10, 2026 15:26

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

This PR refactors the Rust guard labeling code to centralize SHA truncation into a single helper, eliminating duplicated inline truncation logic and making short-SHA formatting consistent across commit-related descriptions/logs.

Changes:

  • Added short_sha(&str) -> &str helper in labels/helpers.rs with unit tests.
  • Replaced 5 inline SHA truncation expressions across labeling modules with short_sha(...).
  • Standardized all short SHA outputs to 7 characters (matching Git/GitHub UI conventions).
Show a summary per file
File Description
guards/github-guard/rust-guard/src/labels/helpers.rs Adds the short_sha helper and unit tests; replaces two in-file truncation sites.
guards/github-guard/rust-guard/src/labels/tool_rules.rs Imports and uses short_sha for commit description formatting.
guards/github-guard/rust-guard/src/labels/response_items.rs Uses short_sha when labeling commit items in legacy (cloning) response labeling.
guards/github-guard/rust-guard/src/labels/response_paths.rs Uses short_sha when labeling commit paths in path-based response labeling.

Copilot's findings

Tip

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

  • Files reviewed: 4/4 changed files
  • Comments generated: 1

Comment thread guards/github-guard/rust-guard/src/labels/helpers.rs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpcox

lpcox commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@copilot fix this failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/27287036012/job/80597223427?pr=7316

The smoke-copilot-pr failure was a transient 401 authentication error when the CI tried to dispatch the smoke-copilot.lock.yml workflow — it's not related to any code changes in this PR. The same job succeeded in the previous run attempt on this branch. I've re-queued the failed job to re-run.

Copilot finished work on behalf of lpcox June 10, 2026 17:19
@lpcox

lpcox commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved in commit 053eb87. There was one conflict in helpers.rs — main had added 5 new extract_repo_scope_with_query_fallback tests right after the spot where this PR inserted the short_sha tests. Both sets are now present and all 466 Rust guard tests pass.

Copilot finished work on behalf of lpcox June 10, 2026 17:39
@lpcox lpcox merged commit 174c7b9 into main Jun 10, 2026
26 checks passed
@lpcox lpcox deleted the repo-assist/refactor-rust-guard-short-sha-7308-11e5da8e97e38d2f branch June 10, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rust-guard] Rust Guard: Extract short_sha helper to fix 5-site duplication and 7-vs-8 inconsistency

3 participants