Skip to content

Commit

Permalink
fix(pkg/poiana): fix token retrieval from file.
Browse files Browse the repository at this point in the history
Properly trim newline chars at end of line.
Moreover, gh token MUST be passed, thus semplify `poiana.NewClient` method.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Feb 14, 2023
1 parent 6343ca3 commit deace84
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func initOpts() {
if verbose {
logrus.SetLevel(logrus.DebugLevel)
}

if ghToken == "" {
logrus.Fatal(`"gh-token" flag must be set`)
}
Expand Down
14 changes: 3 additions & 11 deletions pkg/poiana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package poiana

import (
"context"
"net/http"
"os"

"golang.org/x/oauth2"
"strings"

"github.com/google/go-github/v50/github"
)
Expand All @@ -16,12 +14,6 @@ func NewClient(ctx context.Context, tokenFile string) (*github.Client, error) {
return nil, err
}
ghTok := string(ghTokBytes)
var tc *http.Client
if ghTok != "" {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: ghTok},
)
tc = oauth2.NewClient(ctx, ts)
}
return github.NewClient(tc), nil
ghTok = strings.Trim(ghTok, "\n")
return github.NewTokenClient(ctx, ghTok), nil
}

0 comments on commit deace84

Please sign in to comment.