From 521a2b2c4f33f62479901be5197cfd6ddcb9af6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Lipski?= Date: Mon, 13 Feb 2023 19:23:55 +0100 Subject: [PATCH] Fix GitHub token retrieval logic (#816) --- RELEASE_NOTES.md | 1 + git_machete/github.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index fa54458c4..459bcdcea 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -3,6 +3,7 @@ ## New in git-machete 3.15.2 - fixed: zsh shell completion for the `slide-out` command no longer fails +- fixed: GitHub token retrieval logic ## New in git-machete 3.15.1 diff --git a/git_machete/github.py b/git_machete/github.py index 2355c402b..09de79bb2 100644 --- a/git_machete/github.py +++ b/git_machete/github.py @@ -103,10 +103,15 @@ def __init__(self, self.__domain = domain self.__value: Optional[str] = None self.__provider: Optional[str] = None - for token_retrieval_method in [self.__get_token_from_hub, self.__get_token_from_gh, self.__get_token_from_env, - self.__get_token_from_file_in_home_directory]: + for token_retrieval_method in [self.__get_token_from_env, + self.__get_token_from_file_in_home_directory, + self.__get_token_from_gh, + self.__get_token_from_hub]: if not (self.value and self.provider): token_retrieval_method() + if self.value and self.provider: + debug("authenticating via " + self.provider) + break def __bool__(self) -> bool: return self.__value is not None and self.__provider is not None @@ -135,6 +140,7 @@ def __get_token_from_hub(self) -> None: result = re.sub(' *oauth_token: *', '', line).rstrip().replace('"', '') self.__value = result self.__provider = f'auth token for {self.__domain} from `hub` GitHub CLI' + break def __get_token_from_gh(self) -> None: # Abort without error if `gh` isn't available