[Repo Assist] refactor(rust-guard): extract short_sha helper to fix 5-site duplication and 7-vs-8 inconsistency#7316
Conversation
…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>
There was a problem hiding this comment.
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) -> &strhelper inlabels/helpers.rswith 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
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot fix this failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/27287036012/job/80597223427?pr=7316 |
The |
|
@copilot resolve the merge conflicts in this pull request |
Resolved in commit |
🤖 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:helpers.rs×2,tool_rules.rs,response_items.rs)response_paths.rs) — the Git-canonical short SHA lengthThis 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: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 asresponse_paths.rs, matching GitHub's UI andgit log --abbrev.Changes
labels/helpers.rsshort_sha()helper + 3 unit tests; replaced 2 inline expressionslabels/tool_rules.rsshort_shato imports; replaced 1 inline expressionlabels/response_items.rshelpers::*glob)labels/response_paths.rshelpers::*glob)Test Status
✅ Rust guard tests: All 461 tests pass, including 3 new
short_shaunit tests:short_sha_truncates_full_sha_to_7short_sha_leaves_short_shas_intactshort_sha_handles_empty_stringproxy.golang.orgis 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.orgSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run