diff --git a/internal/ghinstance/host.go b/internal/ghinstance/host.go index 30dafb79675..1fde25e23d0 100644 --- a/internal/ghinstance/host.go +++ b/internal/ghinstance/host.go @@ -22,6 +22,10 @@ func IsEnterprise(h string) bool { return normalizedHostName != defaultHostname && normalizedHostName != localhost } +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) @@ -47,6 +51,9 @@ func HostnameValidator(hostname string) error { } func GraphQLEndpoint(hostname string) string { + if isGarage(hostname) { + return fmt.Sprintf("https://%s/api/graphql", hostname) + } if IsEnterprise(hostname) { return fmt.Sprintf("https://%s/api/graphql", hostname) } @@ -57,6 +64,9 @@ func GraphQLEndpoint(hostname string) string { } func RESTPrefix(hostname string) string { + if isGarage(hostname) { + return fmt.Sprintf("https://%s/api/v3/", hostname) + } if IsEnterprise(hostname) { return fmt.Sprintf("https://%s/api/v3/", hostname) } @@ -77,6 +87,9 @@ func GistPrefix(hostname string) string { } func GistHost(hostname string) string { + if isGarage(hostname) { + return fmt.Sprintf("%s/gist/", hostname) + } if IsEnterprise(hostname) { return fmt.Sprintf("%s/gist/", hostname) } diff --git a/internal/ghinstance/host_test.go b/internal/ghinstance/host_test.go index 5feecbe630f..5fa6eb4f321 100644 --- a/internal/ghinstance/host_test.go +++ b/internal/ghinstance/host_test.go @@ -27,6 +27,10 @@ func TestIsEnterprise(t *testing.T) { host: "api.github.localhost", want: false, }, + { + host: "garage.github.com", + want: false, + }, { host: "ghe.io", want: true, @@ -74,6 +78,10 @@ func TestNormalizeHostname(t *testing.T) { host: "api.github.localhost", want: "github.localhost", }, + { + host: "garage.github.com", + want: "github.com", + }, { host: "GHE.IO", want: "ghe.io", @@ -144,6 +152,10 @@ func TestGraphQLEndpoint(t *testing.T) { host: "github.localhost", want: "http://api.github.localhost/graphql", }, + { + host: "garage.github.com", + want: "https://garage.github.com/api/graphql", + }, { host: "ghe.io", want: "https://ghe.io/api/graphql", @@ -171,6 +183,10 @@ func TestRESTPrefix(t *testing.T) { host: "github.localhost", want: "http://api.github.localhost/", }, + { + host: "garage.github.com", + want: "https://garage.github.com/api/v3/", + }, { host: "ghe.io", want: "https://ghe.io/api/v3/",