Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/gitfetch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,15 @@ def set_custom_box(self, box: str) -> None:
self.config['DEFAULT'] = {}
self.config['DEFAULT']['custom_box'] = box

def get_token(self) -> Optional[str]:
def get_token(self) -> str:
"""
Get the personal access token from config.

Returns:
Token or None if not set
"""
token = self.config.get('DEFAULT', 'token', fallback='')
return token if token else None
return token if token else ''

def set_token(self, token: str) -> None:
"""
Expand Down
8 changes: 3 additions & 5 deletions src/gitfetch/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ 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 []
Expand Down Expand Up @@ -217,7 +216,7 @@ def _gh_api(self, endpoint: str, method: str = "GET") -> Any:
capture_output=True,
text=True,
timeout=30,
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
env={'GH_TOKEN': self.token} if self.token != None else {}
)
if result.returncode != 0:
raise Exception(f"gh api failed: {result.stderr}")
Expand Down Expand Up @@ -442,7 +441,7 @@ def _search_items(self, query: str, per_page: int = 5) -> Dict[str, Any]:
capture_output=True,
text=True,
timeout=30,
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
env={'GH_TOKEN': self.token} if self.token != None else {}
)
if result.returncode != 0:
return {'total_count': 0, 'items': []}
Expand Down Expand Up @@ -554,7 +553,7 @@ def _fetch_contribution_graph(self, username: str) -> list:
capture_output=True,
text=True,
timeout=30,
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
env={'GH_TOKEN': self.token} if self.token != None else {}
)

if result.returncode != 0:
Expand Down Expand Up @@ -647,7 +646,6 @@ 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}")
Expand Down