Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/utils/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/utils/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down