branch_policies
Creates, updates, deletes, gets or lists a branch_policies resource.
Overview
| Name | branch_policies |
| Type | Resource |
| Id | github.repos.branch_policies |
Fields
The following fields are returned by SELECT queries:
- get_deployment_branch_policy
- list_deployment_branch_policies
Response
| Name | Datatype | Description |
|---|---|---|
id | integer | The unique identifier of the branch or tag policy. |
name | string | The name pattern that branches or tags must match in order to deploy to the environment. (example: release/*) |
node_id | string | (example: MDE2OkdhdGVCcmFuY2hQb2xpY3kzNjE0NzE=) |
type | string | Whether this rule targets a branch or tag. (branch, tag) (example: branch) |
Response
| Name | Datatype | Description |
|---|---|---|
branch_policies | array | |
total_count | integer | The number of deployment branch policies for the environment. |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
get_deployment_branch_policy | select | owner, repo, environment_name, branch_policy_id | Gets a deployment branch or tag policy for an environment. Anyone with read access to the repository can use this endpoint. OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository. | |
list_deployment_branch_policies | select | owner, repo, environment_name | per_page, page | Lists the deployment branch policies for an environment. Anyone with read access to the repository can use this endpoint. OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository. |
create_deployment_branch_policy | insert | owner, repo, environment_name, name | Creates a deployment branch or tag policy for an environment. OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint. | |
update_deployment_branch_policy | replace | owner, repo, environment_name, branch_policy_id, name | Updates a deployment branch or tag policy for an environment. OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint. | |
delete_deployment_branch_policy | delete | owner, repo, environment_name, branch_policy_id | Deletes a deployment branch or tag policy for an environment. 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 |
|---|---|---|
branch_policy_id | integer | The unique identifier of the branch policy. |
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. |
repo | string | The name of the repository without the .git extension. The name is not case sensitive. |
page | integer | The page number of the results to fetch. For more information, see "Using pagination in the REST API." |
per_page | integer | The number of results per page (max 100). For more information, see "Using pagination in the REST API." |
SELECT examples
- get_deployment_branch_policy
- list_deployment_branch_policies
Gets a deployment branch or tag policy for an environment.
Anyone with read access to the repository can use this endpoint.
OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.
SELECT
id,
name,
node_id,
type
FROM github.repos.branch_policies
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND environment_name = '{{ environment_name }}' -- required
AND branch_policy_id = '{{ branch_policy_id }}' -- required
;
Lists the deployment branch policies for an environment.
Anyone with read access to the repository can use this endpoint.
OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint with a private repository.
SELECT
branch_policies,
total_count
FROM github.repos.branch_policies
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND environment_name = '{{ environment_name }}' -- required
AND per_page = '{{ per_page }}'
AND page = '{{ page }}'
;
INSERT examples
- create_deployment_branch_policy
- Manifest
Creates a deployment branch or tag policy for an environment.
OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.
INSERT INTO github.repos.branch_policies (
name,
type,
owner,
repo,
environment_name
)
SELECT
'{{ name }}' /* required */,
'{{ type }}',
'{{ owner }}',
'{{ repo }}',
'{{ environment_name }}'
RETURNING
id,
name,
node_id,
type
;
# Description fields are for documentation purposes
- name: branch_policies
props:
- name: owner
value: "{{ owner }}"
description: Required parameter for the branch_policies resource.
- name: repo
value: "{{ repo }}"
description: Required parameter for the branch_policies resource.
- name: environment_name
value: "{{ environment_name }}"
description: Required parameter for the branch_policies resource.
- name: name
value: "{{ name }}"
description: |
The name pattern that branches or tags must match in order to deploy to the environment.
Wildcard characters will not match `/`. For example, to match branches that begin with `release/` and contain an additional single slash, use `release/*/*`.
For more information about pattern matching syntax, see the [Ruby File.fnmatch documentation](https://ruby-doc.org/core-2.5.1/File.html#method-c-fnmatch).
- name: type
value: "{{ type }}"
description: |
Whether this rule targets a branch or tag
valid_values: ['branch', 'tag']
REPLACE examples
- update_deployment_branch_policy
Updates a deployment branch or tag policy for an environment.
OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.
REPLACE github.repos.branch_policies
SET
name = '{{ name }}'
WHERE
owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND environment_name = '{{ environment_name }}' --required
AND branch_policy_id = '{{ branch_policy_id }}' --required
AND name = '{{ name }}' --required
RETURNING
id,
name,
node_id,
type;
DELETE examples
- delete_deployment_branch_policy
Deletes a deployment branch or tag policy for an environment.
OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.
DELETE FROM github.repos.branch_policies
WHERE owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND environment_name = '{{ environment_name }}' --required
AND branch_policy_id = '{{ branch_policy_id }}' --required
;