Skip to content

Commit 68e15f5

Browse files
committed
GitLab, Gitea, Forgejo, Codeberg, Sourcehut.
1 parent ce3c306 commit 68e15f5

File tree

4 files changed

+559
-37
lines changed

4 files changed

+559
-37
lines changed

README.md

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# gitfetch
22

3-
A neofetch-style CLI tool for GitHub statistics. Display your GitHub profile and stats in a beautiful, colorful terminal interface.
3+
A neofetch-style CLI tool for GitHub, GitLab, Gitea, Forgejo, Codeberg, and Sourcehut statistics. Display your profile and stats from various git hosting platforms in a beautiful, colorful terminal interface.
44

55
<img width="3024" height="1964" alt="image" src="https://github.com/user-attachments/assets/bbb18d5d-4787-4998-a352-e8f4e59642c0" />
66

@@ -9,41 +9,33 @@ A neofetch-style CLI tool for GitHub statistics. Display your GitHub profile and
99
## Features
1010

1111
- Neofetch-style display with ASCII art
12-
- Comprehensive GitHub statistics
12+
- Comprehensive statistics from multiple git hosting platforms
1313
- Smart SQLite-based caching system for faster subsequent runs
1414
- Persistent configuration with default username support
15-
- Uses GitHub CLI (gh) for authentication - no rate limits!
1615
- Cross-platform support (macOS and Linux)
17-
- First-run initialization with interactive setup
16+
- First-run initialization with interactive provider selection
1817

19-
## Prerequisites
18+
## Supported Platforms
2019

21-
**GitHub CLI (gh) must be installed and authenticated:**
20+
- **GitHub** - Uses GitHub CLI (gh) for authentication
21+
- **GitLab** - Uses GitLab CLI (glab) for authentication
22+
- **Gitea/Forgejo/Codeberg** - Uses personal access tokens
23+
- **Sourcehut** - Uses personal access tokens
2224

23-
See installation instructions at: https://github.com/cli/cli#installation
25+
## Installation
2426

25-
### macOS
27+
`gitfetch` can be installed without any prerequisites. During first-run setup, you'll be guided to install and authenticate with the necessary CLI tools or provide access tokens for your chosen git hosting platform.
2628

27-
```bash
28-
brew install gh
29-
gh auth login
30-
```
31-
32-
### Linux
33-
34-
Then authenticate:
35-
36-
```bash
37-
gh auth login
38-
```
29+
## First-run Setup
3930

40-
### Verify Installation
31+
When you run `gitfetch` for the first time, you'll be prompted to:
4132

42-
```bash
43-
gh auth status
44-
```
33+
1. **Choose your git hosting provider** (GitHub, GitLab, Gitea/Forgejo/Codeberg, or Sourcehut)
34+
2. **Install required CLI tools** (if using GitHub or GitLab)
35+
3. **Authenticate** with your chosen platform
36+
4. **Configure access tokens** (if using Gitea/Forgejo/Codeberg or Sourcehut)
4537

46-
You should see: `✓ Logged in to github.com as YOUR_USERNAME`
38+
The setup process will provide helpful error messages and installation instructions if anything is missing.
4739

4840
## Installing `gitfetch`
4941

src/gitfetch/cli.py

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import sys
77
from typing import Optional
88

9-
from .fetcher import GitHubFetcher
109
from .display import DisplayFormatter
1110
from .cache import CacheManager
1211
from .config import ConfigManager
@@ -105,7 +104,9 @@ def main() -> int:
105104
# Initialize components
106105
cache_expiry = config_manager.get_cache_expiry_hours()
107106
cache_manager = CacheManager(cache_expiry_hours=cache_expiry)
108-
fetcher = GitHubFetcher() # Uses gh CLI, no token needed
107+
provider = config_manager.get_provider()
108+
provider_url = config_manager.get_provider_url()
109+
fetcher = _create_fetcher(provider, provider_url)
109110
formatter = DisplayFormatter(config_manager)
110111
if args.spaced:
111112
spaced = True
@@ -192,15 +193,59 @@ def refresh_cache():
192193

193194

194195
def _prompt_username() -> Optional[str]:
195-
"""Prompt user for GitHub username if not provided."""
196+
"""Prompt user for username if not provided."""
196197
try:
197-
username = input("Enter GitHub username: ").strip()
198+
username = input("Enter username: ").strip()
198199
return username if username else None
199200
except (KeyboardInterrupt, EOFError):
200201
print()
201202
return None
202203

203204

