Skip to main content

mesa_dev/client/
repo.rs

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