diff --git a/pkg/utils/api.go b/pkg/utils/api.go index 4a8d14e4ef..7a008b6791 100644 --- a/pkg/utils/api.go +++ b/pkg/utils/api.go @@ -301,10 +301,12 @@ const ( ) func classifyHost(u *url.URL) HostType { + // Hostnames are case-insensitive, so "https://GitHub.com" is still github.com. + hostname := strings.ToLower(u.Hostname()) switch { - case u.Hostname() == "github.com" || strings.HasSuffix(u.Hostname(), ".github.com"): + case hostname == "github.com" || strings.HasSuffix(hostname, ".github.com"): return HostTypeDotcom - case u.Hostname() == "ghe.com" || strings.HasSuffix(u.Hostname(), ".ghe.com"): + case hostname == "ghe.com" || strings.HasSuffix(hostname, ".ghe.com"): return HostTypeGHEC default: return HostTypeGHES diff --git a/pkg/utils/api_test.go b/pkg/utils/api_test.go index baa1eb30ce..0ef753e35b 100644 --- a/pkg/utils/api_test.go +++ b/pkg/utils/api_test.go @@ -55,6 +55,16 @@ func TestParseAPIHost(t *testing.T) { input: "https://myghe.com", wantRestURL: "https://myghe.com/api/v3/", }, + { + name: "mixed case github.com hostname", + input: "https://GitHub.com", + wantRestURL: "https://api.github.com/", + }, + { + name: "mixed case ghe.com subdomain", + input: "https://Contoso.GHE.com", + wantRestURL: "https://api.Contoso.GHE.com/", + }, { name: "missing scheme", input: "github.com",