205+
def _prompt_provider() -> Optional[str]:
206+
"""Prompt user for git provider."""
207+
try:
208+
print("Available git providers:")
209+
print("1. GitHub")
210+
print("2. GitLab")
211+
print("3. Gitea/Forgejo/Codeberg")
212+
print("4. Sourcehut")
213+
214+
while True:
215+
choice = input("Choose your git provider (1-4): ").strip()
216+
if choice == '1':
217+
return 'github'
218+
elif choice == '2':
219+
return 'gitlab'
220+
elif choice == '3':
221+
return 'gitea'
222+
elif choice == '4':
223+
return 'sourcehut'
224+
else:
225+
print("Invalid choice. Please enter 1-4.")
226+
except (KeyboardInterrupt, EOFError):
227+
print()
228+
return None
229+
230+
231+
def _create_fetcher(provider: str, base_url: str):
232+
"""Create the appropriate fetcher for the provider."""
233+
if provider == 'github':
234+
from .fetcher import GitHubFetcher
235+
return GitHubFetcher()
236+
elif provider == 'gitlab':
237+
from .fetcher import GitLabFetcher
238+
return GitLabFetcher(base_url)
239+
elif provider == 'gitea':
240+
from .fetcher import GiteaFetcher
241+
return GiteaFetcher(base_url)
242+
elif provider == 'sourcehut':
243+
from .fetcher import SourcehutFetcher
244+
return SourcehutFetcher(base_url)
245+
else:
246+
raise ValueError(f"Unsupported provider: {provider}")
247+
248+
204249
def _initialize_gitfetch(config_manager: ConfigManager) -> bool:
205250
"""
206251
Initialize gitfetch by creating config directory and setting
@@ -213,14 +258,42 @@ def _initialize_gitfetch(config_manager: ConfigManager) -> bool:
213258
True if initialization succeeded, False otherwise
214259
"""
215260
try:
216-
# Try to get authenticated user from GitHub CLI
217-
fetcher = GitHubFetcher()
261+
# Ask user for git provider
262+
provider = _prompt_provider()
263+
if not provider:
264+
return False
265+
266+
config_manager.set_provider(provider)
267+
268+
# Set default URL for known providers
269+
if provider == 'github':
270+
config_manager.set_provider_url('https://api.github.com')
271+
elif provider == 'gitlab':
272+
config_manager.set_provider_url('https://gitlab.com')
273+
elif provider == 'gitea':
274+
url = input("Enter Gitea/Forgejo/Codeberg URL: ").strip()
275+
if not url:
276+
print("Provider URL required", file=sys.stderr)
277+
return False
278+
config_manager.set_provider_url(url)
279+
elif provider == 'sourcehut':
280+
config_manager.set_provider_url('https://git.sr.ht')
281+
282+
# Create appropriate fetcher
283+
fetcher = _create_fetcher(provider, config_manager.get_provider_url())
284+
285+
# Try to get authenticated user
218286
try:
219287
username = fetcher.get_authenticated_user()
220-
print(f"Using authenticated GitHub user: {username}")
288+
print(f"Using authenticated user: {username}")
221289
except Exception as e:
222290
print(f"Could not get authenticated user: {e}")
223-
print("Please ensure GitHub CLI is authenticated with: gh auth login")
291+
if provider == 'github':
292+
print("Please authenticate with: gh auth login")
293+
elif provider == 'gitlab':
294+
print("Please authenticate with: glab auth login")
295+
else:
296+
print("Please ensure you have a valid token configured")
224297
return False
225298

226299
# Save configuration

src/gitfetch/config.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,53 @@ def is_initialized(self) -> bool:
126126
Check if gitfetch has been initialized.
127127
128128
Returns:
129-
True if config exists and has default username
129+
True if config exists and has default username and provider
130130
"""
131-
return self.CONFIG_FILE.exists() and bool(self.get_default_username())
131+
return (self.CONFIG_FILE.exists() and
132+
bool(self.get_default_username()) and
133+
bool(self.get_provider()))
134+
135+
def get_provider(self) -> Optional[str]:
136+
"""
137+
Get the git provider from config.
138+
139+
Returns:
140+
Provider name (github, gitlab, gitea, etc.) or None if not set
141+
"""
142+
provider = self.config.get('DEFAULT', 'provider', fallback='')
143+
return provider if provider else None
144+
145+
def set_provider(self, provider: str) -> None:
146+
"""
147+
Set the git provider in config.
148+
149+
Args:
150+
provider: Git provider name (github, gitlab, gitea, etc.)
151+
"""
152+
if 'DEFAULT' not in self.config:
153+
self.config['DEFAULT'] = {}
154+
self.config['DEFAULT']['provider'] = provider
155+
156+
def get_provider_url(self) -> Optional[str]:
157+
"""
158+
Get the provider base URL from config.
159+
160+
Returns:
161+
Base URL for the git provider or None if not set
162+
"""
163+
url = self.config.get('DEFAULT', 'provider_url', fallback='')
164+
return url if url else None
165+
166+
def set_provider_url(self, url: str) -> None:
167+
"""
168+
Set the provider base URL in config.
169+
170+
Args:
171+
url: Base URL for the git provider
172+
"""
173+
if 'DEFAULT' not in self.config:
174+
self.config['DEFAULT'] = {}
175+
self.config['DEFAULT']['provider_url'] = url
132176

133177
def save(self) -> None:
134178
"""Save configuration to file."""

0 commit comments

Comments
 (0)