You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过GitLab REST API添加合并请求多行注释及解决报错

GitLab REST API 添加合并请求多行注释问题

我查阅了GitLab文档,但搞不懂怎么通过REST API给合并请求添加多行注释。

当前多行注释请求代码

{
    "body": "Via Rest",
    "position": {
        "base_sha": "bcdfbfd57c8f3cd6cd65998464bb71a562d49948",
        "start_sha": "bcdfbfd57c8f3cd6cd65998464bb71a562d49948",
        "head_sha": "5828c8f62744f8c63d2e35cfb17988380a3a63d6",
        "new_path": "README.md",
        "position_type": "text",
        "line_range": {
            "start": {
                "line_code": "8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_0_6",
                "type": "new"
            },
            "end": {
                "line_code": "8ec9a00bfd09b3190ac6b22251dbb1aa95a0579d_0_11",
                "type": "new"
            }
        }
    }
}

返回的错误信息

"message": "400 Bad request - Note {:line_code=>[\"can't be blank\", \"must be a valid line code\"], :position=>[\"is incomplete\"]}"

疑问点

  • 明明已经填写了line_code,却被提示为空且无效
  • 不理解line_code的工作机制:添加的是新注释,无旧行引用,SHA1HASH_OLDLINE_NEWLINE格式不适用;复制现有多行注释的line_code也无法解决问题

补充测试发现

我使用的是GitLab 创建新合并请求线程 API。测试发现问题可能并非错误提示所述:用以下JSON创建单行合并请求线程时,路径为src/main/java/com/example/demo/DemoApplication.java会返回相同错误,但换成README.md就能正常工作,且两个文件均存在,长路径文件似乎存在问题。

单行注释请求代码

{
    "body": "Via Postman",
    "position": {
        "position_type": "text",
        "base_sha": "bcdfbfd57c8f3cd6cd65998464bb71a562d49948",
        "head_sha": "5828c8f62744f8c63d2e35cfb17988380a3a63d6",
        "start_sha": "bcdfbfd57c8f3cd6cd65998464bb71a562d49948",
        "new_path": "src/main/java/com/example/demo/DemoApplication.java",
        "old_path": "src/main/java/com/example/demo/DemoApplication.java",
        "new_line": 1
    }
}

内容的提问来源于stack exchange,提问作者Loading

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 04:15:29