rust-cnb 0.1.2

[DEPRECATED - use `cnb` crate instead] rust-cnb with Generated API client
Documentation
//! GitSettings API 客户端

use crate::error::{ApiError, Result};
use reqwest::Client;
use serde_json::Value;
use url::Url;

/// GitSettings API 客户端
pub struct GitSettingsClient {
    base_url: String,
    client: Client,
}

impl GitSettingsClient {
    /// 创建新的 GitSettings API 客户端
    pub fn new(base_url: String, client: Client) -> Self {
        Self { base_url, client }
    }

    /// 设置认证信息
    pub fn with_auth(self, token: &str) -> Self {
        // 这里可以扩展认证逻辑
        self
    }

    /// 查询仓库云原生构建设置。List pipeline settings.
    pub async fn get_repo_settings_cloud_native_build(
        &self,
        repo: String,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/cloud-native-build", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

                let request = self.client.request(
            reqwest::Method::GET,
            url
        );
        



        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 更新仓库云原生构建设置。Update pipeline settings.
    pub async fn put_repo_settings_cloud_native_build(
        &self,
        repo: String,
        pipeline_form: serde_json::Value,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/cloud-native-build", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

        
        let mut request = self.client.request(
            reqwest::Method::PUT,
            url
        );



        request = request.json(&pipeline_form);

        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 查询仓库保护分支规则列表。List branch protection rules.
    pub async fn get_repo_settings_branch_protections(
        &self,
        repo: String,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/branch-protections", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

                let request = self.client.request(
            reqwest::Method::GET,
            url
        );
        



        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 新增仓库保护分支规则。Create branch protection rule.
    pub async fn post_repo_settings_branch_protections(
        &self,
        repo: String,
        branch_protection_form: serde_json::Value,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/branch-protections", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

        
        let mut request = self.client.request(
            reqwest::Method::POST,
            url
        );



        request = request.json(&branch_protection_form);

        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 查询仓库合并请求设置。List pull request settings.
    pub async fn get_repo_settings_pull_request(
        &self,
        repo: String,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/pull-request", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

                let request = self.client.request(
            reqwest::Method::GET,
            url
        );
        



        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 更新仓库合并请求设置。Set pull request settings.
    pub async fn put_repo_settings_pull_request(
        &self,
        repo: String,
        pull_request_form: serde_json::Value,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/pull-request", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

        
        let mut request = self.client.request(
            reqwest::Method::PUT,
            url
        );



        request = request.json(&pull_request_form);

        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 查询仓库保护分支规则。Get branch protection rule.
    pub async fn get_repo_settings_branch_protections_id(
        &self,
        repo: String,
        id: String,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/branch-protections/{}", repo, id);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

                let request = self.client.request(
            reqwest::Method::GET,
            url
        );
        



        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 删除仓库保护分支规则。 Delete branch protection rule.
    pub async fn delete_repo_settings_branch_protections_id(
        &self,
        repo: String,
        id: String,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/branch-protections/{}", repo, id);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

                let request = self.client.request(
            reqwest::Method::DELETE,
            url
        );
        



        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 更新仓库保护分支规则。Update branch protection rule.
    pub async fn patch_repo_settings_branch_protections_id(
        &self,
        repo: String,
        id: String,
        branch_protection_form: serde_json::Value,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/branch-protections/{}", repo, id);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

        
        let mut request = self.client.request(
            reqwest::Method::PATCH,
            url
        );



        request = request.json(&branch_protection_form);

        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 查询仓库推送设置。List push limit settings.
    pub async fn get_repo_settings_push_limit(
        &self,
        repo: String,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/push-limit", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

                let request = self.client.request(
            reqwest::Method::GET,
            url
        );
        



        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

    /// 设置仓库推送设置。Set push limit settings.
    pub async fn put_repo_settings_push_limit(
        &self,
        repo: String,
        push_limit_form: serde_json::Value,
    ) -> Result<Value> {
        let path = format!("/{}/-/settings/push-limit", repo);
        let url = Url::parse(&format!("{}{}", self.base_url, path))?;
        

        
        let mut request = self.client.request(
            reqwest::Method::PUT,
            url
        );



        request = request.json(&push_limit_form);

        let response = request.send().await?;
        
        if response.status().is_success() {
            let json: Value = response.json().await?;
            Ok(json)
        } else {
            Err(ApiError::HttpError(response.status().as_u16()))
        }
    }

}