Help us learn about your current experience with the documentation. Take the survey.

草稿注释 API

  • 版本:Free, Premium, Ultimate
  • 产品形态:GitLab.com, GitLab Self-Managed, GitLab Dedicated

使用此 API 管理草稿注释。这些注释是合并请求中待处理、未发布的评论。 草稿注释可以发起讨论,也可以作为回复继续现有讨论。

发布前,草稿注释仅对作者可见。

列出所有合并请求的草稿注释

获取单个合并请求的所有草稿注释列表。

GET /projects/:id/merge_requests/:merge_request_iid/draft_notes
属性 类型 是否必需 描述
id integer 或 string 项目的 ID 或 URL 编码路径
merge_request_iid integer 项目合并请求的 IID
[
  {
    "id": 5,
    "author_id": 23,
    "merge_request_id": 11,
    "resolve_discussion": false,
    "discussion_id": null,
    "note": "Example title",
    "commit_id": null,
    "line_code": null,
    "position": {
      "base_sha": null,
      "start_sha": null,
      "head_sha": null,
      "old_path": null,
      "new_path": null,
      "position_type": "text",
      "old_line": null,
      "new_line": null,
      "line_range": null
    }
  }
]
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/14/merge_requests/11/draft_notes"

获取单个草稿注释

返回指定合并请求的单个草稿注释。

GET /projects/:id/merge_requests/:merge_request_iid/draft_notes/:draft_note_id
属性 类型 是否必需 描述
id integer 或 string 项目的 ID 或 URL 编码路径
draft_note_id integer 草稿注释的 ID。
merge_request_iid integer 项目合并请求的 IID。
[
  {
    "id": 5,
    "author_id": 23,
    "merge_request_id": 11,
    "resolve_discussion": false,
    "discussion_id": null,
    "note": "Example title",
    "commit_id": null,
    "line_code": null,
    "position": {
      "base_sha": null,
      "start_sha": null,
      "head_sha": null,
      "old_path": null,
      "new_path": null,
      "position_type": "text",
      "old_line": null,
      "new_line": null,
      "line_range": null
    }
  }
]
curl --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/14/merge_requests/11/draft_notes/5"

创建草稿注释

为指定的合并请求创建草稿注释。

POST /projects/:id/merge_requests/:merge_request_iid/draft_notes
属性 类型 是否必需 描述
id integer 或 string 项目的 ID 或 URL 编码路径
merge_request_iid integer 项目合并请求的 IID。
note string 注释的内容。
commit_id string 要将草稿注释关联到的提交的 SHA。
in_reply_to_discussion_id string 草稿注释所回复的讨论的 ID。
resolve_discussion boolean 是否应解决关联的讨论。
position[base_sha] string 源分支中的基础提交 SHA。
position[head_sha] string 引用此合并请求 HEAD 的 SHA。
position[start_sha] string 引用目标分支中提交的 SHA。
position[new_path] string 是 (如果位置类型为 text) 更改后的文件路径。
position[old_path] string 是 (如果位置类型为 text) 更改前的文件路径。
position[position_type] string 位置引用的类型。允许的值:textimagefilefile 于 GitLab 16.4 引入
position hash 创建 diff 注释时的位置。
position[new_line] integer 对于 text diff 注释,为更改后的行号。
position[old_line] integer 对于 text diff 注释,为更改前的行号。
position[line_range] hash 多行 diff 注释的行范围。
position[width] integer 对于 image diff 注释,为图片的宽度。
position[height] integer 对于 image diff 注释,为图片的高度。
position[x] float 对于 image diff 注释,为 X 坐标。
position[y] float 对于 image diff 注释,为 Y 坐标。
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/14/merge_requests/11/draft_notes?note=note"

修改现有草稿注释

修改指定合并请求的草稿注释。

PUT /projects/:id/merge_requests/:merge_request_iid/draft_notes/:draft_note_id
属性 类型 是否必需 描述
id integer 或 string 项目的 ID 或 URL 编码路径
draft_note_id integer 草稿注释的 ID。
merge_request_iid integer 项目合并请求的 IID。
note string 注释的内容。
position[base_sha] string 源分支中的基础提交 SHA。
position[head_sha] string 引用此合并请求 HEAD 的 SHA。
position[start_sha] string 引用目标分支中提交的 SHA。
position[new_path] string 是 (如果位置类型为 text) 更改后的文件路径。
position[old_path] string 是 (如果位置类型为 text) 更改前的文件路径。
position[position_type] string 位置引用的类型。允许的值:textimagefilefile 于 GitLab 16.4 引入
position hash 创建 diff 注释时的位置。
position[new_line] integer 对于 text diff 注释,为更改后的行号。
position[old_line] integer 对于 text diff 注释,为更改前的行号。
position[line_range] hash 多行 diff 注释的行范围。
position[width] integer 对于 image diff 注释,为图片的宽度。
position[height] integer 对于 image diff 注释,为图片的高度。
position[x] float 对于 image diff 注释,为 X 坐标。
position[y] float 对于 image diff 注释,为 Y 坐标。
curl --request PUT \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/14/merge_requests/11/draft_notes/5"

删除草稿注释

删除指定合并请求的现有草稿注释。

DELETE /projects/:id/merge_requests/:merge_request_iid/draft_notes/:draft_note_id
属性 类型 是否必需 描述
draft_note_id integer 草稿注释的 ID。
id integer 或 string 项目的 ID 或 URL 编码路径
merge_request_iid integer 项目合并请求的 IID。
curl --request DELETE \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/14/merge_requests/11/draft_notes/5"

发布草稿注释

发布指定合并请求的现有草稿注释。

PUT /projects/:id/merge_requests/:merge_request_iid/draft_notes/:draft_note_id/publish
属性 类型 是否必需 描述
draft_note_id integer 草稿注释的 ID。
id integer 或 string 项目的 ID 或 URL 编码路径
merge_request_iid integer 项目合并请求的 IID。
curl --request PUT \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/14/merge_requests/11/draft_notes/5/publish"

发布所有待处理的草稿注释

批量发布指定合并请求中属于该用户的所有现有草稿注释。

POST /projects/:id/merge_requests/:merge_request_iid/draft_notes/bulk_publish
属性 类型 是否必需 描述
id integer 或 string 项目的 ID 或 URL 编码路径
merge_request_iid integer 项目合并请求的 IID。
curl --request POST \
  --header "PRIVATE-TOKEN: <your_access_token>" \
  --url "https://gitlab.example.com/api/v4/projects/14/merge_requests/11/draft_notes/bulk_publish"