Skip to content

Commit

Permalink
Merge pull request #84 from k1LoW/show-source
Browse files Browse the repository at this point in the history
Show sources
  • Loading branch information
k1LoW authored May 11, 2023
2 parents 69c8184 + 34c1c31 commit 0ed9942
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 0ed9942

Please sign in to comment.