Skip to content

Commit

Permalink
Show sources
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed May 11, 2023
1 parent 3659656 commit a33ee6b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions gh/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/cli/go-gh/v2/pkg/api"
"github.com/cli/go-gh/v2/pkg/auth"
"github.com/google/go-github/v52/github"
"github.com/k1LoW/go-github-client/v52/factory"
"golang.org/x/exp/slog"
Expand Down Expand Up @@ -39,18 +40,20 @@ const (
)

func newClient(ctx context.Context, owner, repo string) (*client, error) {
host, hostSource := auth.DefaultHost()
_, tokenSource := auth.TokenForHost(host)
token, v3ep, _, _ := factory.GetTokenAndEndpoints()
if token == "" {
slog.Info("No credentials found, access without credentials", slog.String("endpoint", v3ep), slog.String("owner", owner), slog.String("repo", repo))
return newNoAuthClient(ctx, owner, repo, v3ep)
}
slog.Info("Access with credentials", slog.String("endpoint", v3ep), slog.String("owner", owner), slog.String("repo", repo))
slog.Info("Access with credentials", slog.String("endpoint", v3ep), slog.String("owner", owner), slog.String("repo", repo), slog.String("host_source", hostSource), slog.String("token_source", tokenSource))
gc, err := factory.NewGithubClient(factory.SkipAuth(true))
if err != nil {
return nil, err
}
if _, _, err := gc.Repositories.Get(ctx, owner, repo); err != nil {
slog.Info("Authentication failed, access without credentials", slog.String("endpoint", v3ep), slog.String("owner", owner), slog.String("repo", repo))
slog.Info("Authentication failed, access without credentials", slog.String("endpoint", v3ep), slog.String("owner", owner), slog.String("repo", repo), slog.String("host_source", hostSource), slog.String("token_source", tokenSource))
return newNoAuthClient(ctx, owner, repo, v3ep)
}
hc, err := api.DefaultHTTPClient()
Expand Down

0 comments on commit a33ee6b

Please sign in to comment.