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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion src/gitfetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/gitfetch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion src/gitfetch/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
20 changes: 13 additions & 7 deletions src/gitfetch/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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': []}
Expand Down Expand Up @@ -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 {{
Expand All @@ -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:
Expand Down Expand Up @@ -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}")
Expand Down