Skip to content

branch_protections

Accessed as client.repos.branch_protections; the async client mirrors it.

ReposBranchProtections

The repos.branch_protections namespace.

create

create(
    owner: str,
    repo: str,
    *,
    apply_to_admins: bool | None = None,
    approvals_whitelist_teams: list[str] | None = None,
    approvals_whitelist_username: list[str] | None = None,
    block_on_official_review_requests: bool | None = None,
    block_on_outdated_branch: bool | None = None,
    block_on_rejected_reviews: bool | None = None,
    branch_name: str | None = None,
    dismiss_stale_approvals: bool | None = None,
    enable_approvals_whitelist: bool | None = None,
    enable_merge_whitelist: bool | None = None,
    enable_push: bool | None = None,
    enable_push_whitelist: bool | None = None,
    enable_status_check: bool | None = None,
    ignore_stale_approvals: bool | None = None,
    merge_whitelist_teams: list[str] | None = None,
    merge_whitelist_usernames: list[str] | None = None,
    protected_file_patterns: str | None = None,
    push_whitelist_deploy_keys: bool | None = None,
    push_whitelist_teams: list[str] | None = None,
    push_whitelist_usernames: list[str] | None = None,
    require_signed_commits: bool | None = None,
    required_approvals: int | None = None,
    rule_name: str | None = None,
    status_check_contexts: list[str] | None = None,
    unprotected_file_patterns: str | None = None,
) -> BranchProtection

Create a branch protections for a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
apply_to_admins bool | None
None
approvals_whitelist_teams list[str] | None
None
approvals_whitelist_username list[str] | None
None
block_on_official_review_requests bool | None
None
block_on_outdated_branch bool | None
None
block_on_rejected_reviews bool | None
None
branch_name str | None

Deprecated: true

None
dismiss_stale_approvals bool | None
None
enable_approvals_whitelist bool | None
None
enable_merge_whitelist bool | None
None
enable_push bool | None
None
enable_push_whitelist bool | None
None
enable_status_check bool | None
None
ignore_stale_approvals bool | None
None
merge_whitelist_teams list[str] | None
None
merge_whitelist_usernames list[str] | None
None
protected_file_patterns str | None
None
push_whitelist_deploy_keys bool | None
None
push_whitelist_teams list[str] | None
None
push_whitelist_usernames list[str] | None
None
require_signed_commits bool | None
None
required_approvals int | None
None
rule_name str | None
None
status_check_contexts list[str] | None
None
unprotected_file_patterns str | None
None

Returns:

Type Description
BranchProtection

BranchProtection.

Raises:

Type Description
ForbiddenError
  1. APIForbiddenError is a forbidden error response.
NotFoundError
  1. APINotFound is a not found error response.
UnprocessableEntityError
  1. APIValidationError is error format response related to input validation.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoCreateBranchProtection

delete

delete(owner: str, repo: str, name: str) -> None

Delete a specific branch protection for the repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
name str

name of protected branch

required

Returns:

Type Description
None

No content.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoDeleteBranchProtection

get

get(owner: str, repo: str, name: str) -> BranchProtection

Get a specific branch protection for the repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
name str

name of protected branch

required

Returns:

Type Description
BranchProtection

BranchProtection.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoGetBranchProtection

list

list(owner: str, repo: str) -> list[BranchProtection]

List branch protections for a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required

Returns:

Type Description
list[BranchProtection]

BranchProtectionList.

Operation ID: repoListBranchProtection

update

