From 2db3f8d3037186855b800f60fa1e4185fdf72ad4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 19 May 2026 23:50:54 +0000 Subject: [PATCH 1/2] Add debug logging to deriveAPIFromServerURL Log entry and each switch-case result in deriveAPIFromServerURL so that operators can understand which GitHub API URL resolution path was taken (GitHub.com, GHEC *.ghe.com tenant, or GHES /api/v3 fallback). Also log the default-URL fallback path in DeriveGitHubAPIURL. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- internal/envutil/github.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/internal/envutil/github.go b/internal/envutil/github.go index 1551b66d8..5dfceb661 100644 --- a/internal/envutil/github.go +++ b/internal/envutil/github.go @@ -70,7 +70,9 @@ func DeriveGitHubAPIURL(defaultURL string) string { return derived } } - return strings.TrimRight(strings.TrimSpace(defaultURL), "/") + result := strings.TrimRight(strings.TrimSpace(defaultURL), "/") + logGitHub.Printf("GitHub API URL falling back to provided default: %s", result) + return result } // deriveAPIFromServerURL converts a GITHUB_SERVER_URL to the corresponding API endpoint. @@ -78,11 +80,15 @@ func DeriveGitHubAPIURL(defaultURL string) string { // GitHub.com: https://github.com → https://api.github.com // GHES (all others): https://github.example.com → https://github.example.com/api/v3 func deriveAPIFromServerURL(serverURL string) string { + logGitHub.Printf("Deriving API URL from server URL: %s", serverURL) + parsed, err := url.Parse(strings.TrimRight(serverURL, "/")) if err != nil || parsed.Host == "" { + logGitHub.Printf("Failed to parse server URL or empty host: serverURL=%s, err=%v", serverURL, err) return "" } if parsed.Scheme != "http" && parsed.Scheme != "https" { + logGitHub.Printf("Unsupported scheme in server URL: scheme=%s, serverURL=%s", parsed.Scheme, serverURL) return "" } @@ -90,13 +96,20 @@ func deriveAPIFromServerURL(serverURL string) string { switch { case hostname == "github.com" || hostname == "www.github.com": + logGitHub.Printf("GitHub.com detected, using default API URL: %s", DefaultGitHubAPIBaseURL) return DefaultGitHubAPIBaseURL case strings.HasSuffix(hostname, ".ghe.com"): + var apiURL string if port := parsed.Port(); port != "" { - return fmt.Sprintf("%s://copilot-api.%s:%s", parsed.Scheme, hostname, port) + apiURL = fmt.Sprintf("%s://copilot-api.%s:%s", parsed.Scheme, hostname, port) + } else { + apiURL = fmt.Sprintf("%s://copilot-api.%s", parsed.Scheme, hostname) } - return fmt.Sprintf("%s://copilot-api.%s", parsed.Scheme, hostname) + logGitHub.Printf("GHEC tenant detected, using copilot-api subdomain: hostname=%s, apiURL=%s", hostname, apiURL) + return apiURL default: - return fmt.Sprintf("%s://%s/api/v3", parsed.Scheme, parsed.Host) + apiURL := fmt.Sprintf("%s://%s/api/v3", parsed.Scheme, parsed.Host) + logGitHub.Printf("GHES instance detected, using /api/v3 path: host=%s, apiURL=%s", parsed.Host, apiURL) + return apiURL } } From d5a93a8d7d89f5d93444a8ad4d82178228e85fbe Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 20 May 2026 00:01:20 +0000 Subject: [PATCH 2/2] Redact URL values in GitHub API debug logs --- internal/envutil/github.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/envutil/github.go b/internal/envutil/github.go index 5dfceb661..a82c9301c 100644 --- a/internal/envutil/github.go +++ b/internal/envutil/github.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/github/gh-aw-mcpg/internal/logger" + "github.com/github/gh-aw-mcpg/internal/logger/sanitize" ) var logGitHub = logger.New("envutil:github") @@ -66,12 +67,12 @@ func DeriveGitHubAPIURL(defaultURL string) string { if serverURL := strings.TrimSpace(os.Getenv("GITHUB_SERVER_URL")); serverURL != "" { derived := deriveAPIFromServerURL(serverURL) if derived != "" { - logGitHub.Printf("GitHub API URL derived from GITHUB_SERVER_URL=%s: %s", serverURL, derived) + logGitHub.Printf("GitHub API URL derived from GITHUB_SERVER_URL=%s: %s", sanitize.RedactURL(serverURL), sanitize.RedactURL(derived)) return derived } } result := strings.TrimRight(strings.TrimSpace(defaultURL), "/") - logGitHub.Printf("GitHub API URL falling back to provided default: %s", result) + logGitHub.Printf("GitHub API URL falling back to provided default: %s", sanitize.RedactURL(result)) return result } @@ -80,15 +81,15 @@ func DeriveGitHubAPIURL(defaultURL string) string { // GitHub.com: https://github.com → https://api.github.com // GHES (all others): https://github.example.com → https://github.example.com/api/v3 func deriveAPIFromServerURL(serverURL string) string { - logGitHub.Printf("Deriving API URL from server URL: %s", serverURL) + logGitHub.Printf("Deriving API URL from server URL: %s", sanitize.RedactURL(serverURL)) parsed, err := url.Parse(strings.TrimRight(serverURL, "/")) if err != nil || parsed.Host == "" { - logGitHub.Printf("Failed to parse server URL or empty host: serverURL=%s, err=%v", serverURL, err) + logGitHub.Printf("Failed to parse server URL or empty host: serverURL=%s, err=%v", sanitize.RedactURL(serverURL), err) return "" } if parsed.Scheme != "http" && parsed.Scheme != "https" { - logGitHub.Printf("Unsupported scheme in server URL: scheme=%s, serverURL=%s", parsed.Scheme, serverURL) + logGitHub.Printf("Unsupported scheme in server URL: scheme=%s, serverURL=%s", parsed.Scheme, sanitize.RedactURL(serverURL)) return "" }