pub struct BranchProtection {Show 13 fields
pub id: u64,
pub repo_key: String,
pub pattern: String,
pub require_pr: bool,
pub required_reviews: u32,
pub required_status_checks: HashSet<String>,
pub dismiss_stale_reviews: bool,
pub require_code_owner_review: bool,
pub restrict_pushes: bool,
pub allow_force_push: bool,
pub allow_deletion: bool,
pub created_at: u64,
pub updated_at: u64,
}Expand description
Branch protection rule for a repository.
Branch protection prevents direct pushes to important branches, requiring pull requests with reviews instead.
Fields§
§id: u64Unique rule ID.
repo_key: StringRepository key (e.g., “owner/repo”).
pattern: StringBranch pattern (e.g., “main”, “release/*”).
require_pr: boolRequire changes via pull request.
required_reviews: u32Minimum number of approving reviews required.
required_status_checks: HashSet<String>Required status checks that must pass.
dismiss_stale_reviews: boolDismiss stale reviews when new commits are pushed.
require_code_owner_review: boolRequire review from code owners.
restrict_pushes: boolRestrict who can push (only admins if true).
allow_force_push: boolAllow force pushes.
allow_deletion: boolAllow branch deletion.
created_at: u64When the rule was created (Unix timestamp).
updated_at: u64When the rule was last updated (Unix timestamp).
Implementations§
Source§impl BranchProtection
impl BranchProtection
Sourcepub fn new(id: u64, repo_key: String, pattern: String) -> Self
pub fn new(id: u64, repo_key: String, pattern: String) -> Self
Create a new branch protection rule with defaults.
Sourcepub fn allows_direct_push(&self, is_admin: bool) -> bool
pub fn allows_direct_push(&self, is_admin: bool) -> bool
Check if a direct push is allowed (without PR).
Sourcepub fn allows_force_push(&self) -> bool
pub fn allows_force_push(&self) -> bool
Check if a force push is allowed.
Sourcepub fn allows_deletion(&self) -> bool
pub fn allows_deletion(&self) -> bool
Check if branch deletion is allowed.
Sourcepub fn check_reviews(
&self,
approving_reviews: u32,
has_code_owner_review: bool,
) -> bool
pub fn check_reviews( &self, approving_reviews: u32, has_code_owner_review: bool, ) -> bool
Check if a PR meets the review requirements.
Sourcepub fn check_status(&self, passed_checks: &HashSet<String>) -> bool
pub fn check_status(&self, passed_checks: &HashSet<String>) -> bool
Check if all required status checks have passed.
Sourcepub fn add_required_check(&mut self, check: String)
pub fn add_required_check(&mut self, check: String)
Add a required status check.
Sourcepub fn remove_required_check(&mut self, check: &str) -> bool
pub fn remove_required_check(&mut self, check: &str) -> bool
Remove a required status check.
Trait Implementations§
Source§impl Clone for BranchProtection
impl Clone for BranchProtection
Source§fn clone(&self) -> BranchProtection
fn clone(&self) -> BranchProtection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more