此版本的 GitHub Enterprise 已停止服务 2022-06-03. 即使针对重大安全问题,也不会发布补丁。 要获得更好的性能、改进的安全性和新功能,请升级到 GitHub Enterprise 的最新版本。 如需升级方面的帮助,请联系 GitHub Enterprise 支持。
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.
预接收挂钩
预接收挂钩 API 允许您创建、列出、更新和� 除预接收挂钩。
它只适用于经过身份验证的站点管理员。普通用户尝试访问它时会收到 404
响应。
对象属性
预接收挂钩
名称 | 类型 | 描述 |
---|---|---|
name | 字符串 | 挂钩的名称。 |
script | 字符串 | 挂钩运行的脚本。 |
script_repository | 对象 | 保存脚本的 GitHub 仓库。 |
environment | 对象 | 执行脚本的预接收环境。 |
enforcement | 字符串 | 此挂钩的实施状态。 |
allow_downstream_configuration | 布尔值 | 是否可以在组织或仓库级别上覆盖实施。 |
enforcement 的可能值包括 enabled
、disabled
和 testing
。 disabled
表示预接收挂钩不会运行。 enabled
表示它将运行并拒绝会导致非零状态的任何推送。 testing
表示脚本将运行,但不会导致任何推送被拒绝。
List pre-receive hooks
参数
� �头 |
---|
名称, 类型, 描述 |
accept stringSetting to |
查询参数 |
名称, 类型, 描述 |
per_page integerThe number of results per page (max 100). 默认值: |
page integerPage number of the results to fetch. 默认值: |
direction stringThe direction to sort the results by. 默认值: 可以是以下其中之一: |
sort stringThe property to sort the results by. 默认值: 可以是以下其中之一: |
HTTP 响应状态代� �
状态代� � | 描述 |
---|---|
200 | OK |
代� �示例
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks
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": 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
}
]
预览通知
APIs for managing pre-receive hooks are currently available for developers to preview. During the preview period, the APIs may change without advance notice.
To access the API you must provide a custom media type in the Accept
header:
application/vnd.github.eye-scream-preview
Create a pre-receive hook
参数
� �头 |
---|
名称, 类型, 描述 |
accept stringSetting to |
正文参数 |
名称, 类型, 描述 |
name string必选The name of the hook. |
script string必选The script that the hook runs. |
script_repository object必选The GitHub repository where the script is kept. |
environment object必选The pre-receive environment where the script is executed. |
enforcement stringThe state of enforcement for this hook. default: |
allow_downstream_configuration booleanWhether enforcement can be overridden at the org or repo level. default: |
HTTP 响应状态代� �
状态代� � | 描述 |
---|---|
201 | Created |
代� �示例
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <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
}
预览通知
APIs for managing pre-receive hooks are currently available for developers to preview. During the preview period, the APIs may change without advance notice.
To access the API you must provide a custom media type in the Accept
header:
application/vnd.github.eye-scream-preview
Get a pre-receive hook
参数
� �头 |
---|
名称, 类型, 描述 |
accept stringSetting to |
路径参数 |
名称, 类型, 描述 |
pre_receive_hook_id integer必选The unique identifier of the pre-receive hook. |
HTTP 响应状态代� �
状态代� � | 描述 |
---|---|
200 | OK |
代� �示例
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID
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": 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
}
预览通知
APIs for managing pre-receive hooks are currently available for developers to preview. During the preview period, the APIs may change without advance notice.
To access the API you must provide a custom media type in the Accept
header:
application/vnd.github.eye-scream-preview
Update a pre-receive hook
参数
� �头 |
---|
名称, 类型, 描述 |
accept stringSetting to |
路径参数 |
名称, 类型, 描述 |
pre_receive_hook_id integer必选The unique identifier of the pre-receive hook. |
正文参数 |
名称, 类型, 描述 |
name stringThe name of the hook. |
script stringThe script that the hook runs. |
script_repository objectThe GitHub repository where the script is kept. |
environment objectThe pre-receive environment where the script is executed. |
enforcement stringThe state of enforcement for this hook. |
allow_downstream_configuration booleanWhether enforcement can be overridden at the org or repo level. |
HTTP 响应状态代� �
状态代� � | 描述 |
---|---|
200 | OK |
代� �示例
curl \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <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
}
预览通知
APIs for managing pre-receive hooks are currently available for developers to preview. During the preview period, the APIs may change without advance notice.
To access the API you must provide a custom media type in the Accept
header:
application/vnd.github.eye-scream-preview
Delete a pre-receive hook
参数
� �头 |
---|
名称, 类型, 描述 |
accept stringSetting to |
路径参数 |
名称, 类型, 描述 |
pre_receive_hook_id integer必选The unique identifier of the pre-receive hook. |
HTTP 响应状态代� �
状态代� � | 描述 |
---|---|
204 | No Content |
代� �示例
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID
Response
Status: 204
预览通知
APIs for managing pre-receive hooks are currently available for developers to preview. During the preview period, the APIs may change without advance notice.
To access the API you must provide a custom media type in the Accept
header:
application/vnd.github.eye-scream-preview