Build Forgejo-backed community prototype
This commit is contained in:
parent
797ae5ea35
commit
6671a01d26
16 changed files with 2485 additions and 293 deletions
19
settings.py
19
settings.py
|
|
@ -7,8 +7,12 @@ from functools import lru_cache
|
|||
|
||||
@dataclass(frozen=True)
|
||||
class Settings:
|
||||
app_base_url: str | None
|
||||
forgejo_base_url: str
|
||||
forgejo_token: str | None
|
||||
forgejo_oauth_client_id: str | None
|
||||
forgejo_oauth_client_secret: str | None
|
||||
forgejo_oauth_scopes: tuple[str, ...]
|
||||
forgejo_repo_scan_limit: int
|
||||
forgejo_recent_issue_limit: int
|
||||
forgejo_request_timeout_seconds: float
|
||||
|
|
@ -33,16 +37,29 @@ def _parse_calendar_feed_urls(raw_value: str | None) -> tuple[str, ...]:
|
|||
return tuple(entry.strip() for entry in value.replace("\n", ",").split(",") if entry.strip())
|
||||
|
||||
|
||||
def _parse_scopes(raw_value: str | None) -> tuple[str, ...]:
|
||||
value = (raw_value or "").strip()
|
||||
if not value:
|
||||
return ("openid", "profile")
|
||||
return tuple(scope for scope in value.replace(",", " ").split() if scope)
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_settings() -> Settings:
|
||||
return Settings(
|
||||
app_base_url=_normalize_base_url(os.getenv("APP_BASE_URL"))
|
||||
if os.getenv("APP_BASE_URL")
|
||||
else None,
|
||||
forgejo_base_url=_normalize_base_url(os.getenv("FORGEJO_BASE_URL")),
|
||||
forgejo_token=os.getenv("FORGEJO_TOKEN") or None,
|
||||
forgejo_oauth_client_id=os.getenv("FORGEJO_OAUTH_CLIENT_ID") or None,
|
||||
forgejo_oauth_client_secret=os.getenv("FORGEJO_OAUTH_CLIENT_SECRET") or None,
|
||||
forgejo_oauth_scopes=_parse_scopes(os.getenv("FORGEJO_OAUTH_SCOPES")),
|
||||
forgejo_repo_scan_limit=int(os.getenv("FORGEJO_REPO_SCAN_LIMIT", "30")),
|
||||
forgejo_recent_issue_limit=int(os.getenv("FORGEJO_RECENT_ISSUE_LIMIT", "6")),
|
||||
forgejo_request_timeout_seconds=float(
|
||||
os.getenv("FORGEJO_REQUEST_TIMEOUT_SECONDS", "10.0"),
|
||||
),
|
||||
calendar_feed_urls=_parse_calendar_feed_urls(os.getenv("CALENDAR_FEED_URLS")),
|
||||
calendar_event_limit=int(os.getenv("CALENDAR_EVENT_LIMIT", "6")),
|
||||
calendar_event_limit=int(os.getenv("CALENDAR_EVENT_LIMIT", "3")),
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue