Skip to content

Commit 567fa1c

Browse files
committed
provider class
1 parent 2107bed commit 567fa1c

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

src/gitfetch/providers.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"""
2+
Provider definitions and configuration for gitfetch.
3+
"""
4+
5+
from dataclasses import dataclass
6+
from enum import Enum
7+
from typing import Optional
8+
9+
10+
class ProviderType(Enum):
11+
"""Supported git hosting providers."""
12+
GITHUB = "github"
13+
GITLAB = "gitlab"
14+
GITEA = "gitea"
15+
SOURCEHUT = "sourcehut"
16+
17+
18+
# Environment variable names for each provider's token
19+
PROVIDER_ENV_VARS = {
20+
"github": "GH_TOKEN",
21+
"gitlab": "GITLAB_TOKEN",
22+
"gitea": "GITEA_TOKEN",
23+
"sourcehut": "SOURCEHUT_TOKEN",
24+
}
25+
26+
# Default URLs for providers
27+
PROVIDER_DEFAULT_URLS = {
28+
"github": "https://api.github.com",
29+
"gitlab": "https://gitlab.com",
30+
"sourcehut": "https://git.sr.ht",
31+
# gitea requires user-provided URL
32+
}
33+
34+
35+
@dataclass
36+
class ProviderConfig:
37+
"""Configuration for a git provider."""
38+
name: str
39+
username: str
40+
url: str
41+
token: str = ""
42+
43+
@property
44+
def token_env_var(self) -> str:
45+
"""Get the environment variable name for this provider's token."""
46+
return PROVIDER_ENV_VARS.get(self.name, "")
47+
48+
@property
49+
def default_url(self) -> Optional[str]:
50+
"""Get the default URL for this provider, if any."""
51+
return PROVIDER_DEFAULT_URLS.get(self.name)
52+
53+
def has_token(self) -> bool:
54+
"""Check if a token is configured."""
55+
return bool(self.token)

0 commit comments

Comments
 (0)