Repository navigation
Treat tenancy as non enterprise - #151
Conversation
andyfeller
left a comment
There was a problem hiding this comment.
Would we want to bring over the isTenancy() tests over too?
| // TenancyHost is the domain name of a tenancy GitHub instance. | ||
| const tenancyHost = "ghe.com" | ||
|
|
||
| func isEnterprise(host string) bool { | ||
| return host != github && host != localhost | ||
| return host != github && host != localhost && !isTenancy(host) | ||
| } | ||
|
|
||
| func isTenancy(host string) bool { | ||
| return strings.HasSuffix(host, "."+tenancyHost) | ||
| } |
There was a problem hiding this comment.
Any concerns about cli/go-gh not 1) normalizing the hostname as part of the boolean checks or 2) extracting the tenant name from a host name like cli/cli?
// IsEnterprise reports whether a non-normalized host name looks like a GHE instance.
func IsEnterprise(h string) bool {
normalizedHostName := NormalizeHostname(h)
return normalizedHostName != defaultHostname && normalizedHostName != localhost
}
// IsTenancy reports whether a non-normalized host name looks like a tenancy instance.
func IsTenancy(h string) bool {
normalizedHostName := NormalizeHostname(h)
return strings.HasSuffix(normalizedHostName, "."+tenancyHost)
}
// TenantName extracts the tenant name from tenancy host name and
// reports whether it found the tenant name.
func TenantName(h string) (string, bool) {
normalizedHostName := NormalizeHostname(h)
return cutSuffix(normalizedHostName, "."+tenancyHost)
}
func isGarage(h string) bool {
return strings.EqualFold(h, "garage.github.com")
}
// NormalizeHostname returns the canonical host name of a GitHub instance.
func NormalizeHostname(h string) string {
hostname := strings.ToLower(h)
if strings.HasSuffix(hostname, "."+defaultHostname) {
return defaultHostname
}
if strings.HasSuffix(hostname, "."+localhost) {
return localhost
}
if before, found := cutSuffix(hostname, "."+tenancyHost); found {
idx := strings.LastIndex(before, ".")
return fmt.Sprintf("%s.%s", before[idx+1:], tenancyHost)
}
return hostname
}There was a problem hiding this comment.
Any concerns about cli/go-gh not 1) normalizing the hostname as part of the boolean checks
Gah, I don't know. Some normalization does happen in go-gh so maybe? I just don't have a clear picture of when this happens and why it is important. It's probably best to match behaviour though even if we don't fully understand.
Lines 155 to 164 in d88d88f
- extracting the tenant name from a host name like cli/cli?
Don't see any reason to have this behaviour, it's used for something to do with repo remote URLs and SSH (though I do wonder if the same thing should be happening for gists, that's a separate issue.
Not specifically but this reminded me that I definitely want to add tests to Line 10 in d88d88f Really silly of me to forget. |
acdb31f to
2054b1b
Compare
| return hostname | ||
| } | ||
|
|
||
| // Backport strings.CutSuffix from Go 1.20. |
There was a problem hiding this comment.
Strictly speaking we shouldn't need this backport anymore but I'd rather change cli/cli and this at the same time, and I don't want to change cli/cli right now.
2054b1b to
ee82f3a
Compare
I know, but I hate to say we have a test suite for Lines 229 to 258 in ee82f3a You really sure? |
andyfeller
left a comment
There was a problem hiding this comment.
Looks good all in all.
I'm going to defer to you if you really don't think bringing over the tests for isTenancy is necessary here.
Following on the heels of #151, this commit exports the internal logic used to determine if a host is GHES deployment or a tenant. Exporting these functions allow extension authors like `github/gh-copilot` to provide tailored experiences consistently with `gh`.

Description
I think there's some things I'd like to move from https://github.com/cli/cli/blob/24481c5c2e49d3529a6621953b8878fe0514ff22/internal/ghinstance/host.go into
go-ghbut I think having this behaviour as an obvious standalone change is valuable without muddying the waters.