fix: 实现 Agent 任务中私有 Gitea 仓库克隆的 Token 认证支持

This commit is contained in:
vinland100 2025-12-25 15:26:47 +08:00
parent 9bfde8ec24
commit d10f023a7e
1 changed files with 14 additions and 0 deletions

View File

@ -292,6 +292,7 @@ async def _execute_agent_task(task_id: str):
other_config = (user_config or {}).get('otherConfig', {})
github_token = other_config.get('githubToken') or settings.GITHUB_TOKEN
gitlab_token = other_config.get('gitlabToken') or settings.GITLAB_TOKEN
gitea_token = other_config.get('giteaToken') or settings.GITEA_TOKEN
# 获取项目根目录(传递任务指定的分支和认证 token
# 🔥 传递 event_emitter 以发送克隆进度
@ -301,6 +302,7 @@ async def _execute_agent_task(task_id: str):
task.branch_name,
github_token=github_token,
gitlab_token=gitlab_token,
gitea_token=gitea_token, # 🔥 新增
event_emitter=event_emitter, # 🔥 新增
)
@ -2213,6 +2215,7 @@ async def _get_project_root(
branch_name: Optional[str] = None,
github_token: Optional[str] = None,
gitlab_token: Optional[str] = None,
gitea_token: Optional[str] = None, # 🔥 新增
event_emitter: Optional[Any] = None, # 🔥 新增:用于发送实时日志
) -> str:
"""
@ -2228,6 +2231,7 @@ async def _get_project_root(
branch_name: 分支名称仓库项目使用优先于 project.default_branch
github_token: GitHub 访问令牌用于私有仓库
gitlab_token: GitLab 访问令牌用于私有仓库
gitea_token: Gitea 访问令牌用于私有仓库
event_emitter: 事件发送器用于发送实时日志
Returns:
@ -2476,6 +2480,16 @@ async def _get_project_root(
parsed.fragment
))
await emit(f"🔐 使用 GitLab Token 认证")
elif repo_type == "gitea" and gitea_token:
auth_url = urlunparse((
parsed.scheme,
f"{gitea_token}@{parsed.netloc}",
parsed.path,
parsed.params,
parsed.query,
parsed.fragment
))
await emit(f"🔐 使用 Gitea Token 认证")
for branch in branches_to_try:
check_cancelled()