Skip to content

Commit

Permalink
Fix bug where graphQL enterprise client would try to use graphQL (#40)
Browse files Browse the repository at this point in the history
Fix bug where graphQL enterprise client would try to use graphQL endpoint to fetch token.
Use only hostname in GITHUB_HOST
  • Loading branch information
Oded-B authored Mar 3, 2023
1 parent fbac736 commit 96e55c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Environment variables for the webhook process:

`GITHUB_OAUTH_TOKEN` GitHub main OAuth token for all other GH operations

`GITHUB_HOST` URL for github API, needed for Github Enterprise Server, should include http scheme but no `/api/v3` path, e.g. :`https://my-gh-host.com/`
`GITHUB_HOST` Host name for github API, needed for Github Enterprise Server, should not include http scheme and path, e.g. :`my-gh-host.com`

`GITHUB_WEBHOOK_SECRET` secret used to sign webhook payload to be validated by the WH server, must match the sting in repo settings/hooks page

Expand Down
11 changes: 6 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func createGithubRestClient(tokenEnvVarName string, githubRestAltURL string, ctx
return client
}

func createGithubAppGraphQlClient(githubAppPrivateKeyPath string, githubGraphqlAltURL string, ctx context.Context) *githubv4.Client {
httpClient, _ := createGithubInstalltionHttpClient(githubAppPrivateKeyPath, githubGraphqlAltURL, ctx)
func createGithubAppGraphQlClient(githubAppPrivateKeyPath string, githubGraphqlAltURL string, githubRestAltURL string, ctx context.Context) *githubv4.Client {
httpClient, _ := createGithubInstalltionHttpClient(githubAppPrivateKeyPath, githubRestAltURL, ctx)
var client *githubv4.Client
if githubGraphqlAltURL != "" {
client = githubv4.NewEnterpriseClient(githubGraphqlAltURL, httpClient)
Expand Down Expand Up @@ -190,16 +190,17 @@ func main() {
var githubRestAltURL string
var githubGraphqlAltURL string
if githubHost != "" {
githubRestAltURL = githubHost + "/api/v3"
githubGraphqlAltURL = githubHost + "api/graphql"
githubRestAltURL = "https://" + githubHost + "/api/v3"
githubGraphqlAltURL = "https://" + githubHost + "/api/graphql"
log.Infof("Github REST API endpoint is configured to %s", githubRestAltURL)
log.Infof("Github graphql API endpoint is configured to %s", githubGraphqlAltURL)
} else {
log.Infof("Using public Github API endpoint")
}
if githubAppPrivateKeyPath != "" {
log.Infoln("Using GH app auth")
mainGithubClient = createGithubAppRestClient(githubAppPrivateKeyPath, githubRestAltURL, ctx)
githubGraphQlClient = createGithubAppGraphQlClient(githubAppPrivateKeyPath, githubGraphqlAltURL, ctx)
githubGraphQlClient = createGithubAppGraphQlClient(githubAppPrivateKeyPath, githubGraphqlAltURL, githubRestAltURL, ctx)
} else {
mainGithubClient = createGithubRestClient("GITHUB_OAUTH_TOKEN", githubRestAltURL, ctx)
githubGraphQlClient = createGithubGraphQlClient("GITHUB_OAUTH_TOKEN", githubGraphqlAltURL)
Expand Down

0 comments on commit 96e55c0

Please sign in to comment.