Skip to main content
We publish frequent updates to our documentation, and translation of this page may still be in progress. For the most current information, please visit the English documentation.

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 查看和修改存储库可用的预接收挂钩的强制执行。

关于存储库预接收挂钩

名称类型说明
namestring挂钩的名称。
enforcementstring此仓库中挂钩的实施状态。
configuration_urlstring设置实施的端点 URL。

强制执行的可能值为 enableddisabledtestingdisabled 表示预接收挂钩不会运行。 enabled 表示它将运行并拒绝任何导致非零状态的推送。 testing 表示脚本将运行但不会导致任何推送被拒绝。

configuration_url 可能是此存储库、其组织所有者或全局配置的链接。 configuration_url 终结点的访问授权在所有者或站点管理员级别确定。

List pre-receive hooks for a repository

Works with GitHub Apps

List all pre-receive hooks that are enabled or testing for this repository as well as any disabled hooks that are allowed to be enabled at the repository level. Pre-receive hooks that are disabled at a higher level and are not configurable will not be listed.

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

Query parameters
名称, Type, 说明
per_pageinteger

The number of results per page (max 100).

Default: 30

pageinteger

Page number of the results to fetch.

Default: 1

directionstring

The direction to sort the results by.

Default: desc

Can be one of: asc, desc

sortstring

Default: created

Can be one of: created, updated, name

HTTP response status codes

Status code说明
200

OK

Code samples

get/repos/{owner}/{repo}/pre-receive-hooks
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/pre-receive-hooks

Response

Status: 200
[ { "id": 42, "name": "Check Commits", "enforcement": "disabled", "configuration_url": "https://github.example.com/api/v3/orgs/octocat/pre-receive-hooks/42" } ]

Get a pre-receive hook for a repository

Works with GitHub Apps

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

pre_receive_hook_idintegerRequired

The unique identifier of the pre-receive hook.

HTTP response status codes

Status code说明
200

OK

Code samples

get/repos/{owner}/{repo}/pre-receive-hooks/{pre_receive_hook_id}
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/pre-receive-hooks/PRE_RECEIVE_HOOK_ID

Response

Status: 200
{ "id": 42, "name": "Check Commits", "enforcement": "disabled", "configuration_url": "https://github.example.com/api/v3/orgs/octocat/pre-receive-hooks/42" }

Update pre-receive hook enforcement for a repository

Works with GitHub Apps

For pre-receive hooks which are allowed to be configured at the repo level, you can set enforcement

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

pre_receive_hook_idintegerRequired

The unique identifier of the pre-receive hook.

Body parameters
名称, Type, 说明
enforcementstring

The state of enforcement for the hook on this repository.

Can be one of: enabled, disabled, testing

HTTP response status codes

Status code说明
200

OK

Code samples

patch/repos/{owner}/{repo}/pre-receive-hooks/{pre_receive_hook_id}
curl \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/pre-receive-hooks/PRE_RECEIVE_HOOK_ID \ -d '{"enforcement":"enabled"}'

Response

Status: 200
{ "id": 42, "name": "Check Commits", "enforcement": "enabled", "configuration_url": "https://github.example.com/api/v3/repos/octocat/hello-world/pre-receive-hooks/42" }

Remove pre-receive hook enforcement for a repository

Works with GitHub Apps

Deletes any overridden enforcement on this repository for the specified hook.

Responds with effective values inherited from owner and/or global level.

Parameters

Headers
名称, Type, 说明
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
名称, Type, 说明
ownerstringRequired

The account owner of the repository. The name is not case sensitive.

repostringRequired

The name of the repository. The name is not case sensitive.

pre_receive_hook_idintegerRequired

The unique identifier of the pre-receive hook.

HTTP response status codes

Status code说明
200

Responds with effective values inherited from owner and/or global level.

Code samples

delete/repos/{owner}/{repo}/pre-receive-hooks/{pre_receive_hook_id}
curl \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/pre-receive-hooks/PRE_RECEIVE_HOOK_ID

Responds with effective values inherited from owner and/or global level.

Status: 200
{ "id": 42, "name": "Check Commits", "enforcement": "disabled", "configuration_url": "https://github.example.com/api/v3/orgs/octocat/pre-receive-hooks/42" }