gitea_sdk/api/repos/
generate.rs

1use build_it::Builder;
2use serde::Serialize;
3
4use crate::{error::Result, model::repos::Repository};
5
6#[derive(Debug, Clone, PartialEq, Serialize, Builder)]
7#[build_it(into)]
8#[serde(default)]
9pub struct GenerateRepoBuilder {
10    /// The template repository owner
11    #[skip]
12    #[serde(skip)]
13    template_owner: String,
14    /// The template repository name
15    #[skip]
16    #[serde(skip)]
17    template_repo: String,
18    /// Include avatar of the template repo
19    avatar: Option<bool>,
20    /// Default branch of the new repository
21    default_branch: Option<bool>,
22    /// Description of the repository to create
23    description: Option<String>,
24    /// Include git content of default branch in template repo, set as true by default
25    git_content: Option<bool>,
26    /// Include git hooks in template repo
27    git_hooks: Option<bool>,
28    /// Include labels in template repo
29    labels: Option<bool>,
30    /// The name of the repository to create, must be unique.
31    #[skip]
32    name: String,
33    /// The owner of the repository to create.
34    #[skip]
35    owner: String,
36    /// Whether the repository is private
37    private: Option<bool>,
38    /// Include topics in template repo
39    topics: Option<bool>,
40    /// Include webhooks in template repo
41    webhooks: Option<bool>,
42}
43
44impl GenerateRepoBuilder {
45    pub fn new(
46        owner: impl ToString,
47        repo: impl ToString,
48        template_owner: impl ToString,
49        template_repo: impl ToString,
50    ) -> Self {
51        Self {
52            template_owner: template_owner.to_string(),
53            template_repo: template_repo.to_string(),
54            avatar: None,
55            default_branch: None,
56            description: None,
57            // Set as true by default else we get vague error, most users will likely mean this when
58            // using template
59            git_content: Some(true),
60            git_hooks: None,
61            labels: None,
62            name: repo.to_string(),
63            owner: owner.to_string(),
64            private: None,
65            topics: None,
66            webhooks: None,
67        }
68    }
69    /// Send the request to generate the repository.
70    pub async fn send(&self, client: &crate::Client) -> Result<Repository> {
71        let template_owner = &self.template_owner;
72        let template_repo = &self.template_repo;
73        let req = client
74            .post(format!("repos/{template_owner}/{template_repo}/generate"))
75            .json(&self)
76            .build()?;
77        let res = client.make_request(req).await?;
78        client.parse_response(res).await
79    }
80}