gitea_sdk/api/repos/
edit.rs

1use build_it::Builder;
2use serde::Serialize;
3
4use crate::{
5    error::Result,
6    model::repos::{ExternalTracker, ExternalWiki, Repository},
7};
8
9#[derive(Debug, Clone, PartialEq, Serialize, Builder)]
10#[build_it(into)]
11#[serde(default)]
12pub struct EditRepoBuilder {
13    #[skip]
14    #[serde(skip)]
15    owner: String,
16    #[skip]
17    #[serde(skip)]
18    repo: String,
19
20    /// Either `true` to allow fast-forward-only merging pull requests, or `false` to prevent fast-forward-only merging.
21    allow_fast_forward_only_merge: Option<bool>,
22    /// Either `true` to allow mark pr as merged manually, or `false` to prevent it.
23    allow_manual_merge: Option<bool>,
24    /// Either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
25    allow_merge_commits: Option<bool>,
26    /// Either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.
27    allow_rebase: Option<bool>,
28    /// Either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits.
29    allow_rebase_explicit: Option<bool>,
30    /// Either `true` to allow updating pull request branch by rebase, or `false` to prevent it.
31    allow_rebase_update: Option<bool>,
32    /// Either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging.
33    allow_squash_merge: Option<bool>,
34    /// Set to `true` to archive this repository.
35    archived: Option<bool>,
36    /// Either `true` to enable AutodetectManualMerge, or `false` to prevent it. Note: In some special cases, misjudgments can occur.
37    autodetect_manual_merge: Option<bool>,
38    /// Set to `true` to allow edits from maintainers by default
39    default_allow_maintainer_edit: Option<bool>,
40    /// Sets the default branch for this repository.
41    default_branch: Option<String>,
42    /// Set to `true` to delete pr branch after merge by default
43    default_delete_branch_after_merge: Option<bool>,
44    /// Set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", "squash", or "fast-forward-only".
45    default_merge_style: Option<String>,
46    /// A short description of the repository.
47    description: Option<String>,
48    /// Enable prune - remove obsolete remote-tracking references when mirroring
49    enable_prune: Option<bool>,
50    /// ExternalTracker represents settings for external tracker
51    external_tracker: Option<ExternalTracker>,
52    /// ExternalWiki represents setting for external wiki
53    external_wiki: Option<ExternalWiki>,
54    /// Either `true` to enable actions unit, or `false` to disable them.
55    has_actions: Option<bool>,
56    /// Either `true` to enable issues for this repository or `false` to disable them.
57    has_issues: Option<bool>,
58    /// Either `true` to enable packages unit, or `false` to disable them.
59    has_packages: Option<bool>,
60    /// Either `true` to enable project unit, or `false` to disable them.
61    has_projects: Option<bool>,
62    /// Either `true` to allow pull requests, or `false` to prevent pull request.
63    has_pull_requests: Option<bool>,
64    /// Either `true` to enable releases unit, or `false` to disable them.
65    has_releases: Option<bool>,
66    /// Either `true` to enable the wiki for this repository or `false` to disable it.
67    has_wiki: Option<bool>,
68    /// Either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
69    ignore_whitespace_conflicts: Option<bool>,
70    /// Set to a string like `8h30m0s` to set the mirror interval time
71    mirror_interval: Option<String>,
72    /// Name of the repository
73    name: Option<String>,
74    /// Either `true` to make the repository private or `false` to make it public.
75    ///
76    /// NOTE: you will get a 422 error if the organization restricts changing repository visibility
77    /// To organization owners and a non-owner tries to change the value of private.
78    private: Option<bool>,
79    /// `repo` to only allow repo-level projects, `owner` to only allow owner projects, `all` to allow both.
80    projects_mode: Option<String>,
81    /// Either `true` to make this repository a template or `false` to make it a normal repository
82    template: Option<bool>,
83    /// A URL with more information about the repository.
84    website: Option<String>,
85}
86
87impl EditRepoBuilder {
88    pub fn new(owner: impl ToString, repo: impl ToString) -> Self {
89        Self {
90            owner: owner.to_string(),
91            repo: repo.to_string(),
92            allow_fast_forward_only_merge: None,
93            allow_manual_merge: None,
94            allow_merge_commits: None,
95            allow_rebase: None,
96            allow_rebase_explicit: None,
97            allow_rebase_update: None,
98            allow_squash_merge: None,
99            archived: None,
100            autodetect_manual_merge: None,
101            default_allow_maintainer_edit: None,
102            default_branch: None,
103            default_delete_branch_after_merge: None,
104            default_merge_style: None,
105            description: None,
106            enable_prune: None,
107            external_tracker: None,
108            external_wiki: None,
109            has_actions: None,
110            has_issues: None,
111            has_packages: None,
112            has_projects: None,
113            has_pull_requests: None,
114            has_releases: None,
115            has_wiki: None,
116            ignore_whitespace_conflicts: None,
117            mirror_interval: None,
118            name: None,
119            private: None,
120            projects_mode: None,
121            template: None,
122            website: None,
123        }
124    }
125    /// Send the request to edit the repository.
126    pub async fn send(&self, client: &crate::Client) -> Result<Repository> {
127        let owner = &self.owner;
128        let repo = &self.repo;
129        let req = client
130            .patch(format!("repos/{owner}/{repo}"))
131            .json(&self)
132            .build()?;
133        let res = client.make_request(req).await?;
134        client.parse_response(res).await
135    }
136}