Skip to main content
Die REST-API verfügt jetzt über eine Versionskontrolle. Weitere Informationen findest du unter Informationen zur API-Versionsverwaltung.

REST-API-Endpunkte für Pre-Receive-Hooks

Verwende die REST-API, um Pre-Receive-Hooks zu erstellen, aufzulisten, zu aktualisieren und zu löschen.

Informationen zu Pre-Receive-Hooks

Diese Endpunkte sind nur für authentifizierte Websiteadministrator*innen verfügbar. Normale Benutzer erhalten eine 404-Antwort.

Diese Endpunkte unterstützen nur die Authentifizierung über ein personal access token (classic). Weitere Informationen findest du unter Verwalten deiner persönlichen Zugriffstoken.

Objektattribute

Pre-Receive-Hook

NameTypBESCHREIBUNG
namestringDer Name des Hooks.
scriptstringDas Skript, das der Hook ausführt
script_repositoryobjectDas GitHub Repository, in dem das Skript aufbewahrt wird
environmentobjectDie vorab empfangene Umgebung, in der das Skript ausgeführt wird
enforcementstringDer Status der Erzwingung für diesen Hook
allow_downstream_configurationbooleanInformation, ob die Erzwingung auf Organisations- oder Repositoryebene außer Kraft gesetzt werden kann

Mögliche Werte für die Erzwingung sind enabled, disabled undtesting. disabled gibt an, dass der Pre-Receive-Hook nicht ausgeführt wird. enabled gibt an, dass alle Pushs ausgeführt und abgelehnt werden, die zu einem anderen Status als null (0) führen. testing bedeutet, dass das Skript zwar ausgeführt wird, aber keine Ablehnung von Pushs auslösen wird.

List pre-receive hooks

Differenzierte Zugriffstoken für "List pre-receive hooks"

Dieser Endpunkt funktioniert nicht mit GitHub-App-Benutzerzugriffstoken, GitHub-App-Installationszugriffstoken oder differenzierten persönlichen Zugriffstoken.

Parameter für „List pre-receive hooks“

Header
Name, type, BESCHREIBUNG
accept string

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

Abfrageparameter
Name, type, BESCHREIBUNG
per_page integer

The number of results per page (max 100). For more information, see "Using pagination in the REST API."

Standard: 30

page integer

The page number of the results to fetch. For more information, see "Using pagination in the REST API."

Standard: 1

direction string

The direction to sort the results by.

Standard: desc

Kann eine der Folgenden sein: asc, desc

sort string

The property to sort the results by.

Standard: created

Kann eine der Folgenden sein: created, updated, name

HTTP-Antwortstatuscodes für „List pre-receive hooks“

StatuscodeBESCHREIBUNG
200

OK

Codebeispiele für „List pre-receive hooks“

Beispiel für eine Anfrage

get/admin/pre-receive-hooks
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ 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

Differenzierte Zugriffstoken für "Create a pre-receive hook"

Dieser Endpunkt funktioniert nicht mit GitHub-App-Benutzerzugriffstoken, GitHub-App-Installationszugriffstoken oder differenzierten persönlichen Zugriffstoken.

Parameter für „Create a pre-receive hook“

Header
Name, type, BESCHREIBUNG
accept string

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

Textparameter
Name, type, BESCHREIBUNG
name string Erforderlich

The name of the hook.

script string Erforderlich

The script that the hook runs.

script_repository object Erforderlich

The GitHub repository where the script is kept.

environment object Erforderlich

The pre-receive environment where the script is executed.

enforcement string

The state of enforcement for this hook. default: disabled

allow_downstream_configuration boolean

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

HTTP-Antwortstatuscodes für „Create a pre-receive hook“

StatuscodeBESCHREIBUNG
201

Created

Codebeispiele für „Create a pre-receive hook“

Beispiel für eine Anfrage

post/admin/pre-receive-hooks
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ 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

Differenzierte Zugriffstoken für "Get a pre-receive hook"

Dieser Endpunkt funktioniert nicht mit GitHub-App-Benutzerzugriffstoken, GitHub-App-Installationszugriffstoken oder differenzierten persönlichen Zugriffstoken.

Parameter für „Get a pre-receive hook“

Header
Name, type, BESCHREIBUNG
accept string

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

Pfadparameter
Name, type, BESCHREIBUNG
pre_receive_hook_id integer Erforderlich

The unique identifier of the pre-receive hook.

HTTP-Antwortstatuscodes für „Get a pre-receive hook“

StatuscodeBESCHREIBUNG
200

OK

Codebeispiele für „Get a pre-receive hook“

Beispiel für eine Anfrage

get/admin/pre-receive-hooks/{pre_receive_hook_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ 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

Differenzierte Zugriffstoken für "Update a pre-receive hook"

Dieser Endpunkt funktioniert nicht mit GitHub-App-Benutzerzugriffstoken, GitHub-App-Installationszugriffstoken oder differenzierten persönlichen Zugriffstoken.

Parameter für „Update a pre-receive hook“

Header
Name, type, BESCHREIBUNG
accept string

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

Pfadparameter
Name, type, BESCHREIBUNG
pre_receive_hook_id integer Erforderlich

The unique identifier of the pre-receive hook.

Textparameter
Name, type, BESCHREIBUNG
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.

HTTP-Antwortstatuscodes für „Update a pre-receive hook“

StatuscodeBESCHREIBUNG
200

OK

Codebeispiele für „Update a pre-receive hook“

Beispiel für eine Anfrage

patch/admin/pre-receive-hooks/{pre_receive_hook_id}
curl -L \ -X PATCH \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ 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

Differenzierte Zugriffstoken für "Delete a pre-receive hook"

Dieser Endpunkt funktioniert nicht mit GitHub-App-Benutzerzugriffstoken, GitHub-App-Installationszugriffstoken oder differenzierten persönlichen Zugriffstoken.

Parameter für „Delete a pre-receive hook“

Header
Name, type, BESCHREIBUNG
accept string

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

Pfadparameter
Name, type, BESCHREIBUNG
pre_receive_hook_id integer Erforderlich

The unique identifier of the pre-receive hook.

HTTP-Antwortstatuscodes für „Delete a pre-receive hook“

StatuscodeBESCHREIBUNG
204

No Content

Codebeispiele für „Delete a pre-receive hook“

Beispiel für eine Anfrage

delete/admin/pre-receive-hooks/{pre_receive_hook_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID

Response

Status: 204