Skip to main content

mesa_dev/client/
repo.rs

1use crate::low_level::apis::{repos_api, Error};
2use crate::models;
3
4use super::{
5    BranchesClient, ChangeClient, CommitsClient, ContentClient, OrgClient, WebhooksClient,
6};
7
8/// Client scoped to a specific repository (`/{org}/{repo}`).
9#[derive(Clone, Debug)]
10pub struct RepoClient<'a> {
11    pub(super) org: &'a OrgClient<'a>,
12    pub(super) repo: &'a str,
13}
14
15impl RepoClient<'_> {
16    /// Get repository metadata.
17    ///
18    /// # Errors
19    ///
20    /// Returns an error if the API request fails.
21    #[tracing::instrument(skip(self), fields(org = self.org.org, repo = self.repo), err(Debug))]
22    pub async fn get(
23        &self,
24    ) -> Result<models::PostByOrgRepos201Response, Error<repos_api::GetByOrgByRepoError>> {
25        repos_api::get_by_org_by_repo(&self.org.client.config, self.org.org, Some(self.repo)).await
26    }
27
28    /// Permanently delete this repository and all its data.
29    ///
30    /// # Errors
31    ///
32    /// Returns an error if the API request fails.
33    #[tracing::instrument(skip(self), fields(org = self.org.org, repo = self.repo), err(Debug))]
34    pub async fn delete(
35        &self,
36    ) -> Result<models::DeleteByOrgApiKeysById200Response, Error<repos_api::DeleteByOrgByRepoError>>
37    {
38        repos_api::delete_by_org_by_repo(&self.org.client.config, self.org.org, self.repo).await
39    }
40
41    /// Update repository name or upstream configuration.
42    ///
43    /// # Errors
44    ///
45    /// Returns an error if the API request fails.
46    #[tracing::instrument(skip(self, request), fields(org = self.org.org, repo = self.repo), err(Debug))]
47    pub async fn update(
48        &self,
49        request: models::PatchByOrgByRepoRequest,
50    ) -> Result<models::PostByOrgRepos201Response, Error<repos_api::PatchByOrgByRepoError>> {
51        repos_api::patch_by_org_by_repo(
52            &self.org.client.config,
53            self.org.org,
54            self.repo,
55            Some(request),
56        )
57        .await
58    }
59
60    /// Access branch operations.
61    #[must_use]
62    pub fn branches(&self) -> BranchesClient<'_> {
63        BranchesClient { repo: self }
64    }
65
66    /// Access commit operations.
67    #[must_use]
68    pub fn commits(&self) -> CommitsClient<'_> {
69        CommitsClient { repo: self }
70    }
71
72    /// Access content operations.
73    #[must_use]
74    pub fn content(&self) -> ContentClient<'_> {
75        ContentClient { repo: self }
76    }
77
78    /// Access webhook operations.
79    #[must_use]
80    pub fn webhooks(&self) -> WebhooksClient<'_> {
81        WebhooksClient { repo: self }
82    }
83
84    /// Access change-based file operations (create, modify, delete, move files).
85    ///
86    /// Fetches the repository UUID via the REST API, which is required by the
87    /// gRPC data plane.
88    ///
89    /// # Errors
90    ///
91    /// Returns an error if the repository metadata cannot be fetched.
92    pub async fn change(&self) -> Result<ChangeClient, Error<repos_api::GetByOrgByRepoError>> {
93        let repo_meta = self.get().await?;
94        Ok(ChangeClient::new(
95            &self.org.client.grpc_channel,
96            self.org.client.config.bearer_access_token.as_deref(),
97            repo_meta.id,
98        ))
99    }
100}