Skip to main content

Enterprise Server 3.21 ist derzeit als Release Candidate verfügbar.

Die REST-API ist jetzt versioniert. 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.

Hinweis

Diese Endpunkte unterstützen nur die Authentifizierung über ein personal access token (classic). Weitere Informationen finden Sie 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 Pre-Receive-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

Fine-grained access tokens for "List pre-receive hooks"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameter für "List pre-receive hooks"

Header
Name, Typ, BESCHREIBUNG
accept string

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

Abfrageparameter
Name, Typ, 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 response status codes for "List pre-receive hooks"

Status codeBESCHREIBUNG
200

OK

Code samples for "List pre-receive hooks"

Request example

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

Fine-grained access tokens for "Create a pre-receive hook"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameter für "Create a pre-receive hook"

Header
Name, Typ, BESCHREIBUNG
accept string

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

Körperparameter
Name, Typ, 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 response status codes for "Create a pre-receive hook"

Status codeBESCHREIBUNG
201

Created

Code samples for "Create a pre-receive hook"

Request example

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: 2026-03-10" \ 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

Fine-grained access tokens for "Get a pre-receive hook"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameter für "Get a pre-receive hook"

Header
Name, Typ, BESCHREIBUNG
accept string

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

Pfadparameter
Name, Typ, BESCHREIBUNG
pre_receive_hook_id string Erforderlich

The unique identifier of the pre-receive hook.

HTTP response status codes for "Get a pre-receive hook"

Status codeBESCHREIBUNG
200

OK

Code samples for "Get a pre-receive hook"

Request example

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: 2026-03-10" \ 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

Fine-grained access tokens for "Update a pre-receive hook"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameter für "Update a pre-receive hook"

Header
Name, Typ, BESCHREIBUNG
accept string

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

Pfadparameter
Name, Typ, BESCHREIBUNG
pre_receive_hook_id string Erforderlich

The unique identifier of the pre-receive hook.

Körperparameter
Name, Typ, 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 response status codes for "Update a pre-receive hook"

Status codeBESCHREIBUNG
200

OK

Code samples for "Update a pre-receive hook"

Request example

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: 2026-03-10" \ 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

Fine-grained access tokens for "Delete a pre-receive hook"

This endpoint does not work with GitHub App user access tokens, GitHub App installation access tokens, or fine-grained personal access tokens.

Parameter für "Delete a pre-receive hook"

Header
Name, Typ, BESCHREIBUNG
accept string

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

Pfadparameter
Name, Typ, BESCHREIBUNG
pre_receive_hook_id string Erforderlich

The unique identifier of the pre-receive hook.

HTTP response status codes for "Delete a pre-receive hook"

Status codeBESCHREIBUNG
204

No Content

Code samples for "Delete a pre-receive hook"

Request example

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: 2026-03-10" \ http(s)://HOSTNAME/api/v3/admin/pre-receive-hooks/PRE_RECEIVE_HOOK_ID

Response

Status: 204