@@ -70,33 +70,46 @@ func DeriveGitHubAPIURL(defaultURL string) string {
7070 return derived
7171 }
7272 }
73- return strings .TrimRight (strings .TrimSpace (defaultURL ), "/" )
73+ result := strings .TrimRight (strings .TrimSpace (defaultURL ), "/" )
74+ logGitHub .Printf ("GitHub API URL falling back to provided default: %s" , result )
75+ return result
7476}
7577
7678// deriveAPIFromServerURL converts a GITHUB_SERVER_URL to the corresponding API endpoint.
7779// GHEC tenants (*.ghe.com): https://tenant.ghe.com → https://copilot-api.tenant.ghe.com
7880// GitHub.com: https://github.com → https://api.github.com
7981// GHES (all others): https://github.example.com → https://github.example.com/api/v3
8082func deriveAPIFromServerURL (serverURL string ) string {
83+ logGitHub .Printf ("Deriving API URL from server URL: %s" , serverURL )
84+
8185 parsed , err := url .Parse (strings .TrimRight (serverURL , "/" ))
8286 if err != nil || parsed .Host == "" {
87+ logGitHub .Printf ("Failed to parse server URL or empty host: serverURL=%s, err=%v" , serverURL , err )
8388 return ""
8489 }
8590 if parsed .Scheme != "http" && parsed .Scheme != "https" {
91+ logGitHub .Printf ("Unsupported scheme in server URL: scheme=%s, serverURL=%s" , parsed .Scheme , serverURL )
8692 return ""
8793 }
8894
8995 hostname := strings .ToLower (parsed .Hostname ())
9096
9197 switch {
9298 case hostname == "github.com" || hostname == "www.github.com" :
99+ logGitHub .Printf ("GitHub.com detected, using default API URL: %s" , DefaultGitHubAPIBaseURL )
93100 return DefaultGitHubAPIBaseURL
94101 case strings .HasSuffix (hostname , ".ghe.com" ):
102+ var apiURL string
95103 if port := parsed .Port (); port != "" {
96- return fmt .Sprintf ("%s://copilot-api.%s:%s" , parsed .Scheme , hostname , port )
104+ apiURL = fmt .Sprintf ("%s://copilot-api.%s:%s" , parsed .Scheme , hostname , port )
105+ } else {
106+ apiURL = fmt .Sprintf ("%s://copilot-api.%s" , parsed .Scheme , hostname )
97107 }
98- return fmt .Sprintf ("%s://copilot-api.%s" , parsed .Scheme , hostname )
108+ logGitHub .Printf ("GHEC tenant detected, using copilot-api subdomain: hostname=%s, apiURL=%s" , hostname , apiURL )
109+ return apiURL
99110 default :
100- return fmt .Sprintf ("%s://%s/api/v3" , parsed .Scheme , parsed .Host )
111+ apiURL := fmt .Sprintf ("%s://%s/api/v3" , parsed .Scheme , parsed .Host )
112+ logGitHub .Printf ("GHES instance detected, using /api/v3 path: host=%s, apiURL=%s" , parsed .Host , apiURL )
113+ return apiURL
101114 }
102115}
0 commit comments