chaitin / chaitin/MonkeyCode

[Bug] Codeup 集成:从仓库下拉列表选择仓库后,创建任务时「获取分支列表失败」(自存 repo_url 与自身 URL 解析器格式不一致)

Open
#919 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.7k
Forks
719
Avg merge
4h 30m
Merged PRs (30d)
83

Description

[Bug] Codeup 集成:从仓库下拉列表选择仓库后,创建任务时「获取分支列表失败」(自存 repo_url 与自身 URL 解析器格式不一致)

环境 / Environment

  • 部署方式:Docker Compose 私有化部署(online 安装包)
  • 版本 / Version:v260720(backend chaitin-registry.cn-hangzhou.cr.aliyuncs.com/monkeycode/backend:v260720
  • Git provider:阿里云效 Codeup(codeup.aliyun.com)
  • 复现稳定性:必现

问题描述 / Summary

已成功绑定 Codeup git 身份,并能在 WebUI「创建项目」时从自动获取的仓库下拉列表中选中一个 Codeup 仓库、成功创建项目。但在创建任务、需要拉取分支列表时报错:

获取分支列表失败: 服务器错误 [trace_id: xxxxxxxx]

关键点:仓库是从下拉列表选择的,并非手工填写地址。这说明 backend 用 token 调用 Codeup「列仓库」API 是成功的(否则下拉不会出现该仓库),但同一个仓库在「列分支」环节却失败。

复现步骤 / Steps to Reproduce

  1. 在 WebUI 绑定 Codeup git 身份(OAuth / Token)。
  2. 创建项目时,从系统自动拉取的 Codeup 仓库下拉列表中选择一个仓库(我的仓库克隆地址为 https://codeup.aliyun.com/<group>/<repo>.git,即 Codeup 标准的两段路径,不含 orgId)。
  3. 项目创建成功。
  4. 创建任务,触发拉取分支列表。
  5. 报错「获取分支列表失败」。

期望 / Expected

从下拉列表选择的仓库,其分支列表能正常获取。

实际 / Actual

分支列表获取失败。backend 日志:

WARN request failed trace_id=... err="list branches: list codeup branches: HTTP 404: {\"code\":404,\"errorCode\":\"SYSTEM_NOT_FOUND_ERROR\",\"errorDescription\":\"Project(<orgId>/<group>/<repo>) not found,current org(<orgId>)\",...}"
WARN request failed trace_id=... err="invalid codeup url, expect orgId/group/repo: https://codeup.aliyun.com/<group>/<repo>.git"

根因分析 / Root Cause

这是 backend Codeup 集成的内部不一致列仓库时存入的 repo_url 格式,喂不进它自己的分支 URL 解析器。

  1. 数据库 projects.repo_url 里存的是 Codeup 标准克隆地址——两段路径、不含 orgId:

    https://codeup.aliyun.com/<group>/<repo>.git
    

    (这是「列仓库」环节自己写入的值。)

  2. 但「列分支」环节用 backend/pkg/git/codeup/codeup.gosplitOrgAndIdentity() 解析同一个 URL,该函数硬性要求至少三段、且第一段为 orgId

    func splitOrgAndIdentity(path, raw string) (string, string, error) {
        parts := strings.Split(strings.Trim(path, "/"), "/")
        if len(parts) < 3 {
            return "", "", fmt.Errorf("invalid codeup url, expect orgId/group/repo: %s", raw)
        }
        orgID := parts[0]
        identity := strings.Join(parts[1:], "/")
        return orgID, identity, nil
    }
    

    期望格式为 codeup.aliyun.com/{orgId}/{group}/{repo},而实际存入的是 codeup.aliyun.com/{group}/{repo}(少了 orgId 段)。

  3. 结果:解析器把 <group> 误当作 orgId,或直接因段数不足报 invalid codeup url;随后又用错误拼接的路径 Project(<orgId>/<group>/<repo>) 去调 Codeup OpenAPI,Codeup 返回 404 SYSTEM_NOT_FOUND_ERROR

补充验证:Codeup 的 git 克隆路径本身就是两段 {group}/{repo}(用 git ls-remote 探测 https://codeup.aliyun.com/<group>/<repo>.git 返回 401 = 路径存在、需认证);而在中间** 插入 orgId** 的三段路径用 git 探测反而 404。也就是说,Codeup 的克隆 URL 与 OpenAPI 的 repositoryId(需要 organizationId + {groupPath}/{repoName})本就是两套标识体系。backend 在「列仓库」时存了前者,「列分支」时却按后者的格式去解析,二者未对齐。

建议修复方向 / Suggested Fix

任选其一,使「列仓库」写入与「列分支」读取对同一仓库标识达成一致:

  • A. 「列仓库」写入 repo_url 时,把 orgId 一并拼入,存成解析器期望的 codeup.aliyun.com/{orgId}/{group}/{repo} 形式;orgId 在 git 身份(git_identities)中已存在。
  • B.splitOrgAndIdentity() 兼容两段路径:当 URL 不含 orgId 段时,从当前 git 身份的 orgId 回退补齐,而非直接报 expect orgId/group/repo
  • C. 不复用「面向用户手填的 URL 解析器」来处理「系统自己从 API 列出的仓库」——列仓库时应直接持久化 Codeup 的 organizationIdrepositoryId(或全路径 identity),列分支时直接 取用,避免二次从 URL 反解。

(推荐 A 或 C:数据源头就存对,比在解析器里做兼容更稳。)

临时绕过 / Workaround

手动把 projects.repo_url 改成三段格式(补上 orgId),即可让分支解析通过:

UPDATE projects
SET repo_url = 'https://codeup.aliyun.com/<orgId>/<group>/<repo>.git'
WHERE repo_url = 'https://codeup.aliyun.com/<group>/<repo>.git';

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with backend/pkg/git/codeup/codeup.go, especially splitOrgAndIdentity(), then trace the Codeup repository-listing and branch-listing paths that read and write projects.repo_url. Confirm the two-segment clone URL and three-segment API identity mismatch, and add or update focused tests for repository selection followed by branch listing. Done means repositories selected from the dropdown can retrieve their branches without the invalid URL or 404 errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.