Skip to content

Commit c481833

Browse files
committed
fix: github enterprise graphql endpoint url
Exposes Client.GraphQLURL to enable testing. fixes drone#31
1 parent 4476a28 commit c481833

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

scm/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ type (
8989
Client *http.Client
9090

9191
// Base URL for API requests.
92-
BaseURL *url.URL
92+
BaseURL *url.URL
93+
GraphQLURL *url.URL
9394

9495
// Services used for communicating with the API.
9596
Driver Driver

scm/driver/github/github.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ func New(uri string) (*scm.Client, error) {
4949
client.Webhooks = &webhookService{client}
5050

5151
graphqlEndpoint := scm.UrlJoin(uri, "/graphql")
52+
if strings.HasSuffix(uri, "/api/v3") {
53+
graphqlEndpoint = scm.UrlJoin(uri[0:len(uri)-2], "graphql")
54+
}
55+
client.GraphQLURL, err = url.Parse(graphqlEndpoint)
56+
if err != nil {
57+
return nil, err
58+
}
5259
client.GraphQL = &dynamicGraphQLClient{client, graphqlEndpoint}
5360

5461
return client.Client, nil

scm/driver/github/github_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ func TestClient(t *testing.T) {
3434
}
3535
}
3636

37+
func TestGraphQLClient(t *testing.T) {
38+
client, err := New("https://api.github.com")
39+
if err != nil {
40+
t.Error(err)
41+
}
42+
if got, want := client.GraphQLURL.String(), "https://api.github.com/graphql"; got != want {
43+
t.Errorf("Want GraphQl Client URL %q, got %q", want, got)
44+
}
45+
}
46+
3747
func TestClient_Base(t *testing.T) {
3848
client, err := New("https://github.example.com/api/v3")
3949
if err != nil {
@@ -44,6 +54,16 @@ func TestClient_Base(t *testing.T) {
4454
}
4555
}
4656

57+
func TestEnterpriseGraphQLClient(t *testing.T) {
58+
client, err := New("https://github.example.com/api/v3")
59+
if err != nil {
60+
t.Error(err)
61+
}
62+
if got, want := client.GraphQLURL.String(), "https://github.example.com/api/graphql"; got != want {
63+
t.Errorf("Want GraphQl Client URL %q, got %q", want, got)
64+
}
65+
}
66+
4767
func TestClient_Default(t *testing.T) {
4868
client := NewDefault()
4969
if got, want := client.BaseURL.String(), "https://api.github.com/"; got != want {

0 commit comments

Comments
 (0)