Merge requests API

Merge requests API

合并请求的每个 API 调用都必须经过验证.

弃用 > 响应属性有利于已弃用references . >推出了GitLab 12.6注意 > references.relative相对于正在请求合并请求的组/项目. 当从其项目中获取合并请求时> relative格式将与short格式相同,并且在跨组/项目进行请求时, relative格式应与full格式相同.

在 GitLab 9.5 中 .

获取所有通过身份验证的用户有权访问的合并请求. 默认情况下,它仅返回当前用户创建的合并请求. 要获取所有合并请求,请使用参数scope=all .

state参数可用于仅获取具有给定状态( openedclosedlockedmerged )或全部( all )的合并请求. 应该注意的是,通过locked进行搜索时,由于它是短暂的过渡状态,因此几乎不会返回任何结果. 分页参数pageper_page可用于限制合并请求的列表.

Parameters:

对于 11.0 之前的版本,请改用现在不建议使用created-by-me范围或created-by-me assigned-to-me范围. | | | author_id | integer | no | 返回由给定用户id创建的合并请求. 与author_username . 与scope=allscope=assigned_to_me | | | author_username | string | no | 返回由给定username创建的合并请求. 与author_id . (在 GitLab 12.10 中引入 | | | assignee_id | integer | no | 返回分配给给定用户id合并请求. None将返回未分配的合并请求. Any退货将请求与受让人合并. | | | approver_ids | 整数数组 | no | 返回将所有具有给定id的用户指定为单独批准者的合并请求. None返回没有批准者的合并请求. Any退货将合并请求与批准人. | | | approved_by_ids | 整数数组 | no | 返回已被所有具有给定id的用户(最大:5)批准的合并请求. None返回没有批准的合并请求. Any退货将请求与批准合并. | | | my_reaction_emoji | string | no | 返回合并请求,该合并请求由已验证的用户通过给定的emoji响应. None返回没有响应的问题. 至少有一个反应, Any回报问题. (在 GitLab 10.0 中 ) | | | source_branch | string | no | 返回具有给定源分支的合并请求 | | | target_branch | string | no | 返回具有给定目标分支的合并请求 | | | search | string | no | 根据titledescription搜索合并请求 | | | in | string | no | 修改search属性的范围. titledescription或以逗号将它们连接在一起的字符串. 默认为title,description | | | wip | string | no | 过滤合并请求对他们的wip状态. yes返回 WIP 合并请求, no ,返回 WIP 合并请求 | | | not | Hash | no | 返回与提供的参数不匹配的合并请求. 接受: labelsmilestoneauthor_idauthor_usernameassignee_idassignee_usernamemy_reaction_emoji | |

注意: 从 GitLab 13.0 开始 ,列出合并请求可能不会主动更新merge_status字段(这也会影响has_conflicts字段),因为这可能是一项昂贵的操作. 如果您对此端点的这些字段的值感兴趣,请在查询with_merge_status_recheck参数设置为true .注意: 当对此端点发出请求时,将异步检查每个合并请求的可合并性( merge_status ). 轮询此 API 端点以获取更新状态. 这会影响has_conflicts属性,因为它取决于merge_status . 除非merge_statuscannot_be_merged否则它将返回false .

  1. [ { "id": 1, "iid": 1, "project_id": 3, "title": "test1", "description": "fixed login page css paddings", "state": "merged", "merged_by": { "id": 87854, "name": "Douwe Maan", "username": "DouweM", "state": "active", "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", "web_url": "https://gitlab.com/DouweM" }, "merged_at": "2018-09-07T11:16:17.520Z", "closed_by": null, "closed_at": null, "created_at": "2017-04-29T08:46:00Z", "updated_at": "2017-04-29T08:46:00Z", "target_branch": "master", "source_branch": "test1", "upvotes": 0, "downvotes": 0, "author": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignee": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 2, "target_project_id": 3, "labels": [ "Community contribution", "Manage" ], "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 3, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": "2018-09-22", "start_date": "2018-08-08", "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" }, "merge_when_pipeline_succeeds": true, "merge_status": "can_be_merged", "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "discussion_locked": null, "should_remove_source_branch": true, "force_remove_source_branch": false, "allow_collaboration": false, "allow_maintainer_to_push": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "my-group/my-project!1", "full": "my-group/my-project!1" }, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "squash": false, "task_completion_status":{ "count":0, "completed_count":0 } } ]

在 GitLab 用户入门,青铜或更高还会看到approvals_before_merge参数:

  1. [ { "id": 1, "title": "test1", "approvals_before_merge": null ... } ]

List project merge requests

获取此项目的所有合并请求. state参数可用于仅获取具有给定状态( openedclosedlockedmerged )或全部( all )的合并请求. 分页参数pageper_page可用于限制合并请求的列表.

  1. GET /projects/:id/merge_requests
  2. GET /projects/:id/merge_requests?state=opened
  3. GET /projects/:id/merge_requests?state=all
  4. GET /projects/:id/merge_requests?iids[]=42&iids[]=43
  5. GET /projects/:id/merge_requests?milestone=release
  6. GET /projects/:id/merge_requests?labels=bug,reproduced
  7. GET /projects/:id/merge_requests?my_reaction_emoji=star

project_id代表 MR 所在项目的 ID. project_id将始终等于target_project_id .

如果来自同一项目的合并请求,则source_project_idtarget_project_idproject_id将相同. 对于来自派生的合并请求, target_project_idproject_id将相同,并且source_project_id将是派生项目的 ID.

Parameters:

