Skip to content

Commit

Permalink
print if github token is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
bakito committed Oct 11, 2024
1 parent 3ef03f5 commit 55d439f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions pkg/github/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ func LatestRelease(client *resty.Client, repo string, quiet bool) (*types.Github
ghc := client.R().
SetResult(ghr).
SetHeader("Accept", "application/json")
if t, ok := os.LookupEnv("GITHUB_TOKEN"); ok {
if !quiet {
log.Printf("🔑 Using github token\n")
}
ghc = ghc.SetAuthToken(t)
}
handleGithubToken(ghc, quiet)
_, err := ghc.Get(latestReleaseURL(repo))
if err != nil {
return nil, http.CheckError(err)
Expand All @@ -49,18 +44,26 @@ func LatestRelease(client *resty.Client, repo string, quiet bool) (*types.Github
return ghr, nil
}

func handleGithubToken(ghc *resty.Request, quiet bool) {
if t, ok := os.LookupEnv("GITHUB_TOKEN"); ok {
if !quiet {
log.Printf("🔑 Using github token\n")
}
ghc.SetAuthToken(t)
} else if !quiet {
log.Printf("⚠️ github token 'GITHUB_TOKEN' is not set.\n")
}
}

func Release(client *resty.Client, repo string, version string, quiet bool) (*types.GithubRelease, error) {
ghr := &types.GithubRelease{}

ghc := client.R().
SetResult(ghr).
SetHeader("Accept", "application/json")
if t, ok := os.LookupEnv("GITHUB_TOKEN"); ok {
if !quiet {
log.Printf("🔑 Using github token\n")
}
ghc = ghc.SetAuthToken(t)
}

handleGithubToken(ghc, quiet)

_, err := ghc.Get(releaseURL(repo, version))
if err != nil {
return nil, http.CheckError(err)
Expand Down

0 comments on commit 55d439f

Please sign in to comment.