Esta versão do GitHub Enterprise foi descontinuada em 2022-10-12. Nenhum lançamento de patch será feito, mesmo para questões críticas de segurança. Para obter melhor desempenho, segurança aprimorada e novos recursos, atualize para a última versão do GitHub Enterprise. Para obter ajuda com a atualização, entre em contato com o suporte do 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.
Pre-receive Hooks
The Pre-receive Hooks API allows you to create, list, update and delete pre-receive hooks.
It is only available to authenticated site administrators. Normal users will receive a 404
response if they try to access it.
Object attributes
Pre-receive Hook
Name | Type | Description |
---|---|---|
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 | string | The state of enforcement for this hook. |
allow_downstream_configuration | boolean | Whether enforcement can be overridden at the org or repo level. |
Possible values for enforcement are enabled
, disabled
andtesting
. disabled
indicates the pre-receive hook will not run. enabled
indicates it will run and reject
any pushes that result in a non-zero status. testing
means the script will run but will not cause any pushes to be rejected.
List pre-receive hooks
Parâmetros
Headers |
---|
Name, Type, Description |
accept stringSetting to |
Query parameters |
Name, Type, Description |
per_page integerThe number of results per page (max 100). Default: |
page integerPage number of the results to fetch. Default: |
direction stringThe direction to sort the results by. Default: Can be one of: |
sort stringThe property to sort the results by. Default: Can be one of: |
Códigos de status de resposta HTTP
Código de status | Descrição |
---|---|
200 | OK |
Exemplos de código
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 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 |
---|
Name, Type, Description |
accept stringSetting to |
Body parameters |
Name, Type, Description |
name stringRequiredThe name of the hook. |
script stringRequiredThe script that the hook runs. |
script_repository objectRequiredThe GitHub repository where the script is kept. |
environment objectRequiredThe 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: |
Códigos de status de resposta HTTP
Código de status | Descrição |
---|---|
201 | Created |
Exemplos de código
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 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 |
---|
Name, Type, Description |
accept stringSetting to |
Path parameters |
Name, Type, Description |
pre_receive_hook_id integerRequiredThe unique identifier of the pre-receive hook. |
Códigos de status de resposta HTTP
Código de status | Descrição |
---|---|
200 | OK |
Exemplos de código
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 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 |
---|
Name, Type, Description |
accept stringSetting to |
Path parameters |
Name, Type, Description |
pre_receive_hook_id integerRequiredThe unique identifier of the pre-receive hook. |
Body parameters |
Name, Type, Description |
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. |
Códigos de status de resposta HTTP
Código de status | Descrição |
---|---|
200 | OK |
Exemplos de código
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 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 |
---|
Name, Type, Description |
accept stringSetting to |
Path parameters |
Name, Type, Description |
pre_receive_hook_id integerRequiredThe unique identifier of the pre-receive hook. |
Códigos de status de resposta HTTP
Código de status | Descrição |
---|---|
204 | No Content |
Exemplos de código
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 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