rust_cnb/
repo_contributor.rs

1//! RepoContributor API 客户端
2
3use crate::error::{ApiError, Result};
4use reqwest::Client;
5use serde_json::Value;
6use url::Url;
7
8/// RepoContributor API 客户端
9pub struct RepoContributorClient {
10    base_url: String,
11    client: Client,
12}
13
14impl RepoContributorClient {
15    /// 创建新的 RepoContributor API 客户端
16    pub fn new(base_url: String, client: Client) -> Self {
17        Self { base_url, client }
18    }
19
20    /// 设置认证信息
21    pub fn with_auth(self, token: &str) -> Self {
22        // 这里可以扩展认证逻辑
23        self
24    }
25
26    /// 查询仓库贡献者前 100 名的详细趋势数据。Query detailed trend data for top 100 contributors of the repository.
27    pub async fn get_repo_contributor_trend(
28        &self,
29        repo: String,
30        limit: Option<i64>,
31        exclude_external_users: Option<bool>,
32    ) -> Result<Value> {
33        let path = format!("/{}/-/contributor/trend", repo);
34        let mut url = Url::parse(&format!("{}{}", self.base_url, path))?;
35        
36        if let Some(value) = limit {
37            url.query_pairs_mut().append_pair("limit", &value.to_string());
38        }
39        if let Some(value) = exclude_external_users {
40            url.query_pairs_mut().append_pair("exclude_external_users", &value.to_string());
41        }
42
43                let request = self.client.request(
44            reqwest::Method::GET,
45            url
46        );
47        
48
49
50
51        let response = request.send().await?;
52        
53        if response.status().is_success() {
54            let json: Value = response.json().await?;
55            Ok(json)
56        } else {
57            Err(ApiError::HttpError(response.status().as_u16()))
58        }
59    }
60
61}