Attribute Type Required Description
id integer yes 项目 ID
iids[] 整数数组 no 返回具有给定iid的请求
state string no 返回所有合并请求,或者仅返回已openedclosedlockedmerged请求
order_by string no 返回由created_atupdated_at字段排序的请求. 默认为created_at
sort string no 返回请求按ascdesc顺序排序. 默认为desc
milestone string no 返回特定里程碑的合并请求. None返回没有里程碑的合并请求. Any返回将合并具有指定里程碑的请求.
view string no 如果为simple ,则返回iid ,URL,标题,描述和合并请求的基本状态
labels string no 返回与逗号分隔的标签列表匹配的合并请求. None列出所有没有标签的合并请求. Any列出所有具有至少一个标签的合并请求. No+Label (不推荐使用)列出所有没有标签的合并请求. 预定义名称不区分大小写.
with_labels_details boolean no 如果为true ,则响应将为标签字段中的每个标签返回更多详细信息:name:color , , :description_html:text_color . 默认值为false . 在GitLab 12.7 中引入
with_merge_status_recheck boolean no 如果为true ,则此投影请求(但不保证)异步地重新计算merge_status字段. 默认值为false . 在引入
created_after datetime no 返回在给定时间或之后创建的合并请求
created_before datetime no 返回在给定时间或之前创建的合并请求
updated_after datetime no 返回在给定时间或之后更新的合并请求
updated_before datetime no 返回在给定时间或之前更新的合并请求
scope string no 对于给定的范围内返回的合并请求: created_by_meassigned_to_meall .

