合并请求 API
使用合并请求 API 可以自动化代码审查过程的任何部分,并将代码更改连接到外部工具。使用此 API 可以将合并请求的信息发送到非极狐GitLab 系统,包括您自己构建的工具,以您喜欢的格式。根据这些系统返回的数据,使用此 API 可以更新、批准、合并或阻止这些合并请求。
所有对非公开信息的 API 调用都需要身份验证。
API v5 中的删除项
approvals_before_merge 属性已弃用,计划在 API v5 中移除,改用合并请求批准 API。
列出合并请求
获取经过身份验证的用户有权限访问的所有合并请求。默认情况下,它只返回当前用户创建的合并请求。要获取所有合并请求,请使用参数 scope=all。
使用 state 参数仅获取具有给定状态(opened、closed、locked 或 merged)或所有状态(all)的合并请求。搜索 locked 通常不返回结果,因为该状态是短暂且过渡的。使用分页参数 page 和 per_page 来限制合并请求列表。
plaintext1GET /merge_requests 2GET /merge_requests?state=opened 3GET /merge_requests?state=all 4GET /merge_requests?milestone=release 5GET /merge_requests?labels=bug,reproduced 6GET /merge_requests?author_id=5 7GET /merge_requests?author_username=gitlab-bot 8GET /merge_requests?my_reaction_emoji=star 9GET /merge_requests?scope=assigned_to_me 10GET /merge_requests?search=foo&in=title
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| approved_by_ids | 整数数组 | 否 | 返回已获所有给定 id 用户批准的合并请求,最多可达 5 个用户。None 返回没有批准的合并请求。Any 返回有批准的合并请求。仅限专业版和旗舰版。 |
| approver_ids | 整数数组 | 否 | 返回指定所有给定 id 用户作为个人批准者的合并请求。None 返回没有批准者的合并请求。Any 返回有批准者的合并请求。仅限专业版和旗舰版。 |
| approved | 字符串 | 否 | 根据合并请求的 approved 状态过滤合并请求。yes 仅返回已批准的合并请求。no 仅返回未批准的合并请求。在极狐GitLab 15.11 中引入,带有 mr_approved_filter 标志。默认禁用。 |
| assignee_id | 整数 | 否 | 返回分配给给定用户 id 的合并请求。None 返回未分配的合并请求。Any 返回有分配的合并请求。 |
| author_id | 整数 | 否 | 返回由给定用户 id 创建的合并请求。与 author_username 互斥。结合 scope=all 或 scope=assigned_to_me。 |
| author_username | 字符串 | 否 | 返回由给定 username 创建的合并请求。与 author_id 互斥。 |
| created_after | 日期时间 | 否 | 返回在给定时间或之后创建的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| created_before | 日期时间 | 否 | 返回在给定时间或之前创建的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| deployed_after | 日期时间 | 否 | 返回在给定日期/时间之后部署的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| deployed_before | 日期时间 | 否 | 返回在给定日期/时间之前部署的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| environment | 字符串 | 否 | 返回部署到给定环境的合并请求。 |
| in | 字符串 | 否 | 更改 search 属性的范围。title、description 或以逗号连接的字符串。默认是 title,description。 |
| labels | 字符串 | 否 | 返回与逗号分隔的标签列表匹配的合并请求。None 列出所有没有标签的合并请求。Any 列出至少有一个标签的合并请求。预定义名称不区分大小写。 |
| merge_user_id | 整数 | 否 | 返回由给定用户 id 合并的合并请求。与 merge_user_username 互斥。在极狐GitLab 17.0 中引入。 |
| merge_user_username | 字符串 | 否 | 返回由给定 username 合并的合并请求。与 merge_user_id 互斥。在极狐GitLab 17.0 中引入。 |
| milestone | 字符串 | 否 | 返回特定里程碑的合并请求。None 返回没有里程碑的合并请求。Any 返回有分配里程碑的合并请求。 |
| my_reaction_emoji | 字符串 | 否 | 返回由经过身份验证的用户根据给定 emoji 反应的合并请求。None 返回没有给予反应的议题。Any 返回给予至少一个反应的议题。 |
| not | 哈希 | 否 | 返回不匹配所提供参数的合并请求。接受:labels、milestone、author_id、author_username、assignee_id、assignee_username、reviewer_id、reviewer_username、my_reaction_emoji。 |
| order_by | 字符串 | 否 | 根据 created_at、title、merged_at (在极狐GitLab 17.2 中引入) 或 updated_at 字段排序请求。默认是 created_at。 |
| reviewer_id | 整数 | 否 | 返回将用户作为具有给定用户 id 的审核者的合并请求。None 返回没有审核者的合并请求。Any 返回有审核者的合并请求。与 reviewer_username 互斥。 |
| reviewer_username | 字符串 | 否 | 返回将用户作为具有给定 username 的审核者的合并请求。None 返回没有审核者的合并请求。Any 返回有审核者的合并请求。与 reviewer_id 互斥。 |
| scope | 字符串 | 否 | 返回给定范围的合并请求:created_by_me、assigned_to_me 或 all。默认是 created_by_me。 |
| search | 字符串 | 否 | 搜索合并请求的 title 和 description。 |
| sort | 字符串 | 否 | 按 asc 或 desc 顺序排序请求。默认是 desc。 |
| source_branch | 字符串 | 否 | 返回具有给定源分支的合并请求。 |
| state | 字符串 | 否 | 返回所有合并请求或仅返回 opened、closed、locked 或 merged 的合并请求。 |
| target_branch | 字符串 | 否 | 返回具有给定目标分支的合并请求。 |
| updated_after | 日期时间 | 否 | 返回在给定时间或之后更新的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| updated_before | 日期时间 | 否 | 返回在给定时间或之前更新的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| view | 字符串 | 否 | 如果为 simple,返回合并请求的 iid、URL、title、description 和基本状态。 |
| with_labels_details | 布尔值 | 否 | 如果为 true,响应返回每个标签字段的更多详细信息::name、:color、:description、:description_html、:text_color。默认是 false。 |
| with_merge_status_recheck | 布尔值 | 否 | 如果为 true,此投影请求(但不保证)异步重新计算 merge_status 字段。默认是 false。在极狐GitLab 15.11 及更高版本中,启用 restrict_merge_status_recheck 功能FLAG,以忽略由没有至少开发者角色的用户请求此属性。 |
| wip | 字符串 | 否 | 根据其 wip 状态过滤合并请求。使用 yes 仅返回草稿合并请求,no 返回非草稿合并请求。 |
示例响应:
json1[ 2 { 3 "id": 1, 4 "iid": 1, 5 "project_id": 3, 6 "title": "test1", 7 "description": "fixed login page css paddings", 8 "state": "merged", 9 "imported": false, 10 "imported_from": "none", 11 "merged_by": { // 已弃用,将在 API v5 中移除,请使用 `merge_user` 代替 12 "id": 87854, 13 "name": "Douwe Maan", 14 "username": "DouweM", 15 "state": "active", 16 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 17 "web_url": "https://gitlab.com/DouweM" 18 }, 19 "merge_user": { 20 "id": 87854, 21 "name": "Douwe Maan", 22 "username": "DouweM", 23 "state": "active", 24 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 25 "web_url": "https://gitlab.com/DouweM" 26 }, 27 "merged_at": "2018-09-07T11:16:17.520Z", 28 "merge_after": "2018-09-07T11:16:00.000Z", 29 "prepared_at": "2018-09-04T11:16:17.520Z", 30 "closed_by": null, 31 "closed_at": null, 32 "created_at": "2017-04-29T08:46:00Z", 33 "updated_at": "2017-04-29T08:46:00Z", 34 "target_branch": "main", 35 "source_branch": "test1", 36 "upvotes": 0, 37 "downvotes": 0, 38 "author": { 39 "id": 1, 40 "name": "Administrator", 41 "username": "admin", 42 "state": "active", 43 "avatar_url": null, 44 "web_url" : "https://gitlab.example.com/admin" 45 }, 46 "assignee": { 47 "id": 1, 48 "name": "Administrator", 49 "username": "admin", 50 "state": "active", 51 "avatar_url": null, 52 "web_url" : "https://gitlab.example.com/admin" 53 }, 54 "assignees": [{ 55 "name": "Miss Monserrate Beier", 56 "username": "axel.block", 57 "id": 12, 58 "state": "active", 59 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 60 "web_url": "https://gitlab.example.com/axel.block" 61 }], 62 "reviewers": [{ 63 "id": 2, 64 "name": "Sam Bauch", 65 "username": "kenyatta_oconnell", 66 "state": "active", 67 "avatar_url": "https://www.gravatar.com/avatar/956c92487c6f6f7616b536927e22c9a0?s=80&d=identicon", 68 "web_url": "http://gitlab.example.com//kenyatta_oconnell" 69 }], 70 "source_project_id": 2, 71 "target_project_id": 3, 72 "labels": [ 73 "社区贡献", 74 "管理" 75 ], 76 "draft": false, 77 "work_in_progress": false, 78 "milestone": { 79 "id": 5, 80 "iid": 1, 81 "project_id": 3, 82 "title": "v2.0", 83 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 84 "state": "closed", 85 "created_at": "2015-02-02T19:49:26.013Z", 86 "updated_at": "2015-02-02T19:49:26.013Z", 87 "due_date": "2018-09-22", 88 "start_date": "2018-08-08", 89 "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" 90 }, 91 "merge_when_pipeline_succeeds": true, 92 "merge_status": "can_be_merged", 93 "detailed_merge_status": "not_open", 94 "sha": "8888888888888888888888888888888888888888", 95 "merge_commit_sha": null, 96 "squash_commit_sha": null, 97 "user_notes_count": 1, 98 "discussion_locked": null, 99 "should_remove_source_branch": true, 100 "force_remove_source_branch": false, 101 "allow_collaboration": false, 102 "allow_maintainer_to_push": false, 103 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 104 "references": { 105 "short": "!1", 106 "relative": "my-group/my-project!1", 107 "full": "my-group/my-project!1" 108 }, 109 "time_stats": { 110 "time_estimate": 0, 111 "total_time_spent": 0, 112 "human_time_estimate": null, 113 "human_total_time_spent": null 114 }, 115 "squash": false, 116 "task_completion_status":{ 117 "count":0, 118 "completed_count":0 119 } 120 } 121]
合并请求列表响应备注
- 列出合并请求可能不会主动更新 merge_status(这也会影响 has_conflicts),因为这可能是一个昂贵的操作。如果需要从此端点获取这些字段的值,请在查询中设置 with_merge_status_recheck 参数为 true。
- 有关合并请求对象字段的备注,请参阅单个合并请求响应备注。
列出项目合并请求
获取此项目的所有合并请求。
plaintext1GET /projects/:id/merge_requests 2GET /projects/:id/merge_requests?state=opened 3GET /projects/:id/merge_requests?state=all 4GET /projects/:id/merge_requests?iids[]=42&iids[]=43 5GET /projects/:id/merge_requests?milestone=release 6GET /projects/:id/merge_requests?labels=bug,reproduced 7GET /projects/:id/merge_requests?my_reaction_emoji=star
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或URL 编码路径。 |
| approved_by_ids | 整数数组 | 否 | 返回已获所有给定 id 用户批准的合并请求,最多可达 5 个用户。None 返回没有批准的合并请求。Any 返回有批准的合并请求。仅限专业版和旗舰版。 |
| approver_ids | 整数数组 | 否 | 返回指定所有给定 id 用户作为个人批准者的合并请求。None 返回没有批准者的合并请求。Any 返回有批准者的合并请求。仅限专业版和旗舰版。 |
| approved | 字符串 | 否 | 根据合并请求的 approved 状态过滤合并请求。yes 仅返回已批准的合并请求。no 仅返回未批准的合并请求。在极狐GitLab 15.11 中引入,仅在启用 mr_approved_filter 特性标志时可用。 |
| assignee_id | 整数 | 否 | 返回分配给给定用户 id 的合并请求。None 返回未分配的合并请求。Any 返回有分配的合并请求。 |
| author_id | 整数 | 否 | 返回由给定用户 id 创建的合并请求。与 author_username 互斥。 |
| author_username | 字符串 | 否 | 返回由给定 username 创建的合并请求。与 author_id 互斥。 |
| created_after | 日期时间 | 否 | 返回在给定时间或之后创建的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| created_before | 日期时间 | 否 | 返回在给定时间或之前创建的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| environment | 字符串 | 否 | 返回部署到给定环境的合并请求。 |
| iids[] | 整数数组 | 否 | 返回具有给定 iid 的请求。 |
| labels | 字符串 | 否 | 返回与逗号分隔的标签列表匹配的合并请求。None 列出所有没有标签的合并请求。Any 列出至少有一个标签的合并请求。预定义名称不区分大小写。 |
| merge_user_id | 整数 | 否 | 返回由给定用户 id 合并的合并请求。与 merge_user_username 互斥。在极狐GitLab 17.0 中引入。 |
| merge_user_username | 字符串 | 否 | 返回由给定 username 合并的合并请求。与 merge_user_id 互斥。在极狐GitLab 17.0 中引入。 |
| milestone | 字符串 | 否 | 返回特定里程碑的合并请求。None 返回没有里程碑的合并请求。Any 返回有分配里程碑的合并请求。 |
| my_reaction_emoji | 字符串 | 否 | 返回由经过身份验证的用户根据给定 emoji 反应的合并请求。None 返回没有给予反应的议题。Any 返回给予至少一个反应的议题。 |
| not | 哈希 | 否 | 返回不匹配所提供参数的合并请求。接受:labels、milestone、author_id、author_username、assignee_id、assignee_username、reviewer_id、reviewer_username、my_reaction_emoji。 |
| order_by | 字符串 | 否 | 根据 created_at、title 或 updated_at 字段排序请求。默认是 created_at。 |
| page | 整数 | 否 | 要返回的结果页。默认为 1。 |
| per_page | 整数 | 否 | 每页结果数。默认为 20。 |
| reviewer_id | 整数 | 否 | 返回将用户作为具有给定用户 id 的审核者的合并请求。None 返回没有审核者的合并请求。Any 返回有审核者的合并请求。与 reviewer_username 互斥。 |
| reviewer_username | 字符串 | 否 | 返回将用户作为具有给定 username 的审核者的合并请求。None 返回没有审核者的合并请求。Any 返回有审核者的合并请求。与 reviewer_id 互斥。 |
| scope | 字符串 | 否 | 返回给定范围的合并请求:created_by_me、assigned_to_me 或 all。 |
| search | 字符串 | 否 | 搜索合并请求的 title 和 description。 |
| sort | 字符串 | 否 | 按 asc 或 desc 顺序排序请求。默认是 desc。 |
| source_branch | 字符串 | 否 | 返回具有给定源分支的合并请求。 |
| state | 字符串 | 否 | 返回所有合并请求(all)或仅返回 opened、closed、locked 或 merged 的合并请求。 |
| target_branch | 字符串 | 否 | 返回具有给定目标分支的合并请求。 |
| updated_after | 日期时间 | 否 | 返回在给定时间或之后更新的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| updated_before | 日期时间 | 否 | 返回在给定时间或之前更新的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| view | 字符串 | 否 | 如果为 simple,返回合并请求的 iid、URL、title、description 和基本状态。 |
| wip | 字符串 | 否 | 根据其 wip 状态过滤合并请求。使用 yes 仅返回草稿合并请求,no 返回非草稿合并请求。 |
| with_labels_details | 布尔值 | 否 | 如果为 true,响应返回每个标签字段的更多详细信息::name、:color、:description、:description_html、:text_color。默认是 false。 |
| with_merge_status_recheck | 布尔值 | 否 | 如果为 true,此投影请求(但不保证)异步重新计算 merge_status 字段。默认是 false。在极狐GitLab 15.11 及更高版本中,启用 restrict_merge_status_recheck 特性FLAG,以忽略由没有至少开发者角色的用户请求此属性。 |
如果成功,返回200 OK和以下响应属性:
| 属性 | 类型 | 描述 |
|---|---|---|
| [].id | 整数 | 合并请求的 ID。 |
| [].iid | 整数 | 合并请求的内部 ID。 |
| [].approvals_before_merge | 整数 | 此合并请求可以合并之前所需的批准数量。要配置批准规则,请参阅合并请求批准 API。在极狐GitLab 16.0 中已弃用。仅限专业版和旗舰版。 |
| [].assignee | 对象 | 合并请求的第一个分配者。 |
| [].assignees | 数组 | 合并请求的分配者。 |
| [].author | 对象 | 创建此合并请求的用户。 |
| [].blocking_discussions_resolved | 布尔值 | 指示是否所有讨论都已解决,仅当所有讨论都在合并请求可以合并之前是必需的时。 |
| [].closed_at | 日期时间 | 合并请求关闭的时间戳。 |
| [].closed_by | 对象 | 关闭此合并请求的用户。 |
| [].created_at | 日期时间 | 合并请求创建的时间戳。 |
| [].description | 字符串 | 合并请求的描述。 |
| [].detailed_merge_status | 字符串 | 合并请求的详细合并状态。有关潜在值列表,请参阅合并状态。 |
| [].discussion_locked | 布尔值 | 指示合并请求上的评论是否仅限于成员。 |
| [].downvotes | 整数 | 合并请求的反对票数量。 |
| [].draft | 布尔值 | 指示合并请求是否是草稿。 |
| [].force_remove_source_branch | 布尔值 | 指示项目设置是否导致合并后删除源分支。 |
| [].has_conflicts | 布尔值 | 指示合并请求是否存在冲突且无法合并。取决于 merge_status 属性。除非 merge_status 是 cannot_be_merged,否则返回 false。 |
| [].labels | 数组 | 合并请求的标签。 |
| [].merge_commit_sha | 字符串 | 合并请求提交的 SHA。在合并之前返回 null。 |
| [].merge_status | 字符串 | 合并请求的状态。可以是 unchecked、checking、can_be_merged、cannot_be_merged 或 cannot_be_merged_recheck。影响 has_conflicts 属性。有关响应数据的重要备注,请参阅单个合并请求响应备注。在极狐GitLab 15.6 中已弃用。请使用 detailed_merge_status 代替。 |
| [].merge_user | 对象 | 合并此合并请求的用户,或设置为自动合并的用户,或 null。 |
| [].merge_when_pipeline_succeeds | 布尔值 | 指示合并是否已设置为在其流水线成功时合并。 |
| [].merged_at | 日期时间 | 合并请求合并的时间戳。 |
| [].merged_by | 对象 | 合并此合并请求或将其设置为自动合并的用户。在极狐GitLab 14.7 中已弃用,并计划在API 版本 5中移除。请使用 merge_user 代替。 |
| [].milestone | 对象 | 合并请求的里程碑。 |
| [].prepared_at | 日期时间 | 合并请求准备的时间戳。此字段在所有准备步骤完成后仅填充一次,并且如果添加更多更改,不会更新。 |
| [].project_id | 整数 | 合并请求所在项目的 ID。始终等于 target_project_id。 |
| [].reference | 字符串 | 合并请求的内部引用。默认返回缩短格式。在极狐GitLab 12.7 中已弃用,并计划在 API 版本 5 中移除。请使用 references 代替。 |
| [].references | 对象 | 合并请求的内部引用。包括 short、relative 和 full 引用。references.relative 是相对于合并请求的群组或项目的。当从合并请求的项目中获取时,relative 和 short 格式是相同的。当跨群组或项目请求时,relative 和 full 格式是相同的。 |
| [].reviewers | 数组 | 合并请求的审核者。 |
| [].sha | 字符串 | 合并请求的差异头 SHA。 |
| [].should_remove_source_branch | 布尔值 | 指示合并后是否应删除合并请求的源分支。 |
| [].source_branch | 字符串 | 合并请求的源分支。 |
| [].source_project_id | 整数 | 合并请求源项目的 ID。除非合并请求来自分叉,否则等于 target_project_id。 |
| [].squash | 布尔值 | 如果为 true,则在合并时将所有提交合并为一个提交。项目设置可能会覆盖此值。请使用 squash_on_merge 以考虑项目合并选项。 |
| [].squash_commit_sha | 字符串 | 压缩提交的 SHA。在合并之前为空。 |
| [].squash_on_merge | 布尔值 | 指示合并时是否压缩合并请求。 |
| [].state | 字符串 | 合并请求的状态。可以是 opened、closed、merged、locked。 |
| [].target_branch | 字符串 | 合并请求的目标分支。 |
| [].target_project_id | 整数 | 合并请求目标项目的 ID。 |
| [].task_completion_status | 对象 | 任务的完成状态。包括 count 和 completed_count。 |
| [].time_stats | 对象 | 合并请求的时间跟踪统计。包括 time_estimate、total_time_spent、human_time_estimate 和 human_total_time_spent。 |
| [].title | 字符串 | 合并请求的标题。 |
| [].updated_at | 日期时间 | 合并请求更新的时间戳。 |
| [].upvotes | 整数 | 合并请求的赞成票数量。 |
| [].user_notes_count | 整数 | 合并请求的用户备注数量。 |
| [].web_url | 字符串 | 合并请求的网页 URL。 |
| [].work_in_progress | 布尔值 | 已弃用:请使用 draft 代替。指示合并请求是否是草稿。 |
示例请求:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests"
示例响应:
json1[ 2 { 3 "id": 1, 4 "iid": 1, 5 "project_id": 3, 6 "title": "test1", 7 "description": "fixed login page css paddings", 8 "state": "merged", 9 "imported": false, 10 "imported_from": "none", 11 "merged_by": { // 已弃用,将在 API v5 中移除,请使用 `merge_user` 代替 12 "id": 87854, 13 "name": "Douwe Maan", 14 "username": "DouweM", 15 "state": "active", 16 "locked": false, 17 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 18 "web_url": "https://gitlab.com/DouweM" 19 }, 20 "merge_user": { 21 "id": 87854, 22 "name": "Douwe Maan", 23 "username": "DouweM", 24 "state": "active", 25 "locked": false, 26 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 27 "web_url": "https://gitlab.com/DouweM" 28 }, 29 "merged_at": "2018-09-07T11:16:17.520Z", 30 "merge_after": "2018-09-07T11:16:00.000Z", 31 "prepared_at": "2018-09-04T11:16:17.520Z", 32 "closed_by": null, 33 "closed_at": null, 34 "created_at": "2017-04-29T08:46:00Z", 35 "updated_at": "2017-04-29T08:46:00Z", 36 "target_branch": "main", 37 "source_branch": "test1", 38 "upvotes": 0, 39 "downvotes": 0, 40 "author": { 41 "id": 1, 42 "name": "Administrator", 43 "username": "admin", 44 "state": "active", 45 "locked": false, 46 "avatar_url": null, 47 "web_url" : "https://gitlab.example.com/admin" 48 }, 49 "assignee": { 50 "id": 1, 51 "name": "Administrator", 52 "username": "admin", 53 "state": "active", 54 "locked": false, 55 "avatar_url": null, 56 "web_url" : "https://gitlab.example.com/admin" 57 }, 58 "assignees": [{ 59 "name": "Miss Monserrate Beier", 60 "username": "axel.block", 61 "id": 12, 62 "state": "active", 63 "locked": false, 64 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 65 "web_url": "https://gitlab.example.com/axel.block" 66 }], 67 "reviewers": [{ 68 "id": 2, 69 "name": "Sam Bauch", 70 "username": "kenyatta_oconnell", 71 "state": "active", 72 "avatar_url": "https://www.gravatar.com/avatar/956c92487c6f6f7616b536927e22c9a0?s=80&d=identicon", 73 "web_url": "http://gitlab.example.com//kenyatta_oconnell" 74 }], 75 "source_project_id": 2, 76 "target_project_id": 3, 77 "labels": [ 78 "社区贡献", 79 "管理" 80 ], 81 "draft": false, 82 "work_in_progress": false, 83 "milestone": { 84 "id": 5, 85 "iid": 1, 86 "project_id": 3, 87 "title": "v2.0", 88 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 89 "state": "closed", 90 "created_at": "2015-02-02T19:49:26.013Z", 91 "updated_at": "2015-02-02T19:49:26.013Z", 92 "due_date": "2018-09-22", 93 "start_date": "2018-08-08", 94 "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" 95 }, 96 "merge_when_pipeline_succeeds": true, 97 "merge_status": "can_be_merged", 98 "detailed_merge_status": "not_open", 99 "sha": "8888888888888888888888888888888888888888", 100 "merge_commit_sha": null, 101 "squash_commit_sha": null, 102 "user_notes_count": 1, 103 "discussion_locked": null, 104 "should_remove_source_branch": true, 105 "force_remove_source_branch": false, 106 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 107 "reference": "!1", 108 "references": { 109 "short": "!1", 110 "relative": "!1", 111 "full": "my-group/my-project!1" 112 }, 113 "time_stats": { 114 "time_estimate": 0, 115 "total_time_spent": 0, 116 "human_time_estimate": null, 117 "human_total_time_spent": null 118 }, 119 "squash": false, 120 "task_completion_status":{ 121 "count":0, 122 "completed_count":0 123 }, 124 "has_conflicts": false, 125 "blocking_discussions_resolved": true, 126 "approvals_before_merge": 2 127 } 128]
有关响应数据的重要备注,请参阅合并请求列表响应备注。
列出群组合并请求
获取此群组及其子群组的所有合并请求。
plaintext1GET /groups/:id/merge_requests 2GET /groups/:id/merge_requests?state=opened 3GET /groups/:id/merge_requests?state=all 4GET /groups/:id/merge_requests?milestone=release 5GET /groups/:id/merge_requests?labels=bug,reproduced 6GET /groups/:id/merge_requests?my_reaction_emoji=star
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 群组的 ID 或URL 编码路径。 |
| approved_by_ids | 整数数组 | 否 | 返回已获所有给定 id 用户批准的合并请求,最多可达 5 个用户。None 返回没有批准的合并请求。Any 返回有批准的合并请求。仅限专业版和旗舰版。 |
| approved_by_usernames | 字符串数组 | 否 | 返回已获所有给定 username 用户批准的合并请求,最多可达 5 个用户。None 返回没有批准的合并请求。Any 返回有批准的合并请求。仅限专业版和旗舰版。 |
| approver_ids | 整数数组 | 否 | 返回指定所有给定 id 用户作为个人批准者的合并请求。None 返回没有批准者的合并请求。Any 返回有批准者的合并请求。仅限专业版和旗舰版。 |
| approved | 字符串 | 否 | 根据合并请求的 approved 状态过滤合并请求。yes 仅返回已批准的合并请求。no 仅返回未批准的合并请求。在极狐GitLab 15.11 中引入。仅在启用 mr_approved_filter 特性标志时可用。 |
| assignee_id | 整数 | 否 | 返回分配给给定用户 id 的合并请求。None 返回未分配的合并请求。Any 返回有分配的合并请求。 |
| author_id | 整数 | 否 | 返回由给定用户 id 创建的合并请求。与 author_username 互斥。 |
| author_username | 字符串 | 否 | 返回由给定 username 创建的合并请求。与 author_id 互斥。 |
| created_after | 日期时间 | 否 | 返回在给定时间或之后创建的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| created_before | 日期时间 | 否 | 返回在给定时间或之前创建的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| labels | 字符串 | 否 | 返回与逗号分隔的标签列表匹配的合并请求。None 列出所有没有标签的合并请求。Any 列出至少有一个标签的合并请求。预定义名称不区分大小写。 |
| merge_user_id | 整数 | 否 | 返回由给定用户 id 合并的合并请求。与 merge_user_username 互斥。在极狐GitLab 17.0 中引入。 |
| merge_user_username | 字符串 | 否 | 返回由给定 username 合并的合并请求。与 merge_user_id 互斥。在极狐GitLab 17.0 中引入。 |
| milestone | 字符串 | 否 | 返回特定里程碑的合并请求。None 返回没有里程碑的合并请求。Any 返回有分配里程碑的合并请求。 |
| my_reaction_emoji | 字符串 | 否 | 返回由经过身份验证的用户根据给定 emoji 反应的合并请求。None 返回没有给予反应的议题。Any 返回给予至少一个反应的议题。 |
| non_archived | 布尔值 | 否 | 仅返回非归档项目的合并请求。默认为 true。 |
| not | 哈希 | 否 | 返回不匹配所提供参数的合并请求。接受:labels、milestone、author_id、author_username、assignee_id、assignee_username、reviewer_id、reviewer_username、my_reaction_emoji。 |
| order_by | 字符串 | 否 | 根据 created_at、title 或 updated_at 字段排序返回的合并请求。默认是 created_at。 |
| reviewer_id | 整数 | 否 | 返回将用户作为具有给定用户 id 的审核者的合并请求。None 返回没有审核者的合并请求。Any 返回有审核者的合并请求。与 reviewer_username 互斥。 |
| reviewer_username | 字符串 | 否 | 返回将用户作为具有给定 username 的审核者的合并请求。None 返回没有审核者的合并请求。Any 返回有审核者的合并请求。与 reviewer_id 互斥。 |
| scope | 字符串 | 否 | 返回给定范围的合并请求:created_by_me、assigned_to_me 或 all。 |
| search | 字符串 | 否 | 搜索合并请求的 title 和 description。 |
| source_branch | 字符串 | 否 | 返回具有给定源分支的合并请求。 |
| sort | 字符串 | 否 | 按 asc 或 desc 顺序返回排序的合并请求。默认是 desc。 |
| state | 字符串 | 否 | 返回所有合并请求(all)或仅返回 opened、closed、locked 或 merged 的合并请求。 |
| target_branch | 字符串 | 否 | 返回具有给定目标分支的合并请求。 |
| updated_after | 日期时间 | 否 | 返回在给定时间或之后更新的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| updated_before | 日期时间 | 否 | 返回在给定时间或之前更新的合并请求。期望格式为 ISO 8601(2019-03-15T08:00:00Z)。 |
| view | 字符串 | 否 | 如果为 simple,返回合并请求的 iid、URL、title、description 和基本状态。 |
| with_labels_details | 布尔值 | 否 | 如果为 true,响应返回每个标签字段的更多详细信息::name、:color、:description、:description_html、:text_color。默认是 false。 |
| with_merge_status_recheck | 布尔值 | 否 | 如果为 true,此投影请求(但不保证)异步重新计算 merge_status 字段。默认是 false。在极狐GitLab 15.11 及更高版本中,启用 restrict_merge_status_recheck 功能标志,以忽略由没有至少开发者角色的用户请求此属性。 |
要限制合并请求列表,请使用分页参数 page 和 per_page。
在响应中,group_id 表示包含合并请求所在项目的群组 ID。
示例响应:
json1[ 2 { 3 "id": 1, 4 "iid": 1, 5 "project_id": 3, 6 "title": "test1", 7 "description": "fixed login page css paddings", 8 "state": "merged", 9 "imported": false, 10 "imported_from": "none", 11 "merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead 12 "id": 87854, 13 "name": "Douwe Maan", 14 "username": "DouweM", 15 "state": "active", 16 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 17 "web_url": "https://gitlab.com/DouweM" 18 }, 19 "merge_user": { 20 "id": 87854, 21 "name": "Douwe Maan", 22 "username": "DouweM", 23 "state": "active", 24 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 25 "web_url": "https://gitlab.com/DouweM" 26 }, 27 "merged_at": "2018-09-07T11:16:17.520Z", 28 "merge_after": "2018-09-07T11:16:00.000Z", 29 "prepared_at": "2018-09-04T11:16:17.520Z", 30 "closed_by": null, 31 "closed_at": null, 32 "created_at": "2017-04-29T08:46:00Z", 33 "updated_at": "2017-04-29T08:46:00Z", 34 "target_branch": "main", 35 "source_branch": "test1", 36 "upvotes": 0, 37 "downvotes": 0, 38 "author": { 39 "id": 1, 40 "name": "Administrator", 41 "username": "admin", 42 "state": "active", 43 "avatar_url": null, 44 "web_url" : "https://gitlab.example.com/admin" 45 }, 46 "assignee": { 47 "id": 1, 48 "name": "Administrator", 49 "username": "admin", 50 "state": "active", 51 "avatar_url": null, 52 "web_url" : "https://gitlab.example.com/admin" 53 }, 54 "assignees": [{ 55 "name": "Miss Monserrate Beier", 56 "username": "axel.block", 57 "id": 12, 58 "state": "active", 59 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 60 "web_url": "https://gitlab.example.com/axel.block" 61 }], 62 "reviewers": [{ 63 "id": 2, 64 "name": "Sam Bauch", 65 "username": "kenyatta_oconnell", 66 "state": "active", 67 "avatar_url": "https://www.gravatar.com/avatar/956c92487c6f6f7616b536927e22c9a0?s=80&d=identicon", 68 "web_url": "http://gitlab.example.com//kenyatta_oconnell" 69 }], 70 "source_project_id": 2, 71 "target_project_id": 3, 72 "labels": [ 73 "Community contribution", 74 "Manage" 75 ], 76 "draft": false, 77 "work_in_progress": false, 78 "milestone": { 79 "id": 5, 80 "iid": 1, 81 "project_id": 3, 82 "title": "v2.0", 83 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 84 "state": "closed", 85 "created_at": "2015-02-02T19:49:26.013Z", 86 "updated_at": "2015-02-02T19:49:26.013Z", 87 "due_date": "2018-10-22", 88 "start_date": "2018-09-08", 89 "web_url": "gitlab.example.com/my-group/my-project/milestones/1" 90 }, 91 "merge_when_pipeline_succeeds": true, 92 "merge_status": "can_be_merged", 93 "detailed_merge_status": "not_open", 94 "sha": "8888888888888888888888888888888888888888", 95 "merge_commit_sha": null, 96 "squash_commit_sha": null, 97 "user_notes_count": 1, 98 "discussion_locked": null, 99 "should_remove_source_branch": true, 100 "force_remove_source_branch": false, 101 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 102 "references": { 103 "short": "!1", 104 "relative": "my-project!1", 105 "full": "my-group/my-project!1" 106 }, 107 "time_stats": { 108 "time_estimate": 0, 109 "total_time_spent": 0, 110 "human_time_estimate": null, 111 "human_total_time_spent": null 112 }, 113 "squash": false, 114 "task_completion_status":{ 115 "count":0, 116 "completed_count":0 117 }, 118 "has_conflicts": false, 119 "blocking_discussions_resolved": true 120 } 121]
有关响应数据的重要说明,请参阅 合并请求列表响应说明。
获取单个合并请求
显示有关单个合并请求的信息。
plaintextGET /projects/:id/merge_requests/:merge_request_iid
支持的属性:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer or string | Yes | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | Yes | 合并请求的内部 ID。 |
| include_diverged_commits_count | boolean | No | 如果为 true,响应包含目标分支后面的提交。 |
| include_rebase_in_progress | boolean | No | 如果为 true,响应包含是否正在进行的 rebase 操作。 |
| render_html | boolean | No | 如果为 true,响应包含标题和描述的渲染 HTML。 |
响应
| Attribute | Type | Description |
|---|---|---|
| approvals_before_merge | integer | 此合并请求可以合并前所需的批准数量。要配置批准规则,请参阅 合并请求批准 API。在极狐GitLab 16.0 中弃用。 仅限专业版和旗舰版。 |
| assignee | object | 合并请求的首个受托人。 |
| assignees | array | 合并请求的受托人。 |
| author | object | 创建此合并请求的用户。 |
| blocking_discussions_resolved | boolean | 指示是否所有讨论都已解决,仅当所有讨论都必须在合并请求可以合并之前解决时。 |
| changes_count | string | 合并请求所做的更改数量。当合并请求创建时为空,并异步填充。一个字符串,而不是一个整数。当合并请求有太多更改无法显示和存储时,值被限制为 1000 并返回字符串 "1000+"。参阅 新的合并请求的空 API 字段。 |
| closed_at | datetime | 合并请求关闭的时间戳。 |
| closed_by | object | 关闭此合并请求的用户。 |
| created_at | datetime | 合并请求创建的时间戳。 |
| description | string | 合并请求的描述。包含作为 HTML 缓存渲染的 Markdown。 |
| detailed_merge_status | string | 合并请求的详细合并状态。有关潜在值的列表,请参阅 合并状态。 |
| diff_refs | object | 此合并请求的基础 SHA、头 SHA 和开始 SHA 的引用。对应于合并请求的最新差异版本。当合并请求创建时为空,并异步填充。参阅 新的合并请求的空 API 字段。 |
| discussion_locked | boolean | 指示合并请求上的评论是否仅对成员锁定。 |
| downvotes | integer | 合并请求的反对票数。 |
| draft | boolean | 指示合并请求是否为草稿。 |
| first_contribution | boolean | 指示合并请求是否为作者的首次贡献。 |
| first_deployed_to_production_at | datetime | 第一次部署完成的时间戳。 |
| force_remove_source_branch | boolean | 指示项目设置是否导致源分支在合并后被删除。 |
| has_conflicts | boolean | 指示合并请求是否有冲突且无法合并。依赖于 merge_status 属性。除非 merge_status 为 cannot_be_merged,否则返回 false。 |
| head_pipeline | object | 在合并请求的分支头上运行的流水线。使用此代替 pipeline,因为它包含更完整的信息。 |
| id | integer | 合并请求的 ID。 |
| iid | integer | 合并请求的内部 ID。 |
| labels | array | 合并请求的标签。 |
| latest_build_finished_at | datetime | 合并请求的最新构建完成的时间戳。 |
| latest_build_started_at | datetime | 合并请求的最新构建开始的时间戳。 |
| merge_commit_sha | string | 合并请求提交的 SHA。在合并之前返回 null。 |
| merge_error | string | 合并失败时显示的错误信息。要检查合并性,请改用 detailed_merge_status |
| merge_user | object | 合并此合并请求的用户、将其设置为自动合并的用户或 null。 |
| merge_status | string | 合并请求的状态。可以是 unchecked、checking、can_be_merged、cannot_be_merged 或 cannot_be_merged_recheck。影响 has_conflicts 属性。有关响应数据的重要说明,请参阅 单个合并请求响应说明。在极狐GitLab 15.6 弃用。改用 detailed_merge_status。 |
| merge_when_pipeline_succeeds | boolean | 指示合并是否设置为在其流水线成功时合并。 |
| merged_at | datetime | 合并请求合并的时间戳。 |
| merged_by | object | 合并此合并请求或将其设置为自动合并的用户。在极狐GitLab 14.7 弃用,并计划在 API 版本 5 中移除。改用 merge_user。 |
| milestone | object | 合并请求的里程碑。 |
| pipeline | object | 在合并请求的分支头上运行的流水线。考虑使用 head_pipeline,因为它包含更多信息。 |
| prepared_at | datetime | 合并请求准备好的时间戳。此字段填充一次,仅在所有 准备步骤 完成后,并且如果添加更多更改不会更新。 |
| project_id | integer | 合并请求项目的 ID。 |
| reference | string | 合并请求的内部引用。默认以缩短格式返回。在极狐GitLab 12.7 中弃用,并计划在 API 版本 5 中移除。改用 references。 |
| references | object | 合并请求的内部引用。包括 short、relative 和 full 引用。references.relative 相对于合并请求的群组或项目。当从合并请求的项目中获取时,relative 和 short 格式相同。当跨群组或项目请求时,relative 和 full 格式相同。 |
| reviewers | array | 合并请求的评审者。 |
| sha | string | 合并请求的差异头 SHA。 |
| should_remove_source_branch | boolean | 指示合并请求的源分支是否应在合并后删除。 |
| source_branch | string | 合并请求的源分支。 |
| source_project_id | integer | 合并请求源项目的 ID。 |
| squash | boolean | 指示是否启用合并时 squash。 |
| squash_commit_sha | string | 合并时 squash 提交的 SHA。在合并之前为空。 |
| state | string | 合并请求的状态。可以是 opened、closed、merged 或 locked。 |
| subscribed | boolean | 指示当前认证用户是否订阅此合并请求。 |
| target_branch | string | 合并请求的目标分支。 |
| target_project_id | integer | 合并请求目标项目的 ID。 |
| task_completion_status | object | 任务的完成状态。 |
| title | string | 合并请求的标题。 |
| updated_at | datetime | 合并请求更新的时间戳。 |
| upvotes | integer | 合并请求的赞成票数。 |
| user | object | 请求合并请求的用户权限。 |
| user_notes_count | integer | 合并请求的用户备注计数。 |
| web_url | string | 合并请求的网页 URL。 |
| work_in_progress | boolean | 弃用:请改用 draft。指示合并请求是否为草稿。 |
示例响应:
json1{ 2 "id": 155016530, 3 "iid": 133, 4 "project_id": 15513260, 5 "title": "Manual job rules", 6 "description": "", 7 "state": "opened", 8 "imported": false, 9 "imported_from": "none", 10 "created_at": "2022-05-13T07:26:38.402Z", 11 "updated_at": "2022-05-14T03:38:31.354Z", 12 "merged_by": null, // Deprecated and will be removed in API v5. Use `merge_user` instead. 13 "merge_user": null, 14 "merged_at": null, 15 "merge_after": "2018-09-07T11:16:00.000Z", 16 "prepared_at": "2018-09-04T11:16:17.520Z", 17 "closed_by": null, 18 "closed_at": null, 19 "target_branch": "main", 20 "source_branch": "manual-job-rules", 21 "user_notes_count": 0, 22 "upvotes": 0, 23 "downvotes": 0, 24 "author": { 25 "id": 4155490, 26 "username": "marcel.amirault", 27 "name": "Marcel Amirault", 28 "state": "active", 29 "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/4155490/avatar.png", 30 "web_url": "https://gitlab.com/marcel.amirault" 31 }, 32 "assignees": [], 33 "assignee": null, 34 "reviewers": [], 35 "source_project_id": 15513260, 36 "target_project_id": 15513260, 37 "labels": [], 38 "draft": false, 39 "work_in_progress": false, 40 "milestone": null, 41 "merge_when_pipeline_succeeds": false, 42 "merge_status": "can_be_merged", 43 "detailed_merge_status": "can_be_merged", 44 "sha": "e82eb4a098e32c796079ca3915e07487fc4db24c", 45 "merge_commit_sha": null, 46 "squash_commit_sha": null, 47 "discussion_locked": null, 48 "should_remove_source_branch": null, 49 "force_remove_source_branch": true, 50 "reference": "!133", // Deprecated. Use `references` instead. 51 "references": { 52 "short": "!133", 53 "relative": "!133", 54 "full": "marcel.amirault/test-project!133" 55 }, 56 "web_url": "https://gitlab.com/marcel.amirault/test-project/-/merge_requests/133", 57 "time_stats": { 58 "time_estimate": 0, 59 "total_time_spent": 0, 60 "human_time_estimate": null, 61 "human_total_time_spent": null 62 }, 63 "squash": false, 64 "task_completion_status": { 65 "count": 0, 66 "completed_count": 0 67 }, 68 "has_conflicts": false, 69 "blocking_discussions_resolved": true, 70 "approvals_before_merge": null, // deprecated, use [Merge request approvals API](merge_request_approvals.md) 71 "subscribed": true, 72 "changes_count": "1", 73 "latest_build_started_at": "2022-05-13T09:46:50.032Z", 74 "latest_build_finished_at": null, 75 "first_deployed_to_production_at": null, 76 "pipeline": { // Use `head_pipeline` instead. 77 "id": 538317940, 78 "iid": 1877, 79 "project_id": 15513260, 80 "sha": "1604b0c46c395822e4e9478777f8e54ac99fe5b9", 81 "ref": "refs/merge-requests/133/merge", 82 "status": "failed", 83 "source": "merge_request_event", 84 "created_at": "2022-05-13T09:46:39.560Z", 85 "updated_at": "2022-05-13T09:47:20.706Z", 86 "web_url": "https://gitlab.com/marcel.amirault/test-project/-/pipelines/538317940" 87 }, 88 "head_pipeline": { 89 "id": 538317940, 90 "iid": 1877, 91 "project_id": 15513260, 92 "sha": "1604b0c46c395822e4e9478777f8e54ac99fe5b9", 93 "ref": "refs/merge-requests/133/merge", 94 "status": "failed", 95 "source": "merge_request_event", 96 "created_at": "2022-05-13T09:46:39.560Z", 97 "updated_at": "2022-05-13T09:47:20.706Z", 98 "web_url": "https://gitlab.com/marcel.amirault/test-project/-/pipelines/538317940", 99 "before_sha": "1604b0c46c395822e4e9478777f8e54ac99fe5b9", 100 "tag": false, 101 "yaml_errors": null, 102 "user": { 103 "id": 4155490, 104 "username": "marcel.amirault", 105 "name": "Marcel Amirault", 106 "state": "active", 107 "avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/4155490/avatar.png", 108 "web_url": "https://gitlab.com/marcel.amirault" 109 }, 110 "started_at": "2022-05-13T09:46:50.032Z", 111 "finished_at": "2022-05-13T09:47:20.697Z", 112 "committed_at": null, 113 "duration": 30, 114 "queued_duration": 10, 115 "coverage": null, 116 "detailed_status": { 117 "icon": "status_failed", 118 "text": "failed", 119 "label": "failed", 120 "group": "failed", 121 "tooltip": "failed", 122 "has_details": true, 123 "details_path": "/marcel.amirault/test-project/-/pipelines/538317940", 124 "illustration": null, 125 "favicon": "/assets/ci_favicons/favicon_status_failed-41304d7f7e3828808b0c26771f0309e55296819a9beea3ea9fbf6689d9857c12.png" 126 } 127 }, 128 "diff_refs": { 129 "base_sha": "1162f719d711319a2efb2a35566f3bfdadee8bab", 130 "head_sha": "e82eb4a098e32c796079ca3915e07487fc4db24c", 131 "start_sha": "1162f719d711319a2efb2a35566f3bfdadee8bab" 132 }, 133 "merge_error": null, 134 "first_contribution": false, 135 "user": { 136 "can_merge": true 137 }, 138 "approvals_before_merge": { // Available for 极狐GitLab 专业版和旗舰版 tiers only 139 "id": 1, 140 "title": "test1", 141 "approvals_before_merge": null 142 }, 143}
单个合并请求响应说明
每个合并请求的可合并性 (merge_status) 在请求此端点时异步检查。轮询此 API 端点 以获取更新的状态。这会影响 has_conflicts 属性,因为它依赖于 merge_status。除非 merge_status 是 cannot_be_merged,否则它返回 false。
合并状态
History
- merge_status 在极狐GitLab 15.6 中弃用。
- detailed_merge_status 在极狐GitLab 15.6 中引入。
使用 detailed_merge_status 而不是 merge_status 来考虑所有潜在状态。
- detailed_merge_status 字段可以包含以下与合并请求相关的值之一:
- approvals_syncing:合并请求的批准正在同步。
- checking:Git 正在测试是否可以进行有效合并。
- ci_must_pass:合并前必须成功通过 CI/CD 流水线。
- ci_still_running:CI/CD 流水线仍在运行。
- commits_status:源分支应存在,并包含提交。
- conflict:源分支和目标分支之间存在冲突。
- discussions_not_resolved:所有讨论必须在合并前解决。
- draft_status:无法合并,因为合并请求是草稿。
- jira_association_missing:标题或描述必须引用 Jira 议题。要配置,请参阅 要求关联的 Jira 议题以便合并请求合并。
- mergeable:分支可以干净地合并到目标分支。
- merge_request_blocked:被另一个合并请求阻止。
- merge_time:可能不会在指定时间后合并。
- need_rebase:合并请求必须重新基准。
- not_approved:合并前需要批准。
- not_open:合并请求必须在合并前打开。
- preparing:正在创建合并请求差异。
- requested_changes:合并请求有评审者要求更改。
- security_policy_violations:必须满足所有安全策略。 需要启用 policy_mergability_check 功能标志。
- status_checks_must_pass:合并前必须通过所有状态检查。
- unchecked:Git 尚未测试是否可以进行有效合并。
- locked_paths:其他用户锁定的路径必须在合并到默认分支前解锁。
- locked_lfs_files:其他用户锁定的 LFS 文件必须在合并前解锁。
准备步骤
prepared_at 字段填充一次,仅在这些步骤完成后:
- 创建差异。
- 创建流水线。
- 检查可合并性。
- 链接所有 Git LFS 对象。
- 发送通知。
如果添加更多更改,prepared_at 字段不会更新。
获取单个合并请求参与者
获取合并请求参与者列表。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/participants
支持的属性:
| Attribute | Type | Required | Description |
|---|---|---|---|
| id | integer or string | Yes | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | Yes | 合并请求的内部 ID。 |
示例响应:
json1[ 2 { 3 "id": 1, 4 "name": "John Doe1", 5 "username": "user1", 6 "state": "active", 7 "avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon", 8 "web_url": "http://localhost/user1" 9 }, 10 { 11 "id": 2, 12 "name": "John Doe2", 13 "username": "user2", 14 "state": "active", 15 "avatar_url": "http://www.gravatar.com/avatar/10fc7f102be8de7657fb4d80898bbfe3?s=80&d=identicon", 16 "web_url": "http://localhost/user2" 17 } 18]
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的内部 ID。 |
示例响应:
json1[ 2 { 3 "id": 1, 4 "name": "John Doe1", 5 "username": "user1", 6 "state": "active", 7 "avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon", 8 "web_url": "http://localhost/user1" 9 }, 10 { 11 "id": 2, 12 "name": "John Doe2", 13 "username": "user2", 14 "state": "active", 15 "avatar_url": "http://www.gravatar.com/avatar/10fc7f102be8de7657fb4d80898bbfe3?s=80&d=identicon", 16 "web_url": "http://localhost/user2" 17 } 18]
获取单个合并请求审阅者
获取合并请求审阅者列表。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/reviewers
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的内部 ID。 |
示例响应:
json1[ 2 { 3 "user": { 4 "id": 1, 5 "name": "John Doe1", 6 "username": "user1", 7 "state": "active", 8 "avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon", 9 "web_url": "http://localhost/user1" 10 }, 11 "state": "unreviewed", 12 "created_at": "2022-07-27T17:03:27.684Z" 13 }, 14 { 15 "user": { 16 "id": 2, 17 "name": "John Doe2", 18 "username": "user2", 19 "state": "active", 20 "avatar_url": "http://www.gravatar.com/avatar/10fc7f102be8de7657fb4d80898bbfe3?s=80&d=identicon", 21 "web_url": "http://localhost/user2" 22 }, 23 "state": "reviewed", 24 "created_at": "2022-07-27T17:03:27.684Z" 25 } 26]
获取单个合并请求提交
获取合并请求提交列表。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/commits
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的内部 ID。 |
如果成功,将返回 200 OK 和以下响应属性:
| 属性 | 类型 | 描述 |
|---|---|---|
| commits | object array | 合并请求中的提交。 |
| commits[].id | string | 提交的 ID。 |
| commits[].short_id | string | 提交的短 ID。 |
| commits[].created_at | datetime | 与 committed_date 字段相同。 |
| commits[].parent_ids | array | 父提交的 ID。 |
| commits[].title | string | 提交标题。 |
| commits[].message | string | 提交信息。 |
| commits[].author_name | string | 提交作者的姓名。 |
| commits[].author_email | string | 提交作者的电子邮件地址。 |
| commits[].authored_date | datetime | 提交的创作日期。 |
| commits[].committer_name | string | 提交者的姓名。 |
| commits[].committer_email | string | 提交者的电子邮件地址。 |
| commits[].committed_date | datetime | 提交日期。 |
| commits[].trailers | object | 为提交解析的 Git trailers。重复键只包含最后一个值。 |
| commits[].extended_trailers | object | 为提交解析的 Git trailers。 |
| commits[].web_url | string | 合并请求的 Web URL。 |
示例请求:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/commits"
示例响应:
json1[ 2 { 3 "id": "ed899a2f4b50b4370feeea94676502b42383c746", 4 "short_id": "ed899a2f4b5", 5 "title": "Replace sanitize with escape once", 6 "author_name": "Example User", 7 "author_email": "user@example.com", 8 "authored_date": "2012-09-20T11:50:22+03:00", 9 "committer_name": "Example User", 10 "committer_email": "user@example.com", 11 "committed_date": "2012-09-20T11:50:22+03:00", 12 "created_at": "2012-09-20T11:50:22+03:00", 13 "message": "Replace sanitize with escape once", 14 "trailers": {}, 15 "extended_trailers": {}, 16 "web_url": "https://gitlab.example.com/project/-/commit/ed899a2f4b50b4370feeea94676502b42383c746" 17 }, 18 { 19 "id": "6104942438c14ec7bd21c6cd5bd995272b3faff6", 20 "short_id": "6104942438c", 21 "title": "Sanitize for network graph", 22 "author_name": "Example User", 23 "author_email": "user@example.com", 24 "authored_date": "2012-09-20T09:06:12+03:00", 25 "committer_name": "Example User", 26 "committer_email": "user@example.com", 27 "committed_date": "2012-09-20T09:06:12+03:00", 28 "created_at": "2012-09-20T09:06:12+03:00", 29 "message": "Sanitize for network graph", 30 "trailers": {}, 31 "extended_trailers": {}, 32 "web_url": "https://gitlab.example.com/project/-/commit/6104942438c14ec7bd21c6cd5bd995272b3faff6" 33 } 34]
获取合并请求依赖项
显示有关必须在合并前解决的合并请求依赖项的信息。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/blocks
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
示例请求:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/blocks"
示例响应:
json1[ 2 { 3 "id": 1, 4 "blocking_merge_request": { 5 "id": 145, 6 "iid": 12, 7 "project_id": 7, 8 "title": "Interesting MR", 9 "description": "Does interesting things.", 10 "state": "opened", 11 "created_at": "2024-07-05T21:29:11.172Z", 12 "updated_at": "2024-07-05T21:29:11.172Z", 13 "merged_by": null, 14 "merge_user": null, 15 "merged_at": null, 16 "merge_after": "2018-09-07T11:16:00.000Z", 17 "closed_by": null, 18 "closed_at": null, 19 "target_branch": "master", 20 "source_branch": "v2.x", 21 "user_notes_count": 0, 22 "upvotes": 0, 23 "downvotes": 0, 24 "author": { 25 "id": 2, 26 "username": "aiguy123", 27 "name": "AI GUY", 28 "state": "active", 29 "locked": false, 30 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 31 "web_url": "https://localhost/aiguy123" 32 }, 33 "assignees": [ 34 { 35 "id": 2, 36 "username": "aiguy123", 37 "name": "AI GUY", 38 "state": "active", 39 "locked": false, 40 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 41 "web_url": "https://localhost/aiguy123" 42 } 43 ], 44 "assignee": { 45 "id": 2, 46 "username": "aiguy123", 47 "name": "AI GUY", 48 "state": "active", 49 "locked": false, 50 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 51 "web_url": "https://localhost/aiguy123" 52 }, 53 "reviewers": [ 54 { 55 "id": 2, 56 "username": "aiguy123", 57 "name": "AI GUY", 58 "state": "active", 59 "locked": false, 60 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 61 "web_url": "https://localhost/aiguy123" 62 }, 63 { 64 "id": 1, 65 "username": "root", 66 "name": "Administrator", 67 "state": "active", 68 "locked": false, 69 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 70 "web_url": "https://localhost/root" 71 } 72 ], 73 "source_project_id": 7, 74 "target_project_id": 7, 75 "labels": [], 76 "draft": false, 77 "imported": false, 78 "imported_from": "none", 79 "work_in_progress": false, 80 "milestone": null, 81 "merge_when_pipeline_succeeds": false, 82 "merge_status": "unchecked", 83 "detailed_merge_status": "unchecked", 84 "sha": "ce7e4f2d0ce13cb07479bb39dc10ee3b861c08a6", 85 "merge_commit_sha": null, 86 "squash_commit_sha": null, 87 "discussion_locked": null, 88 "should_remove_source_branch": null, 89 "force_remove_source_branch": true, 90 "prepared_at": null, 91 "reference": "!12", 92 "references": { 93 "short": "!12", 94 "relative": "!12", 95 "full": "my-group/my-project!12" 96 }, 97 "web_url": "https://localhost/my-group/my-project/-/merge_requests/12", 98 "time_stats": { 99 "time_estimate": 0, 100 "total_time_spent": 0, 101 "human_time_estimate": null, 102 "human_total_time_spent": null 103 }, 104 "squash": false, 105 "squash_on_merge": false, 106 "task_completion_status": { 107 "count": 0, 108 "completed_count": 0 109 }, 110 "has_conflicts": false, 111 "blocking_discussions_resolved": true, 112 "approvals_before_merge": null 113 }, 114 "blocked_merge_request": { 115 "id": 146, 116 "iid": 13, 117 "project_id": 7, 118 "title": "Really cool MR", 119 "description": "Adds some stuff", 120 "state": "opened", 121 "created_at": "2024-07-05T21:31:34.811Z", 122 "updated_at": "2024-07-27T02:57:08.054Z", 123 "merged_by": null, 124 "merge_user": null, 125 "merged_at": null, 126 "merge_after": "2018-09-07T11:16:00.000Z", 127 "closed_by": null, 128 "closed_at": null, 129 "target_branch": "master", 130 "source_branch": "remove-from", 131 "user_notes_count": 0, 132 "upvotes": 1, 133 "downvotes": 0, 134 "author": { 135 "id": 2, 136 "username": "aiguy123", 137 "name": "AI GUY", 138 "state": "active", 139 "locked": false, 140 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 141 "web_url": "https://localhose/aiguy123" 142 }, 143 "assignees": [ 144 { 145 "id": 2, 146 "username": "aiguy123", 147 "name": "AI GUY", 148 "state": "active", 149 "locked": false, 150 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 151 "web_url": "https://localhost/aiguy123" 152 } 153 ], 154 "assignee": { 155 "id": 2, 156 "username": "aiguy123", 157 "name": "AI GUY", 158 "state": "active", 159 "locked": false, 160 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 161 "web_url": "https://localhost/aiguy123" 162 }, 163 "reviewers": [ 164 { 165 "id": 1, 166 "username": "root", 167 "name": "Administrator", 168 "state": "active", 169 "locked": false, 170 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 171 "web_url": "https://localhost/root" 172 } 173 ], 174 "source_project_id": 7, 175 "target_project_id": 7, 176 "labels": [], 177 "draft": false, 178 "imported": false, 179 "imported_from": "none", 180 "work_in_progress": false, 181 "milestone": { 182 "id": 59, 183 "iid": 6, 184 "project_id": 7, 185 "title": "Sprint 1718897375", 186 "description": "Accusantium omnis iusto a animi.", 187 "state": "active", 188 "created_at": "2024-06-20T15:29:35.739Z", 189 "updated_at": "2024-06-20T15:29:35.739Z", 190 "due_date": null, 191 "start_date": null, 192 "expired": false, 193 "web_url": "https://localhost/my-group/my-project/-/milestones/6" 194 }, 195 "merge_when_pipeline_succeeds": false, 196 "merge_status": "cannot_be_merged", 197 "detailed_merge_status": "not_approved", 198 "sha": "daa75b9b17918f51f43866ff533987fda71375ea", 199 "merge_commit_sha": null, 200 "squash_commit_sha": null, 201 "discussion_locked": null, 202 "should_remove_source_branch": null, 203 "force_remove_source_branch": true, 204 "prepared_at": "2024-07-11T18:50:46.215Z", 205 "reference": "!13", 206 "references": { 207 "short": "!13", 208 "relative": "!13", 209 "full": "my-group/my-project!12" 210 }, 211 "web_url": "https://localhost/my-group/my-project/-/merge_requests/13", 212 "time_stats": { 213 "time_estimate": 0, 214 "total_time_spent": 0, 215 "human_time_estimate": null, 216 "human_total_time_spent": null 217 }, 218 "squash": false, 219 "squash_on_merge": false, 220 "task_completion_status": { 221 "count": 0, 222 "completed_count": 0 223 }, 224 "has_conflicts": true, 225 "blocking_discussions_resolved": true, 226 "approvals_before_merge": null 227 }, 228 "project_id": 7 229 } 230]
删除合并请求依赖项
删除合并请求依赖项。
plaintextDELETE /projects/:id/merge_requests/:merge_request_iid/blocks/:block_id
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 被认证用户拥有的项目 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的内部 ID。 |
| block_id | integer | 是 | 阻塞的内部 ID。 |
示例请求:
shellcurl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/blocks/1"
返回:
- 如果依赖项成功删除,则返回 204 No Content。
- 如果用户缺乏更新合并请求的权限,则返回 403 Forbidden。
- 如果用户缺乏读取阻塞合并请求的权限,则返回 403 Forbidden。
创建合并请求依赖项
创建合并请求依赖项。
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/blocks
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 被认证用户拥有的项目 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的内部 ID。 |
| blocking_merge_request_id | integer | 是 | 阻塞合并请求的内部 ID。 |
示例请求:
shellcurl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/blocks?blocking_merge_request_id=2"
返回:
- 如果依赖项成功创建,则返回 201 Created。
- 如果阻塞合并请求保存失败,则返回 400 Bad request。
- 如果用户缺乏读取阻塞合并请求的权限,则返回 403 Forbidden。
- 如果找不到阻塞合并请求,则返回 404 Not found。
- 如果块已经存在,则返回 409 Conflict。
示例响应:
json1{ 2 "id": 1, 3 "blocking_merge_request": { 4 "id": 145, 5 "iid": 12, 6 "project_id": 7, 7 "title": "Interesting MR", 8 "description": "Does interesting things.", 9 "state": "opened", 10 "created_at": "2024-07-05T21:29:11.172Z", 11 "updated_at": "2024-07-05T21:29:11.172Z", 12 "merged_by": null, 13 "merge_user": null, 14 "merged_at": null, 15 "merge_after": "2018-09-07T11:16:00.000Z", 16 "closed_by": null, 17 "closed_at": null, 18 "target_branch": "master", 19 "source_branch": "v2.x", 20 "user_notes_count": 0, 21 "upvotes": 0, 22 "downvotes": 0, 23 "author": { 24 "id": 2, 25 "username": "aiguy123", 26 "name": "AI GUY", 27 "state": "active", 28 "locked": false, 29 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 30 "web_url": "https://localhost/aiguy123" 31 }, 32 "assignees": [ 33 { 34 "id": 2, 35 "username": "aiguy123", 36 "name": "AI GUY", 37 "state": "active", 38 "locked": false, 39 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 40 "web_url": "https://localhost/aiguy123" 41 } 42 ], 43 "assignee": { 44 "id": 2, 45 "username": "aiguy123", 46 "name": "AI GUY", 47 "state": "active", 48 "locked": false, 49 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 50 "web_url": "https://localhost/aiguy123" 51 }, 52 "reviewers": [ 53 { 54 "id": 2, 55 "username": "aiguy123", 56 "name": "AI GUY", 57 "state": "active", 58 "locked": false, 59 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 60 "web_url": "https://localhost/aiguy123" 61 }, 62 { 63 "id": 1, 64 "username": "root", 65 "name": "Administrator", 66 "state": "active", 67 "locked": false, 68 "avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon", 69 "web_url": "https://localhost/root" 70 } 71 ], 72 "source_project_id": 7, 73 "target_project_id": 7, 74 "labels": [], 75 "draft": false, 76 "imported": false, 77 "imported_from": "none", 78 "work_in_progress": false, 79 "milestone": null, 80 "merge_when_pipeline_succeeds": false, 81 "merge_status": "unchecked", 82 "detailed_merge_status": "unchecked", 83 "sha": "ce7e4f2d0ce13cb07479bb39dc10ee3b861c08a6", 84 "merge_commit_sha": null, 85 "squash_commit_sha": null, 86 "discussion_locked": null, 87 "should_remove_source_branch": null, 88 "force_remove_source_branch": true, 89 "prepared_at": null, 90 "reference": "!12", 91 "references": { 92 "short": "!12", 93 "relative": "!12", 94 "full": "my-group/my-project!12" 95 }, 96 "web_url": "https://localhost/my-group/my-project/-/merge_requests/12", 97 "time_stats": { 98 "time_estimate": 0, 99 "total_time_spent": 0, 100 "human_time_estimate": null, 101 "human_total_time_spent": null 102 }, 103 "squash": false, 104 "squash_on_merge": false, 105 "task_completion_status": { 106 "count": 0, 107 "completed_count": 0 108 }, 109 "has_conflicts": false, 110 "blocking_discussions_resolved": true, 111 "approvals_before_merge": null 112 }, 113 "project_id": 7 114}
获取被合并请求阻塞的 MR
显示被当前合并请求阻塞的合并请求的信息。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/blockees
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
示例请求:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/blockees"
示例响应:
json1[ 2 { 3 "id": 18, 4 "blocking_merge_request": { 5 "id": 71, 6 "iid": 10, 7 "project_id": 7, 8 "title": "At quaerat occaecati voluptate ex explicabo nisi.", 9 "description": "Aliquid distinctio officia corrupti ad nemo natus ipsum culpa.", 10 "state": "merged", 11 "created_at": "2024-07-05T19:44:14.023Z", 12 "updated_at": "2024-07-05T19:44:14.023Z", 13 "merged_by": { 14 "id": 40, 15 "username": "i-user-0-1720208283", 16 "name": "I User0", 17 "state": "active", 18 "locked": false, 19 "avatar_url": "https://www.gravatar.com/avatar/8325417f0f7919e3724957543b4414fdeca612cade1e4c0be45685fdaa2be0e2?s=80&d=identicon", 20 "web_url": "http://127.0.0.1:3000/i-user-0-1720208283" 21 }, 22 "merge_user": { 23 "id": 40, 24 "username": "i-user-0-1720208283", 25 "name": "I User0", 26 "state": "active", 27 "locked": false, 28 "avatar_url": "https://www.gravatar.com/avatar/8325417f0f7919e3724957543b4414fdeca612cade1e4c0be45685fdaa2be0e2?s=80&d=identicon", 29 "web_url": "http://127.0.0.1:3000/i-user-0-1720208283" 30 }, 31 "merged_at": "2024-06-26T19:44:14.123Z", 32 "closed_by": null, 33 "closed_at": null, 34 "target_branch": "master", 35 "source_branch": "Brickwood-Brunefunc-417", 36 "user_notes_count": 0, 37 "upvotes": 0, 38 "downvotes": 0, 39 "author": { 40 "id": 40, 41 "username": "i-user-0-1720208283", 42 "name": "I User0", 43 "state": "active", 44 "locked": false, 45 "avatar_url": "https://www.gravatar.com/avatar/8325417f0f7919e3724957543b4414fdeca612cade1e4c0be45685fdaa2be0e2?s=80&d=identicon", 46 "web_url": "http://127.0.0.1:3000/i-user-0-1720208283" 47 }, 48 "assignees": [], 49 "assignee": null, 50 "reviewers": [], 51 "source_project_id": 7, 52 "target_project_id": 7, 53 "labels": [], 54 "draft": false, 55 "imported": false, 56 "imported_from": "none", 57 "work_in_progress": false, 58 "milestone": null, 59 "merge_when_pipeline_succeeds": false, 60 "merge_status": "can_be_merged", 61 "detailed_merge_status": "not_open", 62 "merge_after": null, 63 "sha": null, 64 "merge_commit_sha": null, 65 "squash_commit_sha": null, 66 "discussion_locked": null, 67 "should_remove_source_branch": null, 68 "force_remove_source_branch": null, 69 "prepared_at": null, 70 "reference": "!10", 71 "references": { 72 "short": "!10", 73 "relative": "!10", 74 "full": "flightjs/Flight!10" 75 }, 76 "web_url": "http://127.0.0.1:3000/flightjs/Flight/-/merge_requests/10", 77 "time_stats": { 78 "time_estimate": 0, 79 "total_time_spent": 0, 80 "human_time_estimate": null, 81 "human_total_time_spent": null 82 }, 83 "squash": false, 84 "squash_on_merge": false, 85 "task_completion_status": { 86 "count": 0, 87 "completed_count": 0 88 }, 89 "has_conflicts": false, 90 "blocking_discussions_resolved": true, 91 "approvals_before_merge": null 92 }, 93 "blocked_merge_request": { 94 "id": 176, 95 "iid": 14, 96 "project_id": 7, 97 "title": "second_mr", 98 "description": "Signed-off-by: Lucas Zampieri <lzampier@redhat.com>", 99 "state": "opened", 100 "created_at": "2024-07-08T19:12:29.089Z", 101 "updated_at": "2024-08-27T19:27:17.045Z", 102 "merged_by": null, 103 "merge_user": null, 104 "merged_at": null, 105 "closed_by": null, 106 "closed_at": null, 107 "target_branch": "master", 108 "source_branch": "second_mr", 109 "user_notes_count": 0, 110 "upvotes": 0, 111 "downvotes": 0, 112 "author": { 113 "id": 1, 114 "username": "root", 115 "name": "Administrator", 116 "state": "active", 117 "locked": false, 118 "avatar_url": "https://www.gravatar.com/avatar/fc3634394c590e212d964e8e0a34c4d9b8c17c992f4d6d145d75f9c21c1c3b6e?s=80&d=identicon", 119 "web_url": "http://127.0.0.1:3000/root" 120 }, 121 "assignees": [], 122 "assignee": null, 123 "reviewers": [], 124 "source_project_id": 7, 125 "target_project_id": 7, 126 "labels": [], 127 "draft": false, 128 "imported": false, 129 "imported_from": "none", 130 "work_in_progress": false, 131 "milestone": null, 132 "merge_when_pipeline_succeeds": false, 133 "merge_status": "cannot_be_merged", 134 "detailed_merge_status": "commits_status", 135 "merge_after": null, 136 "sha": "3a576801e528db79a75fbfea463673054ff224fb", 137 "merge_commit_sha": null, 138 "squash_commit_sha": null, 139 "discussion_locked": null, 140 "should_remove_source_branch": null, 141 "force_remove_source_branch": true, 142 "prepared_at": null, 143 "reference": "!14", 144 "references": { 145 "short": "!14", 146 "relative": "!14", 147 "full": "flightjs/Flight!14" 148 }, 149 "web_url": "http://127.0.0.1:3000/flightjs/Flight/-/merge_requests/14", 150 "time_stats": { 151 "time_estimate": 0, 152 "total_time_spent": 0, 153 "human_time_estimate": null, 154 "human_total_time_spent": null 155 }, 156 "squash": false, 157 "squash_on_merge": false, 158 "task_completion_status": { 159 "count": 0, 160 "completed_count": 0 161 }, 162 "has_conflicts": true, 163 "blocking_discussions_resolved": true, 164 "approvals_before_merge": null 165 }, 166 "project_id": 7 167 } 168]
获取单个合并请求更改
显示有关合并请求的信息,包括其文件和更改。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/changes
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的内部 ID。 |
| access_raw_diffs | boolean | 否 | 通过 Gitaly 检索更改差异。 |
| unidiff | boolean | 否 | 以统一差异格式显示更改差异。默认值为 false。在极狐GitLab 16.5 中引入。 |
与更改集合相关的差异应用与其他差异相同的大小限制,通过 API 返回或通过 UI 查看。当这些限制影响结果时,overflow 字段值为 true。通过添加 access_raw_diffs 参数检索没有这些限制的差异数据,该参数从 Gitaly 直接访问差异,而不是从数据库中。这种方法通常较慢且资源密集,但不受数据库支持的差异的大小限制。Gitaly 本身的限制仍然适用。
示例响应:
json1{ 2 "id": 21, 3 "iid": 1, 4 "project_id": 4, 5 "title": "Blanditiis beatae suscipit hic assumenda et molestias nisi asperiores repellat et.", 6 "state": "reopened", 7 "created_at": "2015-02-02T19:49:39.159Z", 8 "updated_at": "2015-02-02T20:08:49.959Z", 9 "target_branch": "secret_token", 10 "source_branch": "version-1-9", 11 "upvotes": 0, 12 "downvotes": 0, 13 "author": { 14 "name": "Chad Hamill", 15 "username": "jarrett", 16 "id": 5, 17 "state": "active", 18 "avatar_url": "http://www.gravatar.com/avatar/b95567800f828948baf5f4160ebb2473?s=40&d=identicon", 19 "web_url" : "https://gitlab.example.com/jarrett" 20 }, 21 "assignee": { 22 "name": "Administrator", 23 "username": "root", 24 "id": 1, 25 "state": "active", 26 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40&d=identicon", 27 "web_url" : "https://gitlab.example.com/root" 28 }, 29 "assignees": [{ 30 "name": "Miss Monserrate Beier", 31 "username": "axel.block", 32 "id": 12, 33 "state": "active", 34 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 35 "web_url": "https://gitlab.example.com/axel.block" 36 }], 37 "reviewers": [{ 38 "name": "Miss Monserrate Beier", 39 "username": "axel.block", 40 "id": 12, 41 "state": "active", 42 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 43 "web_url": "https://gitlab.example.com/axel.block" 44 }], 45 "source_project_id": 4, 46 "target_project_id": 4, 47 "labels": [ ], 48 "description": "Qui voluptatibus placeat ipsa alias quasi. Deleniti rem ut sint. Optio velit qui distinctio.", 49 "draft": false, 50 "work_in_progress": false, 51 "milestone": { 52 "id": 5, 53 "iid": 1, 54 "project_id": 4, 55 "title": "v2.0", 56 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 57 "state": "closed", 58 "created_at": "2015-02-02T19:49:26.013Z", 59 "updated_at": "2015-02-02T19:49:26.013Z", 60 "due_date": null 61 }, 62 "merge_when_pipeline_succeeds": true, 63 "merge_status": "can_be_merged", 64 "detailed_merge_status": "can_be_merged", 65 "subscribed" : true, 66 "sha": "8888888888888888888888888888888888888888", 67 "merge_commit_sha": null, 68 "squash_commit_sha": null, 69 "user_notes_count": 1, 70 "changes_count": "1", 71 "should_remove_source_branch": true, 72 "force_remove_source_branch": false, 73 "squash": false, 74 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 75 "references": { 76 "short": "!1", 77 "relative": "!1", 78 "full": "my-group/my-project!1" 79 }, 80 "discussion_locked": false, 81 "time_stats": { 82 "time_estimate": 0, 83 "total_time_spent": 0, 84 "human_time_estimate": null, 85 "human_total_time_spent": null 86 }, 87 "task_completion_status":{ 88 "count":0, 89 "completed_count":0 90 }, 91 "changes": [ 92 { 93 "old_path": "VERSION", 94 "new_path": "VERSION", 95 "a_mode": "100644", 96 "b_mode": "100644", 97 "diff": "@@ -1 +1 @@\ -1.9.7\ +1.9.8", 98 "new_file": false, 99 "renamed_file": false, 100 "deleted_file": false 101 } 102 ], 103 "overflow": false 104}
列出合并请求差异
History
- 在极狐GitLab 16.9 中引入 generated_file,并带有名为 collapse_generated_diff_files 的标志。默认情况下禁用。
- 在极狐GitLab 16.10 中,在 JihuLab.com 和极狐GitLab 私有化部署上启用。
- 在极狐GitLab 16.11 中,generated_file GA。移除 collapse_generated_diff_files 功能标志。
列出合并请求中更改的文件的差异。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/diffs
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的内部 ID。 |
| page | integer | 否 | 要返回的结果页。默认为 1。 |
| per_page | integer | 否 | 每页结果数。默认为 20。 |
| unidiff | boolean | 否 | 以统一差异格式显示差异。默认值为 false。在极狐GitLab 16.5 中引入。 |
如果成功,将返回 200 OK 和以下响应属性:
| 属性 | 类型 | 描述 |
|---|---|---|
| old_path | string | 文件的旧路径。 |
| new_path | string | 文件的新路径。 |
| a_mode | string | 文件的旧文件模式。 |
| b_mode | string | 文件的新文件模式。 |
| diff | string | 对文件进行的更改的差异表示。 |
| new_file | boolean | 指示文件是否刚刚添加。 |
| renamed_file | boolean | 指示文件是否已重命名。 |
| deleted_file | boolean | 指示文件是否已删除。 |
| generated_file | boolean | 指示文件是否标记为生成。在极狐GitLab 16.9 中引入。 |
示例请求:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/diffs?page=1&per_page=2"
示例响应:
json1[ 2 { 3 "old_path": "README", 4 "new_path": "README", 5 "a_mode": "100644", 6 "b_mode": "100644", 7 "diff": "@@ -1 +1 @@\ -Title\ +README", 8 "new_file": false, 9 "renamed_file": false, 10 "deleted_file": false, 11 "generated_file": false 12 }, 13 { 14 "old_path": "VERSION", 15 "new_path": "VERSION", 16 "a_mode": "100644", 17 "b_mode": "100644", 18 "diff": "@@\ -1.9.7\ +1.9.8", 19 "new_file": false, 20 "renamed_file": false, 21 "deleted_file": false, 22 "generated_file": false 23 } 24]
显示合并请求原始差异
显示合并请求中更改的文件的原始差异。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/raw_diffs
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
如果成功,返回 200 OK 和可编程使用的原始差异响应:
示例请求:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/raw_diffs"
示例响应:
diff1 diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb 2index 31525ad523553c8d7eff163db3e539058efd6d3a..f30e36d6fdf4cd4fa25f62e08ecdbf4a7b169681 100644 3--- a/lib/api/helpers.rb 4+++ b/lib/api/helpers.rb 5@@ -944,6 +944,10 @@ def send_git_blob(repository, blob) 6 body '' 7 end 8 9+ def send_git_diff(repository, diff_refs) 10+ header(*Gitlab::Workhorse.send_git_diff(repository, diff_refs)) 11+ end 12+ 13 def send_git_archive(repository, **kwargs) 14 header(*Gitlab::Workhorse.send_git_archive(repository, **kwargs)) 15 16diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb 17index e02d9eea1852f19fe5311acda6aa17465eeb422e..f32b38585398a18fea75c11d7b8ebb730eeb3fab 100644 18--- a/lib/api/merge_requests.rb 19+++ b/lib/api/merge_requests.rb 20@@ -6,6 +6,8 @@ class MergeRequests < ::API::Base 21 include PaginationParams 22 include Helpers::Unidiff 23 24+ helpers ::API::Helpers::HeadersHelpers 25+ 26 CONTEXT_COMMITS_POST_LIMIT = 20 27 28 before { authenticate_non_get! }
列出合并请求流水线
获取合并请求流水线的列表。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/pipelines
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的内部 ID。 |
为了限制合并请求流水线的列表,可以使用分页参数 page 和 per_page。
示例响应:
json1[ 2 { 3 "id": 77, 4 "sha": "959e04d7c7a30600c894bd3c0cd0e1ce7f42c11d", 5 "ref": "main", 6 "status": "success" 7 } 8]
创建合并请求流水线
创建新的 合并请求的流水线。从此端点创建的流水线不会运行常规的分支/标签流水线。要创建作业,请使用 only: [merge_requests] 配置 .gitlab-ci.yml。
新的流水线可以是:
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/pipelines
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的内部 ID。 |
示例响应:
json1{ 2 "id": 2, 3 "sha": "b83d6e391c22777fca1ed3012fce84f633d7fed0", 4 "ref": "refs/merge-requests/1/head", 5 "status": "pending", 6 "web_url": "http://localhost/user1/project1/pipelines/2", 7 "before_sha": "0000000000000000000000000000000000000000", 8 "tag": false, 9 "yaml_errors": null, 10 "user": { 11 "id": 1, 12 "name": "John Doe1", 13 "username": "user1", 14 "state": "active", 15 "avatar_url": "https://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon", 16 "web_url": "http://example.com" 17 }, 18 "created_at": "2019-09-04T19:20:18.267Z", 19 "updated_at": "2019-09-04T19:20:18.459Z", 20 "started_at": null, 21 "finished_at": null, 22 "committed_at": null, 23 "duration": null, 24 "coverage": null, 25 "detailed_status": { 26 "icon": "status_pending", 27 "text": "pending", 28 "label": "pending", 29 "group": "pending", 30 "tooltip": "pending", 31 "has_details": false, 32 "details_path": "/user1/project1/pipelines/2", 33 "illustration": null, 34 "favicon": "/assets/ci_favicons/favicon_status_pending-5bdf338420e5221ca24353b6bff1c9367189588750632e9a871b7af09ff6a2ae.png" 35 } 36}
创建合并请求
创建一个新的合并请求。
plaintextPOST /projects/:id/merge_requests
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
| source_branch | string | 是 | 源分支。 |
| target_branch | string | 是 | 目标分支。 |
| title | string | 是 | 合并请求的标题。 |
| allow_collaboration | boolean | 否 | 允许能够合并到目标分支的成员提交。 |
| approvals_before_merge | integer | 否 | 合并前需要的审批数量(见下文)。要配置审批规则,请参见合并请求审批 API。在极狐GitLab 16.0 中已弃用,仅适用于专业版和旗舰版。 |
| allow_maintainer_to_push | boolean | 否 | allow_collaboration 的别名。 |
| assignee_id | integer | 否 | 指派的用户 ID。 |
| assignee_ids | integer array | 否 | 指派合并请求的用户 ID。设置为 0 或提供空值以取消指派所有指派人员。 |
| description | string | 否 | 合并请求的描述。限制为 1,048,576 个字符。 |
| labels | string | 否 | 合并请求的标签,作为逗号分隔列表。如果标签尚不存在,则创建新的项目标签并将其分配给合并请求。 |
| merge_after | string | 否 | 合并请求可以合并后的日期。 在极狐GitLab 17.8 中引入。 |
| milestone_id | integer | 否 | 里程碑的全局 ID。 |
| remove_source_branch | boolean | 否 | 表示合并请求在合并时是否应删除源分支的标志。 |
| reviewer_ids | integer array | 否 | 添加为合并请求审阅者的用户 ID。如果设置为 0 或留空,则不添加审阅者。 |
| squash | boolean | 否 | 如果为 true,则在合并时将所有提交压缩为一个提交。项目设置可能会覆盖此值。 |
| target_project_id | integer | 否 | 目标项目的数字 ID。 |
示例响应:
json1{ 2 "id": 1, 3 "iid": 1, 4 "project_id": 3, 5 "title": "test1", 6 "description": "fixed login page css paddings", 7 "state": "merged", 8 "imported": false, 9 "imported_from": "none", 10 "created_at": "2017-04-29T08:46:00Z", 11 "updated_at": "2017-04-29T08:46:00Z", 12 "target_branch": "main", 13 "source_branch": "test1", 14 "upvotes": 0, 15 "downvotes": 0, 16 "author": { 17 "id": 1, 18 "name": "Administrator", 19 "username": "admin", 20 "state": "active", 21 "avatar_url": null, 22 "web_url" : "https://gitlab.example.com/admin" 23 }, 24 "assignee": { 25 "id": 1, 26 "name": "Administrator", 27 "username": "admin", 28 "state": "active", 29 "avatar_url": null, 30 "web_url" : "https://gitlab.example.com/admin" 31 }, 32 "source_project_id": 2, 33 "target_project_id": 3, 34 "labels": [ 35 "Community contribution", 36 "Manage" 37 ], 38 "draft": false, 39 "work_in_progress": false, 40 "milestone": { 41 "id": 5, 42 "iid": 1, 43 "project_id": 3, 44 "title": "v2.0", 45 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 46 "state": "closed", 47 "created_at": "2015-02-02T19:49:26.013Z", 48 "updated_at": "2015-02-02T19:49:26.013Z", 49 "due_date": "2018-09-22", 50 "start_date": "2018-08-08", 51 "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" 52 }, 53 "merge_when_pipeline_succeeds": true, 54 "merge_status": "can_be_merged", 55 "detailed_merge_status": "not_open", 56 "merge_error": null, 57 "sha": "8888888888888888888888888888888888888888", 58 "merge_commit_sha": null, 59 "squash_commit_sha": null, 60 "user_notes_count": 1, 61 "discussion_locked": null, 62 "should_remove_source_branch": true, 63 "force_remove_source_branch": false, 64 "allow_collaboration": false, 65 "allow_maintainer_to_push": false, 66 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 67 "references": { 68 "short": "!1", 69 "relative": "!1", 70 "full": "my-group/my-project!1" 71 }, 72 "time_stats": { 73 "time_estimate": 0, 74 "total_time_spent": 0, 75 "human_time_estimate": null, 76 "human_total_time_spent": null 77 }, 78 "squash": false, 79 "subscribed": false, 80 "changes_count": "1", 81 "merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead 82 "id": 87854, 83 "name": "Douwe Maan", 84 "username": "DouweM", 85 "state": "active", 86 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 87 "web_url": "https://gitlab.com/DouweM" 88 }, 89 "merge_user": { 90 "id": 87854, 91 "name": "Douwe Maan", 92 "username": "DouweM", 93 "state": "active", 94 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 95 "web_url": "https://gitlab.com/DouweM" 96 }, 97 "merged_at": "2018-09-07T11:16:17.520Z", 98 "merge_after": "2018-09-07T11:16:00.000Z", 99 "prepared_at": "2018-09-04T11:16:17.520Z", 100 "closed_by": null, 101 "closed_at": null, 102 "latest_build_started_at": "2018-09-07T07:27:38.472Z", 103 "latest_build_finished_at": "2018-09-07T08:07:06.012Z", 104 "first_deployed_to_production_at": null, 105 "pipeline": { 106 "id": 29626725, 107 "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 108 "ref": "patch-28", 109 "status": "success", 110 "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" 111 }, 112 "diff_refs": { 113 "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", 114 "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 115 "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" 116 }, 117 "diverged_commits_count": 2, 118 "task_completion_status":{ 119 "count":0, 120 "completed_count":0 121 } 122}
有关响应数据的重要说明,请参阅单个合并请求响应说明。
更新合并请求
更新现有的合并请求。您可以更改目标分支、标题,甚至关闭合并请求。
plaintextPUT /projects/:id/merge_requests/:merge_request_iid
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | integer | 是 | 合并请求的 ID。 |
| add_labels | string | 否 | 要添加到合并请求的逗号分隔标签名称。如果标签尚不存在,则创建新的项目标签并将其分配给合并请求。 |
| allow_collaboration | boolean | 否 | 允许能够合并到目标分支的成员提交。 |
| allow_maintainer_to_push | boolean | 否 | allow_collaboration 的别名。 |
| assignee_id | integer | 否 | 指派合并请求的用户 ID。设置为 0 或提供空值以取消指派所有指派人员。 |
| assignee_ids | integer array | 否 | 指派合并请求的用户 ID。设置为 0 或提供空值以取消指派所有指派人员。 |
| description | string | 否 | 合并请求的描述。限制为 1,048,576 个字符。 |
| discussion_locked | boolean | 否 | 表示合并请求讨论是否被锁定的标志。只有项目成员可以添加、编辑或解决锁定讨论的评论。 |
| labels | string | 否 | 合并请求的逗号分隔标签名称。设置为空字符串以取消分配所有标签。如果标签尚不存在,则创建新的项目标签并将其分配给合并请求。 |
| merge_after | string | 否 | 合并请求可以合并后的日期。 在极狐GitLab 17.8 中引入。 |
| milestone_id | integer | 否 | 指派合并请求的里程碑的全局 ID。设置为 0 或提供空值以取消分配里程碑。 |
| remove_labels | string | 否 | 要从合并请求中删除的逗号分隔标签名称。 |
| remove_source_branch | boolean | 否 | 表示合并请求在合并时是否应删除源分支的标志。 |
| reviewer_ids | integer array | 否 | 设置为合并请求审阅者的用户 ID。将值设置为 0 或提供空值以取消设置所有审阅者。 |
| squash | boolean | 否 | 如果为 true,则在合并时将所有提交压缩为一个提交。项目设置可能会覆盖此值。 |
| state_event | string | 否 | 新状态(关闭/重新打开)。 |
| target_branch | string | 否 | 目标分支。 |
| title | string | 否 | 合并请求的标题。 |
必须包含上述至少一个非必需属性。
示例响应:
json1{ 2 "id": 1, 3 "iid": 1, 4 "project_id": 3, 5 "title": "test1", 6 "description": "fixed login page css paddings", 7 "state": "merged", 8 "created_at": "2017-04-29T08:46:00Z", 9 "updated_at": "2017-04-29T08:46:00Z", 10 "target_branch": "main", 11 "source_branch": "test1", 12 "upvotes": 0, 13 "downvotes": 0, 14 "author": { 15 "id": 1, 16 "name": "Administrator", 17 "username": "admin", 18 "state": "active", 19 "avatar_url": null, 20 "web_url" : "https://gitlab.example.com/admin" 21 }, 22 "assignee": { 23 "id": 1, 24 "name": "Administrator", 25 "username": "admin", 26 "state": "active", 27 "avatar_url": null, 28 "web_url" : "https://gitlab.example.com/admin" 29 }, 30 "assignees": [{ 31 "name": "Miss Monserrate Beier", 32 "username": "axel.block", 33 "id": 12, 34 "state": "active", 35 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 36 "web_url": "https://gitlab.example.com/axel.block" 37 }], 38 "reviewers": [{ 39 "name": "Miss Monserrate Beier", 40 "username": "axel.block", 41 "id": 12, 42 "state": "active", 43 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 44 "web_url": "https://gitlab.example.com/axel.block" 45 }], 46 "source_project_id": 2, 47 "target_project_id": 3, 48 "labels": [ 49 "Community contribution", 50 "Manage" 51 ], 52 "draft": false, 53 "work_in_progress": false, 54 "milestone": { 55 "id": 5, 56 "iid": 1, 57 "project_id": 3, 58 "title": "v2.0", 59 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 60 "state": "closed", 61 "created_at": "2015-02-02T19:49:26.013Z", 62 "updated_at": "2015-02-02T19:49:26.013Z", 63 "due_date": "2018-09-22", 64 "start_date": "2018-08-08", 65 "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" 66 }, 67 "merge_when_pipeline_succeeds": true, 68 "merge_status": "can_be_merged", 69 "detailed_merge_status": "not_open", 70 "merge_error": null, 71 "sha": "8888888888888888888888888888888888888888", 72 "merge_commit_sha": null, 73 "squash_commit_sha": null, 74 "user_notes_count": 1, 75 "discussion_locked": null, 76 "should_remove_source_branch": true, 77 "force_remove_source_branch": false, 78 "allow_collaboration": false, 79 "allow_maintainer_to_push": false, 80 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 81 "references": { 82 "short": "!1", 83 "relative": "!1", 84 "full": "my-group/my-project!1" 85 }, 86 "time_stats": { 87 "time_estimate": 0, 88 "total_time_spent": 0, 89 "human_time_estimate": null, 90 "human_total_time_spent": null 91 }, 92 "squash": false, 93 "subscribed": false, 94 "changes_count": "1", 95 "merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead 96 "id": 87854, 97 "name": "Douwe Maan", 98 "username": "DouweM", 99 "state": "active", 100 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 101 "web_url": "https://gitlab.com/DouweM" 102 }, 103 "merge_user": { 104 "id": 87854, 105 "name": "Douwe Maan", 106 "username": "DouweM", 107 "state": "active", 108 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 109 "web_url": "https://gitlab.com/DouweM" 110 }, 111 "merged_at": "2018-09-07T11:16:17.520Z", 112 "merge_after": "2018-09-07T11:16:00.000Z", 113 "prepared_at": "2018-09-04T11:16:17.520Z", 114 "closed_by": null, 115 "closed_at": null, 116 "latest_build_started_at": "2018-09-07T07:27:38.472Z", 117 "latest_build_finished_at": "2018-09-07T08:07:06.012Z", 118 "first_deployed_to_production_at": null, 119 "pipeline": { 120 "id": 29626725, 121 "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 122 "ref": "patch-28", 123 "status": "success", 124 "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" 125 }, 126 "diff_refs": { 127 "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", 128 "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 129 "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" 130 }, 131 "diverged_commits_count": 2, 132 "task_completion_status":{ 133 "count":0, 134 "completed_count":0 135 } 136}
有关响应数据的重要说明,请参阅单个合并请求响应说明。
删除合并请求
仅适用于管理员和项目所有者。删除相关的合并请求。
plaintextDELETE /projects/:id/merge_requests/:merge_request_iid
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
shellcurl --request DELETE \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/4/merge_requests/85"
合并合并请求
使用此 API 接受并合并通过合并请求提交的更改。
plaintextPUT /projects/:id/merge_requests/:merge_request_iid/merge
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
| auto_merge | 布尔值 | 否 | 如果为 true,当流水线成功时合并请求将被合并。 |
| merge_commit_message | 字符串 | 否 | 自定义合并提交消息。 |
| merge_when_pipeline_succeeds | 布尔值 | 否 | 在极狐GitLab 17.11 中弃用。请使用 auto_merge。 |
| sha | 字符串 | 否 | 如果存在,则此 SHA 必须与源分支的 HEAD 匹配,否则合并失败。 |
| should_remove_source_branch | 布尔值 | 否 | 如果为 true,则删除源分支。 |
| squash_commit_message | 字符串 | 否 | 自定义压缩提交消息。 |
| squash | 布尔值 | 否 | 如果为 true,在合并时将所有提交压缩为一个提交。 |
此 API 在失败时返回特定的 HTTP 状态码:
| HTTP 状态 | 消息 | 原因 |
|---|---|---|
| 401 | 401 Unauthorized | 此用户无权接受此合并请求。 |
| 405 | 405 Method Not Allowed | 无法合并合并请求。 |
| 409 | SHA does not match HEAD of source branch | 提供的 sha 参数与源的 HEAD 不匹配。 |
| 422 | Branch cannot be merged | 合并请求合并失败。 |
有关响应数据的重要说明,请参阅单个合并请求响应说明。
示例响应:
json1{ 2 "id": 1, 3 "iid": 1, 4 "project_id": 3, 5 "title": "test1", 6 "description": "fixed login page css paddings", 7 "state": "merged", 8 "created_at": "2017-04-29T08:46:00Z", 9 "updated_at": "2017-04-29T08:46:00Z", 10 "target_branch": "main", 11 "source_branch": "test1", 12 "upvotes": 0, 13 "downvotes": 0, 14 "author": { 15 "id": 1, 16 "name": "Administrator", 17 "username": "admin", 18 "state": "active", 19 "avatar_url": null, 20 "web_url" : "https://gitlab.example.com/admin" 21 }, 22 "assignee": { 23 "id": 1, 24 "name": "Administrator", 25 "username": "admin", 26 "state": "active", 27 "avatar_url": null, 28 "web_url" : "https://gitlab.example.com/admin" 29 }, 30 "assignees": [{ 31 "name": "Miss Monserrate Beier", 32 "username": "axel.block", 33 "id": 12, 34 "state": "active", 35 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 36 "web_url": "https://gitlab.example.com/axel.block" 37 }], 38 "reviewers": [{ 39 "name": "Miss Monserrate Beier", 40 "username": "axel.block", 41 "id": 12, 42 "state": "active", 43 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 44 "web_url": "https://gitlab.example.com/axel.block" 45 }], 46 "source_project_id": 2, 47 "target_project_id": 3, 48 "labels": [ 49 "Community contribution", 50 "Manage" 51 ], 52 "draft": false, 53 "work_in_progress": false, 54 "milestone": { 55 "id": 5, 56 "iid": 1, 57 "project_id": 3, 58 "title": "v2.0", 59 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 60 "state": "closed", 61 "created_at": "2015-02-02T19:49:26.013Z", 62 "updated_at": "2015-02-02T19:49:26.013Z", 63 "due_date": "2018-09-22", 64 "start_date": "2018-08-08", 65 "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" 66 }, 67 "merge_when_pipeline_succeeds": true, 68 "merge_status": "can_be_merged", 69 "detailed_merge_status": "not_open", 70 "merge_error": null, 71 "sha": "8888888888888888888888888888888888888888", 72 "merge_commit_sha": null, 73 "squash_commit_sha": null, 74 "user_notes_count": 1, 75 "discussion_locked": null, 76 "should_remove_source_branch": true, 77 "force_remove_source_branch": false, 78 "allow_collaboration": false, 79 "allow_maintainer_to_push": false, 80 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 81 "references": { 82 "short": "!1", 83 "relative": "!1", 84 "full": "my-group/my-project!1" 85 }, 86 "time_stats": { 87 "time_estimate": 0, 88 "total_time_spent": 0, 89 "human_time_estimate": null, 90 "human_total_time_spent": null 91 }, 92 "squash": false, 93 "subscribed": false, 94 "changes_count": "1", 95 "merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead 96 "id": 87854, 97 "name": "Douwe Maan", 98 "username": "DouweM", 99 "state": "active", 100 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 101 "web_url": "https://gitlab.com/DouweM" 102 }, 103 "merge_user": { 104 "id": 87854, 105 "name": "Douwe Maan", 106 "username": "DouweM", 107 "state": "active", 108 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 109 "web_url": "https://gitlab.com/DouweM" 110 }, 111 "merged_at": "2018-09-07T11:16:17.520Z", 112 "merge_after": "2018-09-07T11:16:00.000Z", 113 "prepared_at": "2018-09-04T11:16:17.520Z", 114 "closed_by": null, 115 "closed_at": null, 116 "latest_build_started_at": "2018-09-07T07:27:38.472Z", 117 "latest_build_finished_at": "2018-09-07T08:07:06.012Z", 118 "first_deployed_to_production_at": null, 119 "pipeline": { 120 "id": 29626725, 121 "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 122 "ref": "patch-28", 123 "status": "success", 124 "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" 125 }, 126 "diff_refs": { 127 "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", 128 "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 129 "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" 130 }, 131 "diverged_commits_count": 2, 132 "task_completion_status":{ 133 "count":0, 134 "completed_count":0 135 } 136}
合并到默认合并引用路径
如果可能,将合并请求源和目标分支之间的更改合并到目标项目存储库的 refs/merge-requests/:iid/merge 引用中。此引用具有目标分支进行常规合并操作后的状态。
此操作不是常规合并操作,因为它不会以任何方式改变合并请求目标分支的状态。
提交请求到此 API 时,此引用(refs/merge-requests/:iid/merge)不一定会被覆盖,但会确保引用具有最新可能的状态。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/merge_ref
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
此 API 返回特定的 HTTP 状态码:
| HTTP 状态 | 消息 | 原因 |
|---|---|---|
| 200 | (none) | 成功。返回 refs/merge-requests/:iid/merge 的 HEAD 提交。 |
| 400 | Merge request is not mergeable | 合并请求有冲突。 |
| 400 | Merge ref cannot be updated | |
| 400 | Unsupported operation | 极狐GitLab 数据库处于只读模式。 |
示例响应:
json{ "commit_id": "854a3a7a17acbcc0bbbea170986df1eb60435f34" }
取消当流水线成功时的合并
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
此 API 返回特定的 HTTP 状态码:
| HTTP 状态 | 消息 | 原因 |
|---|---|---|
| 201 | (none) | 成功,或合并请求已合并。 |
| 406 | Can't cancel the automatic merge | 合并请求已关闭。 |
有关响应数据的重要说明,请参阅单个合并请求响应说明。
示例响应:
json1{ 2 "id": 1, 3 "iid": 1, 4 "project_id": 3, 5 "title": "test1", 6 "description": "fixed login page css paddings", 7 "state": "merged", 8 "created_at": "2017-04-29T08:46:00Z", 9 "updated_at": "2017-04-29T08:46:00Z", 10 "target_branch": "main", 11 "source_branch": "test1", 12 "upvotes": 0, 13 "downvotes": 0, 14 "author": { 15 "id": 1, 16 "name": "Administrator", 17 "username": "admin", 18 "state": "active", 19 "avatar_url": null, 20 "web_url" : "https://gitlab.example.com/admin" 21 }, 22 "assignee": { 23 "id": 1, 24 "name": "Administrator", 25 "username": "admin", 26 "state": "active", 27 "avatar_url": null, 28 "web_url" : "https://gitlab.example.com/admin" 29 }, 30 "assignees": [{ 31 "name": "Miss Monserrate Beier", 32 "username": "axel.block", 33 "id": 12, 34 "state": "active", 35 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 36 "web_url": "https://gitlab.example.com/axel.block" 37 }], 38 "reviewers": [{ 39 "name": "Miss Monserrate Beier", 40 "username": "axel.block", 41 "id": 12, 42 "state": "active", 43 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 44 "web_url": "https://gitlab.example.com/axel.block" 45 }], 46 "source_project_id": 2, 47 "target_project_id": 3, 48 "labels": [ 49 "Community contribution", 50 "Manage" 51 ], 52 "draft": false, 53 "work_in_progress": false, 54 "milestone": { 55 "id": 5, 56 "iid": 1, 57 "project_id": 3, 58 "title": "v2.0", 59 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 60 "state": "closed", 61 "created_at": "2015-02-02T19:49:26.013Z", 62 "updated_at": "2015-02-02T19:49:26.013Z", 63 "due_date": "2018-09-22", 64 "start_date": "2018-08-08", 65 "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" 66 }, 67 "merge_when_pipeline_succeeds": false, 68 "merge_status": "can_be_merged", 69 "detailed_merge_status": "not_open", 70 "merge_error": null, 71 "sha": "8888888888888888888888888888888888888888", 72 "merge_commit_sha": null, 73 "squash_commit_sha": null, 74 "user_notes_count": 1, 75 "discussion_locked": null, 76 "should_remove_source_branch": true, 77 "force_remove_source_branch": false, 78 "allow_collaboration": false, 79 "allow_maintainer_to_push": false, 80 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 81 "references": { 82 "short": "!1", 83 "relative": "!1", 84 "full": "my-group/my-project!1" 85 }, 86 "time_stats": { 87 "time_estimate": 0, 88 "total_time_spent": 0, 89 "human_time_estimate": null, 90 "human_total_time_spent": null 91 }, 92 "squash": false, 93 "subscribed": false, 94 "changes_count": "1", 95 "merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead 96 "id": 87854, 97 "name": "Douwe Maan", 98 "username": "DouweM", 99 "state": "active", 100 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 101 "web_url": "https://gitlab.com/DouweM" 102 }, 103 "merge_user": { 104 "id": 87854, 105 "name": "Douwe Maan", 106 "username": "DouweM", 107 "state": "active", 108 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 109 "web_url": "https://gitlab.com/DouweM" 110 }, 111 "merged_at": "2018-09-07T11:16:17.520Z", 112 "merge_after": "2018-09-07T11:16:00.000Z", 113 "prepared_at": "2018-09-04T11:16:17.520Z", 114 "closed_by": null, 115 "closed_at": null, 116 "latest_build_started_at": "2018-09-07T07:27:38.472Z", 117 "latest_build_finished_at": "2018-09-07T08:07:06.012Z", 118 "first_deployed_to_production_at": null, 119 "pipeline": { 120 "id": 29626725, 121 "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 122 "ref": "patch-28", 123 "status": "success", 124 "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" 125 }, 126 "diff_refs": { 127 "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", 128 "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 129 "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" 130 }, 131 "diverged_commits_count": 2, 132 "task_completion_status":{ 133 "count":0, 134 "completed_count":0 135 } 136}
重新基准合并请求
自动将合并请求的 source_branch 重新基准到其 target_branch。
plaintextPUT /projects/:id/merge_requests/:merge_request_iid/rebase
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
| skip_ci | 布尔值 | 否 | 设置为 true 以跳过创建 CI 流水线。 |
shellcurl --request PUT \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/76/merge_requests/1/rebase"
此 API 返回特定的 HTTP 状态码:
| HTTP 状态 | 消息 | 原因 |
|---|---|---|
| 202 | (no message) | 成功入队。 |
| 403 | Cannot push to source branch | 您无权推送到合并请求的源分支。 |
| 403 | Source branch does not exist | 您无权推送到合并请求的源分支。 |
| 403 | Source branch is protected from force push | 您无权推送到合并请求的源分支。 |
| 409 | Failed to enqueue the rebase operation | 长期事务可能阻止了您的请求。 |
如果请求成功添加到队列中,响应包含:
json{ "rebase_in_progress": true }
您可以通过 include_rebase_in_progress 参数轮询获取单个 MR端点以检查异步请求的状态。
如果重新基准操作正在进行中,响应包括以下内容:
json{ "rebase_in_progress": true, "merge_error": null }
重新基准操作成功完成后,响应包括以下内容:
json{ "rebase_in_progress": false, "merge_error": null }
如果重新基准操作失败,响应包括以下内容:
json{ "rebase_in_progress": false, "merge_error": "Rebase failed. Please rebase locally" }
合并请求评论
注释资源用于创建评论。
列出合并时关闭的议题
获取通过合并提供的合并请求将关闭的所有议题。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/closes_issues
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
如果成功,返回200 OK及以下响应属性,当您使用极狐GitLab 议题追踪器时:
| 属性 | 类型 | 描述 |
|---|---|---|
| [].assignee | 对象 | 议题的第一位指派人。 |
| [].assignees | 数组 | 议题的指派人。 |
| [].author | 对象 | 创建此议题的用户。 |
| [].blocking_issues_count | 整数 | 此议题阻止的议题数量。 |
| [].closed_at | 日期时间 | 议题关闭的时间戳。 |
| [].closed_by | 对象 | 关闭此议题的用户。 |
| [].confidential | 布尔值 | 指示议题是否为保密。 |
| [].created_at | 日期时间 | 议题创建的时间戳。 |
| [].description | 字符串 | 议题的描述。 |
| [].discussion_locked | 布尔值 | 指示议题的评论是否仅限于成员。 |
| [].downvotes | 整数 | 议题收到的反对票数。 |
| [].due_date | 日期时间 | 议题的截止日期。 |
| [].id | 整数 | 议题的 ID。 |
| [].iid | 整数 | 议题的内部 ID。 |
| [].issue_type | 字符串 | 议题的类型。可以是 issue、incident、test_case、requirement、task。 |
| [].labels | 数组 | 议题的标签。 |
| [].merge_requests_count | 整数 | 合并时关闭议题的合并请求数量。 |
| [].milestone | 对象 | 议题的里程碑。 |
| [].project_id | 整数 | 议题项目的 ID。 |
| [].state | 字符串 | 议题的状态。可以是 opened 或 closed。 |
| [].task_completion_status | 对象 | 包括 count 和 completed_count。 |
| [].time_stats | 对象 | 议题的时间统计。包括 time_estimate、total_time_spent、human_time_estimate 和 human_total_time_spent。 |
| [].title | 字符串 | 议题的标题。 |
| [].type | 字符串 | 议题的类型。与 issue_type 相同,但为大写。 |
| [].updated_at | 日期时间 | 议题更新的时间戳。 |
| [].upvotes | 整数 | 议题收到的支持票数。 |
| [].user_notes_count | 整数 | 议题的用户注释计数。 |
| [].web_url | 字符串 | 议题的网页 URL。 |
| [].weight | 整数 | 议题的权重。 |
如果成功,返回200 OK及以下响应属性,当您使用外部议题追踪器(如 Jira)时:
| 属性 | 类型 | 描述 |
|---|---|---|
| [].id | 整数 | 议题的 ID。 |
| [].title | 字符串 | 议题的标题。 |
示例请求:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/76/merge_requests/1/closes_issues"
使用极狐GitLab 议题追踪器时的示例响应:
json1[ 2 { 3 "id": 76, 4 "iid": 6, 5 "project_id": 1, 6 "title": "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.", 7 "description": "Ratione dolores corrupti mollitia soluta quia.", 8 "state": "opened", 9 "created_at": "2024-09-06T10:58:49.002Z", 10 "updated_at": "2024-09-06T11:01:40.710Z", 11 "closed_at": null, 12 "closed_by": null, 13 "labels": [ 14 "label" 15 ], 16 "milestone": { 17 "project_id": 1, 18 "description": "Ducimus nam enim ex consequatur cumque ratione.", 19 "state": "closed", 20 "due_date": null, 21 "iid": 2, 22 "created_at": "2016-01-04T15:31:39.996Z", 23 "title": "v4.0", 24 "id": 17, 25 "updated_at": "2016-01-04T15:31:39.996Z" 26 }, 27 "assignees": [ 28 { 29 "id": 1, 30 "username": "root", 31 "name": "Administrator", 32 "state": "active", 33 "locked": false, 34 "avatar_url": null, 35 "web_url": "https://gitlab.example.com/root" 36 } 37 ], 38 "author": { 39 "id": 18, 40 "username": "eileen.lowe", 41 "name": "Alexandra Bashirian", 42 "state": "active", 43 "locked": false, 44 "avatar_url": null, 45 "web_url": "https://gitlab.example.com/eileen.lowe" 46 }, 47 "type": "ISSUE", 48 "assignee": { 49 "id": 1, 50 "username": "root", 51 "name": "Administrator", 52 "state": "active", 53 "locked": false, 54 "avatar_url": null, 55 "web_url": "https://gitlab.example.com/root" 56 }, 57 "user_notes_count": 1, 58 "merge_requests_count": 1, 59 "upvotes": 0, 60 "downvotes": 0, 61 "due_date": null, 62 "confidential": false, 63 "discussion_locked": null, 64 "issue_type": "issue", 65 "web_url": "https://gitlab.example.com/my-group/my-project/-/issues/6", 66 "time_stats": { 67 "time_estimate": 0, 68 "total_time_spent": 0, 69 "human_time_estimate": null, 70 "human_total_time_spent": null 71 }, 72 "task_completion_status": { 73 "count": 0, 74 "completed_count": 0 75 }, 76 "weight": null, 77 "blocking_issues_count": 0 78 } 79]
使用外部议题追踪器(如 Jira)时的示例响应:
json1[ 2 { 3 "id" : "PROJECT-123", 4 "title" : "Title of this issue" 5 } 6]
列出与合并请求相关的议题
获取合并请求的标题、描述、提交消息、评论和讨论中的所有相关议题。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/related_issues
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/76/merge_requests/1/related_issues"
使用极狐GitLab 议题追踪器时的示例响应:
json1[ 2 { 3 "state" : "opened", 4 "description" : "Ratione dolores corrupti mollitia soluta quia.", 5 "author" : { 6 "state" : "active", 7 "id" : 18, 8 "web_url" : "https://gitlab.example.com/eileen.lowe", 9 "name" : "Alexandra Bashirian", 10 "avatar_url" : null, 11 "username" : "eileen.lowe" 12 }, 13 "milestone" : { 14 "project_id" : 1, 15 "description" : "Ducimus nam enim ex consequatur cumque ratione.", 16 "state" : "closed", 17 "due_date" : null, 18 "iid" : 2, 19 "created_at" : "2016-01-04T15:31:39.996Z", 20 "title" : "v4.0", 21 "id" : 17, 22 "updated_at" : "2016-01-04T15:31:39.996Z" 23 }, 24 "project_id" : 1, 25 "assignee" : { 26 "state" : "active", 27 "id" : 1, 28 "name" : "Administrator", 29 "web_url" : "https://gitlab.example.com/root", 30 "avatar_url" : null, 31 "username" : "root" 32 }, 33 "updated_at" : "2016-01-04T15:31:51.081Z", 34 "id" : 76, 35 "title" : "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.", 36 "created_at" : "2016-01-04T15:31:51.081Z", 37 "iid" : 6, 38 "labels" : [], 39 "user_notes_count": 1, 40 "changes_count": "1" 41 } 42]
使用外部议题追踪器(如 Jira)时的示例响应:
json1[ 2 { 3 "id" : "PROJECT-123", 4 "title" : "Title of this issue" 5 } 6]
订阅合并请求
将认证用户订阅到合并请求以接收通知。
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/subscribe
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
如果用户已订阅合并请求,端点返回状态码 HTTP 304 Not Modified。
shellcurl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/5/merge_requests/17/subscribe"
示例响应:
json1{ 2 "id": 1, 3 "iid": 1, 4 "project_id": 3, 5 "title": "test1", 6 "description": "fixed login page css paddings", 7 "state": "merged", 8 "created_at": "2017-04-29T08:46:00Z", 9 "updated_at": "2017-04-29T08:46:00Z", 10 "target_branch": "main", 11 "source_branch": "test1", 12 "upvotes": 0, 13 "downvotes": 0, 14 "author": { 15 "id": 1, 16 "name": "Administrator", 17 "username": "admin", 18 "state": "active", 19 "avatar_url": null, 20 "web_url" : "https://gitlab.example.com/admin" 21 }, 22 "assignee": { 23 "id": 1, 24 "name": "Administrator", 25 "username": "admin", 26 "state": "active", 27 "avatar_url": null, 28 "web_url" : "https://gitlab.example.com/admin" 29 }, 30 "assignees": [{ 31 "name": "Miss Monserrate Beier", 32 "username": "axel.block", 33 "id": 12, 34 "state": "active", 35 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 36 "web_url": "https://gitlab.example.com/axel.block" 37 }], 38 "reviewers": [{ 39 "name": "Miss Monserrate Beier", 40 "username": "axel.block", 41 "id": 12, 42 "state": "active", 43 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 44 "web_url": "https://gitlab.example.com/axel.block" 45 }], 46 "source_project_id": 2, 47 "target_project_id": 3, 48 "labels": [ 49 "Community contribution", 50 "Manage" 51 ], 52 "draft": false, 53 "work_in_progress": false, 54 "milestone": { 55 "id": 5, 56 "iid": 1, 57 "project_id": 3, 58 "title": "v2.0", 59 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 60 "state": "closed", 61 "created_at": "2015-02-02T19:49:26.013Z", 62 "updated_at": "2015-02-02T19:49:26.013Z", 63 "due_date": "2018-09-22", 64 "start_date": "2018-08-08", 65 "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" 66 }, 67 "merge_when_pipeline_succeeds": true, 68 "merge_status": "can_be_merged", 69 "detailed_merge_status": "not_open", 70 "sha": "8888888888888888888888888888888888888888", 71 "merge_commit_sha": null, 72 "squash_commit_sha": null, 73 "user_notes_count": 1, 74 "discussion_locked": null, 75 "should_remove_source_branch": true, 76 "force_remove_source_branch": false, 77 "allow_collaboration": false, 78 "allow_maintainer_to_push": false, 79 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 80 "references": { 81 "short": "!1", 82 "relative": "!1", 83 "full": "my-group/my-project!1" 84 }, 85 "time_stats": { 86 "time_estimate": 0, 87 "total_time_spent": 0, 88 "human_time_estimate": null, 89 "human_total_time_spent": null 90 }, 91 "squash": false, 92 "subscribed": false, 93 "changes_count": "1", 94 "merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead 95 "id": 87854, 96 "name": "Douwe Maan", 97 "username": "DouweM", 98 "state": "active", 99 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 100 "web_url": "https://gitlab.com/DouweM" 101 }, 102 "merge_user": { 103 "id": 87854, 104 "name": "Douwe Maan", 105 "username": "DouweM", 106 "state": "active", 107 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 108 "web_url": "https://gitlab.com/DouweM" 109 }, 110 "merged_at": "2018-09-07T11:16:17.520Z", 111 "merge_after": "2018-09-07T11:16:00.000Z", 112 "prepared_at": "2018-09-04T11:16:17.520Z", 113 "closed_by": null, 114 "closed_at": null, 115 "latest_build_started_at": "2018-09-07T07:27:38.472Z", 116 "latest_build_finished_at": "2018-09-07T08:07:06.012Z", 117 "first_deployed_to_production_at": null, 118 "pipeline": { 119 "id": 29626725, 120 "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 121 "ref": "patch-28", 122 "status": "success", 123 "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" 124 }, 125 "diff_refs": { 126 "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", 127 "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 128 "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" 129 }, 130 "diverged_commits_count": 2, 131 "task_completion_status":{ 132 "count":0, 133 "completed_count":0 134 } 135}
有关响应数据的重要说明,请参阅单个合并请求响应说明。
取消订阅合并请求
取消认证用户订阅合并请求,以不再接收来自该合并请求的通知。
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/unsubscribe
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
shellcurl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/5/merge_requests/17/unsubscribe"
如果用户未订阅合并请求,端点返回状态码 HTTP 304 Not Modified。
示例响应:
json1{ 2 "id": 1, 3 "iid": 1, 4 "project_id": 3, 5 "title": "test1", 6 "description": "fixed login page css paddings", 7 "state": "merged", 8 "created_at": "2017-04-29T08:46:00Z", 9 "updated_at": "2017-04-29T08:46:00Z", 10 "target_branch": "main", 11 "source_branch": "test1", 12 "upvotes": 0, 13 "downvotes": 0, 14 "author": { 15 "id": 1, 16 "name": "Administrator", 17 "username": "admin", 18 "state": "active", 19 "avatar_url": null, 20 "web_url" : "https://gitlab.example.com/admin" 21 }, 22 "assignee": { 23 "id": 1, 24 "name": "Administrator", 25 "username": "admin", 26 "state": "active", 27 "avatar_url": null, 28 "web_url" : "https://gitlab.example.com/admin" 29 }, 30 "assignees": [{ 31 "name": "Miss Monserrate Beier", 32 "username": "axel.block", 33 "id": 12, 34 "state": "active", 35 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 36 "web_url": "https://gitlab.example.com/axel.block" 37 }], 38 "reviewers": [{ 39 "name": "Miss Monserrate Beier", 40 "username": "axel.block", 41 "id": 12, 42 "state": "active", 43 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 44 "web_url": "https://gitlab.example.com/axel.block" 45 }], 46 "source_project_id": 2, 47 "target_project_id": 3, 48 "labels": [ 49 "Community contribution", 50 "Manage" 51 ], 52 "draft": false, 53 "work_in_progress": false, 54 "milestone": { 55 "id": 5, 56 "iid": 1, 57 "project_id": 3, 58 "title": "v2.0", 59 "description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.", 60 "state": "closed", 61 "created_at": "2015-02-02T19:49:26.013Z", 62 "updated_at": "2015-02-02T19:49:26.013Z", 63 "due_date": "2018-09-22", 64 "start_date": "2018-08-08", 65 "web_url": "https://gitlab.example.com/my-group/my-project/milestones/1" 66 }, 67 "merge_when_pipeline_succeeds": true, 68 "merge_status": "can_be_merged", 69 "detailed_merge_status": "not_open", 70 "sha": "8888888888888888888888888888888888888888", 71 "merge_commit_sha": null, 72 "squash_commit_sha": null, 73 "user_notes_count": 1, 74 "discussion_locked": null, 75 "should_remove_source_branch": true, 76 "force_remove_source_branch": false, 77 "allow_collaboration": false, 78 "allow_maintainer_to_push": false, 79 "web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1", 80 "references": { 81 "short": "!1", 82 "relative": "!1", 83 "full": "my-group/my-project!1" 84 }, 85 "time_stats": { 86 "time_estimate": 0, 87 "total_time_spent": 0, 88 "human_time_estimate": null, 89 "human_total_time_spent": null 90 }, 91 "squash": false, 92 "subscribed": false, 93 "changes_count": "1", 94 "merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead 95 "id": 87854, 96 "name": "Douwe Maan", 97 "username": "DouweM", 98 "state": "active", 99 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 100 "web_url": "https://gitlab.com/DouweM" 101 }, 102 "merge_user": { 103 "id": 87854, 104 "name": "Douwe Maan", 105 "username": "DouweM", 106 "state": "active", 107 "avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png", 108 "web_url": "https://gitlab.com/DouweM" 109 }, 110 "merged_at": "2018-09-07T11:16:17.520Z", 111 "merge_after": "2018-09-07T11:16:00.000Z", 112 "prepared_at": "2018-09-04T11:16:17.520Z", 113 "closed_by": null, 114 "closed_at": null, 115 "latest_build_started_at": "2018-09-07T07:27:38.472Z", 116 "latest_build_finished_at": "2018-09-07T08:07:06.012Z", 117 "first_deployed_to_production_at": null, 118 "pipeline": { 119 "id": 29626725, 120 "sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 121 "ref": "patch-28", 122 "status": "success", 123 "web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725" 124 }, 125 "diff_refs": { 126 "base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00", 127 "head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f", 128 "start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00" 129 }, 130 "diverged_commits_count": 2, 131 "task_completion_status":{ 132 "count":0, 133 "completed_count":0 134 } 135}
有关响应数据的重要备注,请参阅单个合并请求响应备注。
创建待办事项
手动为当前用户在合并请求上创建待办事项。如果该合并请求上已经存在待办事项,此端点返回状态码 HTTP 304 Not Modified。
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/todo
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
shellcurl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/5/merge_requests/27/todo"
示例响应:
json1{ 2 "id": 113, 3 "project": { 4 "id": 3, 5 "name": "GitLab CI/CD", 6 "name_with_namespace": "GitLab Org / GitLab CI/CD", 7 "path": "gitlab-ci", 8 "path_with_namespace": "gitlab-org/gitlab-ci" 9 }, 10 "author": { 11 "name": "Administrator", 12 "username": "root", 13 "id": 1, 14 "state": "active", 15 "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 16 "web_url": "https://gitlab.example.com/root" 17 }, 18 "action_name": "marked", 19 "target_type": "MergeRequest", 20 "target": { 21 "id": 27, 22 "iid": 7, 23 "project_id": 3, 24 "title": "Et voluptas laudantium minus nihil recusandae ut accusamus earum aut non.", 25 "description": "Veniam sunt nihil modi earum cumque illum delectus. Nihil ad quis distinctio quia. Autem eligendi at quibusdam repellendus.", 26 "state": "merged", 27 "created_at": "2016-06-17T07:48:04.330Z", 28 "updated_at": "2016-07-01T11:14:15.537Z", 29 "target_branch": "allow_regex_for_project_skip_ref", 30 "source_branch": "backup", 31 "upvotes": 0, 32 "downvotes": 0, 33 "author": { 34 "name": "Jarret O'Keefe", 35 "username": "francisca", 36 "id": 14, 37 "state": "active", 38 "avatar_url": "http://www.gravatar.com/avatar/a7fa515d53450023c83d62986d0658a8?s=80&d=identicon", 39 "web_url": "https://gitlab.example.com/francisca", 40 "discussion_locked": false 41 }, 42 "assignee": { 43 "name": "Dr. Gabrielle Strosin", 44 "username": "barrett.krajcik", 45 "id": 4, 46 "state": "active", 47 "avatar_url": "http://www.gravatar.com/avatar/733005fcd7e6df12d2d8580171ccb966?s=80&d=identicon", 48 "web_url": "https://gitlab.example.com/barrett.krajcik" 49 }, 50 "assignees": [{ 51 "name": "Miss Monserrate Beier", 52 "username": "axel.block", 53 "id": 12, 54 "state": "active", 55 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 56 "web_url": "https://gitlab.example.com/axel.block" 57 }], 58 "reviewers": [{ 59 "name": "Miss Monserrate Beier", 60 "username": "axel.block", 61 "id": 12, 62 "state": "active", 63 "avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon", 64 "web_url": "https://gitlab.example.com/axel.block" 65 }], 66 "source_project_id": 3, 67 "target_project_id": 3, 68 "labels": [], 69 "draft": false, 70 "work_in_progress": false, 71 "milestone": { 72 "id": 27, 73 "iid": 2, 74 "project_id": 3, 75 "title": "v1.0", 76 "description": "Quis ea accusantium animi hic fuga assumenda.", 77 "state": "active", 78 "created_at": "2016-06-17T07:47:33.840Z", 79 "updated_at": "2016-06-17T07:47:33.840Z", 80 "due_date": null 81 }, 82 "merge_when_pipeline_succeeds": false, 83 "merge_status": "unchecked", 84 "detailed_merge_status": "not_open", 85 "subscribed": true, 86 "sha": "8888888888888888888888888888888888888888", 87 "merge_commit_sha": null, 88 "squash_commit_sha": null, 89 "user_notes_count": 7, 90 "changes_count": "1", 91 "should_remove_source_branch": true, 92 "force_remove_source_branch": false, 93 "squash": false, 94 "web_url": "http://example.com/my-group/my-project/merge_requests/1", 95 "references": { 96 "short": "!1", 97 "relative": "!1", 98 "full": "my-group/my-project!1" 99 } 100 }, 101 "target_url": "https://gitlab.example.com/gitlab-org/gitlab-ci/merge_requests/7", 102 "body": "Et voluptas laudantium minus nihil recusandae ut accusamus earum aut non.", 103 "state": "pending", 104 "created_at": "2016-07-01T11:14:15.530Z" 105}
获取合并请求差异版本
获取合并请求差异版本列表。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/versions
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | 字符串 | 是 | 项目的 ID。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
对于响应中的 SHA 的解释,请参见 API 响应中的 SHA。
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/versions"
示例响应:
json1[{ 2 "id": 110, 3 "head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", 4 "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", 5 "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", 6 "created_at": "2016-07-26T14:44:48.926Z", 7 "merge_request_id": 105, 8 "state": "collected", 9 "real_size": "1", 10 "patch_id_sha": "d504412d5b6e6739647e752aff8e468dde093f2f" 11}, { 12 "id": 108, 13 "head_commit_sha": "3eed087b29835c48015768f839d76e5ea8f07a24", 14 "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", 15 "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", 16 "created_at": "2016-07-25T14:21:33.028Z", 17 "merge_request_id": 105, 18 "state": "collected", 19 "real_size": "1", 20 "patch_id_sha": "72c30d1f0115fc1d2bb0b29b24dc2982cbcdfd32" 21}]
API 响应中的 SHA
| SHA 字段 | 目的 |
|---|---|
| base_commit_sha | 源分支和目标分支之间的合并基础提交 SHA。 |
| head_commit_sha | 源分支的 HEAD 提交。 |
| start_commit_sha | 创建此版本差异时目标分支的 HEAD 提交 SHA。 |
获取单个合并请求差异版本
获取单个合并请求差异版本。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/versions/:version_id
支持的属性:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | 字符串 | 是 | 项目的 ID。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
| version_id | 整数 | 是 | 合并请求差异版本的 ID。 |
| unidiff | 布尔 | 否 | 以统一差异格式呈现差异。默认为 false。在 极狐GitLab 16.5 中引入。 |
如果成功,返回 200 OK 和以下响应属性:
| 属性 | 类型 | 描述 |
|---|---|---|
| id | 整数 | 合并请求差异版本的 ID。 |
| base_commit_sha | 字符串 | 源分支和目标分支之间的合并基础提交 SHA。 |
| commits | 对象数组 | 合并请求差异中的提交。 |
| commits[].id | 字符串 | 提交的 ID。 |
| commits[].short_id | 字符串 | 提交的短 ID。 |
| commits[].created_at | 日期时间 | 与 committed_date 字段相同。 |
| commits[].parent_ids | 数组 | 父提交的 ID。 |
| commits[].title | 字符串 | 提交标题。 |
| commits[].message | 字符串 | 提交信息。 |
| commits[].author_name | 字符串 | 提交作者的姓名。 |
| commits[].author_email | 字符串 | 提交作者的电子邮件地址。 |
| commits[].authored_date | 日期时间 | 提交创作日期。 |
| commits[].committer_name | 字符串 | 提交者的姓名。 |
| commits[].committer_email | 字符串 | 提交者的电子邮件地址。 |
| commits[].committed_date | 日期时间 | 提交日期。 |
| commits[].trailers | 对象 | 为提交解析的 Git trailers。重复键仅包括最后一个值。 |
| commits[].extended_trailers | 对象 | 为提交解析的 Git trailers。 |
| commits[].web_url | 字符串 | 合并请求的 Web URL。 |
| created_at | 日期时间 | 合并请求的创建日期和时间。 |
| diffs | 对象数组 | 合并请求差异版本中的差异。 |
| diffs[].diff | 字符串 | 差异内容。 |
| diffs[].new_path | 字符串 | 文件的新路径。 |
| diffs[].old_path | 字符串 | 文件的旧路径。 |
| diffs[].a_mode | 字符串 | 文件的旧文件模式。 |
| diffs[].b_mode | 字符串 | 文件的新文件模式。 |
| diffs[].new_file | 布尔 | 表示添加的文件。 |
| diffs[].renamed_file | 布尔 | 表示重命名的文件。 |
| diffs[].deleted_file | 布尔 | 表示已删除的文件。 |
| diffs[].generated_file | 布尔 | 表示文件是否被标记为生成。在 极狐GitLab 16.9 中引入。 |
| head_commit_sha | 字符串 | 源分支的 HEAD 提交。 |
| merge_request_id | 整数 | 合并请求的 ID。 |
| patch_id_sha | 字符串 | 合并请求差异的 补丁 ID。 |
| real_size | 字符串 | 合并请求差异中的更改数量。 |
| start_commit_sha | 字符串 | 创建此版本差异时目标分支的 HEAD 提交 SHA。 |
| state | 字符串 | 合并请求差异的状态。可以是 collected, overflow, without_files。不推荐使用的值:timeout, overflow_commits_safe_size, overflow_diff_files_limit, overflow_diff_lines_limit。 |
示例请求:
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/versions/1"
示例响应:
json1{ 2 "id": 110, 3 "head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", 4 "base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", 5 "start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd", 6 "created_at": "2016-07-26T14:44:48.926Z", 7 "merge_request_id": 105, 8 "state": "collected", 9 "real_size": "1", 10 "patch_id_sha": "d504412d5b6e6739647e752aff8e468dde093f2f", 11 "commits": [{ 12 "id": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30", 13 "short_id": "33e2ee85", 14 "parent_ids": [], 15 "title": "Change year to 2018", 16 "author_name": "Administrator", 17 "author_email": "admin@example.com", 18 "authored_date": "2016-07-26T17:44:29.000+03:00", 19 "committer_name": "Administrator", 20 "committer_email": "admin@example.com", 21 "committed_date": "2016-07-26T17:44:29.000+03:00", 22 "created_at": "2016-07-26T17:44:29.000+03:00", 23 "message": "Change year to 2018", 24 "trailers": {}, 25 "extended_trailers": {}, 26 "web_url": "https://gitlab.example.com/project/-/commit/33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30" 27 }, { 28 "id": "aa24655de48b36335556ac8a3cd8bb521f977cbd", 29 "short_id": "aa24655d", 30 "parent_ids": [], 31 "title": "Update LICENSE", 32 "author_name": "Administrator", 33 "author_email": "admin@example.com", 34 "authored_date": "2016-07-25T17:21:53.000+03:00", 35 "committer_name": "Administrator", 36 "committer_email": "admin@example.com", 37 "committed_date": "2016-07-25T17:21:53.000+03:00", 38 "created_at": "2016-07-25T17:21:53.000+03:00", 39 "message": "Update LICENSE", 40 "trailers": {}, 41 "extended_trailers": {}, 42 "web_url": "https://gitlab.example.com/project/-/commit/aa24655de48b36335556ac8a3cd8bb521f977cbd" 43 }, { 44 "id": "3eed087b29835c48015768f839d76e5ea8f07a24", 45 "short_id": "3eed087b", 46 "parent_ids": [], 47 "title": "Add license", 48 "author_name": "Administrator", 49 "author_email": "admin@example.com", 50 "authored_date": "2016-07-25T17:21:20.000+03:00", 51 "committer_name": "Administrator", 52 "committer_email": "admin@example.com", 53 "committed_date": "2016-07-25T17:21:20.000+03:00", 54 "created_at": "2016-07-25T17:21:20.000+03:00", 55 "message": "Add license", 56 "trailers": {}, 57 "extended_trailers": {}, 58 "web_url": "https://gitlab.example.com/project/-/commit/3eed087b29835c48015768f839d76e5ea8f07a24" 59 }], 60 "diffs": [{ 61 "old_path": "LICENSE", 62 "new_path": "LICENSE", 63 "a_mode": "0", 64 "b_mode": "100644", 65 "diff": "@@ -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", 66 "new_file": true, 67 "renamed_file": false, 68 "deleted_file": false, 69 "generated_file": false 70 }] 71}
设置合并请求的时间预估
为此合并请求设置预估工作时间。
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/time_estimate
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
| duration | 字符串 | 是 | 以人类可读格式表示的持续时间,例如 3h30m。 |
shellcurl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/time_estimate?duration=3h30m"
示例响应:
json1{ 2 "human_time_estimate": "3h 30m", 3 "human_total_time_spent": null, 4 "time_estimate": 12600, 5 "total_time_spent": 0 6}
重置合并请求的时间预估
将此合并请求的预估时间重置为 0 秒。
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/reset_time_estimate
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 项目合并请求的内部 ID。 |
shellcurl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/reset_time_estimate"
示例响应:
json1{ 2 "human_time_estimate": null, 3 "human_total_time_spent": null, 4 "time_estimate": 0, 5 "total_time_spent": 0 6}
添加合并请求的耗时
为此合并请求添加耗时。
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/add_spent_time
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
| duration | 字符串 | 是 | 以人类可读格式表示的持续时间,例如 3h30m。 |
| summary | 字符串 | 否 | 时间的使用情况摘要。 |
shellcurl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/add_spent_time?duration=1h"
示例响应:
json1{ 2 "human_time_estimate": null, 3 "human_total_time_spent": "1h", 4 "time_estimate": 0, 5 "total_time_spent": 3600 6}
重置合并请求的耗时
将此合并请求的总耗时重置为 0 秒。
plaintextPOST /projects/:id/merge_requests/:merge_request_iid/reset_spent_time
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 项目合并请求的内部 ID。 |
shellcurl --request POST \ --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/reset_spent_time"
示例响应:
json1{ 2 "human_time_estimate": null, 3 "human_total_time_spent": null, 4 "time_estimate": 0, 5 "total_time_spent": 0 6}
获取时间追踪统计数据
plaintextGET /projects/:id/merge_requests/:merge_request_iid/time_stats
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | 整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
| merge_request_iid | 整数 | 是 | 合并请求的内部 ID。 |
shellcurl --header "PRIVATE-TOKEN: <your_access_token>" \ --url "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/time_stats"
示例响应:
json1{ 2 "human_time_estimate": "2h", 3 "human_total_time_spent": "1h", 4 "time_estimate": 7200, 5 "total_time_spent": 3600 6}
审批
有关审批,请参见 合并请求审批。
列出合并请求状态事件
要跟踪设置的状态、执行者及其发生时间,请查看 资源状态事件 API。
故障排除
新合并请求的空 API 字段
当您创建合并请求时,diff_refs 和 changes_count 字段初始为空。这些字段在您创建合并请求后异步填充。