Skip to content

Commit

Permalink
Set log
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Feb 14, 2023
1 parent d054717 commit a64a9fe
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,16 @@ func contains(s []string, e string) bool {
func client(ctx context.Context) (*github.Client, error) {
token, _, _, _ := factory.GetTokenAndEndpoints()
if token == "" {
log.Println("No credentials found, access without credentials")
return factory.NewGithubClient(factory.SkipAuth(true))
}
log.Println("Access with credentials")
c, err := factory.NewGithubClient()
if err != nil {
return nil, err
}
if _, _, err := c.Users.Get(ctx, ""); err != nil {
log.Println("Authentication failed, access without credentials")
return factory.NewGithubClient(factory.SkipAuth(true))
}
return c, nil
Expand All @@ -272,11 +275,13 @@ func client(ctx context.Context) (*github.Client, error) {
func httpClient() (*http.Client, error) {
token, v3ep, _, _ := factory.GetTokenAndEndpoints()
if token == "" {
log.Println("No credentials found, access without credentials")
return &http.Client{
Timeout: 30 * time.Second,
Transport: http.DefaultTransport.(*http.Transport).Clone(),
}, nil
}
log.Println("Access with credentials")
client, err := gh.HTTPClient(&api.ClientOptions{})
if err != nil {
return nil, err
Expand All @@ -292,6 +297,7 @@ func httpClient() (*http.Client, error) {
}
resp.Body.Close()
if resp.StatusCode != http.StatusOK {
log.Println("Authentication failed, access without credentials")
client = &http.Client{
Timeout: 30 * time.Second,
Transport: http.DefaultTransport.(*http.Transport).Clone(),
Expand Down

0 comments on commit a64a9fe

Please sign in to comment.