Skip to content

Commit c255264

Browse files
authored
Merge pull request #69 from Zeviraty/main
Fixed issues with handling of gh token
2 parents 7ca3776 + 0152c04 commit c255264

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/gitfetch/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,15 +255,15 @@ def set_custom_box(self, box: str) -> None:
255255
self.config['DEFAULT'] = {}
256256
self.config['DEFAULT']['custom_box'] = box
257257

258-
def get_token(self) -> Optional[str]:
258+
def get_token(self) -> str:
259259
"""
260260
Get the personal access token from config.
261261
262262
Returns:
263263
Token or None if not set
264264
"""
265265
token = self.config.get('DEFAULT', 'token', fallback='')
266-
return token if token else None
266+
return token if token else ''
267267

268268
def set_token(self, token: str) -> None:
269269
"""

src/gitfetch/fetcher.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def _build_contribution_graph_from_git(repo_path: str = ".") -> list:
7979
result = subprocess.run(
8080
['git', 'log', '--pretty=format:%ai', '--all'],
8181
capture_output=True, text=True, cwd=repo_path,
82-
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
8382
)
8483
if result.returncode != 0:
8584
return []
@@ -217,7 +216,7 @@ def _gh_api(self, endpoint: str, method: str = "GET") -> Any:
217216
capture_output=True,
218217
text=True,
219218
timeout=30,
220-
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
219+
env={'GH_TOKEN': self.token} if self.token != None else {}
221220
)
222221
if result.returncode != 0:
223222
raise Exception(f"gh api failed: {result.stderr}")
@@ -442,7 +441,7 @@ def _search_items(self, query: str, per_page: int = 5) -> Dict[str, Any]:
442441
capture_output=True,
443442
text=True,
444443
timeout=30,
445-
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
444+
env={'GH_TOKEN': self.token} if self.token != None else {}
446445
)
447446
if result.returncode != 0:
448447
return {'total_count': 0, 'items': []}
@@ -554,7 +553,7 @@ def _fetch_contribution_graph(self, username: str) -> list:
554553
capture_output=True,
555554
text=True,
556555
timeout=30,
557-
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
556+
env={'GH_TOKEN': self.token} if self.token != None else {}
558557
)
559558

560559
if result.returncode != 0:
@@ -647,7 +646,6 @@ def _api_request(self, endpoint: str) -> Any:
647646
capture_output=True,
648647
text=True,
649648
timeout=30,
650-
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
651649
)
652650
if result.returncode != 0:
653651
raise Exception(f"API request failed: {result.stderr}")

0 commit comments

Comments
 (0)