Add multi-username activity support
This commit is contained in:
+28
-1
@@ -1,9 +1,21 @@
|
||||
from functools import lru_cache
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic import Field, field_validator
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
def split_usernames(raw: str) -> list[str]:
|
||||
usernames: list[str] = []
|
||||
seen: set[str] = set()
|
||||
for part in raw.split(","):
|
||||
username = part.strip()
|
||||
if not username or username in seen:
|
||||
continue
|
||||
seen.add(username)
|
||||
usernames.append(username)
|
||||
return usernames
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
model_config = SettingsConfigDict(env_file=".env", case_sensitive=False)
|
||||
|
||||
@@ -20,6 +32,21 @@ class Settings(BaseSettings):
|
||||
default_theme: str = Field(default="light", alias="DEFAULT_THEME")
|
||||
service_title: str = Field(default="git-activity-merge", alias="SERVICE_TITLE")
|
||||
|
||||
@field_validator("github_username", "gitea_username")
|
||||
@classmethod
|
||||
def _validate_username_list(cls, value: str) -> str:
|
||||
if not split_usernames(value):
|
||||
raise ValueError("must contain at least one username")
|
||||
return value
|
||||
|
||||
@property
|
||||
def github_usernames(self) -> list[str]:
|
||||
return split_usernames(self.github_username)
|
||||
|
||||
@property
|
||||
def gitea_usernames(self) -> list[str]:
|
||||
return split_usernames(self.gitea_username)
|
||||
|
||||
|
||||
@lru_cache(maxsize=1)
|
||||
def get_settings() -> Settings:
|
||||
|
||||
Reference in New Issue
Block a user