Skip to main content
Мы публикуем частые обновления нашей документации, и перевод этой страницы, возможно, еще выполняется. Актуальные сведения см. в документации на английском языке.

Поддержка этой версии GitHub Enterprise была прекращена 2023-03-15. Исправления выпускаться не будут даже при критических проблемах безопасности. Для повышения производительности, укрепления безопасности и новых функций установите последнюю версию GitHub Enterprise. Чтобы получить справку по обновлению, обратитесь в службу поддержки GitHub Enterprise.

Недавно мы перенесли некоторые из документации по REST API. Если вы не можете найти то, что ищете, попробуйте использовать страницу REST API Действия.

Перехватчики предварительного получения

Используйте REST API для создания, перечисления, обновления и удаления перехватчиков предварительного получения.

About pre-receive hooks

These endpoints are only available to authenticated site administrators. Normal users will receive a 404 response.

Object attributes

Pre-receive Hook

NameTypeDescription
namestringThe name of the hook.
scriptstringThe script that the hook runs.
script_repositoryobjectThe GitHub repository where the script is kept.
environmentobjectThe pre-receive environment where the script is executed.
enforcementstringThe state of enforcement for this hook.
allow_downstream_configurationbooleanWhether 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

Параметры для "List pre-receive hooks"

Заголовки
Имя, Тип, Описание
acceptstring

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

Параметры запроса
Имя, Тип, Описание
per_pageinteger

The number of results per page (max 100).

Значение по умолчанию: 30

pageinteger

Page number of the results to fetch.

Значение по умолчанию: 1

directionstring

The direction to sort the results by.

Значение по умолчанию: desc

Может быть одним из: asc, desc

sortstring

The property to sort the results by.

Значение по умолчанию: created

Может быть одним из: created, updated, name

Коды состояния HTTP-ответа для "List pre-receive hooks"

Код состоянияОписание
200

OK

Примеры кода для "List pre-receive hooks"

get/admin/pre-receive-hooks
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

Параметры для "Create a pre-receive hook"

Заголовки
Имя, Тип, Описание
acceptstring

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

Параметры запроса
Имя, Тип, Описание
namestringОбязательно

The name of the hook.

scriptstringОбязательно

The script that the hook runs.

script_repositoryobjectОбязательно

The GitHub repository where the script is kept.

environmentobjectОбязательно

The pre-receive environment where the script is executed.

enforcementstring

The state of enforcement for this hook. default: disabled

allow_downstream_configurationboolean

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

Коды состояния HTTP-ответа для "Create a pre-receive hook"

Код состоянияОписание
201

Created

Примеры кода для "Create a pre-receive hook"

post/admin/pre-receive-hooks
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

Параметры для "Get a pre-receive hook"

Заголовки
Имя, Тип, Описание
acceptstring

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

Параметры пути
Имя, Тип, Описание
pre_receive_hook_idintegerОбязательно

The unique identifier of the pre-receive hook.

Коды состояния HTTP-ответа для "Get a pre-receive hook"

Код состоянияОписание
200

OK

Примеры кода для "Get a pre-receive hook"

get/admin/pre-receive-hooks/{pre_receive_hook_id}
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

Параметры для "Update a pre-receive hook"

Заголовки
Имя, Тип, Описание
acceptstring

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

Параметры пути
Имя, Тип, Описание
pre_receive_hook_idintegerОбязательно

The unique identifier of the pre-receive hook.

Параметры запроса
Имя, Тип, Описание
namestring

The name of the hook.

scriptstring

The script that the hook runs.

script_repositoryobject

The GitHub repository where the script is kept.

environmentobject

The pre-receive environment where the script is executed.

enforcementstring

The state of enforcement for this hook.

allow_downstream_configurationboolean

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

Коды состояния HTTP-ответа для "Update a pre-receive hook"

Код состоянияОписание
200

OK

Примеры кода для "Update a pre-receive hook"

patch/admin/pre-receive-hooks/{pre_receive_hook_id}
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

Параметры для "Delete a pre-receive hook"

Заголовки
Имя, Тип, Описание
acceptstring

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

Параметры пути
Имя, Тип, Описание
pre_receive_hook_idintegerОбязательно

The unique identifier of the pre-receive hook.

Коды состояния HTTP-ответа для "Delete a pre-receive hook"

Код состоянияОписание
204

No Content

Примеры кода для "Delete a pre-receive hook"

delete/admin/pre-receive-hooks/{pre_receive_hook_id}
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