Cette version de GitHub Enterprise Server n'est plus disponible depuis le 2024-03-26. Aucune publication de correctifs n’est effectuée, même pour les problèmes de sécurité critiques. Pour de meilleures performances, une sécurité améliorée et de nouvelles fonctionnalités, effectuez une mise à niveau vers la dernière version de GitHub Enterprise. Pour obtenir de l’aide sur la mise à niveau, contactez le support GitHub Enterprise.
Points de terminaison d’API REST pour hooks de pré-réception
Utilisez l’API REST pour créer, lister, mettre à jour et supprimer des hooks de pré-réception.
À propos des hooks de pré-réception
Ces points de terminaison sont uniquement disponibles pour les administrateurs de site authentifiés. Les utilisateurs normaux recevront une réponse 404
.
Attributs d’objet
Hook de pré-réception
Nom | Type | Description |
---|---|---|
name | string | Nom du hook. |
script | string | Script exécuté par le hook. |
script_repository | object | Référentiel GitHub où le script est conservé. |
environment | object | Environnement de pré-réception dans lequel le script est exécuté. |
enforcement | string | État d’application de ce hook. |
allow_downstream_configuration | boolean | Indique si l’application peut être remplacée au niveau de l’organisation ou du référentiel. |
Les valeurs possibles pour enforcement sont enabled
, disabled
et testing
. disabled
indique que le hook pré-réception ne s’exécute pas. enabled
indique qu’il s’exécute et rejette tous les envois qui entraînent un état différent de zéro. testing
signifie que le script s’exécute, mais n’entraîne pas de rejet des envois.
List pre-receive hooks
Paramètres pour « List pre-receive hooks »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
per_page integer The number of results per page (max 100). For more information, see "Using pagination in the REST API." Default: |
page integer The page number of the results to fetch. For more information, see "Using pagination in the REST API." Default: |
direction string The direction to sort the results by. Default: Peut être: |
sort string The property to sort the results by. Default: Peut être: |
Codes d’état de la réponse HTTP pour « List pre-receive hooks »
Code d’état | Description |
---|---|
200 | OK |
Exemples de code pour « List pre-receive hooks »
Exemple de requête
curl -L \
-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
}
]
Create a pre-receive hook
Paramètres pour « Create a pre-receive hook »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
name string ObligatoireThe name of the hook. |
script string ObligatoireThe script that the hook runs. |
script_repository object ObligatoireThe GitHub repository where the script is kept. |
environment object ObligatoireThe 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: |
Codes d’état de la réponse HTTP pour « Create a pre-receive hook »
Code d’état | Description |
---|---|
201 | Created |
Exemples de code pour « Create a pre-receive hook »
Exemple de requête
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
Paramètres pour « Get a pre-receive hook »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
pre_receive_hook_id integer ObligatoireThe unique identifier of the pre-receive hook. |
Codes d’état de la réponse HTTP pour « Get a pre-receive hook »
Code d’état | Description |
---|---|
200 | OK |
Exemples de code pour « Get a pre-receive hook »
Exemple de requête
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_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
}
Update a pre-receive hook
Paramètres pour « Update a pre-receive hook »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
pre_receive_hook_id integer ObligatoireThe unique identifier of the pre-receive hook. |
Nom, 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. |
Codes d’état de la réponse HTTP pour « Update a pre-receive hook »
Code d’état | Description |
---|---|
200 | OK |
Exemples de code pour « Update a pre-receive hook »
Exemple de requête
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
Paramètres pour « Delete a pre-receive hook »
Nom, Type, Description |
---|
accept string Setting to |
Nom, Type, Description |
---|
pre_receive_hook_id integer ObligatoireThe unique identifier of the pre-receive hook. |
Codes d’état de la réponse HTTP pour « Delete a pre-receive hook »
Code d’état | Description |
---|---|
204 | No Content |
Exemples de code pour « Delete a pre-receive hook »
Exemple de requête
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_ID
Response
Status: 204