We've recently moved some of the REST API documentation. If you can't find what you're looking for, you might try the Actions REST API page.
预接收挂钩
使用 REST API 创建、列出、更新和删除预接收挂钩。
关于预接收挂钩
这些终结点仅适用于经过身份验证的网站管理员。 普通用户将收到 404 响应。
对象属性
预接收挂钩
| 名称 | 类型 | 说明 |
|---|---|---|
name | string | 挂钩的名称。 |
script | string | 挂钩运行的脚本。 |
script_repository | object | 保存脚本的 GitHub 仓库。 |
environment | object | 执行脚本的预接收环境。 |
enforcement | string | 此挂钩的实施状态。 |
allow_downstream_configuration | boolean | 是否可以在组织或仓库级别上覆盖实施。 |
强制执行的可能值为 enabled、disabled 和 testing。 disabled 表示预接收挂钩不会运行。 enabled 表示它将运行并拒绝任何导致非零状态的推送。 testing 表示脚本将运行但不会导致任何推送被拒绝。
List pre-receive hooks
Parameters
| Headers |
|---|
| 名称, Type, 说明 |
acceptstringSetting to |
| Query parameters |
| 名称, Type, 说明 |
per_pageintegerThe number of results per page (max 100). Default: |
pageintegerPage number of the results to fetch. Default: |
directionstringThe direction to sort the results by. Default: Can be one of: |
sortstringThe property to sort the results by. Default: Can be one of: |
HTTP response status codes
| Status code | 说明 |
|---|---|
200 | OK |
Code samples
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooksResponse
Status: 200[
{
"id": 1,
"name": "Check Commits",
"enforcement": "disabled",
"script": "scripts/commmit_check.sh",
"script_repository": {
"id": 595,
"full_name": "DevIT/hooks",
"url": "https://github.example.com/api/v3/repos/DevIT/hooks",
"html_url": "https://github.example.com/DevIT/hooks"
},
"environment": {
"id": 2,
"name": "DevTools Hook Env",
"image_url": "https://my_file_server/path/to/devtools_env.tar.gz",
"url": "https://github.example.com/api/v3/admin/pre-receive-environments/2",
"html_url": "https://github.example.com/admin/pre-receive-environments/2",
"default_environment": false,
"created_at": "2016-05-20T11:35:45-05:00",
"hooks_count": 1,
"download": {
"url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest",
"state": "success",
"downloaded_at": "2016-05-26T07:42:53-05:00",
"message": null
}
},
"allow_downstream_configuration": false
}
]Create a pre-receive hook
Parameters
| Headers |
|---|
| 名称, Type, 说明 |
acceptstringSetting to |
| Body parameters |
| 名称, Type, 说明 |
namestringRequiredThe name of the hook. |
scriptstringRequiredThe script that the hook runs. |
script_repositoryobjectRequiredThe GitHub repository where the script is kept. |
environmentobjectRequiredThe pre-receive environment where the script is executed. |
enforcementstringThe state of enforcement for this hook. default: |
allow_downstream_configurationbooleanWhether enforcement can be overridden at the org or repo level. default: |
HTTP response status codes
| Status code | 说明 |
|---|---|
201 | Created |
Code samples
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks \
-d '{"name":"Check Commits","script":"scripts/commit_check.sh","enforcement":"disabled","allow_downstream_configuration":false,"script_repository":{"full_name":"DevIT/hooks"},"environment":{"id":2}}'Response
Status: 201{
"id": 1,
"name": "Check Commits",
"enforcement": "disabled",
"script": "scripts/commmit_check.sh",
"script_repository": {
"id": 595,
"full_name": "DevIT/hooks",
"url": "https://github.example.com/api/v3/repos/DevIT/hooks",
"html_url": "https://github.example.com/DevIT/hooks"
},
"environment": {
"id": 2,
"name": "DevTools Hook Env",
"image_url": "https://my_file_server/path/to/devtools_env.tar.gz",
"url": "https://github.example.com/api/v3/admin/pre-receive-environments/2",
"html_url": "https://github.example.com/admin/pre-receive-environments/2",
"default_environment": false,
"created_at": "2016-05-20T11:35:45-05:00",
"hooks_count": 1,
"download": {
"url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest",
"state": "success",
"downloaded_at": "2016-05-26T07:42:53-05:00",
"message": null
}
},
"allow_downstream_configuration": false
}Get a pre-receive hook
Parameters
| Headers |
|---|
| 名称, Type, 说明 |
acceptstringSetting to |
| Path parameters |
| 名称, Type, 说明 |
pre_receive_hook_idintegerRequiredThe unique identifier of the pre-receive hook. |
HTTP response status codes
| Status code | 说明 |
|---|---|
200 | OK |
Code samples
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_IDResponse
Status: 200{
"id": 1,
"name": "Check Commits",
"enforcement": "disabled",
"script": "scripts/commmit_check.sh",
"script_repository": {
"id": 595,
"full_name": "DevIT/hooks",
"url": "https://github.example.com/api/v3/repos/DevIT/hooks",
"html_url": "https://github.example.com/DevIT/hooks"
},
"environment": {
"id": 2,
"name": "DevTools Hook Env",
"image_url": "https://my_file_server/path/to/devtools_env.tar.gz",
"url": "https://github.example.com/api/v3/admin/pre-receive-environments/2",
"html_url": "https://github.example.com/admin/pre-receive-environments/2",
"default_environment": false,
"created_at": "2016-05-20T11:35:45-05:00",
"hooks_count": 1,
"download": {
"url": "https://github.example.com/api/v3/admin/pre-receive-environments/2/downloads/latest",
"state": "success",
"downloaded_at": "2016-05-26T07:42:53-05:00",
"message": null
}
},
"allow_downstream_configuration": false
}Update a pre-receive hook
Parameters
| Headers |
|---|
| 名称, Type, 说明 |
acceptstringSetting to |
| Path parameters |
| 名称, Type, 说明 |
pre_receive_hook_idintegerRequiredThe unique identifier of the pre-receive hook. |
| Body parameters |
| 名称, Type, 说明 |
namestringThe name of the hook. |
scriptstringThe script that the hook runs. |
script_repositoryobjectThe GitHub repository where the script is kept. |
environmentobjectThe pre-receive environment where the script is executed. |
enforcementstringThe state of enforcement for this hook. |
allow_downstream_configurationbooleanWhether enforcement can be overridden at the org or repo level. |
HTTP response status codes
| Status code | 说明 |
|---|---|
200 | OK |
Code samples
curl \
-X PATCH \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID \
-d '{"name":"Check Commits","environment":{"id":1},"allow_downstream_configuration":true}'Response
Status: 200{
"id": 1,
"name": "Check Commits",
"enforcement": "disabled",
"script": "scripts/commmit_check.sh",
"script_repository": {
"id": 595,
"full_name": "DevIT/hooks",
"url": "https://github.example.com/api/v3/repos/DevIT/hooks",
"html_url": "https://github.example.com/DevIT/hooks"
},
"environment": {
"id": 1,
"name": "Default",
"image_url": "githubenterprise://internal",
"url": "https://github.example.com/api/v3/admin/pre-receive-environments/1",
"html_url": "https://github.example.com/admin/pre-receive-environments/1",
"default_environment": true,
"created_at": "2016-05-20T11:35:45-05:00",
"hooks_count": 1,
"download": {
"url": "https://github.example.com/api/v3/admin/pre-receive-environments/1/downloads/latest",
"state": "success",
"downloaded_at": "2016-05-26T07:42:53-05:00",
"message": null
}
},
"allow_downstream_configuration": true
}Delete a pre-receive hook
Parameters
| Headers |
|---|
| 名称, Type, 说明 |
acceptstringSetting to |
| Path parameters |
| 名称, Type, 说明 |
pre_receive_hook_idintegerRequiredThe unique identifier of the pre-receive hook. |
HTTP response status codes
| Status code | 说明 |
|---|---|
204 | No Content |
Code samples
curl \
-X DELETE \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_IDResponse
Status: 204