From 4c09b7e2a5289f495d60ffee086c5a8565b3a219 Mon Sep 17 00:00:00 2001 From: roc1fr Date: Wed, 29 May 2024 14:13:36 +0200 Subject: [PATCH] fix(github): use different graphql path in enterprise version --- backend/plugins/github_graphql/impl/impl.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/plugins/github_graphql/impl/impl.go b/backend/plugins/github_graphql/impl/impl.go index 45050ad9859..8045cd14539 100644 --- a/backend/plugins/github_graphql/impl/impl.go +++ b/backend/plugins/github_graphql/impl/impl.go @@ -204,11 +204,18 @@ func (p GithubGraphql) PrepareTaskData(taskCtx plugin.TaskContext, options map[s } httpClient := oauth2.NewClient(oauthContext, src) - endpoint, err := errors.Convert01(url.JoinPath(connection.Endpoint, `graphql`)) + endpoint, err := errors.Convert01(url.Parse(connection.Endpoint)) if err != nil { return nil, errors.BadInput.Wrap(err, fmt.Sprintf("malformed connection endpoint supplied: %s", connection.Endpoint)) } - client := graphql.NewClient(endpoint, httpClient) + + // github.com and github enterprise have different graphql endpoints + endpoint.Path = "/graphql" // see https://docs.github.com/en/graphql/guides/forming-calls-with-graphql + if endpoint.Hostname() != "api.github.com" { + // see https://docs.github.com/en/enterprise-server@3.11/graphql/guides/forming-calls-with-graphql + endpoint.Path = "/api/graphql" + } + client := graphql.NewClient(endpoint.String(), httpClient) graphqlClient, err := helper.CreateAsyncGraphqlClient(taskCtx, client, taskCtx.GetLogger(), func(ctx context.Context, client *graphql.Client, logger log.Logger) (rateRemaining int, resetAt *time.Time, err errors.Error) { var query GraphQueryRateLimit