Skip to main content

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.

Hooks pre-receive do repositório

A API de hooks pre-receive do Repositório permite que você veja e modifique a aplicação dos hooks de pre-receive que estão disponíveis em um repositório.

Atributos do objeto

NomeTipoDescrição
namestringO nome do hook.
enforcementstringO estado de aplicação para o hook neste repositório.
configuration_urlstringURL para o ponto de extremidade em que a aplicação é definida.

Os valores possíveis para aplicação são habilitado, desabilitado etestando. desabilitado indica que o hook pre-receive não será executado. habilitado indica que será executado e rejeitará quaisquer pushes que resultem em um estado diferente de zero. testando significa que o script será executado, mas não fará com que quaisquer pushes sejam rejeitados.

configuration_url pode ser um link para este repositório, seu proprietário da organização ou configuração global. A autorização para acessar o ponto de extremidade no configuration_url é determinada no nível de proprietário ou administrador do site.

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.

Parâmetros

Headers
Nome, Tipo, Descrição
acceptstring

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

Ver aviso de pré-visualização
Path parameters
Nome, Tipo, Descrição
ownerstringObrigatório

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

repostringObrigatório

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

Parâmetros de consulta
Nome, Tipo, Descrição
per_pageinteger

The number of results per page (max 100).

Padrão: 30

pageinteger

Page number of the results to fetch.

Padrão: 1

directionstring

The direction to sort the results by.

Padrão: desc

Pode ser uma das ações a seguir: asc, desc

sortstring

Padrão: created

Pode ser uma das ações a seguir: created, updated, name

HTTP response status codes

Status codeDescrição
200

OK

Amostras de código

get/repos/{owner}/{repo}/pre-receive-hooks
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: token <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" } ]

Aviso de pré-visualização

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 for a repository

Works with GitHub Apps

Parâmetros

Headers
Nome, Tipo, Descrição
acceptstring

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

Ver aviso de pré-visualização
Path parameters
Nome, Tipo, Descrição
ownerstringObrigatório

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

repostringObrigatório

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

pre_receive_hook_idintegerObrigatório

The unique identifier of the pre-receive hook.

HTTP response status codes

Status codeDescrição
200

OK

Amostras de código

get/repos/{owner}/{repo}/pre-receive-hooks/{pre_receive_hook_id}
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: token <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" }

Aviso de pré-visualização

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 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

Parâmetros

Headers
Nome, Tipo, Descrição
acceptstring

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

Ver aviso de pré-visualização
Path parameters
Nome, Tipo, Descrição
ownerstringObrigatório

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

repostringObrigatório

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

pre_receive_hook_idintegerObrigatório

The unique identifier of the pre-receive hook.

Body parameters
Nome, Tipo, Descrição
enforcementstring

The state of enforcement for the hook on this repository.

Pode ser uma das ações a seguir: enabled, disabled, testing

HTTP response status codes

Status codeDescrição
200

OK

Amostras de código

patch/repos/{owner}/{repo}/pre-receive-hooks/{pre_receive_hook_id}
curl \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: token <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" }

Aviso de pré-visualização

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

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.

Parâmetros

Headers
Nome, Tipo, Descrição
acceptstring

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

Ver aviso de pré-visualização
Path parameters
Nome, Tipo, Descrição
ownerstringObrigatório

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

repostringObrigatório

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

pre_receive_hook_idintegerObrigatório

The unique identifier of the pre-receive hook.

HTTP response status codes

Status codeDescrição
200

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

Amostras de código

delete/repos/{owner}/{repo}/pre-receive-hooks/{pre_receive_hook_id}
curl \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: token <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" }

Aviso de pré-visualização

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