branch_protection
Creates, updates, deletes, gets or lists a branch_protection resource.
Overview
| Name | branch_protection |
| Type | Resource |
| Id | github.repos.branch_protection |
Fields
The following fields are returned by SELECT queries:
- get_branch_protection
Response
| Name | Datatype | Description |
|---|---|---|
name | string | (example: "branch/with/protection") |
allow_deletions | object | |
allow_force_pushes | object | |
allow_fork_syncing | object | Whether users can pull changes from upstream when the branch is locked. Set to true to allow fork syncing. Set to false to prevent fork syncing. |
block_creations | object | |
enabled | boolean | |
enforce_admins | object | Protected Branch Admin Enforced (title: Protected Branch Admin Enforced) |
lock_branch | object | Whether to set the branch as read-only. If this is true, users will not be able to push to the branch. |
protection_url | string | (example: "https://api.github.com/repos/owner-79e94e2d36b3fd06a32bb213/AAA_Public_Repo/branches/branch/with/protection/protection") |
required_conversation_resolution | object | |
required_linear_history | object | |
required_pull_request_reviews | object | Protected Branch Pull Request Review (title: Protected Branch Pull Request Review) |
required_signatures | object | |
required_status_checks | object | Protected Branch Required Status Check (title: Protected Branch Required Status Check) |
restrictions | object | Branch Restriction Policy (title: Branch Restriction Policy) |
url | string |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
get_branch_protection | select | owner, repo, branch | Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub's products in the GitHub Help documentation. | |
update_branch_protection | replace | owner, repo, branch, required_status_checks, enforce_admins, required_pull_request_reviews, restrictions | Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub's products in the GitHub Help documentation. Protecting a branch requires admin or owner permissions to the repository. > [!NOTE] > Passing new arrays of users and teams replaces their previous values.> [!NOTE] > The list of users, apps, and teams in total is limited to 100 items. | |
delete_branch_protection | delete | owner, repo, branch | Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub's products in the GitHub Help documentation. |
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 | string | The name of the branch. Cannot contain wildcard characters. To use wildcard characters in branch names, use the GraphQL API. |
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. |
SELECT examples
- get_branch_protection
Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub's products in the GitHub Help documentation.
SELECT
name,
allow_deletions,
allow_force_pushes,
allow_fork_syncing,
block_creations,
enabled,
enforce_admins,
lock_branch,
protection_url,
required_conversation_resolution,
required_linear_history,
required_pull_request_reviews,
required_signatures,
required_status_checks,
restrictions,
url
FROM github.repos.branch_protection
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND branch = '{{ branch }}' -- required
;
REPLACE examples
- update_branch_protection
Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub's products in the GitHub Help documentation.
Protecting a branch requires admin or owner permissions to the repository.
> [!NOTE]
> Passing new arrays of users and teams replaces their previous values.
> [!NOTE]
> The list of users, apps, and teams in total is limited to 100 items.
REPLACE github.repos.branch_protection
SET
required_status_checks = '{{ required_status_checks }}',
enforce_admins = {{ enforce_admins }},
required_pull_request_reviews = '{{ required_pull_request_reviews }}',
restrictions = '{{ restrictions }}',
required_linear_history = {{ required_linear_history }},
allow_force_pushes = {{ allow_force_pushes }},
allow_deletions = {{ allow_deletions }},
block_creations = {{ block_creations }},
required_conversation_resolution = {{ required_conversation_resolution }},
lock_branch = {{ lock_branch }},
allow_fork_syncing = {{ allow_fork_syncing }}
WHERE
owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND branch = '{{ branch }}' --required
AND required_status_checks = '{{ required_status_checks }}' --required
AND enforce_admins = {{ enforce_admins }} --required
AND required_pull_request_reviews = '{{ required_pull_request_reviews }}' --required
AND restrictions = '{{ restrictions }}' --required
RETURNING
allow_deletions,
allow_force_pushes,
allow_fork_syncing,
block_creations,
enforce_admins,
lock_branch,
required_conversation_resolution,
required_linear_history,
required_pull_request_reviews,
required_signatures,
required_status_checks,
restrictions,
url;
DELETE examples
- delete_branch_protection
Protected branches are available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see GitHub's products in the GitHub Help documentation.
DELETE FROM github.repos.branch_protection
WHERE owner = '{{ owner }}' --required
AND repo = '{{ repo }}' --required
AND branch = '{{ branch }}' --required
;