Skip to content

Commit

Permalink
Add support for garage.github.com (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Nov 1, 2022
1 parent c2fc965 commit 77a4c4f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/api/gql_client.go
Expand Up @@ -111,6 +111,9 @@ type gqlResponse struct {
}

func gqlEndpoint(host string) string {
if isGarage(host) {
return fmt.Sprintf("https://%s/api/graphql", host)
}
host = normalizeHostname(host)
if isEnterprise(host) {
return fmt.Sprintf("https://%s/api/graphql", host)
Expand Down
5 changes: 5 additions & 0 deletions internal/api/gql_client_test.go
Expand Up @@ -184,6 +184,11 @@ func TestGQLEndpoint(t *testing.T) {
host: "github.localhost",
wantEndpoint: "http://api.github.localhost/graphql",
},
{
name: "garage",
host: "garage.github.com",
wantEndpoint: "https://garage.github.com/api/graphql",
},
{
name: "enterprise",
host: "enterprise.com",
Expand Down
4 changes: 4 additions & 0 deletions internal/api/http.go
Expand Up @@ -109,6 +109,10 @@ func isSameDomain(requestHost, domain string) bool {
return (requestHost == domain) || strings.HasSuffix(requestHost, "."+domain)
}

func isGarage(host string) bool {
return strings.EqualFold(host, "garage.github.com")
}

func isEnterprise(host string) bool {
return host != github && host != localhost
}
Expand Down
3 changes: 3 additions & 0 deletions internal/api/rest_client.go
Expand Up @@ -117,6 +117,9 @@ func restURL(hostname string, pathOrURL string) string {
}

func restPrefix(hostname string) string {
if isGarage(hostname) {
return fmt.Sprintf("https://%s/api/v3/", hostname)
}
hostname = normalizeHostname(hostname)
if isEnterprise(hostname) {
return fmt.Sprintf("https://%s/api/v3/", hostname)
Expand Down
5 changes: 5 additions & 0 deletions internal/api/rest_client_test.go
Expand Up @@ -410,6 +410,11 @@ func TestRestPrefix(t *testing.T) {
host: "github.localhost",
wantEndpoint: "http://api.github.localhost/",
},
{
name: "garage",
host: "garage.github.com",
wantEndpoint: "https://garage.github.com/api/v3/",
},
{
name: "enterprise",
host: "enterprise.com",
Expand Down

0 comments on commit 77a4c4f

Please sign in to comment.