All checks were successful
Build and Deploy Log Center / build-and-deploy (push) Successful in 1m39s
97 lines
3.6 KiB
Python
97 lines
3.6 KiB
Python
"""
|
||
配置管理
|
||
"""
|
||
import os
|
||
from typing import Optional
|
||
from pydantic_settings import BaseSettings
|
||
from pydantic import Field
|
||
|
||
|
||
class Settings(BaseSettings):
|
||
"""Repair Agent 配置"""
|
||
|
||
# Log Center
|
||
log_center_url: str = Field(
|
||
default="https://qiyuan-log-center-api.airlabs.art",
|
||
description="Log Center API 地址"
|
||
)
|
||
|
||
# Claude CLI
|
||
claude_cli_path: str = Field(default="claude", description="Claude CLI 路径")
|
||
claude_timeout: int = Field(default=1000, description="Claude CLI 超时时间(秒)")
|
||
claude_model: str = Field(default="claude-opus-4-6", description="Claude 模型")
|
||
|
||
# Git
|
||
git_user_name: str = Field(default="repair-agent", description="Git 用户名")
|
||
git_user_email: str = Field(default="agent@airlabs.art", description="Git 邮箱")
|
||
|
||
# Gitea
|
||
gitea_url: str = Field(default="https://gitea.airlabs.art", description="Gitea 地址")
|
||
gitea_token: Optional[str] = Field(default=None, description="Gitea Token")
|
||
|
||
# 仓库地址(owner/repo 格式,为空则不执行 git 操作)
|
||
github_repo_rtc_backend: str = Field(default="", description="rtc_backend GitHub 仓库地址")
|
||
github_repo_rtc_web: str = Field(default="", description="rtc_web GitHub 仓库地址")
|
||
github_repo_airhub_app: str = Field(default="", description="airhub_app GitHub 仓库地址")
|
||
|
||
# 定时任务
|
||
watch_interval: int = Field(default=3600, description="定时扫描间隔(秒)")
|
||
|
||
# 安全配置
|
||
max_retry_count: int = Field(default=3, description="最大重试次数")
|
||
max_modified_lines: int = Field(default=500, description="最大修改行数")
|
||
max_modified_files: int = Field(default=20, description="最大修改文件数")
|
||
critical_files: str = Field(
|
||
default="payment,auth,security",
|
||
description="核心文件关键词,逗号分隔"
|
||
)
|
||
|
||
# 项目路径映射
|
||
path_rtc_backend: str = Field(
|
||
default="/Users/maidong/Desktop/zyc/qy_gitlab/rtc_backend",
|
||
description="rtc_backend 本地路径"
|
||
)
|
||
path_rtc_web: str = Field(
|
||
default="/Users/maidong/Desktop/zyc/qy_gitlab/rtc_web",
|
||
description="rtc_web 本地路径"
|
||
)
|
||
path_airhub_app: str = Field(
|
||
default="/Users/maidong/Desktop/zyc/qiyuan_gitea/rtc_prd/airhub_app",
|
||
description="airhub_app 本地路径"
|
||
)
|
||
|
||
class Config:
|
||
env_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), ".env")
|
||
env_file_encoding = "utf-8"
|
||
extra = "ignore"
|
||
|
||
def get_project_path(self, project_id: str) -> Optional[str]:
|
||
"""获取项目本地路径"""
|
||
path_map = {
|
||
"rtc_backend": self.path_rtc_backend,
|
||
"rtc_web": self.path_rtc_web,
|
||
"airhub_app": self.path_airhub_app,
|
||
}
|
||
return path_map.get(project_id)
|
||
|
||
def get_github_repo(self, project_id: str) -> str:
|
||
"""获取项目的 GitHub 仓库地址,为空表示未配置"""
|
||
repo_map = {
|
||
"rtc_backend": self.github_repo_rtc_backend,
|
||
"rtc_web": self.github_repo_rtc_web,
|
||
"airhub_app": self.github_repo_airhub_app,
|
||
}
|
||
return repo_map.get(project_id, "").strip()
|
||
|
||
def is_git_enabled(self, project_id: str) -> bool:
|
||
"""检查项目是否启用了 Git 操作(GitHub 仓库地址不为空)"""
|
||
return bool(self.get_github_repo(project_id))
|
||
|
||
def get_critical_files(self) -> list[str]:
|
||
"""获取核心文件关键词列表"""
|
||
return [f.strip() for f in self.critical_files.split(",") if f.strip()]
|
||
|
||
|
||
# 单例
|
||
settings = Settings()
|