对于 11.0 之前的版本,请改用现在不建议使用created-by-me范围或created-by-me assigned-to-me范围. (在 GitLab 9.5 中引入 .在 GitLab 11.0 中 ) | | | author_id | integer | no | 返回由给定用户id创建的合并请求. 与author_username . (在 GitLab 9.5 中引入 | | | author_username | string | no | 返回由给定username创建的合并请求. 与author_id . (在 GitLab 12.10 中 ) | | | assignee_id | integer | no | 返回分配给给定用户id合并请求. None将返回未分配的合并请求. Any退货将请求与受让人合并. (在 GitLab 9.5 中引入 | | | approver_ids | 整数数组 | no | 返回将所有具有给定id的用户指定为单独批准者的合并请求. None返回没有批准者的合并请求. Any退货将合并请求与批准人. | | | approved_by_ids | 整数数组 | no | 返回已被所有具有给定id的用户(最大:5)批准的合并请求. None返回没有批准的合并请求. Any退货将请求与批准合并. | | | my_reaction_emoji | string | no | 返回合并请求,该合并请求由已验证的用户通过给定的emoji响应. None返回没有响应的问题. 至少有一个反应, Any回报问题. (在 GitLab 10.0 中 ) | | | source_branch | string | no | 返回具有给定源分支的合并请求 | | | target_branch | string | no | 返回具有给定目标分支的合并请求 | | | search | string | no | 根据titledescription搜索合并请求 | | | wip | string | no | 过滤合并请求对他们的wip状态. yes返回 WIP 合并请求, no ,返回 WIP 合并请求 | |

  1. [ { "id": 1, "iid": 1, "project_id": 3, "title": "test1", "description": "fixed login page css paddings", "state": "merged", "merged_by": { "id": 87854, "name": "Douwe Maan", "username": "DouweM", "state": "active", "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", "web_url": "https://gitlab.com/DouweM" }, "merged_at": "2018-09-07T11:16:17.520Z", "closed_by": null, "closed_at": null, "created_at": "2017-04-29T08:46:00Z", "updated_at": "2017-04-29T08:46:00Z", "target_branch": "master", "source_branch": "test1", "upvotes": 0, "downvotes": 0, "author": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignee": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 2, "target_project_id": 3, "labels": [ "Community contribution", "Manage" ], "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 3, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": "2018-09-22", "start_date": "2018-08-08", "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" }, "merge_when_pipeline_succeeds": true, "merge_status": "can_be_merged", "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "discussion_locked": null, "should_remove_source_branch": true, "force_remove_source_branch": false, "allow_collaboration": false, "allow_maintainer_to_push": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "!1", "full": "my-group/my-project!1" }, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "squash": false, "task_completion_status":{ "count":0, "completed_count":0 }, "has_conflicts": false, "blocking_discussions_resolved": true } ]

在 GitLab 用户入门,青铜或更高还会看到approvals_before_merge参数:

  1. [ { "id": 1, "title": "test1", "approvals_before_merge": null ... } ]

List group merge requests

获取该组及其子组的所有合并请求. state参数可用于仅获取具有给定状态( openedclosedlockedmerged )或全部( all )的合并请求. 分页参数pageper_page可用于限制合并请求的列表.

  1. GET /groups/:id/merge_requests
  2. GET /groups/:id/merge_requests?state=opened
  3. GET /groups/:id/merge_requests?state=all
  4. GET /groups/:id/merge_requests?milestone=release
  5. GET /groups/:id/merge_requests?labels=bug,reproduced
  6. GET /groups/:id/merge_requests?my_reaction_emoji=star

group_id代表包含 MR 所在项目的组的 ID.

Parameters:

Attribute Type Required Description
id integer yes 组的 ID
state string no 返回所有合并请求,或者仅返回已openedclosedlockedmerged请求
order_by string no 返回由created_atupdated_at字段排序的合并请求. 默认为created_at
sort string no 返回以ascdesc顺序排序的合并请求. 默认为desc
milestone string no 返回特定里程碑的合并请求. None返回没有里程碑的合并请求. Any返回将合并具有指定里程碑的请求.
view string no If simple, returns the iid, URL, title, description, and basic state of merge request
labels string no 返回与逗号分隔的标签列表匹配的合并请求. None列出所有没有标签的合并请求. Any列出所有具有至少一个标签的合并请求. No+Label (不推荐使用)列出所有没有标签的合并请求. 预定义名称不区分大小写.
with_labels_details boolean no 如果为true ,则响应将为标签字段中的每个标签返回更多详细信息:name:color:description:description_html:text_color . 默认值为false . 在GitLab 12.7 中引入
with_merge_status_recheck boolean no 如果为true ,则此投影请求(但不保证)异步地重新计算merge_status字段. 默认值为false . 在引入
created_after datetime no 返回在给定时间或之后创建的合并请求
created_before datetime no 返回在给定时间或之前创建的合并请求
updated_after datetime no 返回在给定时间或之后更新的合并请求
updated_before datetime no 返回在给定时间或之前更新的合并请求
scope string no 对于给定的范围内返回的合并请求: created_by_meassigned_to_meall .
author_id integer no 返回由给定用户id创建的合并请求. 与author_username . (在 GitLab 9.5 中引入
author_username string no 返回由给定username创建的合并请求. 与author_id . (在 GitLab 12.10 中 )
assignee_id integer no 返回分配给给定用户id合并请求. None将返回未分配的合并请求. Any退货将请求与受让人合并. (在 GitLab 9.5 中引入
approver_ids 整数数组 no 返回将所有具有给定id的用户指定为单独批准者的合并请求. None返回没有批准者的合并请求. Any退货将合并请求与批准人.
approved_by_ids 整数数组 no 返回已被所有具有给定id的用户(最大:5)批准的合并请求. None返回没有批准的合并请求. Any退货将请求与批准合并.
my_reaction_emoji string no 返回合并请求,该合并请求由已验证的用户通过给定的emoji响应. None返回没有响应的问题. 至少有一个反应, Any回报问题. (在 GitLab 10.0 中 )
source_branch string no 返回具有给定源分支的合并请求
target_branch string no 返回具有给定目标分支的合并请求
search string no 根据titledescription搜索合并请求
non_archived boolean no 仅从非归档项目返回合并请求. 默认为 true. (在GitLab 12.8 中引入)
  1. [ { "id": 1, "iid": 1, "project_id": 3, "title": "test1", "description": "fixed login page css paddings", "state": "merged", "merged_by": { "id": 87854, "name": "Douwe Maan", "username": "DouweM", "state": "active", "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", "web_url": "https://gitlab.com/DouweM" }, "merged_at": "2018-09-07T11:16:17.520Z", "closed_by": null, "closed_at": null, "created_at": "2017-04-29T08:46:00Z", "updated_at": "2017-04-29T08:46:00Z", "target_branch": "master", "source_branch": "test1", "upvotes": 0, "downvotes": 0, "author": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignee": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 2, "target_project_id": 3, "labels": [ "Community contribution", "Manage" ], "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 3, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": "2018-10-22", "start_date": "2018-09-08", "web_url": "gitlab.example.com/my-group/my-project/milestones/1" }, "merge_when_pipeline_succeeds": true, "merge_status": "can_be_merged", "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "discussion_locked": null, "should_remove_source_branch": true, "force_remove_source_branch": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "my-project!1", "full": "my-group/my-project!1" }, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "squash": false, "task_completion_status":{ "count":0, "completed_count":0 }, "has_conflicts": false, "blocking_discussions_resolved": true } ]

在 GitLab 用户还会看到approvals_before_merge参数:

  1. [ { "id": 1, "title": "test1", "approvals_before_merge": null ... } ]

Get single MR

显示有关单个合并请求的信息.

注意 :响应中的changes_count值是一个字符串,而不是整数. 这是因为当 MR 有太多要显示和存储的更改时,其上限为 1,000. 在这种情况下,API 将为更改计数返回字符串"1000+" .

  1. GET /projects/:id/merge_requests/:merge_request_iid

Parameters:

  • id (必填)-经过身份验证的用户拥有的 ID 或URL 编码路径
  • merge_request_iid (必需)-合并请求的内部 ID
  • render_html (optional) - If true response includes rendered HTML for title and description
  • include_diverged_commits_count (可选)-如果为true包括目标分支后面的提交
  • include_rebase_in_progress (可选)-如果为true包括是否正在进行 rebase 操作

注意: 当对此端点发出请求时,将异步检查合并请求的可合并性( merge_status ). 轮询此 API 端点以获取更新状态. 这会影响has_conflicts属性,因为它取决于merge_status . 除非merge_statuscannot_be_merged否则它将返回false .

  1. { "id": 1, "iid": 1, "project_id": 3, "title": "test1", "description": "fixed login page css paddings", "state": "merged", "created_at": "2017-04-29T08:46:00Z", "updated_at": "2017-04-29T08:46:00Z", "target_branch": "master", "source_branch": "test1", "upvotes": 0, "downvotes": 0, "author": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "user" : { "can_merge" : false }, "assignee": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 2, "target_project_id": 3, "labels": [ "Community contribution", "Manage" ], "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 3, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": "2018-09-22", "start_date": "2018-08-08", "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" }, "merge_when_pipeline_succeeds": true, "merge_status": "can_be_merged", "merge_error": null, "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "discussion_locked": null, "should_remove_source_branch": true, "force_remove_source_branch": false, "allow_collaboration": false, "allow_maintainer_to_push": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "!1", "full": "my-group/my-project!1" }, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "squash": false, "subscribed": false, "changes_count": "1", "merged_by": { "id": 87854, "name": "Douwe Maan", "username": "DouweM", "state": "active", "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", "web_url": "https://gitlab.com/DouweM" }, "merged_at": "2018-09-07T11:16:17.520Z", "closed_by": null, "closed_at": null, "latest_build_started_at": "2018-09-07T07:27:38.472Z", "latest_build_finished_at": "2018-09-07T08:07:06.012Z", "first_deployed_to_production_at": null, "pipeline": { "id": 29626725, "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "ref": "patch-28", "status": "success", "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" }, "diff_refs": { "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" }, "diverged_commits_count": 2, "rebase_in_progress": false, "first_contribution": false, "task_completion_status":{ "count":0, "completed_count":0 }, "has_conflicts": false, "blocking_discussions_resolved": true }

在 GitLab 用户入门,青铜或更高还会看到approvals_before_merge参数:

  1. { "id": 1, "title": "test1", "approvals_before_merge": null ... }

Get single MR participants

获取合并请求参与者的列表.

  1. GET /projects/:id/merge_requests/:merge_request_iid/participants

Parameters:

  • id (必填)-经过身份验证的用户拥有的项目的 ID 或
  • merge_request_iid (必需)-合并请求的内部 ID
  1. [ { "id": 1, "name": "John Doe1", "username": "user1", "state": "active", "avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon", "web_url": "http://localhost/user1" }, { "id": 2, "name": "John Doe2", "username": "user2", "state": "active", "avatar_url": "http://www.gravatar.com/avatar/10fc7f102be8de7657fb4d80898bbfe3?s=80&d=identicon", "web_url": "http://localhost/user2" } ]

Get single MR commits

获取合并请求提交的列表.

  1. GET /projects/:id/merge_requests/:merge_request_iid/commits

Parameters:

  • id (必填)-经过身份验证的用户拥有的 ID 或URL 编码路径
  • merge_request_iid (必需)-合并请求的内部 ID
  1. [ { "id": "ed899a2f4b50b4370feeea94676502b42383c746", "short_id": "ed899a2f4b5", "title": "Replace sanitize with escape once", "author_name": "Example User", "author_email": "user@example.com", "created_at": "2012-09-20T11:50:22+03:00", "message": "Replace sanitize with escape once" }, { "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", "short_id": "6104942438c", "title": "Sanitize for network graph", "author_name": "Example User", "author_email": "user@example.com", "created_at": "2012-09-20T09:06:12+03:00", "message": "Sanitize for network graph" } ]

Get single MR changes

显示有关合并请求的信息,包括其文件和更改.

  1. GET /projects/:id/merge_requests/:merge_request_iid/changes

Parameters:

  • id (必填)-经过身份验证的用户拥有的项目的 ID 或
  • merge_request_iid (必需)-合并请求的内部 ID
  1. { "id": 21, "iid": 1, "project_id": 4, "title": "Blanditiis beatae suscipit hic assumenda et molestias nisi asperiores repellat et.", "state": "reopened", "created_at": "2015-02-02T19:49:39.159Z", "updated_at": "2015-02-02T20:08:49.959Z", "target_branch": "secret_token", "source_branch": "version-1-9", "upvotes": 0, "downvotes": 0, "author": { "name": "Chad Hamill", "username": "jarrett", "id": 5, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/b95567800f828948baf5f4160ebb2473?s=40&d=identicon", "web_url" : "https://gitlab.example.com/jarrett" }, "assignee": { "name": "Administrator", "username": "root", "id": 1, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40&d=identicon", "web_url" : "https://gitlab.example.com/root" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 4, "target_project_id": 4, "labels": [ ], "description": "Qui voluptatibus placeat ipsa alias quasi. Deleniti rem ut sint. Optio velit qui distinctio.", "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 4, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": null }, "merge_when_pipeline_succeeds": true, "merge_status": "can_be_merged", "subscribed" : true, "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "changes_count": "1", "should_remove_source_branch": true, "force_remove_source_branch": false, "squash": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "!1", "full": "my-group/my-project!1" }, "discussion_locked": false, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "task_completion_status":{ "count":0, "completed_count":0 }, "changes": [ { "old_path": "VERSION", "new_path": "VERSION", "a_mode": "100644", "b_mode": "100644", "diff": "--- a/VERSION\ +++ b/VERSION\ @@ -1 +1 @@\ -1.9.7\ +1.9.8", "new_file": false, "renamed_file": false, "deleted_file": false } ] }

List MR pipelines

在 GitLab 10.5.0 中 .

  1. GET /projects/:id/merge_requests/:merge_request_iid/pipelines

Parameters:

  • id (必填)-经过身份验证的用户拥有的项目的 ID 或
  • (必需)-合并请求的内部 ID
  1. [ { "id": 77, "sha": "959e04d7c7a30600c894bd3c0cd0e1ce7f42c11d", "ref": "master", "status": "success" } ]

Create MR Pipeline

在 GitLab 12.3 中 .

为合并请求创建一个新 . 通过这个端点创建的管道将无法运行常规的分支/标签的管道,它需要.gitlab-ci.yml与配置only: [merge_requests]创造就业机会.

新管道可以是:

  1. POST /projects/:id/merge_requests/:merge_request_iid/pipelines

Parameters:

  • id (必填)-项目的 ID 或URL 编码的路径
  • merge_request_iid (必需)-合并请求的内部 ID
  1. { "id": 2, "sha": "b83d6e391c22777fca1ed3012fce84f633d7fed0", "ref": "refs/merge-requests/1/head", "status": "pending", "web_url": "http://localhost/user1/project1/pipelines/2", "before_sha": "0000000000000000000000000000000000000000", "tag": false, "yaml_errors": null, "user": { "id": 1, "name": "John Doe1", "username": "user1", "state": "active", "avatar_url": "https://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon", "web_url": "http://example.com" }, "created_at": "2019-09-04T19:20:18.267Z", "updated_at": "2019-09-04T19:20:18.459Z", "started_at": null, "finished_at": null, "committed_at": null, "duration": null, "coverage": null, "detailed_status": { "icon": "status_pending", "text": "pending", "label": "pending", "group": "pending", "tooltip": "pending", "has_details": false, "details_path": "/user1/project1/pipelines/2", "illustration": null, "favicon": "/assets/ci_favicons/favicon_status_pending-5bdf338420e5221ca24353b6bff1c9367189588750632e9a871b7af09ff6a2ae.png" } }

创建一个新的合并请求.

  1. POST /projects/:id/merge_requests
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
source_branch string yes 源分支
target_branch string yes 目标分支
title string yes 先生的头衔
assignee_id integer no 受让人用户 ID
assignee_ids 整数数组 no 要将 MR 分配给的用户的 ID. 设置为0或提供一个空值以取消分配所有受让人.
description string no MR 的描述. 限制为 1,048,576 个字符.
target_project_id integer no 目标项目(数字 ID)
labels string no MR 的标签以逗号分隔的列表
milestone_id integer no 里程碑的全局 ID
remove_source_branch boolean no 指示合并请求是否应在合并时删除源分支的标志
allow_collaboration boolean no 允许来自可以合并到目标分支的成员的提交
allow_maintainer_to_push boolean no Deprecated, see allow_collaboration
squash boolean no 合并时将 Squash 提交到单个提交中

如果approvals_before_merge 未提供,它将从目标项目继承值. 如果提供了它,则必须满足以下条件才能使其生效:

  1. 目标项目的approvals_before_merge必须大于零. 零值将禁用该项目的批准.
  2. 所提供的价值approvals_before_merge必须比目标项目的更大approvals_before_merge .
  1. { "id": 1, "iid": 1, "project_id": 3, "title": "test1", "description": "fixed login page css paddings", "state": "merged", "created_at": "2017-04-29T08:46:00Z", "updated_at": "2017-04-29T08:46:00Z", "target_branch": "master", "source_branch": "test1", "upvotes": 0, "downvotes": 0, "author": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignee": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "source_project_id": 2, "target_project_id": 3, "labels": [ "Community contribution", "Manage" ], "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 3, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": "2018-09-22", "start_date": "2018-08-08", "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" }, "merge_when_pipeline_succeeds": true, "merge_status": "can_be_merged", "merge_error": null, "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "discussion_locked": null, "should_remove_source_branch": true, "force_remove_source_branch": false, "allow_collaboration": false, "allow_maintainer_to_push": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "!1", "full": "my-group/my-project!1" }, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "squash": false, "subscribed": false, "changes_count": "1", "merged_by": { "id": 87854, "name": "Douwe Maan", "username": "DouweM", "state": "active", "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", "web_url": "https://gitlab.com/DouweM" }, "merged_at": "2018-09-07T11:16:17.520Z", "closed_by": null, "closed_at": null, "latest_build_started_at": "2018-09-07T07:27:38.472Z", "latest_build_finished_at": "2018-09-07T08:07:06.012Z", "first_deployed_to_production_at": null, "pipeline": { "id": 29626725, "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "ref": "patch-28", "status": "success", "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" }, "diff_refs": { "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" }, "diverged_commits_count": 2, "task_completion_status":{ "count":0, "completed_count":0 } }

在 GitLab 用户还会看到approvals_before_merge参数:

  1. { "id": 1, "title": "test1", "approvals_before_merge": null ... }

Update MR

更新现有的合并请求. 您可以更改目标分支,标题,甚至关闭 MR.

  1. PUT /projects/:id/merge_requests/:merge_request_iid
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
merge_request_iid integer yes 合并请求的 ID
target_branch string no 目标分支
title string no 先生的头衔
assignee_id integer no 要将合并请求分配给的用户的 ID. 设置为0或提供一个空值以取消分配所有受让人.
assignee_ids 整数数组 no 要将 MR 分配给的用户的 ID. 设置为0或提供一个空值以取消分配所有受让人.
milestone_id integer no 要将合并请求分配给的里程碑的全局 ID. 设置为0或提供一个空值以取消分配里程碑.
labels string no 合并请求的逗号分隔标签名称. 设置为空字符串以取消分配所有标签.
add_labels string no 以逗号分隔的标签名称,添加到合并请求中.
remove_labels string no 逗号分隔的标签名称,可从合并请求中删除.
description string no MR 的描述. 限制为 1,048,576 个字符.
state_event string no 新状态(关闭/重新打开)
remove_source_branch boolean no 指示合并请求是否应在合并时删除源分支的标志
squash boolean no 合并时将 Squash 提交到单个提交中
discussion_locked boolean no 指示合并请求的讨论是否已锁定的标志. 如果讨论被锁定,则只有项目成员可以添加,编辑或解决评论.
allow_collaboration boolean no 允许来自可以合并到目标分支的成员的提交
allow_maintainer_to_push boolean no 已弃用,请参见 allow_collaboration

必须至少包含一个以上非必需的属性.

在 GitLab 用户还会看到approvals_before_merge参数:

  1. { "id": 1, "title": "test1", "approvals_before_merge": null ... }

Delete a merge request

仅适用于管理员和项目所有者. 删除相关合并请求.

  1. DELETE /projects/:id/merge_requests/:merge_request_iid
Attribute Type Required Description
id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
merge_request_iid integer yes 合并请求的内部 ID
  1. curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/4/merge_requests/85"

Accept MR

使用此 API 合并通过 MR 提交的更改.

如果合并请求无法被接受(例如:进行中,已关闭,正在等待管道完成或在要求成功时失败)-您将收到405和错误消息”不允许使用方法”

如果存在一些冲突且无法合并-您将收到406 ,并且错误消息”分支无法合并”

如果传递了sha参数,但与源头的 HEAD 不匹配-您将得到409且错误消息” SHA 与源分支的 HEAD 不匹配”

如果您没有接受此合并请求的权限-您会收到401

    Parameters:

    • id (必填)-经过身份验证的用户拥有的项目的 ID 或
    • merge_request_iid (必需) merge_request_iid内部 ID
    • merge_commit_message (optional) - Custom merge commit message
    • squash_commit_message (可选)-自定义南瓜提交消息
    • squash (可选)-如果为true则提交将在合并时被压缩为单个提交
    • should_remove_source_branch (可选)-如果为true删除源分支
    • merge_when_pipeline_succeeds (可选)-如果为true ,则在管道成功时合并 MR
    • sha (可选)-如果存在,则此 SHA 必须与源分支的 HEAD 匹配,否则合并将失败
    1. { "id": 1, "iid": 1, "project_id": 3, "title": "test1", "description": "fixed login page css paddings", "state": "merged", "created_at": "2017-04-29T08:46:00Z", "updated_at": "2017-04-29T08:46:00Z", "target_branch": "master", "source_branch": "test1", "upvotes": 0, "downvotes": 0, "author": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignee": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 2, "target_project_id": 3, "labels": [ "Community contribution", "Manage" ], "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 3, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": "2018-09-22", "start_date": "2018-08-08", "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" }, "merge_when_pipeline_succeeds": true, "merge_status": "can_be_merged", "merge_error": null, "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "discussion_locked": null, "should_remove_source_branch": true, "force_remove_source_branch": false, "allow_collaboration": false, "allow_maintainer_to_push": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "!1", "full": "my-group/my-project!1" }, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "squash": false, "subscribed": false, "changes_count": "1", "merged_by": { "id": 87854, "name": "Douwe Maan", "username": "DouweM", "state": "active", "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", "web_url": "https://gitlab.com/DouweM" }, "merged_at": "2018-09-07T11:16:17.520Z", "closed_by": null, "closed_at": null, "latest_build_started_at": "2018-09-07T07:27:38.472Z", "latest_build_finished_at": "2018-09-07T08:07:06.012Z", "first_deployed_to_production_at": null, "pipeline": { "id": 29626725, "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "ref": "patch-28", "status": "success", "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" }, "diff_refs": { "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" }, "diverged_commits_count": 2, "task_completion_status":{ "count":0, "completed_count":0 } }

    在 GitLab 用户入门,青铜或更高还会看到approvals_before_merge参数:

    1. { "id": 1, "title": "test1", "approvals_before_merge": null ... }

    Merge to default merge ref path

    如果可能,将合并请求源和目标分支之间的更改合并到目标项目存储库的refs/merge-requests/:iid/merge ref 中. 如果执行常规合并操作,此引用将具有目标分支将具有的状态.

    这不是常规的合并操作,因为它不会以任何方式更改合并请求目标分支的状态.

    向此 API 提交请求时,此 ref( refs/merge-requests/:iid/merge )不一定会被覆盖,尽管它可以确保 ref 具有最新的状态.

    如果合并请求有冲突,为空或已经合并,您将收到一条400和一个描述性错误消息.

    如果为200它将在响应正文中返回refs/merge-requests/:iid/merge的 HEAD 提交.

    1. GET /projects/:id/merge_requests/:merge_request_iid/merge_ref

    Parameters:

    • id (必填)-经过身份验证的用户拥有的项目的 ID 或
    • merge_request_iid (必需) merge_request_iid内部 ID
    1. { "commit_id": "854a3a7a17acbcc0bbbea170986df1eb60435f34" }

    Cancel Merge When Pipeline Succeeds

    如果您没有接受此合并请求的权限-您会收到401

    如果合并请求已被合并或关闭-您将收到405和错误消息”不允许使用方法”

    如果在管道成功时未将合并请求设置为要合并,则还会收到406错误.

    1. POST /projects/:id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds

    Parameters:

    • id (必填)-经过身份验证的用户拥有的 ID 或URL 编码路径
    • merge_request_iid (必需) merge_request_iid内部 ID
    1. { "id": 1, "iid": 1, "project_id": 3, "title": "test1", "description": "fixed login page css paddings", "state": "merged", "created_at": "2017-04-29T08:46:00Z", "updated_at": "2017-04-29T08:46:00Z", "target_branch": "master", "source_branch": "test1", "upvotes": 0, "downvotes": 0, "author": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignee": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 2, "target_project_id": 3, "labels": [ "Community contribution", "Manage" ], "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 3, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": "2018-09-22", "start_date": "2018-08-08", "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" }, "merge_when_pipeline_succeeds": false, "merge_status": "can_be_merged", "merge_error": null, "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "discussion_locked": null, "should_remove_source_branch": true, "force_remove_source_branch": false, "allow_collaboration": false, "allow_maintainer_to_push": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "!1", "full": "my-group/my-project!1" }, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "squash": false, "subscribed": false, "changes_count": "1", "merged_by": { "id": 87854, "name": "Douwe Maan", "username": "DouweM", "state": "active", "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", "web_url": "https://gitlab.com/DouweM" }, "merged_at": "2018-09-07T11:16:17.520Z", "closed_by": null, "closed_at": null, "latest_build_started_at": "2018-09-07T07:27:38.472Z", "latest_build_finished_at": "2018-09-07T08:07:06.012Z", "first_deployed_to_production_at": null, "pipeline": { "id": 29626725, "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "ref": "patch-28", "status": "success", "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" }, "diff_refs": { "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" }, "diverged_commits_count": 2, "task_completion_status":{ "count":0, "completed_count":0 } }

    在 GitLab 用户还会看到approvals_before_merge参数:

    1. { "id": 1, "title": "test1", "approvals_before_merge": null ... }

    Rebase a merge request

    自动将合并请求的source_branch与其target_branch .

    1. PUT /projects/:id/merge_requests/:merge_request_iid/rebase
    1. curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/76/merge_requests/1/rebase"

    这是一个异步请求. 如果请求成功入队,API 将返回202 Accepted响应,响应包含:

    1. { "rebase_in_progress": true }

    您可以使用include_rebase_in_progress参数轮询” 端点,以检查异步请求的状态.

    如果正在进行 rebase 操作,则响应将包括以下内容:

    1. { "rebase_in_progress": true, "merge_error": null }

    一旦成功完成了变基操作,响应将包括以下内容:

    1. { "rebase_in_progress": false, "merge_error": null }

    如果 rebase 操作失败,响应将包括以下内容:

    1. { "rebase_in_progress": false, "merge_error": "Rebase failed. Please rebase locally" }

    Comments on merge requests

    注释是通过资源完成的.

    List issues that will close on merge

    通过合并提供的合并请求来获取所有将要解决的问题.

    1. GET /projects/:id/merge_requests/:merge_request_iid/closes_issues
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
    merge_request_iid integer yes 合并请求的内部 ID
    1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/76/merge_requests/1/closes_issues"

    使用 GitLab 问题跟踪器时的示例响应:

    1. [ { "state" : "opened", "description" : "Ratione dolores corrupti mollitia soluta quia.", "author" : { "state" : "active", "id" : 18, "web_url" : "https://gitlab.example.com/eileen.lowe", "name" : "Alexandra Bashirian", "avatar_url" : null, "username" : "eileen.lowe" }, "milestone" : { "project_id" : 1, "description" : "Ducimus nam enim ex consequatur cumque ratione.", "state" : "closed", "due_date" : null, "iid" : 2, "created_at" : "2016-01-04T15:31:39.996Z", "title" : "v4.0", "id" : 17, "updated_at" : "2016-01-04T15:31:39.996Z" }, "project_id" : 1, "assignee" : { "state" : "active", "id" : 1, "name" : "Administrator", "web_url" : "https://gitlab.example.com/root", "avatar_url" : null, "username" : "root" }, "updated_at" : "2016-01-04T15:31:51.081Z", "id" : 76, "title" : "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.", "created_at" : "2016-01-04T15:31:51.081Z", "iid" : 6, "labels" : [], "user_notes_count": 1, "changes_count": "1" } ]

    使用外部问题跟踪器(例如 Jira)时的示例响应:

    1. [ { "id" : "PROJECT-123", "title" : "Title of this issue" } ]

    向已认证的用户订阅合并请求以接收通知. 如果用户已经订阅了合并请求,则返回状态码304 .

    1. POST /projects/:id/merge_requests/:merge_request_iid/subscribe
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
    merge_request_iid integer yes 合并请求的内部 ID
    1. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/17/subscribe"

    响应示例:

    1. { "id": 1, "iid": 1, "project_id": 3, "title": "test1", "description": "fixed login page css paddings", "state": "merged", "created_at": "2017-04-29T08:46:00Z", "updated_at": "2017-04-29T08:46:00Z", "target_branch": "master", "source_branch": "test1", "upvotes": 0, "downvotes": 0, "author": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignee": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 2, "target_project_id": 3, "labels": [ "Community contribution", "Manage" ], "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 3, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": "2018-09-22", "start_date": "2018-08-08", "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" }, "merge_when_pipeline_succeeds": true, "merge_status": "can_be_merged", "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "discussion_locked": null, "should_remove_source_branch": true, "force_remove_source_branch": false, "allow_collaboration": false, "allow_maintainer_to_push": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "!1", "full": "my-group/my-project!1" }, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "squash": false, "subscribed": false, "changes_count": "1", "merged_by": { "id": 87854, "name": "Douwe Maan", "username": "DouweM", "state": "active", "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", "web_url": "https://gitlab.com/DouweM" }, "merged_at": "2018-09-07T11:16:17.520Z", "closed_by": null, "closed_at": null, "latest_build_started_at": "2018-09-07T07:27:38.472Z", "latest_build_finished_at": "2018-09-07T08:07:06.012Z", "first_deployed_to_production_at": null, "pipeline": { "id": 29626725, "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "ref": "patch-28", "status": "success", "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" }, "diff_refs": { "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" }, "diverged_commits_count": 2, "task_completion_status":{ "count":0, "completed_count":0 } }

    在 GitLab 用户还会看到approvals_before_merge参数:

    1. { "id": 1, "title": "test1", "approvals_before_merge": null ... }

    Unsubscribe from a merge request

    从合并请求中退订已认证的用户,以不接收来自该合并请求的通知. 如果用户未订阅合并请求,则返回状态码304 .

    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
    merge_request_iid integer yes 合并请求的内部 ID
    1. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/17/unsubscribe"

    响应示例:

    1. { "id": 1, "iid": 1, "project_id": 3, "title": "test1", "description": "fixed login page css paddings", "state": "merged", "created_at": "2017-04-29T08:46:00Z", "updated_at": "2017-04-29T08:46:00Z", "target_branch": "master", "source_branch": "test1", "upvotes": 0, "downvotes": 0, "author": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignee": { "id": 1, "name": "Administrator", "username": "admin", "state": "active", "avatar_url": null, "web_url" : "https://gitlab.example.com/admin" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 2, "target_project_id": 3, "labels": [ "Community contribution", "Manage" ], "work_in_progress": false, "milestone": { "id": 5, "iid": 1, "project_id": 3, "title": "v2.0", "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", "state": "closed", "created_at": "2015-02-02T19:49:26.013Z", "updated_at": "2015-02-02T19:49:26.013Z", "due_date": "2018-09-22", "start_date": "2018-08-08", "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" }, "merge_when_pipeline_succeeds": true, "merge_status": "can_be_merged", "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 1, "discussion_locked": null, "should_remove_source_branch": true, "force_remove_source_branch": false, "allow_collaboration": false, "allow_maintainer_to_push": false, "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "!1", "full": "my-group/my-project!1" }, "time_stats": { "time_estimate": 0, "total_time_spent": 0, "human_time_estimate": null, "human_total_time_spent": null }, "squash": false, "subscribed": false, "changes_count": "1", "merged_by": { "id": 87854, "name": "Douwe Maan", "username": "DouweM", "state": "active", "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", "web_url": "https://gitlab.com/DouweM" }, "merged_at": "2018-09-07T11:16:17.520Z", "closed_by": null, "closed_at": null, "latest_build_started_at": "2018-09-07T07:27:38.472Z", "latest_build_finished_at": "2018-09-07T08:07:06.012Z", "first_deployed_to_production_at": null, "pipeline": { "id": 29626725, "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "ref": "patch-28", "status": "success", "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" }, "diff_refs": { "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" }, "diverged_commits_count": 2, "task_completion_status":{ "count":0, "completed_count":0 } }

    在 GitLab 用户还会看到approvals_before_merge参数:

    1. { "id": 1, "title": "test1", "approvals_before_merge": null ... }

    Create a todo

    在合并请求上为当前用户手动创建待办事项. 如果在该合并请求上已经存在用户的待办事项,则返回状态码304 .

    1. POST /projects/:id/merge_requests/:merge_request_iid/todo
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
    merge_request_iid integer yes 合并请求的内部 ID
    1. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/27/todo"

    响应示例:

    1. { "id": 113, "project": { "id": 3, "name": "GitLab CI/CD", "name_with_namespace": "GitLab Org / GitLab CI/CD", "path": "gitlab-ci", "path_with_namespace": "gitlab-org/gitlab-ci" }, "author": { "name": "Administrator", "username": "root", "id": 1, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", "web_url": "https://gitlab.example.com/root" }, "action_name": "marked", "target_type": "MergeRequest", "target": { "id": 27, "iid": 7, "project_id": 3, "title": "Et voluptas laudantium minus nihil recusandae ut accusamus earum aut non.", "description": "Veniam sunt nihil modi earum cumque illum delectus. Nihil ad quis distinctio quia. Autem eligendi at quibusdam repellendus.", "state": "merged", "created_at": "2016-06-17T07:48:04.330Z", "updated_at": "2016-07-01T11:14:15.537Z", "target_branch": "allow_regex_for_project_skip_ref", "source_branch": "backup", "upvotes": 0, "downvotes": 0, "author": { "name": "Jarret O'Keefe", "username": "francisca", "id": 14, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/a7fa515d53450023c83d62986d0658a8?s=80&d=identicon", "web_url": "https://gitlab.example.com/francisca", "discussion_locked": false }, "assignee": { "name": "Dr. Gabrielle Strosin", "username": "barrett.krajcik", "id": 4, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/733005fcd7e6df12d2d8580171ccb966?s=80&d=identicon", "web_url": "https://gitlab.example.com/barrett.krajcik" }, "assignees": [{ "name": "Miss Monserrate Beier", "username": "axel.block", "id": 12, "state": "active", "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", "web_url": "https://gitlab.example.com/axel.block" }], "source_project_id": 3, "target_project_id": 3, "labels": [], "work_in_progress": false, "milestone": { "id": 27, "iid": 2, "project_id": 3, "title": "v1.0", "description": "Quis ea accusantium animi hic fuga assumenda.", "state": "active", "created_at": "2016-06-17T07:47:33.840Z", "updated_at": "2016-06-17T07:47:33.840Z", "due_date": null }, "merge_when_pipeline_succeeds": false, "merge_status": "unchecked", "subscribed": true, "sha": "8888888888888888888888888888888888888888", "merge_commit_sha": null, "squash_commit_sha": null, "user_notes_count": 7, "changes_count": "1", "should_remove_source_branch": true, "force_remove_source_branch": false, "squash": false, "web_url": "http://example.com/my-group/my-project/merge_requests/1", "references": { "short": "!1", "relative": "!1", "full": "my-group/my-project!1" }, }, "target_url": "https://gitlab.example.com/gitlab-org/gitlab-ci/merge_requests/7", "body": "Et voluptas laudantium minus nihil recusandae ut accusamus earum aut non.", "state": "pending", "created_at": "2016-07-01T11:14:15.530Z" }

    Get MR diff versions

    获取合并请求差异版本的列表.

    1. GET /projects/:id/merge_requests/:merge_request_iid/versions
    Attribute Type Required Description
    id String yes 项目 ID
    merge_request_iid integer yes 合并请求的内部 ID
    1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/versions"

    响应示例:

    1. [{ "id": 110, "head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", "created_at": "2016-07-26T14:44:48.926Z", "merge_request_id": 105, "state": "collected", "real_size": "1" }, { "id": 108, "head_commit_sha": "3eed087b29835c48015768f839d76e5ea8f07a24", "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", "created_at": "2016-07-25T14:21:33.028Z", "merge_request_id": 105, "state": "collected", "real_size": "1" }]

    Get a single MR diff version

    获取单个合并请求的差异版本.

    1. GET /projects/:id/merge_requests/:merge_request_iid/versions/:version_id
    1. curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/versions/1"

    响应示例:

    1. { "id": 110, "head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", "created_at": "2016-07-26T14:44:48.926Z", "merge_request_id": 105, "state": "collected", "real_size": "1", "commits": [{ "id": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", "short_id": "33e2ee85", "title": "Change year to 2018", "author_name": "Administrator", "author_email": "admin@example.com", "created_at": "2016-07-26T17:44:29.000+03:00", "message": "Change year to 2018" }, { "id": "aa24655de48b36335556ac8a3cd8bb521f977cbd", "short_id": "aa24655d", "title": "Update LICENSE", "author_name": "Administrator", "author_email": "admin@example.com", "created_at": "2016-07-25T17:21:53.000+03:00", "message": "Update LICENSE" }, { "id": "3eed087b29835c48015768f839d76e5ea8f07a24", "short_id": "3eed087b", "title": "Add license", "author_name": "Administrator", "author_email": "admin@example.com", "created_at": "2016-07-25T17:21:20.000+03:00", "message": "Add license" }], "diffs": [{ "old_path": "LICENSE", "new_path": "LICENSE", "a_mode": "0", "b_mode": "100644", "diff": "--- /dev/null\n+++ b/LICENSE\n@@ -0,0 +1,21 @@\n+The MIT License (MIT)\n+\n+Copyright (c) 2018 Administrator\n+\n+Permission is hereby granted, free of charge, to any person obtaining a copy\n+of this software and associated documentation files (the \"Software\"), to deal\n+in the Software without restriction, including without limitation the rights\n+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n+copies of the Software, and to permit persons to whom the Software is\n+furnished to do so, subject to the following conditions:\n+\n+The above copyright notice and this permission notice shall be included in all\n+copies or substantial portions of the Software.\n+\n+THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n+SOFTWARE.\n", "new_file": true, "renamed_file": false, "deleted_file": false }] }

    Set a time estimate for a merge request

    Sets an estimated time of work for this merge request.

    1. POST /projects/:id/merge_requests/:merge_request_iid/time_estimate
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的项目的 ID 或
    merge_request_iid integer yes 合并请求的内部 ID
    duration string yes 以人类格式表示的持续时间. 例如:3h30m
    1. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/time_estimate?duration=3h30m"

    响应示例:

    1. { "human_time_estimate": "3h 30m", "human_total_time_spent": null, "time_estimate": 12600, "total_time_spent": 0 }

    Reset the time estimate for a merge request

    将此合并请求的估计时间重置为 0 秒.

    1. POST /projects/:id/merge_requests/:merge_request_iid/reset_time_estimate
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
    merge_request_iid integer yes 项目的 merge_request 的内部 ID
    1. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/reset_time_estimate"

    响应示例:

    1. { "human_time_estimate": null, "human_total_time_spent": null, "time_estimate": 0, "total_time_spent": 0 }

    Add spent time for a merge request

    增加此合并请求的时间

    1. POST /projects/:id/merge_requests/:merge_request_iid/add_spent_time
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的项目的 ID 或
    merge_request_iid integer yes 合并请求的内部 ID
    duration string yes 以人类格式表示的持续时间. 例如:3h30m
    1. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/add_spent_time?duration=1h"

    响应示例:

    1. { "human_time_estimate": null, "human_total_time_spent": "1h", "time_estimate": 0, "total_time_spent": 3600 }

    Reset spent time for a merge request

    将此合并请求的总花费时间重置为 0 秒.

    1. POST /projects/:id/merge_requests/:merge_request_iid/reset_spent_time
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
    merge_request_iid integer yes 项目的 merge_request 的内部 ID
    1. curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/reset_spent_time"

    响应示例:

    1. { "human_time_estimate": null, "human_total_time_spent": null, "time_estimate": 0, "total_time_spent": 0 }
    1. GET /projects/:id/merge_requests/:merge_request_iid/time_stats
    Attribute Type Required Description
    id integer/string yes 经过身份验证的用户拥有的 ID 或URL 编码路径
    merge_request_iid integer yes 合并请求的内部 ID

    响应示例:

      Approvals

      有关批准,请参阅合并请求批准