diff --git a/config.py b/config.py index 94acb5d..fa39a68 100644 --- a/config.py +++ b/config.py @@ -13,6 +13,9 @@ WEBHOOK_SECRET: str = _cfg["gitea"].get("webhook_secret", "") BOT_USERNAME: str = _cfg["bot"]["username"] LISTEN_PORT: int = _cfg["bot"].get("listen_port", 9880) WORKSPACE_DIR: Path = Path(_cfg["bot"].get("workspace_dir", "/data/src/gitea-bot/workspaces")) +BOT_GIT_NAME: str = _cfg["bot"].get("git_name", BOT_USERNAME) +BOT_GIT_EMAIL: str = _cfg["bot"].get("git_email", f"{BOT_USERNAME}@euphon.net") +ALLOWED_OWNERS: list[str] = _cfg["bot"].get("allowed_owners", []) # Claude CLAUDE_COMMAND: str = _cfg["claude"]["command"] diff --git a/main.py b/main.py index 52c167b..0551362 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,6 @@ log = logging.getLogger("gitea-bot") gitea = GiteaClient() -ALLOWED_OWNER = "euphon" MAX_RESPONSE_LEN = 60000 CLAUDE_TIMEOUT = 3600 # 60 minutes app = FastAPI() @@ -223,7 +222,7 @@ async def webhook(request: Request): owner = repo_data.get("owner", {}).get("login", "") repo = repo_data.get("name", "") - if owner != ALLOWED_OWNER: + if config.ALLOWED_OWNERS and owner not in config.ALLOWED_OWNERS: return {"status": "skip", "reason": f"owner {owner} not allowed"} if event == "issue_comment" and action == "created": diff --git a/workspace.py b/workspace.py index d284b83..c526bcc 100644 --- a/workspace.py +++ b/workspace.py @@ -2,7 +2,7 @@ import asyncio import logging from pathlib import Path -from config import GITEA_URL, GITEA_TOKEN, WORKSPACE_DIR, BOT_USERNAME +from config import GITEA_URL, GITEA_TOKEN, WORKSPACE_DIR, BOT_USERNAME, BOT_GIT_NAME, BOT_GIT_EMAIL log = logging.getLogger("gitea-bot") @@ -54,7 +54,7 @@ async def ensure_repo(owner: str, repo: str, issue_number: int) -> Path: raise RuntimeError(f"git clone failed: {err}") # Configure git user for bot commits - await _run(f'git config user.name "麻薯"', cwd=rp) - await _run(f'git config user.email "ms@euphon.net"', cwd=rp) + await _run(f'git config user.name "{BOT_GIT_NAME}"', cwd=rp) + await _run(f'git config user.email "{BOT_GIT_EMAIL}"', cwd=rp) return rp