Skip to main content

Esta versión de GitHub Enterprise se discontinuó el 2022-10-12. No se realizarán lanzamientos de patch, ni siquiera para problemas de seguridad críticos. Para obtener rendimiento mejorado, seguridad mejorada y nuevas características, actualice a la versión más reciente de GitHub Enterprise. Para obtener ayuda con la actualización, póngase en contacto con el soporte técnico de 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.

Enlaces de recepción previa

La API de Ganchos Pre-recepción te permite crear, listar, actualizar y borrar los ganchos de pre-recepción.

Solo está disponible para los administradores de sitios autenticados. Los usuarios normales recibirán una respuesta 404 si intentan acceder a ella.

Atributos de objeto

Ganchos de pre-recepción

NombreTipoDescripción
namestringEl nombre del gancho.
scriptstringEl script que ejecuta el gancho.
script_repositoryobjectEl repositorio de GitHub en donde se mantiene el script.
environmentobjectEl ambiente de pre-recepción en donde se ejecuta el script.
enforcementstringEl estado de las imposiciones para este gancho.
allow_downstream_configurationbooleanSi las imposiciones pueden o no ignorarse a nivel de organización o de repositorio.

Los valores posibles para la aplicación son enabled, disabled y testing. disabled indica que no se ejecutará el enlace previo a la recepción. enabled indica que se ejecutará y rechazará cualquier inserción que dé como resultado un estado distinto a cero. testing indica que el script se ejecutará pero no rechazará ninguna inserción.

List pre-receive hooks

Parámetros

Headers
Name, Type, Description
acceptstring

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

See preview notice
Query parameters
Name, Type, Description
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

The property to sort the results by.

Default: created

Can be one of: created, updated, name

Códigos de estado de respuesta HTTP

status codeDescripción
200

OK

Ejemplos de código

get/admin/pre-receive-hooks
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-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 previsualización

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
Name, Type, Description
acceptstring

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

See preview notice
Body parameters
Name, Type, Description
namestringRequired

The name of the hook.

scriptstringRequired

The script that the hook runs.

script_repositoryobjectRequired

The GitHub repository where the script is kept.

environmentobjectRequired

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

Códigos de estado de respuesta HTTP

status codeDescripción
201

Created

Ejemplos de código

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

Aviso de previsualización

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
Name, Type, Description
acceptstring

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

See preview notice
Path parameters
Name, Type, Description
pre_receive_hook_idintegerRequired

The unique identifier of the pre-receive hook.

Códigos de estado de respuesta HTTP

status codeDescripción
200

OK

Ejemplos de código

get/admin/pre-receive-hooks/{pre_receive_hook_id}
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-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 previsualización

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
Name, Type, Description
acceptstring

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

See preview notice
Path parameters
Name, Type, Description
pre_receive_hook_idintegerRequired

The unique identifier of the pre-receive hook.

Body parameters
Name, Type, Description
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.

Códigos de estado de respuesta HTTP

status codeDescripción
200

OK

Ejemplos de código

patch/admin/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/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 previsualización

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
Name, Type, Description
acceptstring

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

See preview notice
Path parameters
Name, Type, Description
pre_receive_hook_idintegerRequired

The unique identifier of the pre-receive hook.

Códigos de estado de respuesta HTTP

status codeDescripción
204

No Content

Ejemplos de código

delete/admin/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/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID

Response

Status: 204

Aviso de previsualización

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