- 获取项目外部状态检查服务
- 创建外部状态检查服务
- 更新外部状态检查服务
- 删除外部状态检查服务
- 列出合并请求的状态检查
- 设置外部状态检查的状态
- 重试合并请求的失败状态检查
- 响应
- 发送到外部服务的示例负载
- 相关主题
{{< details >}}
- Tier: 旗舰版
- Offering: JihuLab.com, 私有化部署
{{< /details >}}
获取项目外部状态检查服务
您可以使用以下端点请求有关项目外部状态检查服务的信息:
GET /projects/:id/external_status_checks
参数:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer | 是 | 项目的 ID |
[
{
"id": 1,
"name": "Compliance Tool",
"project_id": 6,
"external_url": "https://jihulab.com/example/compliance-tool",
"hmac": true,
"protected_branches": [
{
"id": 14,
"project_id": 6,
"name": "main",
"created_at": "2020-10-12T14:04:50.787Z",
"updated_at": "2020-10-12T14:04:50.787Z",
"code_owner_approval_required": false
}
]
}
]
创建外部状态检查服务
您可以使用以下端点为项目创建新的外部状态检查服务:
POST /projects/:id/external_status_checks
{{< alert type=”warning” >}}
外部状态检查会将所有适用的合并请求的信息发送到定义的外部服务。这包括机密合并请求。
{{< /alert >}}
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer | 是 | 项目的 ID |
name |
string | 是 | 外部状态检查服务的显示名称 |
external_url |
string | 是 | 外部状态检查服务的 URL |
shared_secret |
string | 否 | 外部状态检查的 HMAC 密钥 |
protected_branch_ids |
array<Integer> |
否 | 要按规则范围限定的受保护分支的 ID |
更新外部状态检查服务
您可以使用以下端点更新项目的现有外部状态检查:
PUT /projects/:id/external_status_checks/:check_id
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer | 是 | 项目的 ID |
check_id |
integer | 是 | 外部状态检查服务的 ID |
name |
string | 否 | 外部状态检查服务的显示名称 |
external_url |
string | 否 | 外部状态检查服务的 URL |
shared_secret |
string | 否 | 外部状态检查的 HMAC 密钥 |
protected_branch_ids |
array<Integer> |
否 | 要按规则范围限定的受保护分支的 ID |
删除外部状态检查服务
您可以使用以下端点删除项目的外部状态检查服务:
DELETE /projects/:id/external_status_checks/:check_id
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
check_id |
integer | 是 | 外部状态检查服务的 ID |
id |
integer | 是 | 项目的 ID |
列出合并请求的状态检查
对于单个合并请求,列出适用于它的外部状态检查服务及其状态。
GET /projects/:id/merge_requests/:merge_request_iid/status_checks
参数:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer | 是 | 项目的 ID |
merge_request_iid |
integer | 是 | 合并请求的 IID |
[
{
"id": 2,
"name": "Service 1",
"external_url": "https://jihulab.com/test-endpoint",
"status": "passed"
},
{
"id": 1,
"name": "Service 2",
"external_url": "https://jihulab.com/test-endpoint-2",
"status": "pending"
}
]
设置外部状态检查的状态
{{< history >}}
-
failed
和passed
的支持在极狐GitLab 15.0 中默认启用。 - 对
pending
的支持在极狐GitLab 16.5 中默认启用。
{{< /history >}}
对于单个合并请求,使用 API 通知极狐GitLab 合并请求已通过外部服务的检查。要设置外部检查的状态,使用的个人访问令牌必须属于合并请求目标项目上至少具有开发者角色的用户。
以有权批准合并请求本身的用户身份执行此 API 调用。
POST /projects/:id/merge_requests/:merge_request_iid/status_check_responses
参数:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer | 是 | 项目的 ID |
merge_request_iid |
integer | 是 | 合并请求的 IID |
sha |
string | 是 | 源分支的 HEAD 上的 SHA |
external_status_check_id |
integer | 是 | 外部状态检查的 ID |
status |
string | 否 | 设置为 pending 以标记检查为待处理,设置为 passed 以通过检查,或设置为 failed 以使其失败 |
{{< alert type=”note” >}}
sha
必须是合并请求源分支的 HEAD
上的 SHA。
{{< /alert >}}
重试合并请求的失败状态检查
{{< history >}}
- 在极狐GitLab 15.7 中引入。
{{< /history >}}
对于单个合并请求,重试指定的失败外部状态检查。即使合并请求没有更改,此端点也会将合并请求的当前状态重新发送到定义的外部服务。
POST /projects/:id/merge_requests/:merge_request_iid/status_checks/:external_status_check_id/retry
参数:
属性 | 类型 | 必需 | 描述 |
---|---|---|---|
id |
integer | 是 | 项目的 ID |
merge_request_iid |
integer | 是 | 合并请求的 IID |
external_status_check_id |
integer | 是 | 失败的外部状态检查的 ID |
响应
成功时状态码为 202。
{
"message": "202 Accepted"
}
如果状态检查已通过,状态码为 422
{
"message": "External status check must be failed"
}
发送到外部服务的示例负载
{
"object_kind": "merge_request",
"event_type": "merge_request",
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"email": "[REDACTED]"
},
"project": {
"id": 6,
"name": "Flight",
"description": "Ipsa minima est consequuntur quisquam.",
"web_url": "http://example.com/flightjs/Flight",
"avatar_url": null,
"git_ssh_url": "ssh://example.com/flightjs/Flight.git",
"git_http_url": "http://example.com/flightjs/Flight.git",
"namespace": "Flightjs",
"visibility_level": 20,
"path_with_namespace": "flightjs/Flight",
"default_branch": "main",
"ci_config_path": null,
"homepage": "http://example.com/flightjs/Flight",
"url": "ssh://example.com/flightjs/Flight.git",
"ssh_url": "ssh://example.com/flightjs/Flight.git",
"http_url": "http://example.com/flightjs/Flight.git"
},
"object_attributes": {
"assignee_id": null,
"author_id": 1,
"created_at": "2022-12-07 07:53:43 UTC",
"description": "",
"head_pipeline_id": 558,
"id": 144,
"iid": 4,
"last_edited_at": null,
"last_edited_by_id": null,
"merge_commit_sha": null,
"merge_error": null,
"merge_params": {
"force_remove_source_branch": "1"
},
"merge_status": "can_be_merged",
"merge_user_id": null,
"merge_when_pipeline_succeeds": false,
"milestone_id": null,
"source_branch": "root-main-patch-30152",
"source_project_id": 6,
"state_id": 1,
"target_branch": "main",
"target_project_id": 6,
"time_estimate": 0,
"title": "Update README.md",
"updated_at": "2022-12-07 07:53:43 UTC",
"updated_by_id": null,
"url": "http://example.com/flightjs/Flight/-/merge_requests/4",
"source": {
"id": 6,
"name": "Flight",
"description": "Ipsa minima est consequuntur quisquam.",
"web_url": "http://example.com/flightjs/Flight",
"avatar_url": null,
"git_ssh_url": "ssh://example.com/flightjs/Flight.git",
"git_http_url": "http://example.com/flightjs/Flight.git",
"namespace": "Flightjs",
"visibility_level": 20,
"path_with_namespace": "flightjs/Flight",
"default_branch": "main",
"ci_config_path": null,
"homepage": "http://example.com/flightjs/Flight",
"url": "ssh://example.com/flightjs/Flight.git",
"ssh_url": "ssh://example.com/flightjs/Flight.git",
"http_url": "http://example.com/flightjs/Flight.git"
},
"target": {
"id": 6,
"name": "Flight",
"description": "Ipsa minima est consequuntur quisquam.",
"web_url": "http://example.com/flightjs/Flight",
"avatar_url": null,
"git_ssh_url": "ssh://example.com/flightjs/Flight.git",
"git_http_url": "http://example.com/flightjs/Flight.git",
"namespace": "Flightjs",
"visibility_level": 20,
"path_with_namespace": "flightjs/Flight",
"default_branch": "main",
"ci_config_path": null,
"homepage": "http://example.com/flightjs/Flight",
"url": "ssh://example.com/flightjs/Flight.git",
"ssh_url": "ssh://example.com/flightjs/Flight.git",
"http_url": "http://example.com/flightjs/Flight.git"
},
"last_commit": {
"id": "141be9714669a4c1ccaa013c6a7f3e462ff2a40f",
"message": "Update README.md",
"title": "Update README.md",
"timestamp": "2022-12-07T07:52:11+00:00",
"url": "http://example.com/flightjs/Flight/-/commit/141be9714669a4c1ccaa013c6a7f3e462ff2a40f",
"author": {
"name": "Administrator",
"email": "admin@example.com"
}
},
"work_in_progress": false,
"total_time_spent": 0,
"time_change": 0,
"human_total_time_spent": null,
"human_time_change": null,
"human_time_estimate": null,
"assignee_ids": [
],
"reviewer_ids": [
],
"labels": [
],
"state": "opened",
"blocking_discussions_resolved": true,
"first_contribution": false,
"detailed_merge_status": "mergeable"
},
"labels": [
],
"changes": {
},
"repository": {
"name": "Flight",
"url": "ssh://example.com/flightjs/Flight.git",
"description": "Ipsa minima est consequuntur quisquam.",
"homepage": "http://example.com/flightjs/Flight"
},
"external_approval_rule": {
"id": 1,
"name": "QA",
"external_url": "https://example.com/"
}
}