Skip to content

Commit

Permalink
feat: support Github Enterprise
Browse files Browse the repository at this point in the history
  • Loading branch information
alozanoff committed Jun 21, 2023
1 parent 373b587 commit e8fa997
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Usage of ./go-github-apps:
Installation ID
-show-insts
show all of the installations for the app
-url string
Full URL for a Github Enterprise installation, example 'https://github.example.com/api/v3'
-version
show version info
```
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ require (
github.com/bradleyfalzon/ghinstallation v1.1.1
github.com/google/go-github/v29 v29.0.3 // indirect
github.com/google/go-github/v52 v52.0.0
github.com/k0kubun/pp/v3 v3.2.0
golang.org/x/crypto v0.8.0 // indirect
)
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ github.com/google/go-github/v52 v52.0.0/go.mod h1:WJV6VEEUPuMo5pXqqa2ZCZEdbQqua4
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/k0kubun/pp/v3 v3.2.0 h1:h33hNTZ9nVFNP3u2Fsgz8JXiF5JINoZfFq4SvKJwNcs=
github.com/k0kubun/pp/v3 v3.2.0/go.mod h1:ODtJQbQcIRfAD3N+theGCV1m/CBxweERz2dapdz1EwA=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
Expand Down Expand Up @@ -62,7 +56,6 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
Expand All @@ -78,7 +71,6 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
23 changes: 18 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/bradleyfalzon/ghinstallation"
"github.com/google/go-github/v52/github"
"github.com/k0kubun/pp/v3"
)

var (
Expand All @@ -30,6 +29,7 @@ func main() {
export := flag.Bool("export", false, "show token as 'export GITHUB_TOKEN=...'")
showVersion := flag.Bool("version", false, "show version info")
showInsts := flag.Bool("show-insts", false, "show all of the installations for the app")
githubURL := flag.String("url", "", "Full URL for a Github Enterprise installation, example 'https://github.example.com/api/v3'")

origUsage := flag.Usage
flag.Usage = func() {
Expand Down Expand Up @@ -60,7 +60,7 @@ func main() {
os.Exit(1)
}

showInstallations(*appID, []byte(key))
showInstallations(*appID, []byte(key), githubURL)

return
}
Expand All @@ -77,6 +77,10 @@ func main() {
log.Fatal(err)
}

if githubURL != nil && *githubURL != "" {
itr.BaseURL = *githubURL
}

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

Expand All @@ -96,13 +100,22 @@ func showExport(token string) {
fmt.Printf("export GITHUB_TOKEN=%s\n", token)
}

func showInstallations(appID int64, key []byte) {
func showInstallations(appID int64, key []byte, githubURL *string) {
atr, err := ghinstallation.NewAppsTransport(http.DefaultTransport, appID, key)
if err != nil {
log.Fatal(err)
}

client := github.NewClient(&http.Client{Transport: atr})
var client *github.Client
if githubURL != nil && *githubURL != "" {
atr.BaseURL = *githubURL
client, err = github.NewEnterpriseClient(*githubURL, *githubURL, &http.Client{Transport: atr})
if err != nil {
log.Fatalf("failed creating enterprise client: %v", err)
}
} else {
client = github.NewClient(&http.Client{Transport: atr})
}

opts := &github.ListOptions{
PerPage: 10,
Expand All @@ -117,7 +130,7 @@ func showInstallations(appID int64, key []byte) {
log.Fatal(err)
}

pp.Println(inst)
fmt.Println(inst)

if resp.NextPage == 0 {
break
Expand Down

0 comments on commit e8fa997

Please sign in to comment.