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
//! The Teams API
mod children;
mod create;
mod edit;
mod invitations;
mod list;
mod members;
mod memberships;
mod team_repos;
pub mod discussions;
#[allow(deprecated)]
pub use self::discussions::{
ListTeamDiscussionCommentReactionsBuilder, ListTeamDiscussionReactionsBuilder, TeamByIdHandler,
};
pub use self::{
children::ListChildTeamsBuilder,
create::CreateTeamBuilder,
edit::EditTeamBuilder,
invitations::ListTeamInvitationsBuilder,
list::ListTeamsBuilder,
members::ListTeamMembersBuilder,
memberships::TeamMembershipBuilder,
team_repos::{ListTeamRepositoriesBuilder, TeamRepoHandler},
};
use http::Uri;
use snafu::ResultExt;
use crate::error::HttpSnafu;
use crate::{models, Octocrab, Result};
/// Handler for GitHub's teams API.
///
/// Created with [`Octocrab::teams`].
pub struct TeamHandler<'octo> {
crab: &'octo Octocrab,
owner: String,
}
impl<'octo> TeamHandler<'octo> {
pub(crate) fn new(crab: &'octo Octocrab, owner: String) -> Self {
Self { crab, owner }
}
/// Lists teams in the organization.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let teams = octocrab::instance()
/// .teams("owner")
/// .list()
/// .per_page(10)
/// .page(1u8)
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn list(&self) -> ListTeamsBuilder<'_, '_> {
ListTeamsBuilder::new(self)
}
/// Gets a team from its slug.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let team = octocrab::instance()
/// .teams("owner")
/// .get("team")
/// .await?;
/// # Ok(())
/// # }
/// ```
pub async fn get(&self, team_slug: impl Into<String>) -> Result<models::teams::Team> {
let route = format!(
"/orgs/{org}/teams/{team}",
org = self.owner,
team = team_slug.into(),
);
self.crab.get(route, None::<&()>).await
}
/// Creates a new team in the organization.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// use octocrab::params;
///
/// octocrab::instance()
/// .teams("owner")
/// .create("new-team")
/// .description("My team created from Octocrab!")
/// .maintainers(&vec![String::from("ferris")])
/// .repo_names(&vec![String::from("crab-stuff")])
/// .privacy(params::teams::Privacy::Closed)
/// .parent_team_id(1u64.into())
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn create(&self, name: impl Into<String>) -> CreateTeamBuilder<'_, '_, '_, '_> {
CreateTeamBuilder::new(self, name.into())
}
/// Creates a new team in the organization.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// use octocrab::params;
///
/// octocrab::instance()
/// .teams("owner")
/// .edit("some-team", "Some Team")
/// .description("I edited from Octocrab!")
/// .privacy(params::teams::Privacy::Secret)
/// .parent_team_id(2u64.into())
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn edit(
&self,
team_slug: impl Into<String>,
name: impl Into<String>,
) -> EditTeamBuilder<'_, '_> {
EditTeamBuilder::new(self, team_slug.into(), name.into())
}
/// Deletes a team from the organization.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// octocrab::instance().teams("owner").delete("some-team").await?;
/// # Ok(())
/// # }
/// ```
pub async fn delete(&self, team_slug: impl Into<String>) -> Result<()> {
let route = format!(
"/orgs/{org}/teams/{team}",
org = self.owner,
team = team_slug.into(),
);
let uri = Uri::builder()
.path_and_query(route)
.build()
.context(HttpSnafu)?;
crate::map_github_error(self.crab._delete(uri, None::<&()>).await?)
.await
.map(drop)
}
/// List the child teams of a team in the organization.
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// octocrab
/// .teams("owner")
/// .list_children("parent-team")
/// .per_page(5)
/// .page(1u8)
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn list_children(&self, team_slug: impl Into<String>) -> ListChildTeamsBuilder<'_, '_> {
ListChildTeamsBuilder::new(self, team_slug.into())
}
/// Creates a new `TeamRepoHandler` for the specified team,
/// that allows you to manage this team's repositories.
pub fn repos(&self, team_slug: impl Into<String>) -> TeamRepoHandler<'_> {
TeamRepoHandler::new(self.crab, self.owner.clone(), team_slug.into())
}
/// List the members of a team in the organization.
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// octocrab
/// .teams("owner")
/// .members("team-name-here")
/// .per_page(5)
/// .page(1u8)
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn members(&self, team_slug: impl Into<String>) -> ListTeamMembersBuilder<'_, '_> {
ListTeamMembersBuilder::new(self, team_slug.into())
}
/// List the pending invitations for a team in an organization.
/// ```no_run
/// # async fn run(octocrab: &octocrab::Octocrab) -> octocrab::Result<()> {
/// octocrab
/// .teams("owner")
/// .invitations("team-name-here")
/// .per_page(5)
/// .page(1u8)
/// .send()
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn invitations(&self, team_slug: impl Into<String>) -> ListTeamInvitationsBuilder<'_, '_> {
ListTeamInvitationsBuilder::new(self, team_slug.into())
}
/// Creates a new `TeamMembershipBuilder` for the specified team,
/// that allows you to manage this team's memberships.
/// ```no_run
/// # async fn run() -> octocrab::Result<()> {
/// let membership = octocrab::instance()
/// .teams("owner")
/// .memberships("team")
/// .get("username")
/// .await?;
/// # Ok(())
/// # }
/// ```
pub fn memberships(&self, team_slug: impl Into<String>) -> TeamMembershipBuilder<'_> {
TeamMembershipBuilder::new(self.crab, self.owner.clone(), team_slug.into())
}
/// Lists reactions for a team discussion.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28)
#[allow(deprecated)]
#[deprecated(note = "Team Discussions have been deprecated and sunset by GitHub.")]
pub fn list_discussion_reactions(
&self,
team_slug: impl Into<String>,
discussion_number: u64,
) -> ListTeamDiscussionReactionsBuilder<'octo, '_> {
ListTeamDiscussionReactionsBuilder::new(
self.crab,
discussions::TeamDiscussionTarget::OrgAndSlug {
org: self.owner.clone(),
team_slug: team_slug.into(),
},
discussion_number,
)
}
/// Creates a reaction for a team discussion.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28)
#[deprecated(note = "Team Discussions have been deprecated and sunset by GitHub.")]
pub async fn create_discussion_reaction(
&self,
team_slug: impl Into<String>,
discussion_number: u64,
content: models::reactions::ReactionContent,
) -> Result<models::reactions::Reaction> {
let route = format!(
"/orgs/{}/teams/{}/discussions/{discussion_number}/reactions",
self.owner,
team_slug.into()
);
self.crab
.post(route, Some(&serde_json::json!({ "content": content })))
.await
}
/// Deletes a reaction for a team discussion.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28)
#[deprecated(note = "Team Discussions have been deprecated and sunset by GitHub.")]
pub async fn delete_discussion_reaction(
&self,
team_slug: impl Into<String>,
discussion_number: u64,
reaction_id: impl Into<models::ReactionId>,
) -> Result<()> {
let reaction_id = reaction_id.into();
let route = format!(
"/orgs/{}/teams/{}/discussions/{discussion_number}/reactions/{reaction_id}",
self.owner,
team_slug.into()
);
crate::map_github_error(self.crab._delete(route, None::<&()>).await?)
.await
.map(drop)
}
/// Lists reactions for a team discussion comment.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28)
#[allow(deprecated)]
#[deprecated(note = "Team Discussions have been deprecated and sunset by GitHub.")]
pub fn list_discussion_comment_reactions(
&self,
team_slug: impl Into<String>,
discussion_number: u64,
comment_number: u64,
) -> ListTeamDiscussionCommentReactionsBuilder<'octo, '_> {
ListTeamDiscussionCommentReactionsBuilder::new(
self.crab,
discussions::TeamDiscussionTarget::OrgAndSlug {
org: self.owner.clone(),
team_slug: team_slug.into(),
},
discussion_number,
comment_number,
)
}
/// Creates a reaction for a team discussion comment.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28)
#[deprecated(note = "Team Discussions have been deprecated and sunset by GitHub.")]
pub async fn create_discussion_comment_reaction(
&self,
team_slug: impl Into<String>,
discussion_number: u64,
comment_number: u64,
content: models::reactions::ReactionContent,
) -> Result<models::reactions::Reaction> {
let route = format!(
"/orgs/{}/teams/{}/discussions/{discussion_number}/comments/{comment_number}/reactions",
self.owner,
team_slug.into()
);
self.crab
.post(route, Some(&serde_json::json!({ "content": content })))
.await
}
/// Deletes a reaction for a team discussion comment.
///
/// See: [GitHub API Documentation](https://docs.github.com/en/rest/reactions/reactions?apiVersion=2022-11-28)
#[deprecated(note = "Team Discussions have been deprecated and sunset by GitHub.")]
pub async fn delete_discussion_comment_reaction(
&self,
team_slug: impl Into<String>,
discussion_number: u64,
comment_number: u64,
reaction_id: impl Into<models::ReactionId>,
) -> Result<()> {
let reaction_id = reaction_id.into();
let route = format!(
"/orgs/{}/teams/{}/discussions/{discussion_number}/comments/{comment_number}/reactions/{reaction_id}",
self.owner,
team_slug.into()
);
crate::map_github_error(self.crab._delete(route, None::<&()>).await?)
.await
.map(drop)
}
}