diff --git a/pkg/api/graphql_client_test.go b/pkg/api/graphql_client_test.go index 7f9f697..b27d38f 100644 --- a/pkg/api/graphql_client_test.go +++ b/pkg/api/graphql_client_test.go @@ -293,6 +293,11 @@ func TestGraphQLEndpoint(t *testing.T) { host: "enterprise.com", wantEndpoint: "https://enterprise.com/api/graphql", }, + { + name: "tenant", + host: "tenant.ghe.com", + wantEndpoint: "https://api.tenant.ghe.com/graphql", + }, } for _, tt := range tests { diff --git a/pkg/api/http_client.go b/pkg/api/http_client.go index 589de91..d20cb37 100644 --- a/pkg/api/http_client.go +++ b/pkg/api/http_client.go @@ -135,7 +135,14 @@ func isGarage(host string) bool { } func isEnterprise(host string) bool { - return host != github && host != localhost + return host != github && host != localhost && !isTenancy(host) +} + +// tenancyHost is the domain name of a tenancy GitHub instance. +const tenancyHost = "ghe.com" + +func isTenancy(host string) bool { + return strings.HasSuffix(host, "."+tenancyHost) } func normalizeHostname(hostname string) string { @@ -146,6 +153,14 @@ func normalizeHostname(hostname string) string { if strings.HasSuffix(hostname, "."+localhost) { return localhost } + // This has been copied over from the cli/cli NormalizeHostname function + // to ensure compatible behaviour but we don't fully understand when or + // why it would be useful here. We can't see what harm will come of + // duplicating the logic. + if before, found := strings.CutSuffix(hostname, "."+tenancyHost); found { + idx := strings.LastIndex(before, ".") + return fmt.Sprintf("%s.%s", before[idx+1:], tenancyHost) + } return hostname } diff --git a/pkg/api/rest_client_test.go b/pkg/api/rest_client_test.go index edbb9d2..bc2917e 100644 --- a/pkg/api/rest_client_test.go +++ b/pkg/api/rest_client_test.go @@ -474,6 +474,11 @@ func TestRestPrefix(t *testing.T) { host: "enterprise.com", wantEndpoint: "https://enterprise.com/api/v3/", }, + { + name: "tenant", + host: "tenant.ghe.com", + wantEndpoint: "https://api.tenant.ghe.com/", + }, } for _, tt := range tests {