Skip to main content

Esta versão do GitHub Enterprise foi descontinuada em 2022-06-03. Nenhum lançamento de patch será feito, mesmo para questões críticas de segurança. Para obter melhor desempenho, melhorar a segurança e novos recursos, upgrade to the latest version of GitHub Enterprise. Para ajuda com a atualização, contact GitHub Enterprise support.

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

A API de hooks pre-receive permite que você crie, liste, atualize e apague hooks pre-receive.

Só está disponível para administradores do site autenticados. Usuários normais receberão uma mensagem 404 se tentarem acessá-la.

Atributos do objeto

Hook pre-receive

NomeTipoDescrição
namestringO nome do hook.
scriptstringO script que o hook executa.
script_repositoryobjetoO repositório do GitHub onde o script é mantido.
ambienteobjetoO ambiente de pre-receive onde o script é executado.
enforcementstringO estado de aplicação para este hook.
allow_downstream_configurationbooleanSe a aplicação pode ser substituída no nível da organização ou do repositório.

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 status diferente de zero. testando significa que o script será executado, mas não fará com que quaisquer pushes sejam rejeitados.

List pre-receive hooks

Parâmetros

Headers
Nome, Tipo, Descrição
acceptstring

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

Ver aviso de pré-visualização
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

The property to sort the results by.

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/admin/pre-receive-hooks
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 } ]

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

Create a pre-receive hook

Parâmetros

Headers
Nome, Tipo, Descrição
acceptstring

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

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

The name of the hook.

scriptstringObrigatório

The script that the hook runs.

script_repositoryobjectObrigatório

The GitHub repository where the script is kept.

environmentobjectObrigatório

The pre-receive environment where the script is executed.

enforcementstring

The state of enforcement for this hook. default: disabled

allow_downstream_configurationboolean

Whether enforcement can be overridden at the org or repo level. default: false

HTTP response status codes

Status codeDescrição
201

Created

Amostras de código

post/admin/pre-receive-hooks
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 }

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

Parâmetros

Headers
Nome, Tipo, Descrição
acceptstring

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

Ver aviso de pré-visualização
Path parameters
Nome, Tipo, Descrição
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/admin/pre-receive-hooks/{pre_receive_hook_id}
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 }

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 a pre-receive hook

Parâmetros

Headers
Nome, Tipo, Descrição
acceptstring

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

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

The unique identifier of the pre-receive hook.

Body parameters
Nome, Tipo, Descrição
namestring

The name of the hook.

scriptstring

The script that the hook runs.

script_repositoryobject

The GitHub repository where the script is kept.

environmentobject

The pre-receive environment where the script is executed.

enforcementstring

The state of enforcement for this hook.

allow_downstream_configurationboolean

Whether enforcement can be overridden at the org or repo level.

HTTP response status codes

Status codeDescrição
200

OK

Amostras de código

patch/admin/pre-receive-hooks/{pre_receive_hook_id}
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 }

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

Delete a pre-receive hook

Parâmetros

Headers
Nome, Tipo, Descrição
acceptstring

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

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

The unique identifier of the pre-receive hook.

HTTP response status codes

Status codeDescrição
204

No Content

Amostras de código

delete/admin/pre-receive-hooks/{pre_receive_hook_id}
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

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