File tree 3 files changed +26
-1
lines changed
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) {
293
293
host : "enterprise.com" ,
294
294
wantEndpoint : "https://enterprise.com/api/graphql" ,
295
295
},
296
+ {
297
+ name : "tenant" ,
298
+ host : "tenant.ghe.com" ,
299
+ wantEndpoint : "https://api.tenant.ghe.com/graphql" ,
300
+ },
296
301
}
297
302
298
303
for _ , tt := range tests {
Original file line number Diff line number Diff line change @@ -135,7 +135,14 @@ func isGarage(host string) bool {
135
135
}
136
136
137
137
func 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 )
139
146
}
140
147
141
148
func normalizeHostname (hostname string ) string {
@@ -146,6 +153,14 @@ func normalizeHostname(hostname string) string {
146
153
if strings .HasSuffix (hostname , "." + localhost ) {
147
154
return localhost
148
155
}
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
+ }
149
164
return hostname
150
165
}
151
166
Original file line number Diff line number Diff line change @@ -474,6 +474,11 @@ func TestRestPrefix(t *testing.T) {
474
474
host : "enterprise.com" ,
475
475
wantEndpoint : "https://enterprise.com/api/v3/" ,
476
476
},
477
+ {
478
+ name : "tenant" ,
479
+ host : "tenant.ghe.com" ,
480
+ wantEndpoint : "https://api.tenant.ghe.com/" ,
481
+ },
477
482
}
478
483
479
484
for _ , tt := range tests {
You can’t perform that action at this time.
0 commit comments