Created
June 16, 2018 07:17
-
-
Save haya14busa/612373686d75c711baad1fbbcf17d5ed to your computer and use it in GitHub Desktop.
find installation test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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