Esta versão do GitHub Enterprise Server foi descontinuada em 2024-03-26. 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 Server. Para obter ajuda com a atualização, entre em contato com o suporte do GitHub Enterprise.
Pontos de extremidade da API REST para hooks pre-receive
Use a API REST para criar, listar, atualizar e excluir ambientes para ganchos de pré-recebimento.
Sobre hooks pre-receive
Esses pontos de extremidade só estão disponíveis para administradores de site autenticados. Os usuários normais receberão uma resposta 404.
Atributos do objeto
Hook pre-receive
| Nome | Tipo | Descrição |
|---|---|---|
name | string | O nome do hook. |
script | string | O script que o hook executa. |
script_repository | object | O repositório do GitHub onde o script é mantido. |
environment | object | O ambiente de pre-receive onde o script é executado. |
enforcement | string | O estado de aplicação para este hook. |
allow_downstream_configuration | boolean | Se a aplicação pode ser substituída no nível da organização ou do repositório. |
Os possíveis valores para a imposição são enabled, disabled e testing. disabled indica que o gancho de pré-recebimento não será executado. enabled indica que ele será executado e rejeitará os pushes que resultem em um status diferente de zero. testing significa que o script será executado, mas não fará com que nenhum push seja rejeitado.
List pre-receive hooks
Parâmetros para "List pre-receive hooks"
| Nome, Tipo, Descrição |
|---|
accept string Setting to |
| Nome, Tipo, Descrição |
|---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." Padrão: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." Padrão: |
direction string The direction to sort the results by. Padrão: Pode ser um dos: |
sort string The property to sort the results by. Padrão: Pode ser um dos: |
Códigos de status de resposta HTTP para "List pre-receive hooks"
| Código de status | Descrição |
|---|---|
200 | OK |
Exemplos de código para "List pre-receive hooks"
Exemplo de solicitação
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooksResponse
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
}
]Create a pre-receive hook
Parâmetros para "Create a pre-receive hook"
| Nome, Tipo, Descrição |
|---|
accept string Setting to |
| Nome, Tipo, Descrição |
|---|
name string ObrigatórioThe name of the hook. |
script string ObrigatórioThe script that the hook runs. |
script_repository object ObrigatórioThe GitHub repository where the script is kept. |
environment object ObrigatórioThe pre-receive environment where the script is executed. |
enforcement string The state of enforcement for this hook. default: |
allow_downstream_configuration boolean Whether enforcement can be overridden at the org or repo level. default: |
Códigos de status de resposta HTTP para "Create a pre-receive hook"
| Código de status | Descrição |
|---|---|
201 | Created |
Exemplos de código para "Create a pre-receive hook"
Exemplo de solicitação
curl -L \
-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
}Get a pre-receive hook
Parâmetros para "Get a pre-receive hook"
| Nome, Tipo, Descrição |
|---|
accept string Setting to |
| Nome, Tipo, Descrição |
|---|
pre_receive_hook_id integer ObrigatórioThe unique identifier of the pre-receive hook. |
Códigos de status de resposta HTTP para "Get a pre-receive hook"
| Código de status | Descrição |
|---|---|
200 | OK |
Exemplos de código para "Get a pre-receive hook"
Exemplo de solicitação
curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>" \
http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_IDResponse
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
}Update a pre-receive hook
Parâmetros para "Update a pre-receive hook"
| Nome, Tipo, Descrição |
|---|
accept string Setting to |
| Nome, Tipo, Descrição |
|---|
pre_receive_hook_id integer ObrigatórioThe unique identifier of the pre-receive hook. |
| Nome, Tipo, Descrição |
|---|
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. |
Códigos de status de resposta HTTP para "Update a pre-receive hook"
| Código de status | Descrição |
|---|---|
200 | OK |
Exemplos de código para "Update a pre-receive hook"
Exemplo de solicitação
curl -L \
-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
}Delete a pre-receive hook
Parâmetros para "Delete a pre-receive hook"
| Nome, Tipo, Descrição |
|---|
accept string Setting to |
| Nome, Tipo, Descrição |
|---|
pre_receive_hook_id integer ObrigatórioThe unique identifier of the pre-receive hook. |
Códigos de status de resposta HTTP para "Delete a pre-receive hook"
| Código de status | Descrição |
|---|---|
204 | No Content |
Exemplos de código para "Delete a pre-receive hook"
Exemplo de solicitação
curl -L \
-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_IDResponse
Status: 204