update(
    owner: str,
    repo: str,
    name: str,
    *,
    apply_to_admins: bool | None = None,
    approvals_whitelist_teams: list[str] | None = None,
    approvals_whitelist_username: list[str] | None = None,
    block_on_official_review_requests: bool | None = None,
    block_on_outdated_branch: bool | None = None,
    block_on_rejected_reviews: bool | None = None,
    dismiss_stale_approvals: bool | None = None,
    enable_approvals_whitelist: bool | None = None,
    enable_merge_whitelist: bool | None = None,
    enable_push: bool | None = None,
    enable_push_whitelist: bool | None = None,
    enable_status_check: bool | None = None,
    ignore_stale_approvals: bool | None = None,
    merge_whitelist_teams: list[str] | None = None,
    merge_whitelist_usernames: list[str] | None = None,
    protected_file_patterns: str | None = None,
    push_whitelist_deploy_keys: bool | None = None,
    push_whitelist_teams: list[str] | None = None,
    push_whitelist_usernames: list[str] | None = None,
    require_signed_commits: bool | None = None,
    required_approvals: int | None = None,
    status_check_contexts: list[str] | None = None,
    unprotected_file_patterns: str | None = None,
) -> BranchProtection

Edit a branch protections for a repository. Only fields that are set will be changed.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
name str

name of protected branch

required
apply_to_admins bool | None
None
approvals_whitelist_teams list[str] | None
None
approvals_whitelist_username list[str] | None
None
block_on_official_review_requests bool | None
None
block_on_outdated_branch bool | None
None
block_on_rejected_reviews bool | None
None
dismiss_stale_approvals bool | None
None
enable_approvals_whitelist bool | None
None
enable_merge_whitelist bool | None
None
enable_push bool | None
None
enable_push_whitelist bool | None
None
enable_status_check bool | None
None
ignore_stale_approvals bool | None
None
merge_whitelist_teams list[str] | None
None
merge_whitelist_usernames list[str] | None
None
protected_file_patterns str | None
None
push_whitelist_deploy_keys bool | None
None
push_whitelist_teams list[str] | None
None
push_whitelist_usernames list[str] | None
None
require_signed_commits bool | None
None
required_approvals int | None
None
status_check_contexts list[str] | None
None
unprotected_file_patterns str | None
None

Returns:

Type Description
BranchProtection

BranchProtection.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.
UnprocessableEntityError
  1. APIValidationError is error format response related to input validation.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoEditBranchProtection

AsyncReposBranchProtections

The repos.branch_protections namespace.

create

create(
    owner: str,
    repo: str,
    *,
    apply_to_admins: bool | None = None,
    approvals_whitelist_teams: list[str] | None = None,
    approvals_whitelist_username: list[str] | None = None,
    block_on_official_review_requests: bool | None = None,
    block_on_outdated_branch: bool | None = None,
    block_on_rejected_reviews: bool | None = None,
    branch_name: str | None = None,
    dismiss_stale_approvals: bool | None = None,
    enable_approvals_whitelist: bool | None = None,
    enable_merge_whitelist: bool | None = None,
    enable_push: bool | None = None,
    enable_push_whitelist: bool | None = None,
    enable_status_check: bool | None = None,
    ignore_stale_approvals: bool | None = None,
    merge_whitelist_teams: list[str] | None = None,
    merge_whitelist_usernames: list[str] | None = None,
    protected_file_patterns: str | None = None,
    push_whitelist_deploy_keys: bool | None = None,
    push_whitelist_teams: list[str] | None = None,
    push_whitelist_usernames: list[str] | None = None,
    require_signed_commits: bool | None = None,
    required_approvals: int | None = None,
    rule_name: str | None = None,
    status_check_contexts: list[str] | None = None,
    unprotected_file_patterns: str | None = None,
) -> BranchProtection

Create a branch protections for a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
apply_to_admins bool | None
None
approvals_whitelist_teams list[str] | None
None
approvals_whitelist_username list[str] | None
None
block_on_official_review_requests bool | None
None
block_on_outdated_branch bool | None
None
block_on_rejected_reviews bool | None
None
branch_name str | None

Deprecated: true

None
dismiss_stale_approvals bool | None
None
enable_approvals_whitelist bool | None
None
enable_merge_whitelist bool | None
None
enable_push bool | None
None
enable_push_whitelist bool | None
None
enable_status_check bool | None
None
ignore_stale_approvals bool | None
None
merge_whitelist_teams list[str] | None
None
merge_whitelist_usernames list[str] | None
None
protected_file_patterns str | None
None
push_whitelist_deploy_keys bool | None
None
push_whitelist_teams list[str] | None
None
push_whitelist_usernames list[str] | None
None
require_signed_commits bool | None
None
required_approvals int | None
None
rule_name str | None
None
status_check_contexts list[str] | None
None
unprotected_file_patterns str | None
None

