External Status Checks API
- Tier: 旗舰版
- Offering: JihuLab.com, 私有化部署
获取项目外部状态检查服务
您可以使用以下端点请求有关项目外部状态检查服务的信息:
plaintextGET /projects/:id/external_status_checks
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer | 是 | 项目的 ID |
json1[ 2 { 3 "id": 1, 4 "name": "Compliance Tool", 5 "project_id": 6, 6 "external_url": "https://jihulab.com/example/compliance-tool", 7 "hmac": true, 8 "protected_branches": [ 9 { 10 "id": 14, 11 "project_id": 6, 12 "name": "main", 13 "created_at": "2020-10-12T14:04:50.787Z", 14 "updated_at": "2020-10-12T14:04:50.787Z", 15 "code_owner_approval_required": false 16 } 17 ] 18 } 19]
创建外部状态检查服务
您可以使用以下端点为项目创建新的外部状态检查服务:
plaintextPOST /projects/:id/external_status_checks
外部状态检查会将所有适用的合并请求的信息发送到定义的外部服务。这包括机密合并请求。
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer | 是 | 项目的 ID |
| name | string | 是 | 外部状态检查服务的显示名称 |
| external_url | string | 是 | 外部状态检查服务的 URL |
| shared_secret | string | 否 | 外部状态检查的 HMAC 密钥 |
| protected_branch_ids | array<Integer> | 否 | 要按规则范围限定的受保护分支的 ID |
更新外部状态检查服务
您可以使用以下端点更新项目的现有外部状态检查:
plaintextPUT /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 |
删除外部状态检查服务
您可以使用以下端点删除项目的外部状态检查服务:
plaintextDELETE /projects/:id/external_status_checks/:check_id
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| check_id | integer | 是 | 外部状态检查服务的 ID |
| id | integer | 是 | 项目的 ID |
列出合并请求的状态检查
对于单个合并请求,列出适用于它的外部状态检查服务及其状态。
plaintextGET /projects/:id/merge_requests/:merge_request_iid/status_checks
参数:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer | 是 | 项目的 ID |
| merge_request_iid | integer | 是 | 合并请求的 IID |
json1[ 2 { 3 "id": 2, 4 "name": "Service 1", 5 "external_url": "https://jihulab.com/test-endpoint", 6 "status": "passed" 7 }, 8 { 9 "id": 1, 10 "name": "Service 2", 11 "external_url": "https://jihulab.com/test-endpoint-2", 12 "status": "pending" 13 } 14]
设置外部状态检查的状态
History
- failed 和 passed 的支持在极狐GitLab 15.0 中默认启用。
- 对 pending 的支持在极狐GitLab 16.5 中默认启用。
对于单个合并请求,使用 API 通知极狐GitLab 合并请求已通过外部服务的检查。要设置外部检查的状态,使用的个人访问令牌必须属于合并请求目标项目上至少具有开发者角色的用户。
以有权批准合并请求本身的用户身份执行此 API 调用。
plaintextPOST /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 以使其失败 |
`sha` 必须是合并请求源分支的 `HEAD` 上的 SHA。
重试合并请求的失败状态检查
History
- 在极狐GitLab 15.7 中引入。
对于单个合并请求,重试指定的失败外部状态检查。即使合并请求没有更改,此端点也会将合并请求的当前状态重新发送到定义的外部服务。
plaintextPOST /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。
json{ "message": "202 Accepted" }
如果状态检查已通过,状态码为 422
json{ "message": "External status check must be failed" }
发送到外部服务的示例负载
json1{ 2 "object_kind": "merge_request", 3 "event_type": "merge_request", 4 "user": { 5 "id": 1, 6 "name": "Administrator", 7 "username": "root", 8 "avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon", 9 "email": "[REDACTED]" 10 }, 11 "project": { 12 "id": 6, 13 "name": "Flight", 14 "description": "Ipsa minima est consequuntur quisquam.", 15 "web_url": "http://example.com/flightjs/Flight", 16 "avatar_url": null, 17 "git_ssh_url": "ssh://example.com/flightjs/Flight.git", 18 "git_http_url": "http://example.com/flightjs/Flight.git", 19 "namespace": "Flightjs", 20 "visibility_level": 20, 21 "path_with_namespace": "flightjs/Flight", 22 "default_branch": "main", 23 "ci_config_path": null, 24 "homepage": "http://example.com/flightjs/Flight", 25 "url": "ssh://example.com/flightjs/Flight.git", 26 "ssh_url": "ssh://example.com/flightjs/Flight.git", 27 "http_url": "http://example.com/flightjs/Flight.git" 28 }, 29 "object_attributes": { 30 "assignee_id": null, 31 "author_id": 1, 32 "created_at": "2022-12-07 07:53:43 UTC", 33 "description": "", 34 "head_pipeline_id": 558, 35 "id": 144, 36 "iid": 4, 37 "last_edited_at": null, 38 "last_edited_by_id": null, 39 "merge_commit_sha": null, 40 "merge_error": null, 41 "merge_params": { 42 "force_remove_source_branch": "1" 43 }, 44 "merge_status": "can_be_merged", 45 "merge_user_id": null, 46 "merge_when_pipeline_succeeds": false, 47 "milestone_id": null, 48 "source_branch": "root-main-patch-30152", 49 "source_project_id": 6, 50 "state_id": 1, 51 "target_branch": "main", 52 "target_project_id": 6, 53 "time_estimate": 0, 54 "title": "Update README.md", 55 "updated_at": "2022-12-07 07:53:43 UTC", 56 "updated_by_id": null, 57 "url": "http://example.com/flightjs/Flight/-/merge_requests/4", 58 "source": { 59 "id": 6, 60 "name": "Flight", 61 "description": "Ipsa minima est consequuntur quisquam.", 62 "web_url": "http://example.com/flightjs/Flight", 63 "avatar_url": null, 64 "git_ssh_url": "ssh://example.com/flightjs/Flight.git", 65 "git_http_url": "http://example.com/flightjs/Flight.git", 66 "namespace": "Flightjs", 67 "visibility_level": 20, 68 "path_with_namespace": "flightjs/Flight", 69 "default_branch": "main", 70 "ci_config_path": null, 71 "homepage": "http://example.com/flightjs/Flight", 72 "url": "ssh://example.com/flightjs/Flight.git", 73 "ssh_url": "ssh://example.com/flightjs/Flight.git", 74 "http_url": "http://example.com/flightjs/Flight.git" 75 }, 76 "target": { 77 "id": 6, 78 "name": "Flight", 79 "description": "Ipsa minima est consequuntur quisquam.", 80 "web_url": "http://example.com/flightjs/Flight", 81 "avatar_url": null, 82 "git_ssh_url": "ssh://example.com/flightjs/Flight.git", 83 "git_http_url": "http://example.com/flightjs/Flight.git", 84 "namespace": "Flightjs", 85 "visibility_level": 20, 86 "path_with_namespace": "flightjs/Flight", 87 "default_branch": "main", 88 "ci_config_path": null, 89 "homepage": "http://example.com/flightjs/Flight", 90 "url": "ssh://example.com/flightjs/Flight.git", 91 "ssh_url": "ssh://example.com/flightjs/Flight.git", 92 "http_url": "http://example.com/flightjs/Flight.git" 93 }, 94 "last_commit": { 95 "id": "141be9714669a4c1ccaa013c6a7f3e462ff2a40f", 96 "message": "Update README.md", 97 "title": "Update README.md", 98 "timestamp": "2022-12-07T07:52:11+00:00", 99 "url": "http://example.com/flightjs/Flight/-/commit/141be9714669a4c1ccaa013c6a7f3e462ff2a40f", 100 "author": { 101 "name": "Administrator", 102 "email": "admin@example.com" 103 } 104 }, 105 "work_in_progress": false, 106 "total_time_spent": 0, 107 "time_change": 0, 108 "human_total_time_spent": null, 109 "human_time_change": null, 110 "human_time_estimate": null, 111 "assignee_ids": [ 112 ], 113 "reviewer_ids": [ 114 ], 115 "labels": [ 116 ], 117 "state": "opened", 118 "blocking_discussions_resolved": true, 119 "first_contribution": false, 120 "detailed_merge_status": "mergeable" 121 }, 122 "labels": [ 123 ], 124 "changes": { 125 }, 126 "repository": { 127 "name": "Flight", 128 "url": "ssh://example.com/flightjs/Flight.git", 129 "description": "Ipsa minima est consequuntur quisquam.", 130 "homepage": "http://example.com/flightjs/Flight" 131 }, 132 "external_approval_rule": { 133 "id": 1, 134 "name": "QA", 135 "external_url": "https://example.com/" 136 } 137}