use anyhow::Result;
use super::BitbucketClient;
use crate::models::{BranchRestriction, Paginated};
impl BitbucketClient {
pub async fn list_branch_restrictions(
&self,
workspace: &str,
repo_slug: &str,
pagelen: Option<u32>,
) -> Result<Paginated<BranchRestriction>> {
let path = format!(
"/repositories/{}/{}/branch-restrictions",
workspace, repo_slug
);
match pagelen {
Some(len) => {
self.get_with_query(&path, &[("pagelen", len.to_string().as_str())])
.await
}
None => self.get(&path).await,
}
}
pub async fn create_branch_restriction(
&self,
workspace: &str,
repo_slug: &str,
kind: &str,
pattern: &str,
value: Option<u64>,
) -> Result<BranchRestriction> {
let mut body = serde_json::json!({
"kind": kind,
"pattern": pattern,
});
if let Some(value) = value {
body["value"] = serde_json::json!(value);
}
let path = format!(
"/repositories/{}/{}/branch-restrictions",
workspace, repo_slug
);
self.post(&path, &body).await
}
pub async fn delete_branch_restriction(
&self,
workspace: &str,
repo_slug: &str,
id: u64,
) -> Result<()> {
let path = format!(
"/repositories/{}/{}/branch-restrictions/{}",
workspace, repo_slug, id
);
self.delete(&path).await
}
}