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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
pub mod create_repo;
pub mod current;
pub mod list_repos;
pub mod orgs;
pub mod settings;
pub mod starred;
pub mod tokens;

pub struct User;

impl User {
    /// Gets the currently authenticated user.
    /// This will return a [User] object representing the currently authenticated user.
    /// As long as the token is valid, this method will always return a user.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn get_authenticated_user() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let user = client
    ///     .user()
    ///     .current()
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    pub fn current(&self) -> current::GetAuthenticatedUserBuilder {
        current::GetAuthenticatedUserBuilder::new()
    }

    /// Creates a new repository for the authenticated user.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn create_repo() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let repo = client
    ///     .user()
    ///     .create_repo("my-new-repo")
    ///     .private(true)
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    /// This will create a new private repository with the name "my-new-repo" for the authenticated user.
    pub fn create_repo(&self, name: impl ToString) -> create_repo::CreateRepoBuilder {
        create_repo::CreateRepoBuilder::new(name)
    }

    /// Lists all repositories for the authenticated user.
    /// This will return a list of all [Repository](crate::model::repos::Repository) objects
    /// owned by the authenticated user.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn list_repos() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let repos = client
    ///     .user()
    ///     .list_repos()
    ///     .limit(10)
    ///     .page(2)
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    pub fn list_repos(&self) -> list_repos::ListReposBuilder {
        list_repos::ListReposBuilder::new()
    }

    /// List the current user's organizations.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn list_orgs() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let orgs = client
    ///     .user()
    ///     .orgs()
    ///     .page(2)
    ///     .limit(10)
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    pub fn orgs(&self) -> orgs::Orgs {
        orgs::Orgs::new()
    }

    /// Creates a new access token for a user.
    /// NOTE: This endpoint requires basic authentication and will fail otherwise.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, CreateAccessTokenOption, Auth};
    /// # async fn create_token() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Basic("username", "password")
    /// );
    /// let token = client
    ///     .user()
    ///     .create_access_token("username", "my-new-token", vec!["write:repository", "read:user"])
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// println!("Token {} created: {}", token.name, token.sha1);
    /// let new_client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token(token.sha1)
    /// );
    /// # }
    /// ```
    /// This will create a new token with the name "my-new-token", which can read all user data and
    /// read and write to repositories.
    ///
    /// If the token is successfully created, this method will return a [AccessToken] object.
    /// If the user is not authenticated correctly (e.g. not using basic auth), this method will
    /// return a 403 status code.
    /// In case of any client-side errors, this method will return a 400 status code.
    pub fn create_access_token(
        &self,
        user: impl ToString,
        name: impl ToString,
        scopes: Vec<impl ToString>,
    ) -> tokens::CreateAccessTokenBuilder {
        tokens::CreateAccessTokenBuilder::new(user, name, scopes)
    }

    /// Lists all access tokens for a user.
    /// NOTE: This endpoint requires basic authentication and will fail otherwise.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn list_tokens() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Basic("username", "password")
    /// );
    /// let tokens = client
    ///     .user()
    ///     .list_access_tokens("username")
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    /// This will list all access tokens for the user "username".
    pub fn list_access_tokens(&self, username: impl ToString) -> tokens::ListAccessTokensBuilder {
        tokens::ListAccessTokensBuilder::new(username)
    }

    /// Deletes an access token by its username and token.
    /// This will delete the token and revoke all permissions associated with it.
    /// NOTE: This endpoint requires basic authentication and will fail otherwise.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn delete_token() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Basic("username", "password")
    /// );
    /// client.
    ///     user()
    ///     .delete_access_token("username", "token")
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    /// This will delete the token with the name "token-name" for the user "username".
    ///
    /// If the token does not exist, this method will return a 404 status code.
    /// If the target user is not the authenticated user and the authenticated user is not an
    /// administrator, this method will return a 403 status code.
    /// For any client-side other errors, this method will return a 422 status code.
    /// If the token is successfully deleted, this method will return a 204 status code.
    pub fn delete_access_token(
        &self,
        user: impl ToString,
        token: impl ToString,
    ) -> tokens::DeleteAccessTokenBuilder {
        tokens::DeleteAccessTokenBuilder::new(user, token)
    }

    /// Gets the current user's settings.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn get_settings() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let settings = client
    ///     .user()
    ///     .get_settings()
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// println!("User settings: {:?}", settings);
    /// # }
    /// ```
    pub fn get_settings(&self) -> settings::GetSettingsBuilder {
        settings::GetSettingsBuilder::new()
    }

    /// Updates the current user's settings.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn update_settings() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let settings = client
    ///     .user()
    ///     .update_settings()
    ///     .theme("dark")
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// println!("User settings: {:?}", settings);
    /// # }
    /// ```
    /// This will update the user's theme to "dark".
    pub fn update_settings(&self) -> settings::UpdateSettingsBuilder {
        settings::UpdateSettingsBuilder::new()
    }

    /// Lists all repositories starred by the authenticated user.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn list_starred_repos() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let repos = client
    ///     .user()
    ///     .list_starred()
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    pub fn list_starred(&self) -> starred::ListStarredBuilder {
        starred::ListStarredBuilder::new()
    }

    /// Checks if the authenticated user has starred a repository.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn is_starred() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// let starred = client
    ///     .user()
    ///     .is_starred("owner", "repo")
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// if starred {
    ///     println!("You have starred this repo!");
    /// } else {
    ///     println!("You have not starred this repo.");
    /// }
    /// # }
    /// ```
    pub fn is_starred(
        &self,
        owner: impl ToString,
        repo: impl ToString,
    ) -> starred::IsStarredBuilder {
        starred::IsStarredBuilder::new(owner, repo)
    }

    /// Stars a repository for the authenticated user.
    /// This will star the repository with the given owner and name.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn star_repo() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// client
    ///     .user()
    ///     .star_repo("owner", "repo")
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    /// This will star the repository "repo" owned by "owner".
    pub fn star_repo(&self, owner: impl ToString, repo: impl ToString) -> starred::StarRepoBuilder {
        starred::StarRepoBuilder::new(owner, repo)
    }

    /// Unstars a repository for the authenticated user.
    /// This will unstar the repository with the given owner and name.
    ///
    /// # Example
    /// ```
    /// # use gitea_sdk::{Client, Auth};
    /// # async fn unstar_repo() {
    /// let client = Client::new(
    ///     "https://gitea.example.com",
    ///     Auth::Token("your-token")
    /// );
    /// client
    ///     .user()
    ///     .unstar_repo("owner", "repo")
    ///     .send(&client)
    ///     .await
    ///     .unwrap();
    /// # }
    /// ```
    pub fn unstar_repo(
        &self,
        owner: impl ToString,
        repo: impl ToString,
    ) -> starred::UnstarRepoBuilder {
        starred::UnstarRepoBuilder::new(owner, repo)
    }
}