Skip to content

Commit

Permalink
Fixes #14 by adding enterprise url support
Browse files Browse the repository at this point in the history
Also only check rate limit when there's one set (our ghe apparently
    doesn't)

Signed-off-by: Gavin Mogan <[email protected]>
  • Loading branch information
halkeye authored and alexellis committed Sep 14, 2023
1 parent 0245cdc commit e6781a6
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ type RepoSummary struct {

func main() {
var (
orgName, userName, token, tokenFile, repoList, reposFile string
days int
punchCard, byRepo bool
orgName, userName, token, tokenFile, repoList, reposFile, apiUrl string
days int
punchCard, byRepo bool
)

flag.StringVar(&orgName, "org", "", "Organization name")
flag.StringVar(&userName, "user", "", "User name")
flag.StringVar(&apiUrl, "apiUrl", "", "Override Github API URL")
flag.StringVar(&token, "token", "", "GitHub token")
flag.StringVar(&tokenFile, "token-file", "", "Path to the file containing the GitHub token")
flag.StringVar(&repoList, "include", "", "List of repos you want stats for eg. 'org/repo1,org/repo2'")
Expand Down Expand Up @@ -67,6 +68,13 @@ func main() {
}

client := github.NewClient(auth)
if len(apiUrl) > 0 {
var err error
client, err = github.NewEnterpriseClient(apiUrl, "", auth)
if err != nil {
log.Fatal(err)
}
}
created := time.Now().AddDate(0, 0, -days)
format := "2006-01-02"
createdQuery := ">=" + created.Format(format)
Expand Down Expand Up @@ -126,7 +134,7 @@ func main() {
log.Fatal(err)
}

if res.Rate.Remaining == 0 {
if res.Rate.Limit > 0 && res.Rate.Remaining == 0 {
panic("Rate limit exceeded")
}

Expand Down

0 comments on commit e6781a6

Please sign in to comment.