Skip to main content
REST API теперь версия. Дополнительные сведения см. в разделе "О управлении версиями API".

Правила защиты

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

Get all deployment protection rules for an environment

Совместим с GitHub Apps

Gets all custom deployment protection rules that are enabled for an environment. Anyone with read access to the repository can use this endpoint. If the repository is private and you want to use a personal access token (classic), you must use an access token with the repo scope. GitHub Apps and fine-grained personal access tokens must have the actions:read permission to use this endpoint. For more information about environments, see "Using environments for deployment."

For more information about the app that is providing this custom deployment rule, see the documentation for the GET /apps/{app_slug} endpoint.

Параметры для "Get all deployment protection rules for an environment"

Заголовки
Имя., Тип, Description
accept string

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

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

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

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

The name of the repository without the .git extension. The name is not case sensitive.

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

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

Коды состояния http-ответа для "Get all deployment protection rules for an environment"

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

List of deployment protection rules

Примеры кода для "Get all deployment protection rules for an environment"

get/repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules

List of deployment protection rules

Status: 200
{ "total_count": 2, "custom_deployment_protection_rules": [ { "id": 3, "node_id": "IEH37kRlcGxveW1lbnRTdGF0ddiv", "enabled": true, "app": { "id": 1, "node_id": "GHT58kRlcGxveW1lbnRTdTY!bbcy", "slug": "a-custom-app", "integration_url": "https://api.github.com/apps/a-custom-app" } }, { "id": 4, "node_id": "MDE2OkRlcGxveW1lbnRTdHJ41128", "enabled": true, "app": { "id": 1, "node_id": "UHVE67RlcGxveW1lbnRTdTY!jfeuy", "slug": "another-custom-app", "integration_url": "https://api.github.com/apps/another-custom-app" } } ] }

Create a custom deployment protection rule on an environment

Совместим с GitHub Apps

Enable a custom deployment protection rule for an environment.

You must authenticate using an access token with the repo scope to use this endpoint. Enabling a custom protection rule requires admin or owner permissions to the repository. GitHub Apps must have the actions:write permission to use this endpoint.

For more information about the app that is providing this custom deployment rule, see the documentation for the GET /apps/{app_slug} endpoint.

Параметры для "Create a custom deployment protection rule on an environment"

Заголовки
Имя., Тип, Description
accept string

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

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

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

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

The name of the repository without the .git extension. The name is not case sensitive.

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

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

Параметры запроса
Имя., Тип, Description
integration_id integer

The ID of the custom app that will be enabled on the environment.

Коды состояния http-ответа для "Create a custom deployment protection rule on an environment"

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

The enabled custom deployment protection rule

Примеры кода для "Create a custom deployment protection rule on an environment"

post/repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules \ -d '{"integration_id":5}'

The enabled custom deployment protection rule

Status: 201
{ "id": 3, "node_id": "IEH37kRlcGxveW1lbnRTdGF0ddiv", "enabled": true, "app": { "id": 1, "node_id": "GHT58kRlcGxveW1lbnRTdTY!bbcy", "slug": "a-custom-app", "integration_url": "https://api.github.com/apps/a-custom-app" } }

List custom deployment rule integrations available for an environment

Совместим с GitHub Apps

Gets all custom deployment protection rule integrations that are available for an environment. Anyone with read access to the repository can use this endpoint. If the repository is private and you want to use a personal access token (classic), you must use an access token with the repo scope. GitHub Apps and fine-grained personal access tokens must have the actions:read permission to use this endpoint.

For more information about environments, see "Using environments for deployment."

For more information about the app that is providing this custom deployment rule, see "GET an app".

Параметры для "List custom deployment rule integrations available for an environment"

Заголовки
Имя., Тип, Description
accept string

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

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

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

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

The name of the repository without the .git extension. The name is not case sensitive.

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

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

Параметры запроса
Имя., Тип, Description
page integer

Page number of the results to fetch.

По умолчанию.: 1

per_page integer

The number of results per page (max 100).

По умолчанию.: 30

Коды состояния http-ответа для "List custom deployment rule integrations available for an environment"

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

A list of custom deployment rule integrations available for this environment.

Примеры кода для "List custom deployment rule integrations available for an environment"

get/repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/apps
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules/apps

A list of custom deployment rule integrations available for this environment.

Status: 200
[ { "total_count": 2 }, { "available_custom_deployment_protection_rule_integrations": [ { "id": 1, "node_id": "GHT58kRlcGxveW1lbnRTdTY!bbcy", "slug": "a-custom-app", "integration_url": "https://api.github.com/apps/a-custom-app" }, { "id": 2, "node_id": "UHVE67RlcGxveW1lbnRTdTY!jfeuy", "slug": "another-custom-app", "integration_url": "https://api.github.com/apps/another-custom-app" } ] } ]

Get a custom deployment protection rule

Совместим с GitHub Apps

Gets an enabled custom deployment protection rule for an environment. Anyone with read access to the repository can use this endpoint. If the repository is private and you want to use a personal access token (classic), you must use an access token with the repo scope. GitHub Apps and fine-grained personal access tokens must have the actions:read permission to use this endpoint. For more information about environments, see "Using environments for deployment."

For more information about the app that is providing this custom deployment rule, see GET /apps/{app_slug}.

Параметры для "Get a custom deployment protection rule"

Заголовки
Имя., Тип, Description
accept string

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

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

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

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

The name of the repository without the .git extension. The name is not case sensitive.

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

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

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

The unique identifier of the protection rule.

Коды состояния http-ответа для "Get a custom deployment protection rule"

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

OK

Примеры кода для "Get a custom deployment protection rule"

get/repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/{protection_rule_id}
curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules/PROTECTION_RULE_ID

Response

Status: 200
{ "id": 3, "node_id": "IEH37kRlcGxveW1lbnRTdGF0ddiv", "enabled": true, "app": { "id": 1, "node_id": "GHT58kRlcGxveW1lbnRTdTY!bbcy", "slug": "a-custom-app", "integration_url": "https://api.github.com/apps/a-custom-app" } }

Disable a custom protection rule for an environment

Совместим с GitHub Apps

Disables a custom deployment protection rule for an environment.

You must authenticate using an access token with the repo scope to use this endpoint. Removing a custom protection rule requires admin or owner permissions to the repository. GitHub Apps must have the actions:write permission to use this endpoint. For more information, see "Get an app".

Параметры для "Disable a custom protection rule for an environment"

Заголовки
Имя., Тип, Description
accept string

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

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

The name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.

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

The name of the repository without the .git extension. The name is not case sensitive.

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

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

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

The unique identifier of the protection rule.

Коды состояния http-ответа для "Disable a custom protection rule for an environment"

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

No Content

Примеры кода для "Disable a custom protection rule for an environment"

delete/repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/{protection_rule_id}
curl -L \ -X DELETE \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/environments/ENVIRONMENT_NAME/deployment_protection_rules/PROTECTION_RULE_ID

Response

Status: 204