fix: set a clear User-Agent for all SonarQube API calls#482
Conversation
Requests previously used the Go http.Client default User-Agent (Go-http-client/1.1), making SMT activity hard to distinguish in SQC logs. Add a userAgentTransport to the shared transport stack in lib/sq-api-go so every request now sends "sonar-migration-tool". Fixes #479 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…eaders debugTransport wrapped authTransport/userAgentTransport from the outside, but both inject their header by cloning the request and mutating the clone, a clone debugTransport never saw since it held the original request object. The debug log headers field was always empty as a result. Reorder buildTransport to: authTransport -> userAgentTransport -> debugTransport (optional) -> retryTransport -> http.Transport, so header injection happens before debug capture. debugTransport still sits outside retryTransport, so it logs once per logical call, not once per retry attempt. Also document the fixed sonar-migration-tool User-Agent in ADVANCED-CONFIG.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
| // authTransport and userAgentTransport sit outside debugTransport (rather | ||
| // than the other way around) because both inject their header by cloning | ||
| // the request and setting it on the clone — a clone debugTransport would | ||
| // never see if it wrapped them from the outside. Retry sits innermost so |
There was a problem hiding this comment.
💡 Quality: Garbled sentence in buildTransport ordering comment
The comment explaining the transport ordering reads: "because both inject their header by cloning the request and setting it on the clone — a clone debugTransport would never see if it wrapped them from the outside." This sentence is grammatically broken and hard to parse ("a clone debugTransport would never see if it wrapped them"). The intended meaning is that authTransport/userAgentTransport set their headers on a cloned request, so a debugTransport wrapping them from the outside would only ever see the caller's original request and miss the injected Authorization/User-Agent headers. Consider rewording for clarity, e.g. "...set it on the clone — a debugTransport wrapping them from the outside would only see the caller's original request and never the injected headers."
Reword the comment so the rationale reads clearly.:
// authTransport and userAgentTransport sit outside debugTransport (rather
// than the other way around) because both inject their header by cloning
// the request and setting it on the clone — a debugTransport wrapping them
// from the outside would only ever see the caller's original, unmodified
// request and never the injected headers. Retry sits innermost so
// debugTransport still logs exactly once per logical call, using the
// final response after any retries.
Was this helpful? React with 👍 / 👎
|
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsInjects a specific 'sonar-migration-tool' User-Agent into all API requests to improve auditability in server logs. Consider clarifying the comment in buildTransport to improve readability. 💡 Quality: Garbled sentence in buildTransport ordering comment📄 lib/sq-api-go/client.go:117-120 The comment explaining the transport ordering reads: "because both inject their header by cloning the request and setting it on the clone — a clone debugTransport would never see if it wrapped them from the outside." This sentence is grammatically broken and hard to parse ("a clone debugTransport would never see if it wrapped them"). The intended meaning is that authTransport/userAgentTransport set their headers on a cloned request, so a debugTransport wrapping them from the outside would only ever see the caller's original request and miss the injected Authorization/User-Agent headers. Consider rewording for clarity, e.g. "...set it on the clone — a debugTransport wrapping them from the outside would only see the caller's original request and never the injected headers." Reword the comment so the rationale reads clearly.🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |



Summary
Fixes #479
Test plan
🤖 Generated with Claude Code