gitea_sdk/api/orgs/
create_repo.rs

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