From b9aefe51f8c990ae03ce2ef9da37ab331775f218 Mon Sep 17 00:00:00 2001 From: Matar <47718015+Matars@users.noreply.github.com> Date: Fri, 19 Dec 2025 15:09:20 +0100 Subject: [PATCH] Revert "Fixed issues with handling of gh token" --- src/gitfetch/config.py | 4 ++-- src/gitfetch/fetcher.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gitfetch/config.py b/src/gitfetch/config.py index 5fb2f42..f01b069 100644 --- a/src/gitfetch/config.py +++ b/src/gitfetch/config.py @@ -255,7 +255,7 @@ def set_custom_box(self, box: str) -> None: self.config['DEFAULT'] = {} self.config['DEFAULT']['custom_box'] = box - def get_token(self) -> str: + def get_token(self) -> Optional[str]: """ Get the personal access token from config. @@ -263,7 +263,7 @@ def get_token(self) -> str: Token or None if not set """ token = self.config.get('DEFAULT', 'token', fallback='') - return token if token else '' + return token if token else None def set_token(self, token: str) -> None: """ diff --git a/src/gitfetch/fetcher.py b/src/gitfetch/fetcher.py index 065ae06..23a1591 100644 --- a/src/gitfetch/fetcher.py +++ b/src/gitfetch/fetcher.py @@ -79,6 +79,7 @@ def _build_contribution_graph_from_git(repo_path: str = ".") -> list: result = subprocess.run( ['git', 'log', '--pretty=format:%ai', '--all'], capture_output=True, text=True, cwd=repo_path, + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: return [] @@ -216,7 +217,7 @@ def _gh_api(self, endpoint: str, method: str = "GET") -> Any: capture_output=True, text=True, timeout=30, - env={'GH_TOKEN': self.token} if self.token != None else {} + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: raise Exception(f"gh api failed: {result.stderr}") @@ -441,7 +442,7 @@ def _search_items(self, query: str, per_page: int = 5) -> Dict[str, Any]: capture_output=True, text=True, timeout=30, - env={'GH_TOKEN': self.token} if self.token != None else {} + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: return {'total_count': 0, 'items': []} @@ -553,7 +554,7 @@ def _fetch_contribution_graph(self, username: str) -> list: capture_output=True, text=True, timeout=30, - env={'GH_TOKEN': self.token} if self.token != None else {} + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: @@ -646,6 +647,7 @@ def _api_request(self, endpoint: str) -> Any: capture_output=True, text=True, timeout=30, + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: raise Exception(f"API request failed: {result.stderr}")