{{< details >}}
- Tier: 专业版,旗舰版
- Offering: JihuLab.com, 私有化部署
{{< /details >}}
每个 合并列车 的 API 调用必须至少具有开发者 角色 的身份验证。
如果用户不是项目成员并且项目是私有的,对该项目的 GET
请求将返回 404
状态码。
如果项目不可用合并列车,则返回 403
状态码。
合并列车 API 分页
默认情况下,GET
请求一次返回 20 个结果,因为 API 结果是分页的。
有关更多信息,请参见 分页。
列出项目的合并列车
获取请求项目的所有合并列车:
GET /projects/:id/merge_trains
GET /projects/:id/merge_trains?scope=complete
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
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"
示例响应:
[
{
"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": "**管理员**",
"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
支持的属性:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
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"
示例响应:
[
{
"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
支持的属性:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
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"
示例响应:
{
"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,提交在合并时被压缩为一个单一提交。 |
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"
示例响应:
[
{
"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
}
]