Skip to content

Commit

Permalink
fix: github enterprise graphql endpoint url
Browse files Browse the repository at this point in the history
Exposes Client.GraphQLURL to enable testing.

fixes #31
  • Loading branch information
hugoduncan committed Sep 27, 2019
1 parent 4476a28 commit c481833
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion scm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ type (
Client *http.Client

// Base URL for API requests.
BaseURL *url.URL
BaseURL *url.URL
GraphQLURL *url.URL

// Services used for communicating with the API.
Driver Driver
Expand Down
7 changes: 7 additions & 0 deletions scm/driver/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func New(uri string) (*scm.Client, error) {
client.Webhooks = &webhookService{client}

graphqlEndpoint := scm.UrlJoin(uri, "/graphql")
if strings.HasSuffix(uri, "/api/v3") {
graphqlEndpoint = scm.UrlJoin(uri[0:len(uri)-2], "graphql")
}
client.GraphQLURL, err = url.Parse(graphqlEndpoint)
if err != nil {
return nil, err
}
client.GraphQL = &dynamicGraphQLClient{client, graphqlEndpoint}

return client.Client, nil
Expand Down
20 changes: 20 additions & 0 deletions scm/driver/github/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ func TestClient(t *testing.T) {
}
}

func TestGraphQLClient(t *testing.T) {
client, err := New("https://api.github.com")
if err != nil {
t.Error(err)
}
if got, want := client.GraphQLURL.String(), "https://api.github.com/graphql"; got != want {
t.Errorf("Want GraphQl Client URL %q, got %q", want, got)
}
}

func TestClient_Base(t *testing.T) {
client, err := New("https://github.example.com/api/v3")
if err != nil {
Expand All @@ -44,6 +54,16 @@ func TestClient_Base(t *testing.T) {
}
}

func TestEnterpriseGraphQLClient(t *testing.T) {
client, err := New("https://github.example.com/api/v3")
if err != nil {
t.Error(err)
}
if got, want := client.GraphQLURL.String(), "https://github.example.com/api/graphql"; got != want {
t.Errorf("Want GraphQl Client URL %q, got %q", want, got)
}
}

func TestClient_Default(t *testing.T) {
client := NewDefault()
if got, want := client.BaseURL.String(), "https://api.github.com/"; got != want {
Expand Down

0 comments on commit c481833

Please sign in to comment.