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

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

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

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

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

About repository pre-receive hooks

NameTypeDescription
namestringThe name of the hook.
enforcementstringThe state of enforcement for the hook on this repository.
configuration_urlstringURL for the endpoint where enforcement is set.

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.

configuration_url may be a link to this repository, it's organization owner or global configuration. Authorization to access the endpoint at configuration_url is determined at the owner or site admin level.

List pre-receive hooks for a repository

Работа с GitHub Apps

List all pre-receive hooks that are enabled or testing for this repository as well as any disabled hooks that are allowed to be enabled at the repository level. Pre-receive hooks that are disabled at a higher level and are not configurable will not be listed.

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

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

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

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

The account owner of the repository. The name is not case sensitive.

repo string Обязательно

The name of the repository. The name is not case sensitive.

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

The number of results per page (max 100).

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

page integer

Page number of the results to fetch.

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

direction string

The direction to sort the results by.

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

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

sort string

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

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

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

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

OK

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

get/repos/{owner}/{repo}/pre-receive-hooks
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/pre-receive-hooks

Response

Status: 200
[ { "id": 42, "name": "Check Commits", "enforcement": "disabled", "configuration_url": "https://github.example.com/api/v3/orgs/octocat/pre-receive-hooks/42" } ]

Get a pre-receive hook for a repository

Работа с GitHub Apps

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

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

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

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

The account owner of the repository. The name is not case sensitive.

repo string Обязательно

The name of the repository. The name is not case sensitive.

pre_receive_hook_id integer Обязательно

The unique identifier of the pre-receive hook.

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

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

OK

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

get/repos/{owner}/{repo}/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/repos/OWNER/REPO/pre-receive-hooks/PRE_RECEIVE_HOOK_ID

Response

Status: 200
{ "id": 42, "name": "Check Commits", "enforcement": "disabled", "configuration_url": "https://github.example.com/api/v3/orgs/octocat/pre-receive-hooks/42" }

Update pre-receive hook enforcement for a repository

Работа с GitHub Apps

For pre-receive hooks which are allowed to be configured at the repo level, you can set enforcement

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

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

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

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

The account owner of the repository. The name is not case sensitive.

repo string Обязательно

The name of the repository. The name is not case sensitive.

pre_receive_hook_id integer Обязательно

The unique identifier of the pre-receive hook.

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

The state of enforcement for the hook on this repository.

Может быть одним из: enabled, disabled, testing

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

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

OK

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

patch/repos/{owner}/{repo}/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/repos/OWNER/REPO/pre-receive-hooks/PRE_RECEIVE_HOOK_ID \ -d '{"enforcement":"enabled"}'

Response

Status: 200
{ "id": 42, "name": "Check Commits", "enforcement": "enabled", "configuration_url": "https://github.example.com/api/v3/repos/octocat/hello-world/pre-receive-hooks/42" }

Remove pre-receive hook enforcement for a repository

Работа с GitHub Apps

Deletes any overridden enforcement on this repository for the specified hook.

Responds with effective values inherited from owner and/or global level.

Параметры для "Remove pre-receive hook enforcement for a repository"

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

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

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

The account owner of the repository. The name is not case sensitive.

repo string Обязательно

The name of the repository. The name is not case sensitive.

pre_receive_hook_id integer Обязательно

The unique identifier of the pre-receive hook.

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

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

Responds with effective values inherited from owner and/or global level.

Примеры кода для "Remove pre-receive hook enforcement for a repository"

delete/repos/{owner}/{repo}/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/repos/OWNER/REPO/pre-receive-hooks/PRE_RECEIVE_HOOK_ID

Responds with effective values inherited from owner and/or global level.

Status: 200
{ "id": 42, "name": "Check Commits", "enforcement": "disabled", "configuration_url": "https://github.example.com/api/v3/orgs/octocat/pre-receive-hooks/42" }