Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
find installation test
package main
import (
"context"
"fmt"
"net/http"
"github.com/bradleyfalzon/ghinstallation"
"github.com/google/go-github/github"
)
const (
integrationID = 0
privateKeyFile = "/path/to/github-apps.private-key.pem"
)
func main() {
ctx := context.Background()
tr := http.DefaultTransport
itr, err := ghinstallation.NewAppsTransportKeyFromFile(tr, integrationID, privateKeyFile)
if err != nil {
panic(err)
}
httpCli := http.DefaultClient
httpCli.Transport = itr
cli := github.NewClient(httpCli)
// haya14busa is GitHub user.
fmt.Println(cli.Apps.FindUserInstallation(ctx, "haya14busa")) // ok
fmt.Println(cli.Apps.FindOrganizationInstallation(ctx, "haya14busa")) // Not found
// vim-jp is GitHub organization.
fmt.Println(cli.Apps.FindOrganizationInstallation(ctx, "vim-jp")) // ok
// also ok (unexpectedly?)
// Asked: https://platform.github.community/t/find-installation-associated-with-repository/4102/11
fmt.Println(cli.Apps.FindUserInstallation(ctx, "vim-jp"))
fmt.Println(cli.Apps.FindRepositoryInstallation(ctx, "haya14busa", "reviewdog")) // ok
fmt.Println(cli.Apps.FindRepositoryInstallation(ctx, "vim-jp", "vital.vim")) // ok
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.