ghinstallation provides Transport, which implements http.RoundTripper to
provide authentication as an installation for GitHub Apps.
This library is designed to provide automatic authentication for https://github.com/google/go-github or your own HTTP client.
Get the package:
go get -u github.com/bradleyfalzon/ghinstallationimport "github.com/bradleyfalzon/ghinstallation"
func main() {
// Shared transport to reuse TCP connections.
tr := http.DefaultTransport
// Wrap the shared transport for use with the app ID 1 authenticating with installation ID 99.
itr, err := ghinstallation.NewKeyFromFile(tr, 1, 99, "2016-10-19.private-key.pem")
if err != nil {
log.Fatal(err)
}
// Use installation transport with github.com/google/go-github
client := github.NewClient(&http.Client{Transport: itr})
}For clients using GitHub Enterprise, set the base URL as follows:
import "github.com/bradleyfalzon/ghinstallation"
const GitHubEnterpriseURL = "https://github.example.com/api/v3"
func main() {
// Shared transport to reuse TCP connections.
tr := http.DefaultTransport
// Wrap the shared transport for use with the app ID 1 authenticating with installation ID 99.
itr, err := ghinstallation.NewKeyFromFile(tr, 1, 99, "2016-10-19.private-key.pem")
if err != nil {
log.Fatal(err)
}
itr.BaseURL = GitHubEnterpriseURL
// Use installation transport with github.com/google/go-github
client := github.NewEnterpriseClient(GitHubEnterpriseURL, GitHubEnterpriseURL, &http.Client{Transport: itr})
}app ID is the GitHub App ID.
You can check as following :
Settings > Developer > settings > GitHub App > About item
installation ID is a part of WebHook request.
You can get the number to check the request.
Settings > Developer > settings > GitHub Apps > Advanced > Payload in Request
tab
WebHook request
...
"installation": {
"id": `installation ID`
}
As of October 1, 2020, github.com uses the branch name ‘main’ when creating the initial default branch for all new repositories. In order to minimize any customizations in our github usage and to support consistent naming conventions, we have made the decision to rename the ‘master’ branch to be called ‘main’ in all Kochava’s github repos.
For local copies of the repo, the following steps will update to the new default branch:
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a