Skip to content

Commit

Permalink
Add support for garage.github.com (#6478)
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Nov 3, 2022
1 parent 9ec2107 commit b94d073
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/ghinstance/host.go
Expand Up @@ -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)
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
16 changes: 16 additions & 0 deletions internal/ghinstance/host_test.go
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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/",
Expand Down

0 comments on commit b94d073

Please sign in to comment.