BranchProtection

Struct BranchProtection 

Source
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: u64

Unique rule ID.

§repo_key: String

Repository key (e.g., “owner/repo”).

§pattern: String

Branch pattern (e.g., “main”, “release/*”).

§require_pr: bool

Require changes via pull request.

§required_reviews: u32

Minimum number of approving reviews required.

§required_status_checks: HashSet<String>

Required status checks that must pass.

§dismiss_stale_reviews: bool

Dismiss stale reviews when new commits are pushed.

§require_code_owner_review: bool

Require review from code owners.

§restrict_pushes: bool

Restrict who can push (only admins if true).

§allow_force_push: bool

Allow force pushes.

§allow_deletion: bool

Allow branch deletion.

§created_at: u64

When the rule was created (Unix timestamp).

§updated_at: u64

When the rule was last updated (Unix timestamp).

Implementations§

Source§

impl BranchProtection

Source

pub fn new(id: u64, repo_key: String, pattern: String) -> Self

Create a new branch protection rule with defaults.

Source

pub fn matches(&self, branch: &str) -> bool

Check if this rule matches a branch name.

Source

pub fn allows_direct_push(&self, is_admin: bool) -> bool

Check if a direct push is allowed (without PR).

Source

pub fn allows_force_push(&self) -> bool

Check if a force push is allowed.

Source

pub fn allows_deletion(&self) -> bool

Check if branch deletion is allowed.

Source

pub fn check_reviews( &self, approving_reviews: u32, has_code_owner_review: bool, ) -> bool

Check if a PR meets the review requirements.

Source

pub fn check_status(&self, passed_checks: &HashSet<String>) -> bool

Check if all required status checks have passed.

Source

pub fn add_required_check(&mut self, check: String)

Add a required status check.

Source

pub fn remove_required_check(&mut self, check: &str) -> bool

Remove a required status check.

Trait Implementations§

Source§

impl Clone for BranchProtection

Source§

fn clone(&self) -> BranchProtection

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BranchProtection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for BranchProtection

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for BranchProtection

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,