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    pub async fn get(
23        &self,
24    ) -> Result<models::PostByOrgRepos201Response, Error<repos_api::GetByOrgByRepoError>> {
25        repos_api::get_by_org_by_repo(self.org.config, self.org.org, 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    pub async fn delete(
34        &self,
35    ) -> Result<models::DeleteByOrgApiKeysById200Response, Error<repos_api::DeleteByOrgByRepoError>>
36    {
37        repos_api::delete_by_org_by_repo(self.org.config, self.org.org, self.repo).await
38    }
39
40    /// Update repository name or upstream configuration.
41    ///
42    /// # Errors
43    ///
44    /// Returns an error if the API request fails.
45    pub async fn update(
46        &self,
47        request: models::PatchByOrgByRepoRequest,
48    ) -> Result<models::PostByOrgRepos201Response, Error<repos_api::PatchByOrgByRepoError>> {
49        repos_api::patch_by_org_by_repo(self.org.config, self.org.org, self.repo, Some(request))
50            .await
51    }
52
53    /// Access branch operations.
54    #[must_use]
55    pub fn branches(&self) -> BranchesClient<'_> {
56        BranchesClient { repo: self }
57    }
58
59    /// Access commit operations.
60    #[must_use]
61    pub fn commits(&self) -> CommitsClient<'_> {
62        CommitsClient { repo: self }
63    }
64
65    /// Access content operations.
66    #[must_use]
67    pub fn content(&self) -> ContentClient<'_> {
68        ContentClient { repo: self }
69    }
70
71    /// Access diff operations.
72    #[must_use]
73    pub fn diff(&self) -> DiffClient<'_> {
74        DiffClient { repo: self }
75    }
76
77    /// Access sync operations.
78    #[must_use]
79    pub fn sync(&self) -> SyncClient<'_> {
80        SyncClient { repo: self }
81    }
82
83    /// Access webhook operations.
84    #[must_use]
85    pub fn webhooks(&self) -> WebhooksClient<'_> {
86        WebhooksClient { repo: self }
87    }
88
89    /// Access LFS operations.
90    #[must_use]
91    pub fn lfs(&self) -> LfsClient<'_> {
92        LfsClient { repo: self }
93    }
94
95    /// Access analytics and AI attribution.
96    #[must_use]
97    pub fn analytics(&self) -> AnalyticsClient<'_> {
98        AnalyticsClient { repo: self }
99    }
100}