From 84ac3d412e42e28c491c655a10930e3b74c528b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 23 Apr 2020 15:41:37 +0200 Subject: [PATCH] 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. --- command/root.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/command/root.go b/command/root.go index 40be6a7e0..a6ea851ce 100644 --- a/command/root.go +++ b/command/root.go @@ -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 }