gitea_sdk/api/repos/
commits.rs

1use build_it::Builder;
2use serde::Serialize;
3
4use crate::{error::Result, model::repos::Commit};
5
6/// Options for getting a list of commits from a repository.
7/// All fields are optional.
8#[derive(Debug, Clone, Serialize, Builder)]
9#[build_it(into)]
10#[serde(default)]
11pub struct GetCommitsBuilder {
12    #[skip]
13    #[serde(skip)]
14    /// The owner of the repository to list commits for.
15    owner: String,
16    #[skip]
17    #[serde(skip)]
18    /// The name of the repository to list commits for.
19    repo: String,
20
21    /// SHA or branch to start listing commits from (usually the default branch).
22    pub sha: Option<String>,
23    /// File path to a file/directory in the repository.
24    /// If provided, only commits affecting this path will be returned.
25    pub path: Option<String>,
26    /// Whether to include the `stat` field in the response.
27    /// Disable to speed-up the response.
28    /// Defaults to true.
29    /// NOTE: Commit verification is not implemented yet, so this setting does nothing.
30    pub stat: Option<bool>,
31    /// Whether to include the `verification` field in the response.
32    /// Disable to speed-up the response.
33    /// Defaults to true.
34    /// NOTE: Commit verification is not implemented yet, so this setting does nothing.
35    pub verification: Option<bool>,
36    /// Whether to include the `files` field in the response.
37    /// Disable to speed-up the response.
38    /// Defaults to true.
39    /// NOTE: Commit verification is not implemented yet, so this setting does nothing.
40    pub files: Option<bool>,
41    /// Optional page number of the results to fetch (1-based).
42    /// Defaults to 1 if not set.
43    pub page: Option<i64>,
44    /// Optional number of commits to return per page (page-size).
45    /// Defaults to the maximum your instance allows if not set.
46    pub limit: Option<i64>,
47    /// Commits that match the given specifier will not be listed.
48    pub not: Option<String>,
49}
50
51impl GetCommitsBuilder {
52    pub fn new(owner: impl ToString, repo: impl ToString) -> Self {
53        Self {
54            owner: owner.to_string(),
55            repo: repo.to_string(),
56            sha: None,
57            path: None,
58            stat: None,
59            verification: None,
60            files: None,
61            page: None,
62            limit: None,
63            not: None,
64        }
65    }
66
67    /// Send the request to get the commits.
68    pub async fn send(&self, client: &crate::Client) -> Result<Vec<Commit>> {
69        let owner = &self.owner;
70        let repo = &self.repo;
71
72        let req = client
73            .get(format!("repos/{owner}/{repo}/commits"))
74            .query(self)
75            .build()?;
76        let res = client.make_request(req).await?;
77        client.parse_response(res).await
78    }
79}