Fix gh updater mechanism for unauthenticated users

Per code documentation: "BasicClient returns an API client that borrows
from but does not depend on user configuration". This means that any
errors while reading `oauth_token` should be tolerated.
This commit is contained in:
Mislav Marohnić 2020-04-23 15:41:37 +02:00
parent a7931a07c9
commit 84ac3d412e

View file

@ -111,20 +111,11 @@ func BasicClient() (*api.Client, error) {
}
opts = append(opts, api.AddHeader("User-Agent", fmt.Sprintf("GitHub CLI %s", Version)))
c, err := config.ParseDefaultConfig()
if err != nil {
return nil, err
if c, err := config.ParseDefaultConfig(); err == nil {
if token, _ := c.Get(defaultHostname, "oauth_token"); token != "" {
opts = append(opts, api.AddHeader("Authorization", fmt.Sprintf("token %s", token)))
}
}
token, err := c.Get(defaultHostname, "oauth_token")
if err != nil {
return nil, err
}
if token == "" {
return nil, fmt.Errorf("no oauth_token set in config")
}
opts = append(opts, api.AddHeader("Authorization", fmt.Sprintf("token %s", token)))
return api.NewClient(opts...), nil
}