diff --git a/pyproject.toml b/pyproject.toml index 829abd6..fc04175 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,8 +27,8 @@ classifiers = [ ] dependencies = [ - "requests>=2.0.0", - "readchar>=4.0.0" + "requests>=2.0.0", + "readchar>=4.0.0", ] [project.optional-dependencies] diff --git a/src/gitfetch/__init__.py b/src/gitfetch/__init__.py index 46813cb..6713085 100644 --- a/src/gitfetch/__init__.py +++ b/src/gitfetch/__init__.py @@ -12,7 +12,7 @@ def _get_version() -> str: # Try to get version from package metadata from importlib import metadata return metadata.version("gitfetch") - except (ImportError, metadata.PackageNotFoundError): + except (ImportError): pass # Fallback: try to read from pyproject.toml (works in development) diff --git a/src/gitfetch/cli.py b/src/gitfetch/cli.py index f271c41..7e25003 100644 --- a/src/gitfetch/cli.py +++ b/src/gitfetch/cli.py @@ -201,6 +201,7 @@ def main() -> int: # Check for --local flag if args.local: + import os if not os.path.exists('.git'): print("Error: --local requires .git folder", file=sys.stderr) return 1 @@ -534,7 +535,7 @@ def _create_fetcher(provider: str, base_url: str, token: Optional[str] = None): def _initialize_gitfetch(config_manager: ConfigManager) -> bool: """ Initialize gitfetch by creating config directory and setting - the authenticated user as default. + multiple configuration options. Args: config_manager: ConfigManager instance @@ -566,9 +567,10 @@ def _initialize_gitfetch(config_manager: ConfigManager) -> bool: # Ask for token if needed token = None - if provider in ['gitlab', 'gitea', 'sourcehut']: + if provider in ['gitlab', 'gitea', 'sourcehut', 'github']: token_input = input( - f"Enter your {provider} personal access token " + f"Enter your {provider} personal access token{', needed for private repositories' if provider == 'github' else ''}\n" + + "(optional, press Enter to skip): " ).strip() if token_input: diff --git a/src/gitfetch/config.py b/src/gitfetch/config.py index 6c67b4f..f01b069 100644 --- a/src/gitfetch/config.py +++ b/src/gitfetch/config.py @@ -76,7 +76,8 @@ def _load_config(self) -> None: # Create default config self.config['DEFAULT'] = { 'username': '', - 'cache_expiry_minutes': '15' + 'cache_expiry_minutes': '15', + 'token': '', } self.config.add_section('COLORS') for key, value in default_colors.items(): diff --git a/src/gitfetch/fetcher.py b/src/gitfetch/fetcher.py index b71e9b8..23a1591 100644 --- a/src/gitfetch/fetcher.py +++ b/src/gitfetch/fetcher.py @@ -78,7 +78,8 @@ def _build_contribution_graph_from_git(repo_path: str = ".") -> list: # Get commit dates result = subprocess.run( ['git', 'log', '--pretty=format:%ai', '--all'], - capture_output=True, text=True, cwd=repo_path + capture_output=True, text=True, cwd=repo_path, + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: return [] @@ -130,8 +131,9 @@ def __init__(self, token: Optional[str] = None): Initialize the GitHub fetcher. Args: - token: Optional GitHub personal access token (ignored, uses gh CLI) + token: Optional GitHub personal access token """ + self.token=token pass def _check_gh_cli(self) -> None: @@ -214,7 +216,8 @@ def _gh_api(self, endpoint: str, method: str = "GET") -> Any: ['gh', 'api', endpoint, '-X', method], capture_output=True, text=True, - timeout=30 + timeout=30, + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: 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]: cmd, capture_output=True, text=True, - timeout=30 + timeout=30, + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: return {'total_count': 0, 'items': []} @@ -531,7 +535,7 @@ def _fetch_contribution_graph(self, username: str) -> list: # GraphQL query for contribution calendar (inline username) query = f'''{{ user(login: "{username}") {{ - contributionsCollection {{ + contributionsCollection(includePrivate: true) {{ contributionCalendar {{ weeks {{ contributionDays {{ @@ -549,7 +553,8 @@ def _fetch_contribution_graph(self, username: str) -> list: ['gh', 'api', 'graphql', '-f', f'query={query}'], capture_output=True, text=True, - timeout=30 + timeout=30, + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: @@ -641,7 +646,8 @@ def _api_request(self, endpoint: str) -> Any: cmd, capture_output=True, text=True, - timeout=30 + timeout=30, + env={**os.environ, 'GH_TOKEN': os.getenv('GH_TOKEN')} ) if result.returncode != 0: raise Exception(f"API request failed: {result.stderr}")