- API v5 中的删除项
- 列出合并请求
- 列出项目合并请求
- 列出群组合并请求
- 获取单个合并请求
- 获取单个合并请求参与者
- 获取单个合并请求审阅者
- 获取单个合并请求提交
- 获取合并请求依赖项
- 删除合并请求依赖项
- 创建合并请求依赖项
- 获取被合并请求阻塞的 MR
- 获取单个合并请求更改
- 列出合并请求差异
- 显示合并请求原始差异
- 列出合并请求流水线
- 创建合并请求流水线
- 创建合并请求
- 更新合并请求
- 删除合并请求
- 合并合并请求
- 合并到默认合并引用路径
- 取消当流水线成功时的合并
- 重新基准合并请求
- 合并请求评论
- 列出合并时关闭的议题
- 列出与合并请求相关的议题
- 订阅合并请求
- 取消订阅合并请求
- 创建待办事项
- 获取合并请求差异版本
- 获取单个合并请求差异版本
- 设置合并请求的时间预估
- 重置合并请求的时间预估
- 添加合并请求的耗时
- 重置合并请求的耗时
- 获取时间追踪统计数据
- 审批
- 列出合并请求状态事件
- 故障排除
使用合并请求 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
来限制合并请求列表。
GET /merge_requests
GET /merge_requests?state=opened
GET /merge_requests?state=all
GET /merge_requests?milestone=release
GET /merge_requests?labels=bug,reproduced
GET /merge_requests?author_id=5
GET /merge_requests?author_username=gitlab-bot
GET /merge_requests?my_reaction_emoji=star
GET /merge_requests?scope=assigned_to_me
GET /merge_requests?search=foo&in=title
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
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 返回非草稿合并请求。 |
示例响应:
[
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"imported": false,
"imported_from": "none",
"merged_by": { // 已弃用,将在 API v5 中移除,请使用 `merge_user` 代替
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merge_user": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "main",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"id": 2,
"name": "Sam Bauch",
"username": "kenyatta_oconnell",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/956c92487c6f6f7616b536927e22c9a0?s=80&d=identicon",
"web_url": "http://gitlab.example.com//kenyatta_oconnell"
}],
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"社区贡献",
"管理"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-09-22",
"start_date": "2018-08-08",
"web_url": "https://gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"allow_collaboration": false,
"allow_maintainer_to_push": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "my-group/my-project!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"task_completion_status":{
"count":0,
"completed_count":0
}
}
]
合并请求列表响应备注
- 列出合并请求可能不会主动更新
merge_status
(这也会影响has_conflicts
),因为这可能是一个昂贵的操作。如果需要从此端点获取这些字段的值,请在查询中设置with_merge_status_recheck
参数为true
。 - 有关合并请求对象字段的备注,请参阅单个合并请求响应备注。
列出项目合并请求
获取此项目的所有合并请求。
GET /projects/:id/merge_requests
GET /projects/:id/merge_requests?state=opened
GET /projects/:id/merge_requests?state=all
GET /projects/:id/merge_requests?iids[]=42&iids[]=43
GET /projects/:id/merge_requests?milestone=release
GET /projects/:id/merge_requests?labels=bug,reproduced
GET /projects/:id/merge_requests?my_reaction_emoji=star
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
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 代替。指示合并请求是否是草稿。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/merge_requests"
示例响应:
[
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"imported": false,
"imported_from": "none",
"merged_by": { // 已弃用,将在 API v5 中移除,请使用 `merge_user` 代替
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merge_user": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"locked": false,
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "main",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"locked": false,
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"locked": false,
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"locked": false,
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"id": 2,
"name": "Sam Bauch",
"username": "kenyatta_oconnell",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/956c92487c6f6f7616b536927e22c9a0?s=80&d=identicon",
"web_url": "http://gitlab.example.com//kenyatta_oconnell"
}],
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"社区贡献",
"管理"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-09-22",
"start_date": "2018-08-08",
"web_url": "https://gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"reference": "!1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"task_completion_status":{
"count":0,
"completed_count":0
},
"has_conflicts": false,
"blocking_discussions_resolved": true,
"approvals_before_merge": 2
}
]
有关响应数据的重要备注,请参阅合并请求列表响应备注。
列出群组合并请求
获取此群组及其子群组的所有合并请求。
GET /groups/:id/merge_requests
GET /groups/:id/merge_requests?state=opened
GET /groups/:id/merge_requests?state=all
GET /groups/:id/merge_requests?milestone=release
GET /groups/:id/merge_requests?labels=bug,reproduced
GET /groups/:id/merge_requests?my_reaction_emoji=star
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
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。
示例响应:
[
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"imported": false,
"imported_from": "none",
"merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merge_user": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "main",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"id": 2,
"name": "Sam Bauch",
"username": "kenyatta_oconnell",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/956c92487c6f6f7616b536927e22c9a0?s=80&d=identicon",
"web_url": "http://gitlab.example.com//kenyatta_oconnell"
}],
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"Community contribution",
"Manage"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-10-22",
"start_date": "2018-09-08",
"web_url": "gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "my-project!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"task_completion_status":{
"count":0,
"completed_count":0
},
"has_conflicts": false,
"blocking_discussions_resolved": true
}
]
有关响应数据的重要说明,请参阅 合并请求列表响应说明。
获取单个合并请求
显示有关单个合并请求的信息。
GET /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 。指示合并请求是否为草稿。 |
示例响应:
{
"id": 155016530,
"iid": 133,
"project_id": 15513260,
"title": "Manual job rules",
"description": "",
"state": "opened",
"imported": false,
"imported_from": "none",
"created_at": "2022-05-13T07:26:38.402Z",
"updated_at": "2022-05-14T03:38:31.354Z",
"merged_by": null, // Deprecated and will be removed in API v5. Use `merge_user` instead.
"merge_user": null,
"merged_at": null,
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"target_branch": "main",
"source_branch": "manual-job-rules",
"user_notes_count": 0,
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 4155490,
"username": "marcel.amirault",
"name": "Marcel Amirault",
"state": "active",
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/4155490/avatar.png",
"web_url": "https://gitlab.com/marcel.amirault"
},
"assignees": [],
"assignee": null,
"reviewers": [],
"source_project_id": 15513260,
"target_project_id": 15513260,
"labels": [],
"draft": false,
"work_in_progress": false,
"milestone": null,
"merge_when_pipeline_succeeds": false,
"merge_status": "can_be_merged",
"detailed_merge_status": "can_be_merged",
"sha": "e82eb4a098e32c796079ca3915e07487fc4db24c",
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": true,
"reference": "!133", // Deprecated. Use `references` instead.
"references": {
"short": "!133",
"relative": "!133",
"full": "marcel.amirault/test-project!133"
},
"web_url": "https://gitlab.com/marcel.amirault/test-project/-/merge_requests/133",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"has_conflicts": false,
"blocking_discussions_resolved": true,
"approvals_before_merge": null, // deprecated, use [Merge request approvals API](merge_request_approvals.md)
"subscribed": true,
"changes_count": "1",
"latest_build_started_at": "2022-05-13T09:46:50.032Z",
"latest_build_finished_at": null,
"first_deployed_to_production_at": null,
"pipeline": { // Use `head_pipeline` instead.
"id": 538317940,
"iid": 1877,
"project_id": 15513260,
"sha": "1604b0c46c395822e4e9478777f8e54ac99fe5b9",
"ref": "refs/merge-requests/133/merge",
"status": "failed",
"source": "merge_request_event",
"created_at": "2022-05-13T09:46:39.560Z",
"updated_at": "2022-05-13T09:47:20.706Z",
"web_url": "https://gitlab.com/marcel.amirault/test-project/-/pipelines/538317940"
},
"head_pipeline": {
"id": 538317940,
"iid": 1877,
"project_id": 15513260,
"sha": "1604b0c46c395822e4e9478777f8e54ac99fe5b9",
"ref": "refs/merge-requests/133/merge",
"status": "failed",
"source": "merge_request_event",
"created_at": "2022-05-13T09:46:39.560Z",
"updated_at": "2022-05-13T09:47:20.706Z",
"web_url": "https://gitlab.com/marcel.amirault/test-project/-/pipelines/538317940",
"before_sha": "1604b0c46c395822e4e9478777f8e54ac99fe5b9",
"tag": false,
"yaml_errors": null,
"user": {
"id": 4155490,
"username": "marcel.amirault",
"name": "Marcel Amirault",
"state": "active",
"avatar_url": "https://gitlab.com/uploads/-/system/user/avatar/4155490/avatar.png",
"web_url": "https://gitlab.com/marcel.amirault"
},
"started_at": "2022-05-13T09:46:50.032Z",
"finished_at": "2022-05-13T09:47:20.697Z",
"committed_at": null,
"duration": 30,
"queued_duration": 10,
"coverage": null,
"detailed_status": {
"icon": "status_failed",
"text": "failed",
"label": "failed",
"group": "failed",
"tooltip": "failed",
"has_details": true,
"details_path": "/marcel.amirault/test-project/-/pipelines/538317940",
"illustration": null,
"favicon": "/assets/ci_favicons/favicon_status_failed-41304d7f7e3828808b0c26771f0309e55296819a9beea3ea9fbf6689d9857c12.png"
}
},
"diff_refs": {
"base_sha": "1162f719d711319a2efb2a35566f3bfdadee8bab",
"head_sha": "e82eb4a098e32c796079ca3915e07487fc4db24c",
"start_sha": "1162f719d711319a2efb2a35566f3bfdadee8bab"
},
"merge_error": null,
"first_contribution": false,
"user": {
"can_merge": true
},
"approvals_before_merge": { // Available for 极狐GitLab 专业版和旗舰版 tiers only
"id": 1,
"title": "test1",
"approvals_before_merge": null
},
}
单个合并请求响应说明
每个合并请求的可合并性 (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 中引入。
{{< /history >}}
使用 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
字段不会更新。
获取单个合并请求参与者
获取合并请求参与者列表。
GET /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。 |
示例响应:
[
{
"id": 1,
"name": "John Doe1",
"username": "user1",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon",
"web_url": "http://localhost/user1"
},
{
"id": 2,
"name": "John Doe2",
"username": "user2",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/10fc7f102be8de7657fb4d80898bbfe3?s=80&d=identicon",
"web_url": "http://localhost/user2"
}
]
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
integer | 是 | 合并请求的内部 ID。 |
示例响应:
[
{
"id": 1,
"name": "John Doe1",
"username": "user1",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon",
"web_url": "http://localhost/user1"
},
{
"id": 2,
"name": "John Doe2",
"username": "user2",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/10fc7f102be8de7657fb4d80898bbfe3?s=80&d=identicon",
"web_url": "http://localhost/user2"
}
]
获取单个合并请求审阅者
获取合并请求审阅者列表。
GET /projects/:id/merge_requests/:merge_request_iid/reviewers
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
integer | 是 | 合并请求的内部 ID。 |
示例响应:
[
{
"user": {
"id": 1,
"name": "John Doe1",
"username": "user1",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon",
"web_url": "http://localhost/user1"
},
"state": "unreviewed",
"created_at": "2022-07-27T17:03:27.684Z"
},
{
"user": {
"id": 2,
"name": "John Doe2",
"username": "user2",
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/10fc7f102be8de7657fb4d80898bbfe3?s=80&d=identicon",
"web_url": "http://localhost/user2"
},
"state": "reviewed",
"created_at": "2022-07-27T17:03:27.684Z"
}
]
获取单个合并请求提交
获取合并请求提交列表。
GET /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。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/commits"
示例响应:
[
{
"id": "ed899a2f4b50b4370feeea94676502b42383c746",
"short_id": "ed899a2f4b5",
"title": "Replace sanitize with escape once",
"author_name": "Example User",
"author_email": "user@example.com",
"authored_date": "2012-09-20T11:50:22+03:00",
"committer_name": "Example User",
"committer_email": "user@example.com",
"committed_date": "2012-09-20T11:50:22+03:00",
"created_at": "2012-09-20T11:50:22+03:00",
"message": "Replace sanitize with escape once",
"trailers": {},
"extended_trailers": {},
"web_url": "https://gitlab.example.com/project/-/commit/ed899a2f4b50b4370feeea94676502b42383c746"
},
{
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
"short_id": "6104942438c",
"title": "Sanitize for network graph",
"author_name": "Example User",
"author_email": "user@example.com",
"authored_date": "2012-09-20T09:06:12+03:00",
"committer_name": "Example User",
"committer_email": "user@example.com",
"committed_date": "2012-09-20T09:06:12+03:00",
"created_at": "2012-09-20T09:06:12+03:00",
"message": "Sanitize for network graph",
"trailers": {},
"extended_trailers": {},
"web_url": "https://gitlab.example.com/project/-/commit/6104942438c14ec7bd21c6cd5bd995272b3faff6"
}
]
获取合并请求依赖项
显示有关必须在合并前解决的合并请求依赖项的信息。
{{< alert type=”note” >}}
如果用户没有访问阻塞合并请求的权限,则不返回 blocking_merge_request
属性。
{{< /alert >}}
GET /projects/:id/merge_requests/:merge_request_iid/blocks
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/blocks"
示例响应:
[
{
"id": 1,
"blocking_merge_request": {
"id": 145,
"iid": 12,
"project_id": 7,
"title": "Interesting MR",
"description": "Does interesting things.",
"state": "opened",
"created_at": "2024-07-05T21:29:11.172Z",
"updated_at": "2024-07-05T21:29:11.172Z",
"merged_by": null,
"merge_user": null,
"merged_at": null,
"merge_after": "2018-09-07T11:16:00.000Z",
"closed_by": null,
"closed_at": null,
"target_branch": "master",
"source_branch": "v2.x",
"user_notes_count": 0,
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
},
"assignees": [
{
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
}
],
"assignee": {
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
},
"reviewers": [
{
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
},
{
"id": 1,
"username": "root",
"name": "Administrator",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/root"
}
],
"source_project_id": 7,
"target_project_id": 7,
"labels": [],
"draft": false,
"imported": false,
"imported_from": "none",
"work_in_progress": false,
"milestone": null,
"merge_when_pipeline_succeeds": false,
"merge_status": "unchecked",
"detailed_merge_status": "unchecked",
"sha": "ce7e4f2d0ce13cb07479bb39dc10ee3b861c08a6",
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": true,
"prepared_at": null,
"reference": "!12",
"references": {
"short": "!12",
"relative": "!12",
"full": "my-group/my-project!12"
},
"web_url": "https://localhost/my-group/my-project/-/merge_requests/12",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"squash_on_merge": false,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"has_conflicts": false,
"blocking_discussions_resolved": true,
"approvals_before_merge": null
},
"blocked_merge_request": {
"id": 146,
"iid": 13,
"project_id": 7,
"title": "Really cool MR",
"description": "Adds some stuff",
"state": "opened",
"created_at": "2024-07-05T21:31:34.811Z",
"updated_at": "2024-07-27T02:57:08.054Z",
"merged_by": null,
"merge_user": null,
"merged_at": null,
"merge_after": "2018-09-07T11:16:00.000Z",
"closed_by": null,
"closed_at": null,
"target_branch": "master",
"source_branch": "remove-from",
"user_notes_count": 0,
"upvotes": 1,
"downvotes": 0,
"author": {
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhose/aiguy123"
},
"assignees": [
{
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
}
],
"assignee": {
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
},
"reviewers": [
{
"id": 1,
"username": "root",
"name": "Administrator",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/root"
}
],
"source_project_id": 7,
"target_project_id": 7,
"labels": [],
"draft": false,
"imported": false,
"imported_from": "none",
"work_in_progress": false,
"milestone": {
"id": 59,
"iid": 6,
"project_id": 7,
"title": "Sprint 1718897375",
"description": "Accusantium omnis iusto a animi.",
"state": "active",
"created_at": "2024-06-20T15:29:35.739Z",
"updated_at": "2024-06-20T15:29:35.739Z",
"due_date": null,
"start_date": null,
"expired": false,
"web_url": "https://localhost/my-group/my-project/-/milestones/6"
},
"merge_when_pipeline_succeeds": false,
"merge_status": "cannot_be_merged",
"detailed_merge_status": "not_approved",
"sha": "daa75b9b17918f51f43866ff533987fda71375ea",
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": true,
"prepared_at": "2024-07-11T18:50:46.215Z",
"reference": "!13",
"references": {
"short": "!13",
"relative": "!13",
"full": "my-group/my-project!12"
},
"web_url": "https://localhost/my-group/my-project/-/merge_requests/13",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"squash_on_merge": false,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"has_conflicts": true,
"blocking_discussions_resolved": true,
"approvals_before_merge": null
},
"project_id": 7
}
]
删除合并请求依赖项
删除合并请求依赖项。
DELETE /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。 |
示例请求:
curl --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
。
创建合并请求依赖项
创建合并请求依赖项。
POST /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。 |
示例请求:
curl --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
。
示例响应:
{
"id": 1,
"blocking_merge_request": {
"id": 145,
"iid": 12,
"project_id": 7,
"title": "Interesting MR",
"description": "Does interesting things.",
"state": "opened",
"created_at": "2024-07-05T21:29:11.172Z",
"updated_at": "2024-07-05T21:29:11.172Z",
"merged_by": null,
"merge_user": null,
"merged_at": null,
"merge_after": "2018-09-07T11:16:00.000Z",
"closed_by": null,
"closed_at": null,
"target_branch": "master",
"source_branch": "v2.x",
"user_notes_count": 0,
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
},
"assignees": [
{
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
}
],
"assignee": {
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
},
"reviewers": [
{
"id": 2,
"username": "aiguy123",
"name": "AI GUY",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/aiguy123"
},
{
"id": 1,
"username": "root",
"name": "Administrator",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/0?s=80&d=identicon",
"web_url": "https://localhost/root"
}
],
"source_project_id": 7,
"target_project_id": 7,
"labels": [],
"draft": false,
"imported": false,
"imported_from": "none",
"work_in_progress": false,
"milestone": null,
"merge_when_pipeline_succeeds": false,
"merge_status": "unchecked",
"detailed_merge_status": "unchecked",
"sha": "ce7e4f2d0ce13cb07479bb39dc10ee3b861c08a6",
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": true,
"prepared_at": null,
"reference": "!12",
"references": {
"short": "!12",
"relative": "!12",
"full": "my-group/my-project!12"
},
"web_url": "https://localhost/my-group/my-project/-/merge_requests/12",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"squash_on_merge": false,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"has_conflicts": false,
"blocking_discussions_resolved": true,
"approvals_before_merge": null
},
"project_id": 7
}
获取被合并请求阻塞的 MR
显示被当前合并请求阻塞的合并请求的信息。
GET /projects/:id/merge_requests/:merge_request_iid/blockees
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/blockees"
示例响应:
[
{
"id": 18,
"blocking_merge_request": {
"id": 71,
"iid": 10,
"project_id": 7,
"title": "At quaerat occaecati voluptate ex explicabo nisi.",
"description": "Aliquid distinctio officia corrupti ad nemo natus ipsum culpa.",
"state": "merged",
"created_at": "2024-07-05T19:44:14.023Z",
"updated_at": "2024-07-05T19:44:14.023Z",
"merged_by": {
"id": 40,
"username": "i-user-0-1720208283",
"name": "I User0",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/8325417f0f7919e3724957543b4414fdeca612cade1e4c0be45685fdaa2be0e2?s=80&d=identicon",
"web_url": "http://127.0.0.1:3000/i-user-0-1720208283"
},
"merge_user": {
"id": 40,
"username": "i-user-0-1720208283",
"name": "I User0",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/8325417f0f7919e3724957543b4414fdeca612cade1e4c0be45685fdaa2be0e2?s=80&d=identicon",
"web_url": "http://127.0.0.1:3000/i-user-0-1720208283"
},
"merged_at": "2024-06-26T19:44:14.123Z",
"closed_by": null,
"closed_at": null,
"target_branch": "master",
"source_branch": "Brickwood-Brunefunc-417",
"user_notes_count": 0,
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 40,
"username": "i-user-0-1720208283",
"name": "I User0",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/8325417f0f7919e3724957543b4414fdeca612cade1e4c0be45685fdaa2be0e2?s=80&d=identicon",
"web_url": "http://127.0.0.1:3000/i-user-0-1720208283"
},
"assignees": [],
"assignee": null,
"reviewers": [],
"source_project_id": 7,
"target_project_id": 7,
"labels": [],
"draft": false,
"imported": false,
"imported_from": "none",
"work_in_progress": false,
"milestone": null,
"merge_when_pipeline_succeeds": false,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"merge_after": null,
"sha": null,
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": null,
"prepared_at": null,
"reference": "!10",
"references": {
"short": "!10",
"relative": "!10",
"full": "flightjs/Flight!10"
},
"web_url": "http://127.0.0.1:3000/flightjs/Flight/-/merge_requests/10",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"squash_on_merge": false,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"has_conflicts": false,
"blocking_discussions_resolved": true,
"approvals_before_merge": null
},
"blocked_merge_request": {
"id": 176,
"iid": 14,
"project_id": 7,
"title": "second_mr",
"description": "Signed-off-by: Lucas Zampieri <lzampier@redhat.com>",
"state": "opened",
"created_at": "2024-07-08T19:12:29.089Z",
"updated_at": "2024-08-27T19:27:17.045Z",
"merged_by": null,
"merge_user": null,
"merged_at": null,
"closed_by": null,
"closed_at": null,
"target_branch": "master",
"source_branch": "second_mr",
"user_notes_count": 0,
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"username": "root",
"name": "Administrator",
"state": "active",
"locked": false,
"avatar_url": "https://www.gravatar.com/avatar/fc3634394c590e212d964e8e0a34c4d9b8c17c992f4d6d145d75f9c21c1c3b6e?s=80&d=identicon",
"web_url": "http://127.0.0.1:3000/root"
},
"assignees": [],
"assignee": null,
"reviewers": [],
"source_project_id": 7,
"target_project_id": 7,
"labels": [],
"draft": false,
"imported": false,
"imported_from": "none",
"work_in_progress": false,
"milestone": null,
"merge_when_pipeline_succeeds": false,
"merge_status": "cannot_be_merged",
"detailed_merge_status": "commits_status",
"merge_after": null,
"sha": "3a576801e528db79a75fbfea463673054ff224fb",
"merge_commit_sha": null,
"squash_commit_sha": null,
"discussion_locked": null,
"should_remove_source_branch": null,
"force_remove_source_branch": true,
"prepared_at": null,
"reference": "!14",
"references": {
"short": "!14",
"relative": "!14",
"full": "flightjs/Flight!14"
},
"web_url": "http://127.0.0.1:3000/flightjs/Flight/-/merge_requests/14",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"squash_on_merge": false,
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"has_conflicts": true,
"blocking_discussions_resolved": true,
"approvals_before_merge": null
},
"project_id": 7
}
]
获取单个合并请求更改
{{< alert type=”warning” >}}
此端点在极狐GitLab 15.7 中已弃用,并计划在 API v5 中移除。请改用 列出合并请求差异 端点。
{{< /alert >}}
显示有关合并请求的信息,包括其文件和更改。
GET /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 本身的限制仍然适用。
示例响应:
{
"id": 21,
"iid": 1,
"project_id": 4,
"title": "Blanditiis beatae suscipit hic assumenda et molestias nisi asperiores repellat et.",
"state": "reopened",
"created_at": "2015-02-02T19:49:39.159Z",
"updated_at": "2015-02-02T20:08:49.959Z",
"target_branch": "secret_token",
"source_branch": "version-1-9",
"upvotes": 0,
"downvotes": 0,
"author": {
"name": "Chad Hamill",
"username": "jarrett",
"id": 5,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/b95567800f828948baf5f4160ebb2473?s=40&d=identicon",
"web_url" : "https://gitlab.example.com/jarrett"
},
"assignee": {
"name": "Administrator",
"username": "root",
"id": 1,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=40&d=identicon",
"web_url" : "https://gitlab.example.com/root"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"source_project_id": 4,
"target_project_id": 4,
"labels": [ ],
"description": "Qui voluptatibus placeat ipsa alias quasi. Deleniti rem ut sint. Optio velit qui distinctio.",
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 4,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": null
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"detailed_merge_status": "can_be_merged",
"subscribed" : true,
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"changes_count": "1",
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"squash": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
},
"discussion_locked": false,
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"task_completion_status":{
"count":0,
"completed_count":0
},
"changes": [
{
"old_path": "VERSION",
"new_path": "VERSION",
"a_mode": "100644",
"b_mode": "100644",
"diff": "@@ -1 +1 @@\ -1.9.7\ +1.9.8",
"new_file": false,
"renamed_file": false,
"deleted_file": false
}
],
"overflow": false
}
列出合并请求差异
{{< 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
功能标志。
{{< /history >}}
列出合并请求中更改的文件的差异。
GET /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 中引入。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/diffs?page=1&per_page=2"
示例响应:
[
{
"old_path": "README",
"new_path": "README",
"a_mode": "100644",
"b_mode": "100644",
"diff": "@@ -1 +1 @@\ -Title\ +README",
"new_file": false,
"renamed_file": false,
"deleted_file": false,
"generated_file": false
},
{
"old_path": "VERSION",
"new_path": "VERSION",
"a_mode": "100644",
"b_mode": "100644",
"diff": "@@\ -1.9.7\ +1.9.8",
"new_file": false,
"renamed_file": false,
"deleted_file": false,
"generated_file": false
}
]
{{< alert type=”note” >}}
此端点受 合并请求差异限制约束。超过差异限制的合并请求将返回有限的结果。
{{< /alert >}}
显示合并请求原始差异
显示合并请求中更改的文件的原始差异。
GET /projects/:id/merge_requests/:merge_request_iid/raw_diffs
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
如果成功,返回 200 OK
和可编程使用的原始差异响应:
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/raw_diffs"
示例响应:
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 31525ad523553c8d7eff163db3e539058efd6d3a..f30e36d6fdf4cd4fa25f62e08ecdbf4a7b169681 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -944,6 +944,10 @@ def send_git_blob(repository, blob)
body ''
end
+ def send_git_diff(repository, diff_refs)
+ header(*Gitlab::Workhorse.send_git_diff(repository, diff_refs))
+ end
+
def send_git_archive(repository, **kwargs)
header(*Gitlab::Workhorse.send_git_archive(repository, **kwargs))
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index e02d9eea1852f19fe5311acda6aa17465eeb422e..f32b38585398a18fea75c11d7b8ebb730eeb3fab 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -6,6 +6,8 @@ class MergeRequests < ::API::Base
include PaginationParams
include Helpers::Unidiff
+ helpers ::API::Helpers::HeadersHelpers
+
CONTEXT_COMMITS_POST_LIMIT = 20
before { authenticate_non_get! }
{{< alert type=”note” >}}
此端点受 合并请求差异限制 约束。超出差异限制的合并请求将返回有限的结果。
{{< /alert >}}
列出合并请求流水线
获取合并请求流水线的列表。
GET /projects/:id/merge_requests/:merge_request_iid/pipelines
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
integer | 是 | 合并请求的内部 ID。 |
为了限制合并请求流水线的列表,可以使用分页参数 page
和 per_page
。
示例响应:
[
{
"id": 77,
"sha": "959e04d7c7a30600c894bd3c0cd0e1ce7f42c11d",
"ref": "main",
"status": "success"
}
]
创建合并请求流水线
创建新的 合并请求的流水线。从此端点创建的流水线不会运行常规的分支/标签流水线。要创建作业,请使用 only: [merge_requests]
配置 .gitlab-ci.yml
。
新的流水线可以是:
POST /projects/:id/merge_requests/:merge_request_iid/pipelines
支持的属性:
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
integer or string | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
integer | 是 | 合并请求的内部 ID。 |
示例响应:
{
"id": 2,
"sha": "b83d6e391c22777fca1ed3012fce84f633d7fed0",
"ref": "refs/merge-requests/1/head",
"status": "pending",
"web_url": "http://localhost/user1/project1/pipelines/2",
"before_sha": "0000000000000000000000000000000000000000",
"tag": false,
"yaml_errors": null,
"user": {
"id": 1,
"name": "John Doe1",
"username": "user1",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon",
"web_url": "http://example.com"
},
"created_at": "2019-09-04T19:20:18.267Z",
"updated_at": "2019-09-04T19:20:18.459Z",
"started_at": null,
"finished_at": null,
"committed_at": null,
"duration": null,
"coverage": null,
"detailed_status": {
"icon": "status_pending",
"text": "pending",
"label": "pending",
"group": "pending",
"tooltip": "pending",
"has_details": false,
"details_path": "/user1/project1/pipelines/2",
"illustration": null,
"favicon": "/assets/ci_favicons/favicon_status_pending-5bdf338420e5221ca24353b6bff1c9367189588750632e9a871b7af09ff6a2ae.png"
}
}
创建合并请求
创建一个新的合并请求。
POST /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。 |
示例响应:
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"imported": false,
"imported_from": "none",
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "main",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"Community contribution",
"Manage"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-09-22",
"start_date": "2018-08-08",
"web_url": "https://gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"merge_error": null,
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"allow_collaboration": false,
"allow_maintainer_to_push": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"subscribed": false,
"changes_count": "1",
"merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merge_user": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"latest_build_started_at": "2018-09-07T07:27:38.472Z",
"latest_build_finished_at": "2018-09-07T08:07:06.012Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 29626725,
"sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"ref": "patch-28",
"status": "success",
"web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725"
},
"diff_refs": {
"base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00",
"head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00"
},
"diverged_commits_count": 2,
"task_completion_status":{
"count":0,
"completed_count":0
}
}
有关响应数据的重要说明,请参阅单个合并请求响应说明。
更新合并请求
更新现有的合并请求。您可以更改目标分支、标题,甚至关闭合并请求。
PUT /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 | 否 | 合并请求的标题。 |
必须包含上述至少一个非必需属性。
示例响应:
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "main",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"Community contribution",
"Manage"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-09-22",
"start_date": "2018-08-08",
"web_url": "https://gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"merge_error": null,
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"allow_collaboration": false,
"allow_maintainer_to_push": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"subscribed": false,
"changes_count": "1",
"merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merge_user": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"latest_build_started_at": "2018-09-07T07:27:38.472Z",
"latest_build_finished_at": "2018-09-07T08:07:06.012Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 29626725,
"sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"ref": "patch-28",
"status": "success",
"web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725"
},
"diff_refs": {
"base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00",
"head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00"
},
"diverged_commits_count": 2,
"task_completion_status":{
"count":0,
"completed_count":0
}
}
有关响应数据的重要说明,请参阅单个合并请求响应说明。
删除合并请求
仅适用于管理员和项目所有者。删除相关的合并请求。
DELETE /projects/:id/merge_requests/:merge_request_iid
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
curl --request DELETE \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/4/merge_requests/85"
合并合并请求
使用此 API 接受并合并通过合并请求提交的更改。
PUT /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 |
合并请求合并失败。 |
有关响应数据的重要说明,请参阅单个合并请求响应说明。
示例响应:
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "main",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"Community contribution",
"Manage"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-09-22",
"start_date": "2018-08-08",
"web_url": "https://gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"merge_error": null,
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"allow_collaboration": false,
"allow_maintainer_to_push": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"subscribed": false,
"changes_count": "1",
"merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merge_user": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"latest_build_started_at": "2018-09-07T07:27:38.472Z",
"latest_build_finished_at": "2018-09-07T08:07:06.012Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 29626725,
"sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"ref": "patch-28",
"status": "success",
"web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725"
},
"diff_refs": {
"base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00",
"head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00"
},
"diverged_commits_count": 2,
"task_completion_status":{
"count":0,
"completed_count":0
}
}
合并到默认合并引用路径
如果可能,将合并请求源和目标分支之间的更改合并到目标项目存储库的 refs/merge-requests/:iid/merge
引用中。此引用具有目标分支进行常规合并操作后的状态。
此操作不是常规合并操作,因为它不会以任何方式改变合并请求目标分支的状态。
提交请求到此 API 时,此引用(refs/merge-requests/:iid/merge
)不一定会被覆盖,但会确保引用具有最新可能的状态。
GET /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 数据库处于只读模式。 |
示例响应:
{
"commit_id": "854a3a7a17acbcc0bbbea170986df1eb60435f34"
}
取消当流水线成功时的合并
POST /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 |
合并请求已关闭。 |
有关响应数据的重要说明,请参阅单个合并请求响应说明。
示例响应:
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "main",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"Community contribution",
"Manage"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-09-22",
"start_date": "2018-08-08",
"web_url": "https://gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": false,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"merge_error": null,
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"allow_collaboration": false,
"allow_maintainer_to_push": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"subscribed": false,
"changes_count": "1",
"merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merge_user": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"latest_build_started_at": "2018-09-07T07:27:38.472Z",
"latest_build_finished_at": "2018-09-07T08:07:06.012Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 29626725,
"sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"ref": "patch-28",
"status": "success",
"web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725"
},
"diff_refs": {
"base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00",
"head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00"
},
"diverged_commits_count": 2,
"task_completion_status":{
"count":0,
"completed_count":0
}
}
重新基准合并请求
自动将合并请求的 source_branch
重新基准到其 target_branch
。
PUT /projects/:id/merge_requests/:merge_request_iid/rebase
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
skip_ci |
布尔值 | 否 | 设置为 true 以跳过创建 CI 流水线。 |
curl --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 |
长期事务可能阻止了您的请求。 |
如果请求成功添加到队列中,响应包含:
{
"rebase_in_progress": true
}
您可以通过 include_rebase_in_progress
参数轮询获取单个 MR端点以检查异步请求的状态。
如果重新基准操作正在进行中,响应包括以下内容:
{
"rebase_in_progress": true,
"merge_error": null
}
重新基准操作成功完成后,响应包括以下内容:
{
"rebase_in_progress": false,
"merge_error": null
}
如果重新基准操作失败,响应包括以下内容:
{
"rebase_in_progress": false,
"merge_error": "Rebase failed. Please rebase locally"
}
合并请求评论
注释资源用于创建评论。
列出合并时关闭的议题
获取通过合并提供的合并请求将关闭的所有议题。
GET /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 |
字符串 | 议题的标题。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/76/merge_requests/1/closes_issues"
使用极狐GitLab 议题追踪器时的示例响应:
[
{
"id": 76,
"iid": 6,
"project_id": 1,
"title": "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.",
"description": "Ratione dolores corrupti mollitia soluta quia.",
"state": "opened",
"created_at": "2024-09-06T10:58:49.002Z",
"updated_at": "2024-09-06T11:01:40.710Z",
"closed_at": null,
"closed_by": null,
"labels": [
"label"
],
"milestone": {
"project_id": 1,
"description": "Ducimus nam enim ex consequatur cumque ratione.",
"state": "closed",
"due_date": null,
"iid": 2,
"created_at": "2016-01-04T15:31:39.996Z",
"title": "v4.0",
"id": 17,
"updated_at": "2016-01-04T15:31:39.996Z"
},
"assignees": [
{
"id": 1,
"username": "root",
"name": "Administrator",
"state": "active",
"locked": false,
"avatar_url": null,
"web_url": "https://gitlab.example.com/root"
}
],
"author": {
"id": 18,
"username": "eileen.lowe",
"name": "Alexandra Bashirian",
"state": "active",
"locked": false,
"avatar_url": null,
"web_url": "https://gitlab.example.com/eileen.lowe"
},
"type": "ISSUE",
"assignee": {
"id": 1,
"username": "root",
"name": "Administrator",
"state": "active",
"locked": false,
"avatar_url": null,
"web_url": "https://gitlab.example.com/root"
},
"user_notes_count": 1,
"merge_requests_count": 1,
"upvotes": 0,
"downvotes": 0,
"due_date": null,
"confidential": false,
"discussion_locked": null,
"issue_type": "issue",
"web_url": "https://gitlab.example.com/my-group/my-project/-/issues/6",
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"task_completion_status": {
"count": 0,
"completed_count": 0
},
"weight": null,
"blocking_issues_count": 0
}
]
使用外部议题追踪器(如 Jira)时的示例响应:
[
{
"id" : "PROJECT-123",
"title" : "Title of this issue"
}
]
列出与合并请求相关的议题
获取合并请求的标题、描述、提交消息、评论和讨论中的所有相关议题。
GET /projects/:id/merge_requests/:merge_request_iid/related_issues
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/76/merge_requests/1/related_issues"
使用极狐GitLab 议题追踪器时的示例响应:
[
{
"state" : "opened",
"description" : "Ratione dolores corrupti mollitia soluta quia.",
"author" : {
"state" : "active",
"id" : 18,
"web_url" : "https://gitlab.example.com/eileen.lowe",
"name" : "Alexandra Bashirian",
"avatar_url" : null,
"username" : "eileen.lowe"
},
"milestone" : {
"project_id" : 1,
"description" : "Ducimus nam enim ex consequatur cumque ratione.",
"state" : "closed",
"due_date" : null,
"iid" : 2,
"created_at" : "2016-01-04T15:31:39.996Z",
"title" : "v4.0",
"id" : 17,
"updated_at" : "2016-01-04T15:31:39.996Z"
},
"project_id" : 1,
"assignee" : {
"state" : "active",
"id" : 1,
"name" : "Administrator",
"web_url" : "https://gitlab.example.com/root",
"avatar_url" : null,
"username" : "root"
},
"updated_at" : "2016-01-04T15:31:51.081Z",
"id" : 76,
"title" : "Consequatur vero maxime deserunt laboriosam est voluptas dolorem.",
"created_at" : "2016-01-04T15:31:51.081Z",
"iid" : 6,
"labels" : [],
"user_notes_count": 1,
"changes_count": "1"
}
]
使用外部议题追踪器(如 Jira)时的示例响应:
[
{
"id" : "PROJECT-123",
"title" : "Title of this issue"
}
]
订阅合并请求
将认证用户订阅到合并请求以接收通知。
POST /projects/:id/merge_requests/:merge_request_iid/subscribe
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
如果用户已订阅合并请求,端点返回状态码 HTTP 304 Not Modified
。
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/merge_requests/17/subscribe"
示例响应:
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "main",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"Community contribution",
"Manage"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-09-22",
"start_date": "2018-08-08",
"web_url": "https://gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"allow_collaboration": false,
"allow_maintainer_to_push": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"subscribed": false,
"changes_count": "1",
"merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merge_user": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"latest_build_started_at": "2018-09-07T07:27:38.472Z",
"latest_build_finished_at": "2018-09-07T08:07:06.012Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 29626725,
"sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"ref": "patch-28",
"status": "success",
"web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725"
},
"diff_refs": {
"base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00",
"head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00"
},
"diverged_commits_count": 2,
"task_completion_status":{
"count":0,
"completed_count":0
}
}
有关响应数据的重要说明,请参阅单个合并请求响应说明。
取消订阅合并请求
取消认证用户订阅合并请求,以不再接收来自该合并请求的通知。
POST /projects/:id/merge_requests/:merge_request_iid/unsubscribe
属性 | 类型 | 是否必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
curl --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
。
示例响应:
{
"id": 1,
"iid": 1,
"project_id": 3,
"title": "test1",
"description": "fixed login page css paddings",
"state": "merged",
"created_at": "2017-04-29T08:46:00Z",
"updated_at": "2017-04-29T08:46:00Z",
"target_branch": "main",
"source_branch": "test1",
"upvotes": 0,
"downvotes": 0,
"author": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignee": {
"id": 1,
"name": "Administrator",
"username": "admin",
"state": "active",
"avatar_url": null,
"web_url" : "https://gitlab.example.com/admin"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"source_project_id": 2,
"target_project_id": 3,
"labels": [
"Community contribution",
"Manage"
],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 5,
"iid": 1,
"project_id": 3,
"title": "v2.0",
"description": "Assumenda aut placeat expedita exercitationem labore sunt enim earum.",
"state": "closed",
"created_at": "2015-02-02T19:49:26.013Z",
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": "2018-09-22",
"start_date": "2018-08-08",
"web_url": "https://gitlab.example.com/my-group/my-project/milestones/1"
},
"merge_when_pipeline_succeeds": true,
"merge_status": "can_be_merged",
"detailed_merge_status": "not_open",
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 1,
"discussion_locked": null,
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"allow_collaboration": false,
"allow_maintainer_to_push": false,
"web_url": "http://gitlab.example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
},
"time_stats": {
"time_estimate": 0,
"total_time_spent": 0,
"human_time_estimate": null,
"human_total_time_spent": null
},
"squash": false,
"subscribed": false,
"changes_count": "1",
"merged_by": { // Deprecated and will be removed in API v5, use `merge_user` instead
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merge_user": {
"id": 87854,
"name": "Douwe Maan",
"username": "DouweM",
"state": "active",
"avatar_url": "https://gitlab.example.com/uploads/-/system/user/avatar/87854/avatar.png",
"web_url": "https://gitlab.com/DouweM"
},
"merged_at": "2018-09-07T11:16:17.520Z",
"merge_after": "2018-09-07T11:16:00.000Z",
"prepared_at": "2018-09-04T11:16:17.520Z",
"closed_by": null,
"closed_at": null,
"latest_build_started_at": "2018-09-07T07:27:38.472Z",
"latest_build_finished_at": "2018-09-07T08:07:06.012Z",
"first_deployed_to_production_at": null,
"pipeline": {
"id": 29626725,
"sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"ref": "patch-28",
"status": "success",
"web_url": "https://gitlab.example.com/my-group/my-project/pipelines/29626725"
},
"diff_refs": {
"base_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00",
"head_sha": "2be7ddb704c7b6b83732fdd5b9f09d5a397b5f8f",
"start_sha": "c380d3acebd181f13629a25d2e2acca46ffe1e00"
},
"diverged_commits_count": 2,
"task_completion_status":{
"count":0,
"completed_count":0
}
}
有关响应数据的重要备注,请参阅单个合并请求响应备注。
创建待办事项
手动为当前用户在合并请求上创建待办事项。如果该合并请求上已经存在待办事项,此端点返回状态码 HTTP 304 Not Modified
。
POST /projects/:id/merge_requests/:merge_request_iid/todo
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/merge_requests/27/todo"
示例响应:
{
"id": 113,
"project": {
"id": 3,
"name": "GitLab CI/CD",
"name_with_namespace": "GitLab Org / GitLab CI/CD",
"path": "gitlab-ci",
"path_with_namespace": "gitlab-org/gitlab-ci"
},
"author": {
"name": "Administrator",
"username": "root",
"id": 1,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "https://gitlab.example.com/root"
},
"action_name": "marked",
"target_type": "MergeRequest",
"target": {
"id": 27,
"iid": 7,
"project_id": 3,
"title": "Et voluptas laudantium minus nihil recusandae ut accusamus earum aut non.",
"description": "Veniam sunt nihil modi earum cumque illum delectus. Nihil ad quis distinctio quia. Autem eligendi at quibusdam repellendus.",
"state": "merged",
"created_at": "2016-06-17T07:48:04.330Z",
"updated_at": "2016-07-01T11:14:15.537Z",
"target_branch": "allow_regex_for_project_skip_ref",
"source_branch": "backup",
"upvotes": 0,
"downvotes": 0,
"author": {
"name": "Jarret O'Keefe",
"username": "francisca",
"id": 14,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/a7fa515d53450023c83d62986d0658a8?s=80&d=identicon",
"web_url": "https://gitlab.example.com/francisca",
"discussion_locked": false
},
"assignee": {
"name": "Dr. Gabrielle Strosin",
"username": "barrett.krajcik",
"id": 4,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/733005fcd7e6df12d2d8580171ccb966?s=80&d=identicon",
"web_url": "https://gitlab.example.com/barrett.krajcik"
},
"assignees": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"reviewers": [{
"name": "Miss Monserrate Beier",
"username": "axel.block",
"id": 12,
"state": "active",
"avatar_url": "http://www.gravatar.com/avatar/46f6f7dc858ada7be1853f7fb96e81da?s=80&d=identicon",
"web_url": "https://gitlab.example.com/axel.block"
}],
"source_project_id": 3,
"target_project_id": 3,
"labels": [],
"draft": false,
"work_in_progress": false,
"milestone": {
"id": 27,
"iid": 2,
"project_id": 3,
"title": "v1.0",
"description": "Quis ea accusantium animi hic fuga assumenda.",
"state": "active",
"created_at": "2016-06-17T07:47:33.840Z",
"updated_at": "2016-06-17T07:47:33.840Z",
"due_date": null
},
"merge_when_pipeline_succeeds": false,
"merge_status": "unchecked",
"detailed_merge_status": "not_open",
"subscribed": true,
"sha": "8888888888888888888888888888888888888888",
"merge_commit_sha": null,
"squash_commit_sha": null,
"user_notes_count": 7,
"changes_count": "1",
"should_remove_source_branch": true,
"force_remove_source_branch": false,
"squash": false,
"web_url": "http://example.com/my-group/my-project/merge_requests/1",
"references": {
"short": "!1",
"relative": "!1",
"full": "my-group/my-project!1"
}
},
"target_url": "https://gitlab.example.com/gitlab-org/gitlab-ci/merge_requests/7",
"body": "Et voluptas laudantium minus nihil recusandae ut accusamus earum aut non.",
"state": "pending",
"created_at": "2016-07-01T11:14:15.530Z"
}
获取合并请求差异版本
获取合并请求差异版本列表。
GET /projects/:id/merge_requests/:merge_request_iid/versions
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
字符串 | 是 | 项目的 ID。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
对于响应中的 SHA 的解释,请参见 API 响应中的 SHA。
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/versions"
示例响应:
[{
"id": 110,
"head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
"base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
"start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
"created_at": "2016-07-26T14:44:48.926Z",
"merge_request_id": 105,
"state": "collected",
"real_size": "1",
"patch_id_sha": "d504412d5b6e6739647e752aff8e468dde093f2f"
}, {
"id": 108,
"head_commit_sha": "3eed087b29835c48015768f839d76e5ea8f07a24",
"base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
"start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
"created_at": "2016-07-25T14:21:33.028Z",
"merge_request_id": 105,
"state": "collected",
"real_size": "1",
"patch_id_sha": "72c30d1f0115fc1d2bb0b29b24dc2982cbcdfd32"
}]
API 响应中的 SHA
SHA 字段 | 目的 |
---|---|
base_commit_sha |
源分支和目标分支之间的合并基础提交 SHA。 |
head_commit_sha |
源分支的 HEAD 提交。 |
start_commit_sha |
创建此版本差异时目标分支的 HEAD 提交 SHA。 |
获取单个合并请求差异版本
获取单个合并请求差异版本。
GET /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 。 |
示例请求:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/1/merge_requests/1/versions/1"
示例响应:
{
"id": 110,
"head_commit_sha": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
"base_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
"start_commit_sha": "eeb57dffe83deb686a60a71c16c32f71046868fd",
"created_at": "2016-07-26T14:44:48.926Z",
"merge_request_id": 105,
"state": "collected",
"real_size": "1",
"patch_id_sha": "d504412d5b6e6739647e752aff8e468dde093f2f",
"commits": [{
"id": "33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30",
"short_id": "33e2ee85",
"parent_ids": [],
"title": "Change year to 2018",
"author_name": "Administrator",
"author_email": "admin@example.com",
"authored_date": "2016-07-26T17:44:29.000+03:00",
"committer_name": "Administrator",
"committer_email": "admin@example.com",
"committed_date": "2016-07-26T17:44:29.000+03:00",
"created_at": "2016-07-26T17:44:29.000+03:00",
"message": "Change year to 2018",
"trailers": {},
"extended_trailers": {},
"web_url": "https://gitlab.example.com/project/-/commit/33e2ee8579fda5bc36accc9c6fbd0b4fefda9e30"
}, {
"id": "aa24655de48b36335556ac8a3cd8bb521f977cbd",
"short_id": "aa24655d",
"parent_ids": [],
"title": "Update LICENSE",
"author_name": "Administrator",
"author_email": "admin@example.com",
"authored_date": "2016-07-25T17:21:53.000+03:00",
"committer_name": "Administrator",
"committer_email": "admin@example.com",
"committed_date": "2016-07-25T17:21:53.000+03:00",
"created_at": "2016-07-25T17:21:53.000+03:00",
"message": "Update LICENSE",
"trailers": {},
"extended_trailers": {},
"web_url": "https://gitlab.example.com/project/-/commit/aa24655de48b36335556ac8a3cd8bb521f977cbd"
}, {
"id": "3eed087b29835c48015768f839d76e5ea8f07a24",
"short_id": "3eed087b",
"parent_ids": [],
"title": "Add license",
"author_name": "Administrator",
"author_email": "admin@example.com",
"authored_date": "2016-07-25T17:21:20.000+03:00",
"committer_name": "Administrator",
"committer_email": "admin@example.com",
"committed_date": "2016-07-25T17:21:20.000+03:00",
"created_at": "2016-07-25T17:21:20.000+03:00",
"message": "Add license",
"trailers": {},
"extended_trailers": {},
"web_url": "https://gitlab.example.com/project/-/commit/3eed087b29835c48015768f839d76e5ea8f07a24"
}],
"diffs": [{
"old_path": "LICENSE",
"new_path": "LICENSE",
"a_mode": "0",
"b_mode": "100644",
"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",
"new_file": true,
"renamed_file": false,
"deleted_file": false,
"generated_file": false
}]
}
设置合并请求的时间预估
为此合并请求设置预估工作时间。
POST /projects/:id/merge_requests/:merge_request_iid/time_estimate
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
duration |
字符串 | 是 | 以人类可读格式表示的持续时间,例如 3h30m 。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/time_estimate?duration=3h30m"
示例响应:
{
"human_time_estimate": "3h 30m",
"human_total_time_spent": null,
"time_estimate": 12600,
"total_time_spent": 0
}
重置合并请求的时间预估
将此合并请求的预估时间重置为 0 秒。
POST /projects/:id/merge_requests/:merge_request_iid/reset_time_estimate
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 项目合并请求的内部 ID。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/reset_time_estimate"
示例响应:
{
"human_time_estimate": null,
"human_total_time_spent": null,
"time_estimate": 0,
"total_time_spent": 0
}
添加合并请求的耗时
为此合并请求添加耗时。
POST /projects/:id/merge_requests/:merge_request_iid/add_spent_time
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
duration |
字符串 | 是 | 以人类可读格式表示的持续时间,例如 3h30m 。 |
summary |
字符串 | 否 | 时间的使用情况摘要。 |
curl --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"
示例响应:
{
"human_time_estimate": null,
"human_total_time_spent": "1h",
"time_estimate": 0,
"total_time_spent": 3600
}
重置合并请求的耗时
将此合并请求的总耗时重置为 0 秒。
POST /projects/:id/merge_requests/:merge_request_iid/reset_spent_time
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 项目合并请求的内部 ID。 |
curl --request POST \
--header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/reset_spent_time"
示例响应:
{
"human_time_estimate": null,
"human_total_time_spent": null,
"time_estimate": 0,
"total_time_spent": 0
}
获取时间追踪统计数据
GET /projects/:id/merge_requests/:merge_request_iid/time_stats
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
整数或字符串 | 是 | 项目的 ID 或 URL 编码路径。 |
merge_request_iid |
整数 | 是 | 合并请求的内部 ID。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" \
--url "https://gitlab.example.com/api/v4/projects/5/merge_requests/93/time_stats"
示例响应:
{
"human_time_estimate": "2h",
"human_total_time_spent": "1h",
"time_estimate": 7200,
"total_time_spent": 3600
}
审批
有关审批,请参见 合并请求审批。
列出合并请求状态事件
要跟踪设置的状态、执行者及其发生时间,请查看 资源状态事件 API。
故障排除
新合并请求的空 API 字段
当您创建合并请求时,diff_refs
和 changes_count
字段初始为空。这些字段在您创建合并请求后异步填充。