Help us learn about your current experience with the documentation. Take the survey.
合并列车 API
- Tier: Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
使用此 API 与合并列车进行交互。
前提条件:
- 您至少需要拥有 Developer 角色。
列出项目的合并列车
获取指定项目的所有合并列车:
GET /projects/:id/merge_trains
GET /projects/:id/merge_trains?scope=complete使用 page 和 per_page 分页 参数来
控制结果的分页。
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码的项目路径。 |
scope |
string | 否 | 根据给定的范围返回筛选后的合并列车。可用的范围有 active(待合并)和 complete(已合并)。 |
sort |
string | 否 | 返回按 asc 或 desc 顺序排序的合并列车。默认值:desc。 |
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/merge_trains"返回:
403: Forbidden如果项目不可用合并列车404: Not Found如果用户不是私有项目的成员
示例响应:
[
{
"id": 110,
"merge_request": {
"id": 126,
"iid": 59,
"project_id": 20,
"title": "Test MR 1580978354",
"description": "",
"state": "merged",
"created_at": "2020-02-06T08:39:14.883Z",
"updated_at": "2020-02-06T08:40:57.038Z",
"web_url": "http://local.gitlab.test:8181/root/merge-train-race-condition/-/merge_requests/59"
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"web_url": "http://local.gitlab.test:8181/root"
},
"pipeline": {
"id": 246,
"sha": "bcc17a8ffd51be1afe45605e714085df28b80b13",
"ref": "refs/merge-requests/59/train",
"status": "success",
"created_at": "2020-02-06T08:40:42.410Z",
"updated_at": "2020-02-06T08:40:46.912Z",
"web_url": "http://local.gitlab.test:8181/root/merge-train-race-condition/pipelines/246"
},
"created_at": "2020-02-06T08:39:47.217Z",
"updated_at": "2020-02-06T08:40:57.720Z",
"target_branch": "feature-1580973432",
"status": "merged",
"merged_at": "2020-02-06T08:40:57.719Z",
"duration": 70
}
]列出合并列车中的合并请求
获取已添加到指定目标分支的合并列车中的所有合并请求。
GET /projects/:id/merge_trains/:target_branch使用 page 和 per_page 分页 参数来
控制结果的分页。
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码的项目路径。 |
target_branch |
string | 是 | 合并列车的目标分支。 |
scope |
string | 否 | 根据给定的范围返回筛选后的合并列车。可用的范围有 active(待合并)和 complete(已合并)。 |
sort |
string | 否 | 返回按 asc 或 desc 顺序排序的合并列车。默认值:desc。 |
示例请求:
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/597/merge_trains/main"返回:
403: Forbidden如果项目不可用合并列车404: Not Found如果用户不是私有项目的成员
示例响应:
[
{
"id": 267,
"merge_request": {
"id": 273,
"iid": 1,
"project_id": 597,
"title": "My title 9",
"description": null,
"state": "opened",
"created_at": "2022-10-31T19:06:05.725Z",
"updated_at": "2022-10-31T19:06:05.725Z",
"web_url": "http://localhost/namespace18/project21/-/merge_requests/1"
},
"user": {
"id": 933,
"username": "user12",
"name": "Sidney Jones31",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/6c8365de387cb3db10ecc7b1880203c4?s=80\u0026d=identicon",
"web_url": "http://localhost/user12"
},
"pipeline": {
"id": 273,
"iid": 1,
"project_id": 598,
"sha": "b83d6e391c22777fca1ed3012fce84f633d7fed0",
"ref": "main",
"status": "pending",
"source": "push",
"created_at": "2022-10-31T19:06:06.231Z",
"updated_at": "2022-10-31T19:06:06.231Z",
"web_url": "http://localhost/namespace19/project22/-/pipelines/273"
},
"created_at": "2022-10-31T19:06:06.237Z",
"updated_at":"2022-10-31T19:06:06.237Z",
"target_branch":"main",
"status":"idle",
"merged_at":null,
"duration":null
}
]获取合并请求在合并列车上的状态
获取指定合并请求的合并列车信息。
GET /projects/:id/merge_trains/merge_requests/:merge_request_iid使用 page 和 per_page 分页 参数来
控制结果的分页。
支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码的项目路径。 |
merge_request_iid |
integer | 是 | 合并请求的内部 ID。 |
示例请求:
curl --request GET --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/597/merge_trains/merge_requests/1"返回:
403: Forbidden如果项目不可用合并列车404: Not Found如果用户不是私有项目的成员
示例响应:
{
"id": 267,
"merge_request": {
"id": 273,
"iid": 1,
"project_id": 597,
"title": "My title 9",
"description": null,
"state": "opened",
"created_at": "2022-10-31T19:06:05.725Z",
"updated_at": "2022-10-31T19:06:05.725Z",
"web_url": "http://localhost/namespace18/project21/-/merge_requests/1"
},
"user": {
"id": 933,
"username": "user12",
"name": "Sidney Jones31",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/6c8365de387cb3db10ecc7b1880203c4?s=80\u0026d=identicon",
"web_url": "http://localhost/user12"
},
"pipeline": {
"id": 273,
"iid": 1,
"project_id": 598,
"sha": "b83d6e391c22777fca1ed3012fce84f633d7fed0",
"ref": "main",
"status": "pending",
"source": "push",
"created_at": "2022-10-31T19:06:06.231Z",
"updated_at": "2022-10-31T19:06:06.231Z",
"web_url": "http://localhost/namespace19/project22/-/pipelines/273"
},
"created_at": "2022-10-31T19:06:06.237Z",
"updated_at":"2022-10-31T19:06:06.237Z",
"target_branch":"main",
"status":"idle",
"merged_at":null,
"duration":null
}将合并请求添加到合并列车
将合并请求添加到以其目标分支为目标的合并列车中。
POST /projects/:id/merge_trains/merge_requests/:merge_request_iid支持的属性:
| 属性 | 类型 | 是否必需 | 描述 |
|---|---|---|---|
id |
integer/string | 是 | 项目的 ID 或 URL 编码的项目路径。 |
merge_request_iid |
integer | 是 | 合并请求的内部 ID。 |
auto_merge |
boolean | 否 | 如果为 true,则在检查通过后,合并请求会被添加到合并列车。如果为 false 或未指定,合并请求会直接添加到合并列车。 |
sha |
string | 否 | 如果存在,则 SHA 必须与源分支的 HEAD 匹配,否则合并将失败。 |
squash |
boolean | 否 | 如果为 true,则在合并时会将多个提交压缩(squash)为一个提交。 |
when_pipeline_succeeds |
boolean | 否 | 在 GitLab 17.11 中已弃用。请改用 auto_merge。 |
示例请求:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/597/merge_trains/merge_requests/1"返回:
403: Forbidden如果项目不可用合并列车
示例响应:
[
{
"id": 267,
"merge_request": {
"id": 273,
"iid": 1,
"project_id": 597,
"title": "My title 9",
"description": null,
"state": "opened",
"created_at": "2022-10-31T19:06:05.725Z",
"updated_at": "2022-10-31T19:06:05.725Z",
"web_url": "http://localhost/namespace18/project21/-/merge_requests/1"
},
"user": {
"id": 933,
"username": "user12",
"name": "Sidney Jones31",
"state": "active",
"avatar_url": "https://www.gravatar.com/avatar/6c8365de387cb3db10ecc7b1880203c4?s=80\u0026d=identicon",
"web_url": "http://localhost/user12"
},
"pipeline": {
"id": 273,
"iid": 1,
"project_id": 598,
"sha": "b83d6e391c22777fca1ed3012fce84f633d7fed0",
"ref": "main",
"status": "pending",
"source": "push",
"created_at": "2022-10-31T19:06:06.231Z",
"updated_at": "2022-10-31T19:06:06.231Z",
"web_url": "http://localhost/namespace19/project22/-/pipelines/273"
},
"created_at": "2022-10-31T19:06:06.237Z",
"updated_at":"2022-10-31T19:06:06.237Z",
"target_branch":"main",
"status":"idle",
"merged_at":null,
"duration":null
}
]