File tree Expand file tree Collapse file tree 3 files changed +26
-1
lines changed
Expand file tree Collapse file tree 3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -293,6 +293,11 @@ func TestGraphQLEndpoint(t *testing.T) {
293293 host : "enterprise.com" ,
294294 wantEndpoint : "https://enterprise.com/api/graphql" ,
295295 },
296+ {
297+ name : "tenant" ,
298+ host : "tenant.ghe.com" ,
299+ wantEndpoint : "https://api.tenant.ghe.com/graphql" ,
300+ },
296301 }
297302
298303 for _ , tt := range tests {
Original file line number Diff line number Diff line change @@ -135,7 +135,14 @@ func isGarage(host string) bool {
135135}
136136
137137func isEnterprise (host string ) bool {
138- return host != github && host != localhost
138+ return host != github && host != localhost && ! isTenancy (host )
139+ }
140+
141+ // tenancyHost is the domain name of a tenancy GitHub instance.
142+ const tenancyHost = "ghe.com"
143+
144+ func isTenancy (host string ) bool {
145+ return strings .HasSuffix (host , "." + tenancyHost )
139146}
140147
141148func normalizeHostname (hostname string ) string {
@@ -146,6 +153,14 @@ func normalizeHostname(hostname string) string {
146153 if strings .HasSuffix (hostname , "." + localhost ) {
147154 return localhost
148155 }
156+ // This has been copied over from the cli/cli NormalizeHostname function
157+ // to ensure compatible behaviour but we don't fully understand when or
158+ // why it would be useful here. We can't see what harm will come of
159+ // duplicating the logic.
160+ if before , found := strings .CutSuffix (hostname , "." + tenancyHost ); found {
161+ idx := strings .LastIndex (before , "." )
162+ return fmt .Sprintf ("%s.%s" , before [idx + 1 :], tenancyHost )
163+ }
149164 return hostname
150165}
151166
Original file line number Diff line number Diff line change @@ -474,6 +474,11 @@ func TestRestPrefix(t *testing.T) {
474474 host : "enterprise.com" ,
475475 wantEndpoint : "https://enterprise.com/api/v3/" ,
476476 },
477+ {
478+ name : "tenant" ,
479+ host : "tenant.ghe.com" ,
480+ wantEndpoint : "https://api.tenant.ghe.com/" ,
481+ },
477482 }
478483
479484 for _ , tt := range tests {
You can’t perform that action at this time.
0 commit comments