Skip to main content

mesa_dev/client/
analytics.rs

1use crate::low_level::apis::{agent_blame_api, Error};
2use crate::models;
3
4use super::RepoClient;
5
6/// Client for analytics and AI attribution (`/{org}/{repo}/analytics`).
7#[derive(Clone, Debug)]
8pub struct AnalyticsClient<'a> {
9    pub(super) repo: &'a RepoClient<'a>,
10}
11
12impl AnalyticsClient<'_> {
13    /// Get repository analytics.
14    ///
15    /// # Errors
16    ///
17    /// Returns an error if the API request fails.
18    pub async fn get(
19        &self,
20        period: Option<&str>,
21    ) -> Result<
22        models::GetByOrgByRepoAnalytics200Response,
23        Error<agent_blame_api::GetByOrgByRepoAnalyticsError>,
24    > {
25        agent_blame_api::get_by_org_by_repo_analytics(
26            self.repo.org.config,
27            self.repo.org.org,
28            self.repo.repo,
29            period,
30        )
31        .await
32    }
33
34    /// Trigger a full re-aggregation of repository analytics.
35    ///
36    /// # Errors
37    ///
38    /// Returns an error if the API request fails.
39    pub async fn refresh(
40        &self,
41    ) -> Result<
42        models::GetByOrgByRepoAnalytics200Response,
43        Error<agent_blame_api::PostByOrgByRepoAnalyticsRefreshError>,
44    > {
45        agent_blame_api::post_by_org_by_repo_analytics_refresh(
46            self.repo.org.config,
47            self.repo.org.org,
48            self.repo.repo,
49        )
50        .await
51    }
52
53    /// Get AI attribution data between two refs.
54    ///
55    /// # Errors
56    ///
57    /// Returns an error if the API request fails.
58    pub async fn agentblame(
59        &self,
60        base: &str,
61        head: &str,
62    ) -> Result<
63        models::GetByOrgByRepoAgentblame200Response,
64        Error<agent_blame_api::GetByOrgByRepoAgentblameError>,
65    > {
66        agent_blame_api::get_by_org_by_repo_agentblame(
67            self.repo.org.config,
68            self.repo.org.org,
69            self.repo.repo,
70            base,
71            head,
72        )
73        .await
74    }
75}