Skip to content

Commit

Permalink
Fix GitHub token retrieval logic (#816)
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski authored Feb 13, 2023
1 parent 3bde9a0 commit 521a2b2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions git_machete/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 521a2b2

Please sign in to comment.