Skip to content

Commit 61550e2

Browse files
authored
Merge pull request #64 from Zeviraty/main
2 parents 27e834a + f9b3a4d commit 61550e2

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ classifiers = [
2727
]
2828

2929
dependencies = [
30-
"requests>=2.0.0",
31-
"readchar>=4.0.0"
30+
"requests>=2.0.0",
31+
"readchar>=4.0.0",
3232
]
3333

3434
[project.optional-dependencies]

src/gitfetch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _get_version() -> str:
1212
# Try to get version from package metadata
1313
from importlib import metadata
1414
return metadata.version("gitfetch")
15-
except (ImportError, metadata.PackageNotFoundError):
15+
except (ImportError):
1616
pass
1717

1818
# Fallback: try to read from pyproject.toml (works in development)

src/gitfetch/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def main() -> int:
201201

202202
# Check for --local flag
203203
if args.local:
204+
import os
204205
if not os.path.exists('.git'):
205206
print("Error: --local requires .git folder", file=sys.stderr)
206207
return 1
@@ -534,7 +535,7 @@ def _create_fetcher(provider: str, base_url: str, token: Optional[str] = None):
534535
def _initialize_gitfetch(config_manager: ConfigManager) -> bool:
535536
"""
536537
Initialize gitfetch by creating config directory and setting
537-
the authenticated user as default.
538+
multiple configuration options.
538539
539540
Args:
540541
config_manager: ConfigManager instance
@@ -566,9 +567,10 @@ def _initialize_gitfetch(config_manager: ConfigManager) -> bool:
566567

567568
# Ask for token if needed
568569
token = None
569-
if provider in ['gitlab', 'gitea', 'sourcehut']:
570+
if provider in ['gitlab', 'gitea', 'sourcehut', 'github']:
570571
token_input = input(
571-
f"Enter your {provider} personal access token "
572+
f"Enter your {provider} personal access token{', needed for private repositories' if provider == 'github' else ''}\n"
573+
+
572574
"(optional, press Enter to skip): "
573575
).strip()
574576
if token_input:

src/gitfetch/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def _load_config(self) -> None:
7676
# Create default config
7777
self.config['DEFAULT'] = {
7878
'username': '',
79-
'cache_expiry_minutes': '15'
79+
'cache_expiry_minutes': '15',
80+
'token': '',
8081
}
8182
self.config.add_section('COLORS')
8283
for key, value in default_colors.items():

src/gitfetch/fetcher.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ def _build_contribution_graph_from_git(repo_path: str = ".") -> list:
7878
# Get commit dates
7979
result = subprocess.run(
8080
['git', 'log', '--pretty=format:%ai', '--all'],
81-
capture_output=True, text=True, cwd=repo_path
81+
capture_output=True, text=True, cwd=repo_path,
82+
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
8283
)
8384
if result.returncode != 0:
8485
return []
@@ -130,8 +131,9 @@ def __init__(self, token: Optional[str] = None):
130131
Initialize the GitHub fetcher.
131132
132133
Args:
133-
token: Optional GitHub personal access token (ignored, uses gh CLI)
134+
token: Optional GitHub personal access token
134135
"""
136+
self.token=token
135137
pass
136138

137139
def _check_gh_cli(self) -> None:
@@ -214,7 +216,8 @@ def _gh_api(self, endpoint: str, method: str = "GET") -> Any:
214216
['gh', 'api', endpoint, '-X', method],
215217
capture_output=True,
216218
text=True,
217-
timeout=30
219+
timeout=30,
220+
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
218221
)
219222
if result.returncode != 0:
220223
raise Exception(f"gh api failed: {result.stderr}")
@@ -438,7 +441,8 @@ def _search_items(self, query: str, per_page: int = 5) -> Dict[str, Any]:
438441
cmd,
439442
capture_output=True,
440443
text=True,
441-
timeout=30
444+
timeout=30,
445+
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
442446
)
443447
if result.returncode != 0:
444448
return {'total_count': 0, 'items': []}
@@ -531,7 +535,7 @@ def _fetch_contribution_graph(self, username: str) -> list:
531535
# GraphQL query for contribution calendar (inline username)
532536
query = f'''{{
533537
user(login: "{username}") {{
534-
contributionsCollection {{
538+
contributionsCollection(includePrivate: true) {{
535539
contributionCalendar {{
536540
weeks {{
537541
contributionDays {{
@@ -549,7 +553,8 @@ def _fetch_contribution_graph(self, username: str) -> list:
549553
['gh', 'api', 'graphql', '-f', f'query={query}'],
550554
capture_output=True,
551555
text=True,
552-
timeout=30
556+
timeout=30,
557+
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
553558
)
554559

555560
if result.returncode != 0:
@@ -641,7 +646,8 @@ def _api_request(self, endpoint: str) -> Any:
641646
cmd,
642647
capture_output=True,
643648
text=True,
644-
timeout=30
649+
timeout=30,
650+
env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')}
645651
)
646652
if result.returncode != 0:
647653
raise Exception(f"API request failed: {result.stderr}")

0 commit comments

Comments
 (0)