1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
pub mod commits;
pub mod delete;
pub mod edit;
pub mod forks;
pub mod get;

/// The [Repos] struct provides methods for interacting with repositories.
pub struct Repos {
    pub(crate) owner: String,
    pub(crate) repo: String,
}

impl Repos {
    /// Deletes a repository by its owner and name.
    /// WARNING: This is irreversible and will delete all data associated with the repository.
    /// This action cannot be undone. When invoking this method, you will not be asked for
    /// confirmation. Use with caution, please don't nuke your repositories.
    ///
    /// # Example
    /// ```rust
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn delete_repo() {
    /// let client = Client::new(
    ///    "https://gitea.example.com",
    ///    Auth::Token("your-token")
    /// );
    /// client
    ///    .repos("owner", "repo")
    ///    .delete()
    ///    .send(&client)
    ///    .await
    ///    .unwrap();
    /// # }
    /// ```
    pub fn delete(&self) -> delete::DeleteRepoBuilder {
        delete::DeleteRepoBuilder::new(&self.owner, &self.repo)
    }
    /// Gets a repository by its owner and name.
    /// This will return a [Repository] object if the repository exists and is visible to the
    /// currently authenticated user.
    ///
    /// # Example
    /// ```rust
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn get_repo() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let repo = client
    ///     .repos("owner", "repo")
    ///     .get()
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    ///
    pub fn get(&self) -> get::GetRepoBuilder {
        get::GetRepoBuilder::new(&self.owner, &self.repo)
    }

    /// Forks a repository by its owner and name.
    /// The [CreateForkOption] struct provides a number of optional fields to customize the fork,
    /// but all fields are entirely optional.
    /// If you don't set any fields, the fork will be created with the same name as the original
    /// repository in the authenticated user's account.
    ///
    /// # Examples
    ///
    /// ```rust
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn fork_repo() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let forked_repo = client
    ///     .repos("owner", "repo")
    ///     .create_fork()
    ///     .name("my-fork")
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    /// This will fork the repository "owner/repo" into the authenticated user's account with the
    /// name "my-fork".
    ///
    /// ```rust
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn fork_repo() {
    /// let client = Client::new(
    ///    "https://gitea.example.com",
    ///    Auth::Token("your-token")
    /// );
    /// let forked_repo = client
    ///    .repos("owner", "repo")
    ///    .create_fork()
    ///    .organization("my-org")
    ///    .send(&client)
    ///    .await
    ///    .unwrap();
    /// # }
    /// ```
    /// This will fork the repository "owner/repo" into the organization "my-org" with the same
    /// name as the original repository.
    ///
    /// ```rust
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn fork_repo() {
    /// let client = Client::new(
    ///    "https://gitea.example.com",
    ///    Auth::Token("your-token")
    /// );
    /// let created_repo = client
    ///   .user()
    ///   .create_repo("my-new-repo")
    ///   .send(&client)
    ///   .await
    ///   .unwrap();
    /// let forked_repo = client
    ///    .repos("owner", "my-new-repo")
    ///    .create_fork()
    ///    .name("my-new-repo")
    ///    .send(&client)
    ///    .await
    ///    .expect_err("Repository with the same name should already exist for the current user");
    /// # }
    /// ```
    /// This will create a new repository with the name "my-new-repo" for the authenticated user,
    /// then attempt to fork the repository "owner/repo" into the authenticated user's account.
    /// The fork will fail because a repository with the same name already exists.
    pub fn create_fork(&self) -> forks::CreateForkBuilder {
        forks::CreateForkBuilder::new(&self.owner, &self.repo)
    }

    /// Edits a repository by its owner and name.
    ///
    /// If you don't set any fields, the repository will not be modified.
    ///
    /// # Example
    /// ```rust
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn edit_repo() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///      Auth::Token("your-token")
    /// );
    /// let repo = client
    ///     .repos("owner", "repo")
    ///     .edit()
    ///     .description("A new description")
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    /// This will set the description of the repository "owner/repo" to "A new description".
    /// If you want to remove the description, you can set it to an empty string.
    pub fn edit(&self) -> edit::EditRepoBuilder {
        edit::EditRepoBuilder::new(&self.owner, &self.repo)
    }

    /// Lists the forks of a repository by its owner and name.
    pub fn get_forks(&self) -> forks::ListForksBuilder {
        forks::ListForksBuilder::new(&self.owner, &self.repo)
    }

    /// Gets a list of commits for a repository.
    /// The [GetCommitsOption] struct provides a number of optional fields to filter the results,
    /// but all fields are entirely optional.
    /// If you don't set any fields, you will get the most recent commits for the default branch.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, api::repos::commits::GetCommitsBuilder, Auth};
    /// # async fn get_commits() {
    /// let client = Client::new(
    ///    "https://gitea.example.com",
    ///    Auth::Token("your-token")
    /// );
    /// let commits = client
    ///   .repos("owner", "repo")
    ///   .get_commits()
    ///   .send(&client)
    ///   .await
    ///   .unwrap();
    /// # }
    /// ```
    pub fn get_commits(&self) -> commits::GetCommitsBuilder {
        commits::GetCommitsBuilder::new(&self.owner, &self.repo)
    }
}