cnb 0.2.1

CNB (cnb.cool) API client for Rust — typed, async, production-ready
Documentation
// @generated DO NOT EDIT.
//
// Generated from the CNB OpenAPI specification by `cnb-codegen`.
// Run `cargo run -p cnb-codegen --manifest-path codegen/Cargo.toml \
//      -- --spec codegen/spec/swagger.json --out src` to refresh.

#![allow(clippy::all)]
#![allow(missing_docs)]
#![allow(unused_imports)]
#![allow(unused_mut)]

use reqwest::Method;
use serde::Serialize;

use crate::error::{ApiError, Result};
use crate::http::HttpInner;
use crate::models;

// `GitSettings` resource client (generated, 11 operations).

/// Resource client.
#[derive(Debug, Clone)]
pub struct GitSettingsClient {
    inner: HttpInner,
}

impl GitSettingsClient {
    /// Construct a new resource client. Normally obtained
    /// via [`crate::ApiClient`] rather than directly.
    pub fn new(inner: HttpInner) -> Self {
        Self { inner }
    }

    /// 删除仓库保护分支规则。 Delete branch protection rule.
    ///
    /// `DELETE /{repo}/-/settings/branch-protections/{id}`
    pub async fn delete_branch_protection(
        &self,
        repo: String,
        id: String,
    ) -> Result<serde_json::Value> {
        let path = format!("/{}/-/settings/branch-protections/{}", repo, id);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<serde_json::Value>(Method::DELETE, url)
            .await
    }

    /// 查询仓库保护分支规则。Get branch protection rule.
    ///
    /// `GET /{repo}/-/settings/branch-protections/{id}`
    pub async fn get_branch_protection(
        &self,
        repo: String,
        id: String,
    ) -> Result<crate::models::BranchProtection> {
        let path = format!("/{}/-/settings/branch-protections/{}", repo, id);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<crate::models::BranchProtection>(Method::GET, url)
            .await
    }

    /// 查询仓库云原生构建设置。List pipeline settings.
    ///
    /// `GET /{repo}/-/settings/cloud-native-build`
    pub async fn get_pipeline_settings(
        &self,
        repo: String,
    ) -> Result<crate::models::PipelineSettings> {
        let path = format!("/{}/-/settings/cloud-native-build", repo);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<crate::models::PipelineSettings>(Method::GET, url)
            .await
    }

    /// 查询仓库合并请求设置。List pull request settings.
    ///
    /// `GET /{repo}/-/settings/pull-request`
    pub async fn get_pull_request_settings(
        &self,
        repo: String,
    ) -> Result<crate::models::PullRequestSettings> {
        let path = format!("/{}/-/settings/pull-request", repo);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<crate::models::PullRequestSettings>(Method::GET, url)
            .await
    }

    /// 查询仓库推送设置。List push limit settings.
    ///
    /// `GET /{repo}/-/settings/push-limit`
    pub async fn get_push_limit_settings(
        &self,
        repo: String,
    ) -> Result<crate::models::PushLimitSettings> {
        let path = format!("/{}/-/settings/push-limit", repo);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<crate::models::PushLimitSettings>(Method::GET, url)
            .await
    }

    /// 查询仓库保护分支规则列表。List branch protection rules.
    ///
    /// `GET /{repo}/-/settings/branch-protections`
    pub async fn list_branch_protections(
        &self,
        repo: String,
    ) -> Result<Vec<crate::models::BranchProtection>> {
        let path = format!("/{}/-/settings/branch-protections", repo);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<Vec<crate::models::BranchProtection>>(Method::GET, url)
            .await
    }

    /// 更新仓库保护分支规则。Update branch protection rule.
    ///
    /// `PATCH /{repo}/-/settings/branch-protections/{id}`
    pub async fn patch_branch_protection(
        &self,
        repo: String,
        id: String,
        body: &crate::models::BranchProtection,
    ) -> Result<serde_json::Value> {
        let path = format!("/{}/-/settings/branch-protections/{}", repo, id);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<serde_json::Value, _>(Method::PATCH, url, body)
            .await
    }

    /// 新增仓库保护分支规则。Create branch protection rule.
    ///
    /// `POST /{repo}/-/settings/branch-protections`
    pub async fn post_branch_protection(
        &self,
        repo: String,
        body: &crate::models::BranchProtection,
    ) -> Result<serde_json::Value> {
        let path = format!("/{}/-/settings/branch-protections", repo);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<serde_json::Value, _>(Method::POST, url, body)
            .await
    }

    /// 更新仓库云原生构建设置。Update pipeline settings.
    ///
    /// `PUT /{repo}/-/settings/cloud-native-build`
    pub async fn put_pipeline_settings(
        &self,
        repo: String,
        body: &crate::models::PipelineSettings,
    ) -> Result<serde_json::Value> {
        let path = format!("/{}/-/settings/cloud-native-build", repo);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<serde_json::Value, _>(Method::PUT, url, body)
            .await
    }

    /// 更新仓库合并请求设置。Set pull request settings.
    ///
    /// `PUT /{repo}/-/settings/pull-request`
    pub async fn put_pull_request_settings(
        &self,
        repo: String,
        body: &crate::models::PullRequestSettings,
    ) -> Result<serde_json::Value> {
        let path = format!("/{}/-/settings/pull-request", repo);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<serde_json::Value, _>(Method::PUT, url, body)
            .await
    }

    /// 设置仓库推送设置。Set push limit settings.
    ///
    /// `PUT /{repo}/-/settings/push-limit`
    pub async fn put_push_limit_settings(
        &self,
        repo: String,
        body: &crate::models::PushLimitSettings,
    ) -> Result<serde_json::Value> {
        let path = format!("/{}/-/settings/push-limit", repo);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<serde_json::Value, _>(Method::PUT, url, body)
            .await
    }
}