[Repo Assist] refactor: simplify TruncateSecret and extract HTTP client clone helper#9115
Merged
lpcox merged 2 commits intoJul 11, 2026
Conversation
- internal/sanitize: inline TruncateSecret logic, removing cross-package dependency on util.TruncateWithSuffix for a trivial 1-liner. Introduce named const prefixLen=4 for clarity. Behaviour is identical for all inputs. - internal/mcp: extract cloneHTTPClientWithTransport and resolveBaseTransport helpers to eliminate the repeated 4-line 'resolve default transport + shallow clone + assign new transport' idiom shared by buildHTTPClientWithHeaders and buildHTTPClientWithOIDC (reported as duplicate-code pattern in #9100). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors secret truncation and HTTP client transport wrapping without changing behavior.
Changes:
- Inlines four-byte secret truncation.
- Extracts HTTP client cloning and transport resolution helpers.
Show a summary per file
| File | Description |
|---|---|
internal/sanitize/sanitize.go |
Removes unnecessary utility dependency. |
internal/mcp/http_transport_client.go |
Deduplicates HTTP client wrapping logic. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Medium
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jul 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
Two small, low-risk refactors that reduce code duplication and cross-package coupling.
1.
internal/sanitize: InlineTruncateSecretlogicPreviously,
TruncateSecretdelegated toutil.TruncateWithSuffix(input, 4, "...")for thelen > 4case. That cross-package call was unnecessary: the operation is justinput[:4] + "...", a single expression that is more readable than the indirection.Changes:
internal/utilfromsanitizepackageutil.TruncateWithSuffix(input, 4, "...")withinput[:prefixLen] + "..."prefixLen = 4for clarity2.
internal/mcp: ExtractcloneHTTPClientWithTransport/resolveBaseTransporthelpersbuildHTTPClientWithHeadersandbuildHTTPClientWithOIDCshared an identical 4-line pattern:This pattern was identified as duplicate code in issue #9100. The helpers centralise this idiom, making each builder function a concise 2–3 liner.
Trade-offs
sanitizechange removes a dependency edge (sanitize→util), which slightly reduces coupling.mcpchange adds two tiny unexported helpers; they are package-private and easy to remove if the transport logic ever diverges.Test Status
Network access to
proxy.golang.orgis blocked in this sandbox, preventinggo buildandgo testfrom downloading modules. The changes are syntactically valid (confirmed withgofmt -l). Both modified functions are covered by existing tests (sanitize_test.go,http_transport_client_test.go) which will run in CI.Partially addresses #9100 (the per-logger boilerplate pattern in #9099 is a separate, larger refactor).
Warning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
awmgmcpgproxy.golang.orgSee Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run