多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# Merge requests API > 原文:[https://docs.gitlab.com/ee/api/merge_requests.html](https://docs.gitlab.com/ee/api/merge_requests.html) * [List merge requests](#list-merge-requests) * [List project merge requests](#list-project-merge-requests) * [List group merge requests](#list-group-merge-requests) * [Get single MR](#get-single-mr) * [Get single MR participants](#get-single-mr-participants) * [Get single MR commits](#get-single-mr-commits) * [Get single MR changes](#get-single-mr-changes) * [List MR pipelines](#list-mr-pipelines) * [Create MR Pipeline](#create-mr-pipeline) * [Create MR](#create-mr) * [Update MR](#update-mr) * [Delete a merge request](#delete-a-merge-request) * [Accept MR](#accept-mr) * [Merge to default merge ref path](#merge-to-default-merge-ref-path) * [Cancel Merge When Pipeline Succeeds](#cancel-merge-when-pipeline-succeeds) * [Rebase a merge request](#rebase-a-merge-request) * [Comments on merge requests](#comments-on-merge-requests) * [List issues that will close on merge](#list-issues-that-will-close-on-merge) * [Subscribe to a merge request](#subscribe-to-a-merge-request) * [Unsubscribe from a merge request](#unsubscribe-from-a-merge-request) * [Create a todo](#create-a-todo) * [Get MR diff versions](#get-mr-diff-versions) * [Get a single MR diff version](#get-a-single-mr-diff-version) * [Set a time estimate for a merge request](#set-a-time-estimate-for-a-merge-request) * [Reset the time estimate for a merge request](#reset-the-time-estimate-for-a-merge-request) * [Add spent time for a merge request](#add-spent-time-for-a-merge-request) * [Reset spent time for a merge request](#reset-spent-time-for-a-merge-request) * [Get time tracking stats](#get-time-tracking-stats) * [Approvals](#approvals-starter) # Merge requests API[](#merge-requests-api "Permalink") 合并请求的每个 API 调用都必须经过验证. **弃用** > `reference`响应属性有利于已弃用`references` . >推出了[GitLab 12.6](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/20354)**注意** > `references.relative`相对于正在请求合并请求的组/项目. 当从其项目中获取合并请求时> `relative`格式将与`short`格式相同,并且在跨组/项目进行请求时, `relative`格式应与`full`格式相同. ## List merge requests[](#list-merge-requests "Permalink") 在 GitLab 9.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13060) . 获取所有通过身份验证的用户有权访问的合并请求. 默认情况下,它仅返回当前用户创建的合并请求. 要获取所有合并请求,请使用参数`scope=all` . `state`参数可用于仅获取具有给定状态( `opened` , `closed` , `locked`或`merged` )或全部( `all` )的合并请求. 应该注意的是,通过`locked`进行搜索时,由于它是短暂的过渡状态,因此几乎不会返回任何结果. 分页参数`page`和`per_page`可用于限制合并请求的列表. ``` GET /merge_requests GET /merge_requests?state=opened GET /merge_requests?state=all GET /merge_requests?milestone=release GET /merge_requests?labels=bug,reproduced GET /merge_requests?author_id=5 GET /merge_requests?author_username=gitlab-bot GET /merge_requests?my_reaction_emoji=star GET /merge_requests?scope=assigned_to_me GET /merge_requests?search=foo&in=title ``` Parameters: | Attribute | Type | Required | Description |   | | --- | --- | --- | --- | --- | | `state` | string | no | 返回所有合并请求,或者仅返回已`opened` , `closed` , `locked`或`merged`请求 |   | | `order_by` | string | no | 返回由`created_at`或`updated_at`字段排序的请求. 默认为`created_at` |   | | `sort` | string | no | 返回请求按`asc`或`desc`顺序排序. 默认为`desc` |   | | `milestone` | string | no | 返回特定里程碑的合并请求. `None`返回没有里程碑的合并请求. `Any`返回将合并具有指定里程碑的请求. |   | | `view` | string | no | 如果为`simple` ,则返回`iid` ,URL,标题,描述和合并请求的基本状态 |   | | `labels` | string | no | 返回与逗号分隔的标签列表匹配的合并请求. `None`列出所有没有标签的合并请求. `Any`列出所有具有至少一个标签的合并请求. `No+Label` (不推荐使用)列出所有没有标签的合并请求. 预定义名称不区分大小写. |   | | `with_labels_details` | boolean | no | If `true`, response will return more details for each label in labels field: `:name`, `:color`, `:description`, `:description_html`, `:text_color`. Default is `false`. Introduced in [GitLab 12.7](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/21413) |   | | `with_merge_status_recheck` | boolean | no | 如果为`true` ,则此投影请求(但不保证)异步地重新计算`merge_status`字段. 默认值为`false` . 在[GitLab 13.0 中](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31890)引入 |   | | `created_after` | datetime | no | 返回在给定时间或之后创建的合并请求 |   | | `created_before` | datetime | no | 返回在给定时间或之前创建的合并请求 |   | | `updated_after` | datetime | no | 返回在给定时间或之后更新的合并请求 |   | | `updated_before` | datetime | no | 返回在给定时间或之前更新的合并请求 |   | | `scope` | string | no | 对于给定的范围内返回的合并请求: `created_by_me` , `assigned_to_me`或`all` . 默认为`created_by_me` 对于 11.0 之前的版本,请改用现在不建议使用`created-by-me`范围或`created-by-me` `assigned-to-me`范围. |   | | `author_id` | integer | no | 返回由给定用户`id`创建的合并请求. 与`author_username` . 与`scope=all`或`scope=assigned_to_me` |   | | `author_username` | string | no | 返回由给定`username`创建的合并请求. 与`author_id` . *(在 GitLab 12.10 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13060) )* |   | | `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 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/14016) )* |   | | `source_branch` | string | no | 返回具有给定源分支的合并请求 |   | | `target_branch` | string | no | 返回具有给定目标分支的合并请求 |   | | `search` | string | no | 根据`title`和`description`搜索合并请求 |   | | `in` | string | no | 修改`search`属性的范围. `title` , `description`或以逗号将它们连接在一起的字符串. 默认为`title,description` |   | | `wip` | string | no | 过滤合并请求对他们的`wip`状态. `yes` , *仅*返回 WIP 合并请求, `no` ,返回*非* WIP 合并请求 |   | | `not` | Hash | no | 返回与提供的参数不匹配的合并请求. 接受: `labels` , `milestone` , `author_id` , `author_username` , `assignee_id` , `assignee_username` , `my_reaction_emoji` |   | **注意:** [从 GitLab 13.0 开始](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31890) ,列出合并请求可能不会主动更新`merge_status`字段(这也会影响`has_conflicts`字段),因为这可能是一项昂贵的操作. 如果您对此端点的这些字段的值感兴趣,请在查询`with_merge_status_recheck`参数设置为`true` .**注意:** [从 GitLab 12.8 开始,](https://gitlab.com/gitlab-org/gitlab/-/issues/29984)当对此端点发出请求时,将异步检查每个合并请求的可合并性( `merge_status` ). 轮询此 API 端点以获取更新状态. 这会影响`has_conflicts`属性,因为它取决于`merge_status` . 除非`merge_status`为`cannot_be_merged`否则它将返回`false` . ``` [ { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` [ { "id": 1, "title": "test1", "approvals_before_merge": null ... } ] ``` ## List project merge requests[](#list-project-merge-requests "Permalink") 获取此项目的所有合并请求. `state`参数可用于仅获取具有给定状态( `opened` , `closed` , `locked`或`merged` )或全部( `all` )的合并请求. 分页参数`page`和`per_page`可用于限制合并请求的列表. ``` GET /projects/:id/merge_requests GET /projects/:id/merge_requests?state=opened GET /projects/:id/merge_requests?state=all GET /projects/:id/merge_requests?iids[]=42&iids[]=43 GET /projects/:id/merge_requests?milestone=release GET /projects/:id/merge_requests?labels=bug,reproduced GET /projects/:id/merge_requests?my_reaction_emoji=star ``` `project_id`代表 MR 所在项目的 ID. `project_id`将始终等于`target_project_id` . 如果来自同一项目的合并请求,则`source_project_id` , `target_project_id`和`project_id`将相同. 对于来自派生的合并请求, `target_project_id`和`project_id`将相同,并且`source_project_id`将是派生项目的 ID. Parameters: | Attribute | Type | Required | Description |   | | --- | --- | --- | --- | --- | | `id` | integer | yes | 项目 ID |   | | `iids[]` | 整数数组 | no | 返回具有给定`iid`的请求 |   | | `state` | string | no | 返回所有合并请求,或者仅返回已`opened` , `closed` , `locked`或`merged`请求 |   | | `order_by` | string | no | 返回由`created_at`或`updated_at`字段排序的请求. 默认为`created_at` |   | | `sort` | string | no | 返回请求按`asc`或`desc`顺序排序. 默认为`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` , `:description_html` , `:text_color` . 默认值为`false` . 在[GitLab 12.7 中](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/21413)引入 |   | | `with_merge_status_recheck` | boolean | no | 如果为`true` ,则此投影请求(但不保证)异步地重新计算`merge_status`字段. 默认值为`false` . 在[GitLab 13.0 中](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31890)引入 |   | | `created_after` | datetime | no | 返回在给定时间或之后创建的合并请求 |   | | `created_before` | datetime | no | 返回在给定时间或之前创建的合并请求 |   | | `updated_after` | datetime | no | 返回在给定时间或之后更新的合并请求 |   | | `updated_before` | datetime | no | 返回在给定时间或之前更新的合并请求 |   | | `scope` | string | no | 对于给定的范围内返回的合并请求: `created_by_me` , `assigned_to_me`或`all` . 对于 11.0 之前的版本,请改用现在不建议使用`created-by-me`范围或`created-by-me` `assigned-to-me`范围. *(在 GitLab 9.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13060) .在 GitLab 11.0 中[更改为 snake_case](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/18935) )* |   | | `author_id` | integer | no | 返回由给定用户`id`创建的合并请求. 与`author_username` . *(在 GitLab 9.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13060) )* |   | | `author_username` | string | no | 返回由给定`username`创建的合并请求. 与`author_id` . *(在 GitLab 12.10 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13060) )* |   | | `assignee_id` | integer | no | 返回分配给给定用户`id`合并请求. `None`将返回未分配的合并请求. `Any`退货将请求与受让人合并. *(在 GitLab 9.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13060) )* |   | | `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 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/14016) )* |   | | `source_branch` | string | no | 返回具有给定源分支的合并请求 |   | | `target_branch` | string | no | 返回具有给定目标分支的合并请求 |   | | `search` | string | no | 根据`title`和`description`搜索合并请求 |   | | `wip` | string | no | 过滤合并请求对他们的`wip`状态. `yes` , *仅*返回 WIP 合并请求, `no` ,返回*非* WIP 合并请求 |   | ``` [ { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` [ { "id": 1, "title": "test1", "approvals_before_merge": null ... } ] ``` ## List group merge requests[](#list-group-merge-requests "Permalink") 获取该组及其子组的所有合并请求. `state`参数可用于仅获取具有给定状态( `opened` , `closed` , `locked`或`merged` )或全部( `all` )的合并请求. 分页参数`page`和`per_page`可用于限制合并请求的列表. ``` GET /groups/:id/merge_requests GET /groups/:id/merge_requests?state=opened GET /groups/:id/merge_requests?state=all GET /groups/:id/merge_requests?milestone=release GET /groups/:id/merge_requests?labels=bug,reproduced 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 | 返回所有合并请求,或者仅返回已`opened` , `closed` , `locked`或`merged`请求 |   | | `order_by` | string | no | 返回由`created_at`或`updated_at`字段排序的合并请求. 默认为`created_at` |   | | `sort` | string | no | 返回以`asc`或`desc`顺序排序的合并请求. 默认为`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 中](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/21413)引入 |   | | `with_merge_status_recheck` | boolean | no | 如果为`true` ,则此投影请求(但不保证)异步地重新计算`merge_status`字段. 默认值为`false` . 在[GitLab 13.0 中](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/31890)引入 |   | | `created_after` | datetime | no | 返回在给定时间或之后创建的合并请求 |   | | `created_before` | datetime | no | 返回在给定时间或之前创建的合并请求 |   | | `updated_after` | datetime | no | 返回在给定时间或之后更新的合并请求 |   | | `updated_before` | datetime | no | 返回在给定时间或之前更新的合并请求 |   | | `scope` | string | no | 对于给定的范围内返回的合并请求: `created_by_me` , `assigned_to_me`或`all` . |   | | `author_id` | integer | no | 返回由给定用户`id`创建的合并请求. 与`author_username` . *(在 GitLab 9.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13060) )* |   | | `author_username` | string | no | 返回由给定`username`创建的合并请求. 与`author_id` . *(在 GitLab 12.10 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13060) )* |   | | `assignee_id` | integer | no | 返回分配给给定用户`id`合并请求. `None`将返回未分配的合并请求. `Any`退货将请求与受让人合并. *(在 GitLab 9.5 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/13060) )* |   | | `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 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/14016) )* |   | | `source_branch` | string | no | 返回具有给定源分支的合并请求 |   | | `target_branch` | string | no | 返回具有给定目标分支的合并请求 |   | | `search` | string | no | 根据`title`和`description`搜索合并请求 |   | | `non_archived` | boolean | no | 仅从非归档项目返回合并请求. 默认为 true. *(在[GitLab 12.8 中](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/23809)引入)* |   | ``` [ { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` [ { "id": 1, "title": "test1", "approvals_before_merge": null ... } ] ``` ## Get single MR[](#get-single-mr "Permalink") 显示有关单个合并请求的信息. **注意** :响应中的`changes_count`值是一个字符串,而不是整数. 这是因为当 MR 有太多要显示和存储的更改时,其上限为 1,000\. 在这种情况下,API 将为更改计数返回字符串`"1000+"` . ``` GET /projects/:id/merge_requests/:merge_request_iid ``` Parameters: * `id` (必填)-经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) * `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 操作 **注意:** [从 GitLab 12.8 开始,](https://gitlab.com/gitlab-org/gitlab/-/issues/29984)当对此端点发出请求时,将异步检查合并请求的可合并性( `merge_status` ). 轮询此 API 端点以获取更新状态. 这会影响`has_conflicts`属性,因为它取决于`merge_status` . 除非`merge_status`为`cannot_be_merged`否则它将返回`false` . ``` { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` { "id": 1, "title": "test1", "approvals_before_merge": null ... } ``` ## Get single MR participants[](#get-single-mr-participants "Permalink") 获取合并请求参与者的列表. ``` GET /projects/:id/merge_requests/:merge_request_iid/participants ``` Parameters: * `id` (必填)-经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) * `merge_request_iid` (必需)-合并请求的内部 ID ``` [ { "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[](#get-single-mr-commits "Permalink") 获取合并请求提交的列表. ``` GET /projects/:id/merge_requests/:merge_request_iid/commits ``` Parameters: * `id` (必填)-经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) * `merge_request_iid` (必需)-合并请求的内部 ID ``` [ { "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[](#get-single-mr-changes "Permalink") 显示有关合并请求的信息,包括其文件和更改. ``` GET /projects/:id/merge_requests/:merge_request_iid/changes ``` Parameters: * `id` (必填)-经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) * `merge_request_iid` (必需)-合并请求的内部 ID ``` { "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[](#list-mr-pipelines "Permalink") 在 GitLab 10.5.0 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/15454) . 获取合并请求管道的列表. ``` GET /projects/:id/merge_requests/:merge_request_iid/pipelines ``` Parameters: * `id` (必填)-经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) * `merge_request_iid` (必需)-合并请求的内部 ID ``` [ { "id": 77, "sha": "959e04d7c7a30600c894bd3c0cd0e1ce7f42c11d", "ref": "master", "status": "success" } ] ``` ## Create MR Pipeline[](#create-mr-pipeline "Permalink") 在 GitLab 12.3 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/31722) . [为合并请求](../ci/merge_request_pipelines/index.html)创建一个新[管道](../ci/merge_request_pipelines/index.html) . 通过这个端点创建的管道将无法运行常规的分支/标签的管道,它需要`.gitlab-ci.yml`与配置`only: [merge_requests]`创造就业机会. 新管道可以是: * 分离的合并请求管道. * A [pipeline for merged results](../ci/merge_request_pipelines/pipelines_for_merged_results/index.html) if the [project setting is enabled](../ci/merge_request_pipelines/pipelines_for_merged_results/index.html#enable-pipelines-for-merged-results). ``` POST /projects/:id/merge_requests/:merge_request_iid/pipelines ``` Parameters: * `id` (必填)-项目的 ID 或[URL 编码的路径](README.html#namespaced-path-encoding) * `merge_request_iid` (必需)-合并请求的内部 ID ``` { "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" } } ``` ## Create MR[](#create-mr "Permalink") 创建一个新的合并请求. ``` POST /projects/:id/merge_requests ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `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` . ``` { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` { "id": 1, "title": "test1", "approvals_before_merge": null ... } ``` ## Update MR[](#update-mr "Permalink") 更新现有的合并请求. 您可以更改目标分支,标题,甚至关闭 MR. ``` PUT /projects/:id/merge_requests/:merge_request_iid ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `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 | 必须至少包含一个以上非必需的属性. ``` { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` { "id": 1, "title": "test1", "approvals_before_merge": null ... } ``` ## Delete a merge request[](#delete-a-merge-request "Permalink") 仅适用于管理员和项目所有者. 删除相关合并请求. ``` DELETE /projects/:id/merge_requests/:merge_request_iid ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | ``` curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/4/merge_requests/85" ``` ## Accept MR[](#accept-mr "Permalink") 使用此 API 合并通过 MR 提交的更改. 如果合并请求无法被接受(例如:进行中,已关闭,正在等待管道完成或在要求成功时失败)-您将收到`405`和错误消息"不允许使用方法" 如果存在一些冲突且无法合并-您将收到`406` ,并且错误消息"分支无法合并" 如果传递了`sha`参数,但与源头的 HEAD 不匹配-您将得到`409`且错误消息" SHA 与源分支的 HEAD 不匹配" 如果您没有接受此合并请求的权限-您会收到`401` ``` PUT /projects/:id/merge_requests/:merge_request_iid/merge ``` Parameters: * `id` (必填)-经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) * `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 匹配,否则合并将失败 ``` { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` { "id": 1, "title": "test1", "approvals_before_merge": null ... } ``` ## Merge to default merge ref path[](#merge-to-default-merge-ref-path "Permalink") 如果可能,将合并请求源和目标分支之间的更改合并到目标项目存储库的`refs/merge-requests/:iid/merge` ref 中. 如果执行常规合并操作,此引用将具有目标分支将具有的状态. 这不是常规的合并操作,因为它不会以任何方式更改合并请求目标分支的状态. 向此 API 提交请求时,此 ref( `refs/merge-requests/:iid/merge` )不一定会被覆盖,尽管它可以确保 ref 具有最新的状态. 如果合并请求有冲突,为空或已经合并,您将收到一条`400`和一个描述性错误消息. 如果为`200`它将在响应正文中返回`refs/merge-requests/:iid/merge`的 HEAD 提交. ``` GET /projects/:id/merge_requests/:merge_request_iid/merge_ref ``` Parameters: * `id` (必填)-经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) * `merge_request_iid` (必需) `merge_request_iid`内部 ID ``` { "commit_id": "854a3a7a17acbcc0bbbea170986df1eb60435f34" } ``` ## Cancel Merge When Pipeline Succeeds[](#cancel-merge-when-pipeline-succeeds "Permalink") 如果您没有接受此合并请求的权限-您会收到`401` 如果合并请求已被合并或关闭-您将收到`405`和错误消息"不允许使用方法" 如果在管道成功时未将合并请求设置为要合并,则还会收到`406`错误. ``` POST /projects/:id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds ``` Parameters: * `id` (必填)-经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) * `merge_request_iid` (必需) `merge_request_iid`内部 ID ``` { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` { "id": 1, "title": "test1", "approvals_before_merge": null ... } ``` ## Rebase a merge request[](#rebase-a-merge-request "Permalink") 自动将合并请求的`source_branch`与其`target_branch` . 如果您无权推送到合并请求的源分支-您将收到`403 Forbidden`响应. ``` PUT /projects/:id/merge_requests/:merge_request_iid/rebase ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | | `skip_ci` | boolean | no | 设置为`true`以跳过创建 CI 管道 | ``` curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/76/merge_requests/1/rebase" ``` 这是一个异步请求. 如果请求成功入队,API 将返回`202 Accepted`响应,响应包含: ``` { "rebase_in_progress": true } ``` 您可以使用`include_rebase_in_progress`参数轮询" [获取单个 MR"](#get-single-mr)端点,以检查异步请求的状态. 如果正在进行 rebase 操作,则响应将包括以下内容: ``` { "rebase_in_progress": true, "merge_error": null } ``` 一旦成功完成了变基操作,响应将包括以下内容: ``` { "rebase_in_progress": false, "merge_error": null } ``` 如果 rebase 操作失败,响应将包括以下内容: ``` { "rebase_in_progress": false, "merge_error": "Rebase failed. Please rebase locally" } ``` ## Comments on merge requests[](#comments-on-merge-requests "Permalink") 注释是通过[notes](notes.html)资源完成的. ## List issues that will close on merge[](#list-issues-that-will-close-on-merge "Permalink") 通过合并提供的合并请求来获取所有将要解决的问题. ``` GET /projects/:id/merge_requests/:merge_request_iid/closes_issues ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/76/merge_requests/1/closes_issues" ``` 使用 GitLab 问题跟踪器时的示例响应: ``` [ { "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)时的示例响应: ``` [ { "id" : "PROJECT-123", "title" : "Title of this issue" } ] ``` ## Subscribe to a merge request[](#subscribe-to-a-merge-request "Permalink") 向已认证的用户订阅合并请求以接收通知. 如果用户已经订阅了合并请求,则返回状态码`304` . ``` POST /projects/:id/merge_requests/:merge_request_iid/subscribe ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/17/subscribe" ``` 响应示例: ``` { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` { "id": 1, "title": "test1", "approvals_before_merge": null ... } ``` ## Unsubscribe from a merge request[](#unsubscribe-from-a-merge-request "Permalink") 从合并请求中退订已认证的用户,以不接收来自该合并请求的通知. 如果用户未订阅合并请求,则返回状态码`304` . ``` POST /projects/:id/merge_requests/:merge_request_iid/unsubscribe ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/17/unsubscribe" ``` 响应示例: ``` { "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 用户[入门,青铜或更高](https://about.gitlab.com/pricing/)还会看到`approvals_before_merge`参数: ``` { "id": 1, "title": "test1", "approvals_before_merge": null ... } ``` ## Create a todo[](#create-a-todo "Permalink") 在合并请求上为当前用户手动创建待办事项. 如果在该合并请求上已经存在用户的待办事项,则返回状态码`304` . ``` POST /projects/:id/merge_requests/:merge_request_iid/todo ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/27/todo" ``` 响应示例: ``` { "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[](#get-mr-diff-versions "Permalink") 获取合并请求差异版本的列表. ``` GET /projects/:id/merge_requests/:merge_request_iid/versions ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | String | yes | 项目 ID | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/versions" ``` 响应示例: ``` [{ "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[](#get-a-single-mr-diff-version "Permalink") 获取单个合并请求的差异版本. ``` GET /projects/:id/merge_requests/:merge_request_iid/versions/:version_id ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | String | yes | 项目 ID | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | | `version_id` | integer | yes | 合并请求差异版本的 ID | ``` 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", "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[](#set-a-time-estimate-for-a-merge-request "Permalink") Sets an estimated time of work for this merge request. ``` POST /projects/:id/merge_requests/:merge_request_iid/time_estimate ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | | `duration` | string | yes | 以人类格式表示的持续时间. 例如:3h30m | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/time_estimate?duration=3h30m" ``` 响应示例: ``` { "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[](#reset-the-time-estimate-for-a-merge-request "Permalink") 将此合并请求的估计时间重置为 0 秒. ``` POST /projects/:id/merge_requests/:merge_request_iid/reset_time_estimate ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 项目的 merge_request 的内部 ID | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/reset_time_estimate" ``` 响应示例: ``` { "human_time_estimate": null, "human_total_time_spent": null, "time_estimate": 0, "total_time_spent": 0 } ``` ## Add spent time for a merge request[](#add-spent-time-for-a-merge-request "Permalink") 增加此合并请求的时间 ``` POST /projects/:id/merge_requests/:merge_request_iid/add_spent_time ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | | `duration` | string | yes | 以人类格式表示的持续时间. 例如:3h30m | ``` 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" ``` 响应示例: ``` { "human_time_estimate": null, "human_total_time_spent": "1h", "time_estimate": 0, "total_time_spent": 3600 } ``` ## Reset spent time for a merge request[](#reset-spent-time-for-a-merge-request "Permalink") 将此合并请求的总花费时间重置为 0 秒. ``` POST /projects/:id/merge_requests/:merge_request_iid/reset_spent_time ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 项目的 merge_request 的内部 ID | ``` curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/reset_spent_time" ``` 响应示例: ``` { "human_time_estimate": null, "human_total_time_spent": null, "time_estimate": 0, "total_time_spent": 0 } ``` ## Get time tracking stats[](#get-time-tracking-stats "Permalink") ``` GET /projects/:id/merge_requests/:merge_request_iid/time_stats ``` | Attribute | Type | Required | Description | | --- | --- | --- | --- | | `id` | integer/string | yes | 经过身份验证的用户拥有[的项目](README.html#namespaced-path-encoding)的 ID 或[URL 编码路径](README.html#namespaced-path-encoding) | | `merge_request_iid` | integer | yes | 合并请求的内部 ID | ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/time_stats" ``` 响应示例: ``` { "human_time_estimate": "2h", "human_total_time_spent": "1h", "time_estimate": 7200, "total_time_spent": 3600 } ``` ## Approvals[](#approvals-starter "Permalink") 有关批准,请参阅[合并请求批准](merge_request_approvals.html)