更新仓库WebHook¶
PATCH /api/v5/repos/{owner}/{repo}/hooks/{id}
该接口用于更新指定仓库下的某个 WebHook,可修改其远程通知 URL、加密类型与请求密码,并配置各事件类型的触发开关,如代码推送、标签提交、Issue 创建或关闭、评论及合并请求等。
访问令牌支持说明¶
- AtomGit 用户访问令牌(AtomGit user access tokens)
是否允许匿名访问¶
此接口不允许匿名访问
请求参数¶
| 参数名 | 位置 | 类型 | 必填 | 说明 |
|---|---|---|---|---|
owner |
path | string | 是 | 仓库所属空间地址(企业、组织或个人的地址path) |
repo |
path | string | 是 | 仓库路径(path) |
id |
path | integer | 是 | Webhook的ID |
access_token |
query | string | 是 | 用户授权码 |
Request Body:
请求体为 WebHook 的更新信息,采用 JSON 格式:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"url": {
"description": "远程HTTP URL",
"type": "string"
},
"encryption_type": {
"description": "加密类型:0 密码,1 签名密钥",
"type": "integer",
"enum": [0, 1]
},
"password": {
"description": "请求URL时会带上该密码,防止URL被恶意请求",
"type": "string"
},
"push_events": {
"description": "Push代码到仓库",
"type": "boolean"
},
"tag_push_events": {
"description": "提交Tag到仓库",
"type": "boolean"
},
"issues_events": {
"description": "创建/关闭Issue",
"type": "boolean"
},
"note_events": {
"description": "评论了Issue/代码等等",
"type": "boolean"
},
"merge_requests_events": {
"description": "合并请求和合并后",
"type": "boolean"
}
},
"required": ["url"]
}
响应参数¶
| 字段 | 类型 | 必返 | 可为空 | 说明 |
|---|---|---|---|---|
id |
integer | 是 | 否 | WebHook的ID |
url |
string | 是 | 是 | 远程HTTP URL |
password |
string | 是 | 是 | 请求URL时携带的密码,防止URL被恶意请求 |
result |
string | 是 | 是 | 推送结果信息,可能为 null |
project_id |
integer | 是 | 是 | 项目ID |
result_code |
integer | 是 | 是 | 结果码 |
push_events |
boolean | 是 | 是 | 是否推送代码到仓库 |
tag_push_events |
boolean | 是 | 是 | 是否提交Tag到仓库 |
issues_events |
boolean | 是 | 是 | 是否创建/关闭Issue |
note_events |
boolean | 是 | 是 | 是否评论Issue/代码等等 |
merge_requests_events |
boolean | 是 | 是 | 是否在合并请求和合并后触发 |
created_at |
string | 是 | 是 | 创建时间 |
active |
boolean | 是 | 是 | 是否启用 |
失败响应¶
400 参数错误
401 未认证
HTTP 响应状态码¶
| 状态码 | 说明 |
|---|---|
200 |
成功(OK) |
401 |
需要认证(Requires authentication) |
403 |
禁止访问(Forbidden) |
404 |
资源不存在(Not found) |
429 |
请求过于频繁,触发限流(Rate limited) |
500 |
系统内部错误(Internal server error) |
请求示例¶
参数说明¶
<owner>替换为仓库所属空间地址(企业、组织或个人的地址 path);<repo>替换为仓库路径(path);<id>替换为要更新的 WebHook 的 ID;<token>替换为你的 AtomGit 用户访问令牌。
cURL¶
curl -X PATCH 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/hooks/<id>?access_token=<token>' \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"url": "https://api.atomgit.com/webhooks/notify",
"encryption_type": 0,
"password": "123456",
"push_events": true,
"tag_push_events": false,
"issues_events": false,
"note_events": false,
"merge_requests_events": false
}'
JavaScript¶
// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/hooks/<id>?access_token=<token>", {
method: "PATCH",
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://api.atomgit.com/webhooks/notify",
push_events: true,
tag_push_events: false,
issues_events: false,
note_events: false,
merge_requests_events: false,
}),
});
if (!response.ok) {
throw new Error(`请求失败: ${response.status}`);
}
const data = await response.json();
console.log(data);
Python¶
import requests
resp = requests.patch(
"https://api.atomgit.com/api/v5/repos/<owner>/<repo>/hooks/<id>",
params={"access_token": "<token>"},
headers={
"Accept": "application/json",
"Content-Type": "application/json",
},
json={
"url": "https://api.atomgit.com/webhooks/notify",
"push_events": True,
"tag_push_events": False,
"issues_events": False,
"note_events": False,
"merge_requests_events": False,
},
timeout=10,
)
resp.raise_for_status()
print(resp.json())
响应示例¶
状态码: 200
{
"id": 282463,
"url": "https://api.atomgit.com/webhooks/notify",
"password": "123445",
"result": null,
"project_id": 282463,
"result_code": 0,
"push_events": false,
"tag_push_events": false,
"issues_events": true,
"note_events": false,
"merge_requests_events": true,
"created_at": "2024-09-26T16:13:27+08:00",
"active": true
}
错误码¶
| 错误码 | 说明 |
|---|---|
401 |
未认证或凭证无效(缺少/无效的访问凭证) |
400 |
参数错误或请求无法解析 |
404 |
请求路径不存在 |
405 |
请求方法不支持 |
429 |
请求过于频繁,触发限流 |
500 |
系统内部错误 |
本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc