Currently I have an application that leverages both the Github v3 API (using https://github.com/google/go-github) and the v4 API for a number of Pull Request checks. Until recently I was using a personal access token in both libraries for authorization, but I recently switched to a GitHub App.
Here's a snippet of how I instantiate the clients:
// NewClient will generate a configured GitHub client for use.
func NewClient(ctx context.Context) *github.Client {
return github.NewClient(newGitHubAuth(&ctx))
}
// NewGraphClient will generate a configured GitHub client for use against the GraphQL API.
func NewGraphClient(ctx context.Context) *githubv4.Client {
return githubv4.NewClient(newGitHubAuth(&ctx))
}
func newGitHubAuth(ctx *context.Context) *http.Client {
// GitHub App installation
appPem := os.Getenv("GITHUB_APP_PEM")
if appPem != "" {
log.Debug("Pulling credentials for GitHub App")
itr, err := ghinstallation.NewKeyFromFile(http.DefaultTransport, appID, appInstallationID, appPem)
if err != nil {
log.Warning(err)
}
return &http.Client{Transport: itr}
}
// Interactive run by a user
token := os.Getenv("GITHUB_TOKEN")
if token != "" {
log.Debug("Pulling credentials for GitHub Personal Access Token")
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
return oauth2.NewClient(*ctx, ts)
}
log.Error("Unable to find GitHub credentials from the GITHUB_APP_PEM or GITHUB_TOKEN environment variables")
return &http.Client{}
}
Shortly after deploying, the v4 client began throwing a number of could not refresh installation id ... received non 2xx response status errors from the underlying ghinstallation library...but only for the v4 library. The v3 library appears to have continued functioning.
I haven't read anything in this repository around recommended implementations of GitHub Apps. Is using ghinstallation supported? If so, any idea what may be happening?
Currently I have an application that leverages both the Github v3 API (using https://github.com/google/go-github) and the v4 API for a number of Pull Request checks. Until recently I was using a personal access token in both libraries for authorization, but I recently switched to a GitHub App.
Here's a snippet of how I instantiate the clients:
Note that this is using the same https://github.com/bradleyfalzon/ghinstallation library for transport-based authentication as the v3 library is using.
Shortly after deploying, the v4 client began throwing a number of
could not refresh installation id ... received non 2xx response status
errors from the underlying ghinstallation library...but only for the v4 library. The v3 library appears to have continued functioning.I haven't read anything in this repository around recommended implementations of GitHub Apps. Is using ghinstallation supported? If so, any idea what may be happening?