gitea_sdk/api/user/
create_repo.rs

1use build_it::Builder;
2use serde::Serialize;
3
4use crate::{
5    model::repos::{ObjectFormatName, Repository, TrustModel},
6    Result,
7};
8
9/// Represents the options for creating a new repository.
10/// The only required field is `name`.
11#[derive(Debug, Clone, PartialEq, Serialize, Builder)]
12#[build_it(into)]
13#[serde(default)]
14pub struct CreateRepoBuilder {
15    /// Name of the repository to create.
16    /// NOTE: This field is required. Not setting it will result in an error upon
17    /// repository creation.
18    #[skip]
19    name: String,
20    /// Whether the repository should be automatically initialized.
21    /// This will create a README, LICENSE, and .gitignore file.
22    auto_init: Option<bool>,
23    /// Default branch of the repository.
24    default_branch: Option<String>,
25    /// Description of the repository.
26    description: Option<String>,
27    /// Optional Gitignore templates to use.
28    /// Will be ignored if `auto_init` is false.
29    gitignores: Option<String>,
30    /// Optional Issue label-set to use.
31    issue_labels: Option<String>,
32    /// Optional LICENSE to use.
33    license: Option<String>,
34    /// Object Format Name of the underlying git repository.
35    object_format_name: Option<ObjectFormatName>,
36    /// Whether the repository is private.
37    private: Option<bool>,
38    /// Optional README template to use.
39    /// Will be ignored if `auto_init` is false.
40    readme: Option<String>,
41    /// Whether the repository is a template.
42    template: Option<bool>,
43    /// Trust model for verifying commits in the repository.
44    trust_model: Option<TrustModel>,
45}
46
47impl CreateRepoBuilder {
48    pub fn new(name: impl ToString) -> Self {
49        Self {
50            name: name.to_string(),
51            auto_init: None,
52            default_branch: None,
53            description: None,
54            gitignores: None,
55            issue_labels: None,
56            license: None,
57            object_format_name: None,
58            private: None,
59            readme: None,
60            template: None,
61            trust_model: None,
62        }
63    }
64    /// Send the request to create the repository.
65    /// This will return the created repository object.
66    pub async fn send(&self, client: &crate::Client) -> Result<Repository> {
67        let req = client.post("user/repos").json(self).build()?;
68        let res = client.make_request(req).await?;
69        client.parse_response(res).await
70    }
71}