Returns:

Type Description
BranchProtection

BranchProtection.

Raises:

Type Description
ForbiddenError
  1. APIForbiddenError is a forbidden error response.
NotFoundError
  1. APINotFound is a not found error response.
UnprocessableEntityError
  1. APIValidationError is error format response related to input validation.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoCreateBranchProtection

delete

delete(owner: str, repo: str, name: str) -> None

Delete a specific branch protection for the repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
name str

name of protected branch

required

Returns:

Type Description
None

No content.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoDeleteBranchProtection

get

get(owner: str, repo: str, name: str) -> BranchProtection

Get a specific branch protection for the repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
name str

name of protected branch

required

Returns:

Type Description
BranchProtection

BranchProtection.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.

Operation ID: repoGetBranchProtection

list

list(owner: str, repo: str) -> list[BranchProtection]

List branch protections for a repository.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required

Returns:

Type Description
list[BranchProtection]

BranchProtectionList.

Operation ID: repoListBranchProtection

update

update(
    owner: str,
    repo: str,
    name: str,
    *,
    apply_to_admins: bool | None = None,
    approvals_whitelist_teams: list[str] | None = None,
    approvals_whitelist_username: list[str] | None = None,
    block_on_official_review_requests: bool | None = None,
    block_on_outdated_branch: bool | None = None,
    block_on_rejected_reviews: bool | None = None,
    dismiss_stale_approvals: bool | None = None,
    enable_approvals_whitelist: bool | None = None,
    enable_merge_whitelist: bool | None = None,
    enable_push: bool | None = None,
    enable_push_whitelist: bool | None = None,
    enable_status_check: bool | None = None,
    ignore_stale_approvals: bool | None = None,
    merge_whitelist_teams: list[str] | None = None,
    merge_whitelist_usernames: list[str] | None = None,
    protected_file_patterns: str | None = None,
    push_whitelist_deploy_keys: bool | None = None,
    push_whitelist_teams: list[str] | None = None,
    push_whitelist_usernames: list[str] | None = None,
    require_signed_commits: bool | None = None,
    required_approvals: int | None = None,
    status_check_contexts: list[str] | None = None,
    unprotected_file_patterns: str | None = None,
) -> BranchProtection

Edit a branch protections for a repository. Only fields that are set will be changed.

Parameters:

Name Type Description Default
owner str

owner of the repo

required
repo str

name of the repo

required
name str

name of protected branch

required
apply_to_admins bool | None
None
approvals_whitelist_teams list[str] | None
None
approvals_whitelist_username list[str] | None
None
block_on_official_review_requests bool | None
None
block_on_outdated_branch bool | None
None
block_on_rejected_reviews bool | None
None
dismiss_stale_approvals bool | None
None
enable_approvals_whitelist bool | None
None
enable_merge_whitelist bool | None
None
enable_push bool | None
None
enable_push_whitelist bool | None
None
enable_status_check bool | None
None
ignore_stale_approvals bool | None
None
merge_whitelist_teams list[str] | None
None
merge_whitelist_usernames list[str] | None
None
protected_file_patterns str | None
None
push_whitelist_deploy_keys bool | None
None
push_whitelist_teams list[str] | None
None
push_whitelist_usernames list[str] | None
None
require_signed_commits bool | None
None
required_approvals int | None
None
status_check_contexts list[str] | None
None
unprotected_file_patterns str | None
None

Returns:

Type Description
BranchProtection

BranchProtection.

Raises:

Type Description
NotFoundError
  1. APINotFound is a not found error response.
UnprocessableEntityError
  1. APIValidationError is error format response related to input validation.
LockedError
  1. APIRepoArchivedError is an error that is raised when an archived repo should be modified.

Operation ID: repoEditBranchProtection