protection_rules
Creates, updates, deletes, gets or lists a protection_rules resource.
Overview
| Name | protection_rules |
| Type | Resource |
| Id | github.repos.protection_rules |
Fields
The following fields are returned by SELECT queries:
- get_custom_deployment_protection_rule
- get_all_deployment_protection_rules
Response
| Name | Datatype | Description |
|---|---|---|
id | integer | The unique identifier for the deployment protection rule. |
node_id | string | The node ID for the deployment protection rule. (example: MDQ6R2F0ZTM1MTU=) |
app | object | A GitHub App that is providing a custom deployment protection rule. (title: Custom deployment protection rule app) |
enabled | boolean | Whether the deployment protection rule is enabled for the environment. |
List of deployment protection rules
| Name | Datatype | Description |
|---|---|---|
custom_deployment_protection_rules | array | |
total_count | integer | The number of enabled custom deployment protection rules for this environment |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
get_custom_deployment_protection_rule | select | owner, repo, environment_name, protection_rule_id | 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. | |
get_all_deployment_protection_rules | select | environment_name, repo, owner | Gets 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_rule | insert | environment_name, repo, owner | 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. | |
disable_deployment_protection_rule | delete | environment_name, repo, owner, protection_rule_id | 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. |
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.
| Name | Datatype | 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. |
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. |
repo | string | The name of the repository without the .git extension. The name is not case sensitive. |
SELECT examples
- get_custom_deployment_protection_rule
- get_all_deployment_protection_rules
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
;
Gets 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.
SELECT
custom_deployment_protection_rules,
total_count
FROM github.repos.protection_rules
WHERE environment_name = '{{ environment_name }}' -- required
AND repo = '{{ repo }}' -- required
AND owner = '{{ owner }}' -- required
;
INSERT examples
- create_deployment_protection_rule
- Manifest
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
;
# Description fields are for documentation purposes
- name: protection_rules
props:
- name: environment_name
value: "{{ environment_name }}"
description: Required parameter for the protection_rules resource.
- name: repo
value: "{{ repo }}"
description: Required parameter for the protection_rules resource.
- name: owner
value: "{{ owner }}"
description: Required parameter for the protection_rules resource.
- name: integration_id
value: {{ integration_id }}
description: |
The ID of the custom app that will be enabled on the environment.
DELETE examples
- disable_deployment_protection_rule
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
;