Skip to main content

protection_rules

Creates, updates, deletes, gets or lists a protection_rules resource.

Overview

Nameprotection_rules
TypeResource
Idgithub.repos.protection_rules

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
idintegerThe unique identifier for the deployment protection rule.
node_idstringThe node ID for the deployment protection rule. (example: MDQ6R2F0ZTM1MTU=)
appobjectA GitHub App that is providing a custom deployment protection rule. (title: Custom deployment protection rule app)
enabledbooleanWhether the deployment protection rule is enabled for the environment.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_custom_deployment_protection_ruleselectowner, repo, environment_name, protection_rule_idGets an enabled custom deployment protection rule for an environment. Anyone with read access to the repository can 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}.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.
get_all_deployment_protection_rulesselectenvironment_name, repo, ownerGets all custom deployment protection rules that are enabled for an environment. Anyone with read access to the repository can 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.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.
create_deployment_protection_ruleinsertenvironment_name, repo, ownerEnable a custom deployment protection rule for an environment.

The authenticated user must have admin or owner permissions to the repository 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, as well as the guide to creating custom deployment protection rules.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.
disable_deployment_protection_ruledeleteenvironment_name, repo, owner, protection_rule_idDisables a custom deployment protection rule for an environment.

The authenticated user must have admin or owner permissions to the repository to use this endpoint.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
environment_namestringThe name of the environment. The name must be URL encoded. For example, any slashes in the name must be replaced with %2F.
ownerstringThe account owner of the repository. The name is not case sensitive.
protection_rule_idintegerThe unique identifier of the protection rule.
repostringThe name of the repository without the .git extension. The name is not case sensitive.

SELECT examples

Gets an enabled custom deployment protection rule for an environment. Anyone with read access to the repository can 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}.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.

SELECT
id,
node_id,
app,
enabled
FROM github.repos.protection_rules
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND environment_name = '{{ environment_name }}' -- required
AND protection_rule_id = '{{ protection_rule_id }}' -- required
;

INSERT examples

Enable a custom deployment protection rule for an environment.

The authenticated user must have admin or owner permissions to the repository 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, as well as the guide to creating custom deployment protection rules.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

INSERT INTO github.repos.protection_rules (
integration_id,
environment_name,
repo,
owner
)
SELECT
{{ integration_id }},
'{{ environment_name }}',
'{{ repo }}',
'{{ owner }}'
RETURNING
id,
node_id,
app,
enabled
;

DELETE examples

Disables a custom deployment protection rule for an environment.

The authenticated user must have admin or owner permissions to the repository to use this endpoint.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

DELETE FROM github.repos.protection_rules
WHERE environment_name = '{{ environment_name }}' --required
AND repo = '{{ repo }}' --required
AND owner = '{{ owner }}' --required
AND protection_rule_id = '{{ protection_rule_id }}' --required
;