-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ObservableTeamsClient.cs
424 lines (375 loc) · 18.8 KB
/
ObservableTeamsClient.cs
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Org Teams API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/teams/">Orgs API documentation</a> for more information.
/// </remarks>
public class ObservableTeamsClient : IObservableTeamsClient
{
readonly IConnection _connection;
readonly ITeamsClient _client;
/// <summary>
/// Initializes a new Organization Teams API client.
/// </summary>
/// <param name="client">An <see cref="IGitHubClient" /> used to make the requests</param>
public ObservableTeamsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_connection = client.Connection;
_client = client.Organization.Team;
}
/// <summary>
/// Gets a single <see cref="Team"/> by identifier.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#get-team
/// </remarks>
/// <param name="id">The team identifier.</param>
/// <returns>The <see cref="Team"/> with the given identifier.</returns>
public IObservable<Team> Get(int id)
{
return _client.Get(id).ToObservable();
}
/// <summary>
/// Returns all <see cref="Team" />s for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
public IObservable<Team> GetAll(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
return GetAll(org, ApiOptions.None);
}
/// <summary>
/// Returns all <see cref="Team" />s for the current org.
/// </summary>
/// <param name="org">Organization to list all teams of.</param>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
public IObservable<Team> GetAll(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.OrganizationTeams(org), null, AcceptHeaders.NestedTeamsPreview, options);
}
/// <summary>
/// Returns all <see cref="Team" />s for the current user.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the user's <see cref="Team"/>s.</returns>
public IObservable<Team> GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
/// <summary>
/// Returns all <see cref="Team" />s for the current user.
/// </summary>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the user's <see cref="Team"/>s.</returns>
public IObservable<Team> GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.UserTeams(), null, AcceptHeaders.NestedTeamsPreview, options);
}
/// <summary>
/// Returns all child teams of the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-child-teams
/// </remarks>
public IObservable<Team> GetAllChildTeams(int id)
{
return GetAllChildTeams(id, ApiOptions.None);
}
/// <summary>
/// Returns all child teams of the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-child-teams
/// </remarks>
public IObservable<Team> GetAllChildTeams(int id, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.TeamChildTeams(id), null, AcceptHeaders.NestedTeamsPreview, options);
}
/// <summary>
/// Returns all members of the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
public IObservable<User> GetAllMembers(int id)
{
return GetAllMembers(id, ApiOptions.None);
}
/// <summary>
/// Returns all members of the given team.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <param name="id">The team identifier</param>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
public IObservable<User> GetAllMembers(int id, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<User>(ApiUrls.TeamMembers(id), null, AcceptHeaders.NestedTeamsPreview, options);
}
/// <summary>
/// Returns all members with the specified role in the given team of the given role.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <param name="id">The team identifier</param>
/// <param name="request">The request filter</param>
public IObservable<User> GetAllMembers(int id, TeamMembersRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllMembers(id, request, ApiOptions.None);
}
/// <summary>
/// Returns all members with the specified role in the given team of the given role.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <param name="id">The team identifier</param>
/// <param name="request">The request filter</param>
/// <param name="options">Options to change API behaviour.</param>
public IObservable<User> GetAllMembers(int id, TeamMembersRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<User>(ApiUrls.TeamMembers(id), request.ToParametersDictionary(), AcceptHeaders.NestedTeamsPreview, options);
}
/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>Newly created <see cref="Team"/></returns>
public IObservable<Team> Create(string org, NewTeam team)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
Ensure.ArgumentNotNull(team, "team");
return _client.Create(org, team).ToObservable();
}
/// <summary>
/// Returns updated <see cref="Team" /> for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>Updated <see cref="Team"/></returns>
public IObservable<Team> Update(int id, UpdateTeam team)
{
Ensure.ArgumentNotNull(team, "team");
return _client.Update(id, team).ToObservable();
}
/// <summary>
/// Delete a team - must have owner permissions to this
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
public IObservable<Unit> Delete(int id)
{
return _client.Delete(id).ToObservable();
}
/// <summary>
/// Adds a <see cref="User"/> to a <see cref="Team"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-or-update-team-membership">API documentation</a> for more information.
/// </remarks>
/// <param name="id">The team identifier.</param>
/// <param name="login">The user to add to the team.</param>
[Obsolete("Please use AddOrEditMembership instead")]
public IObservable<TeamMembership> AddMembership(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return _client.AddMembership(id, login).ToObservable();
}
/// <summary>
/// Adds a <see cref="User"/> to a <see cref="Team"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-or-update-team-membership">API documentation</a> for more information.
/// </remarks>
/// <param name="id">The team identifier.</param>
/// <param name="login">The user to add to the team.</param>
/// <param name="request">Additional parameters for the request</param>
public IObservable<TeamMembershipDetails> AddOrEditMembership(int id, string login, UpdateTeamMembership request)
{
Ensure.ArgumentNotNullOrEmptyString(login, nameof(login));
Ensure.ArgumentNotNull(request, nameof(request));
return _client.AddOrEditMembership(id, login, request).ToObservable();
}
/// <summary>
/// Removes a <see cref="User"/> from a <see cref="Team"/>.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#remove-team-member">API documentation</a> for more information.
/// </remarks>
/// <param name="id">The team identifier.</param>
/// <param name="login">The user to remove from the team.</param>
/// <returns><see langword="true"/> if the user was removed from the team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> RemoveMembership(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return _client.RemoveMembership(id, login).ToObservable();
}
/// <summary>
/// Gets whether the user with the given <paramref name="login"/>
/// is a member of the team with the given <paramref name="id"/>.
/// </summary>
/// <param name="id">The team to check.</param>
/// <param name="login">The user to check.</param>
[Obsolete("Please use GetMembershipDetails instead")]
public IObservable<TeamMembership> GetMembership(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return _client.GetMembership(id, login).ToObservable();
}
/// <summary>
/// Gets whether the user with the given <paramref name="login"/>
/// is a member of the team with the given <paramref name="id"/>.
/// A <see cref="NotFoundException"/> is thrown if the user is not a member.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#get-team-membership">API documentation</a> for more information.
/// </remarks>
/// <param name="id">The team to check.</param>
/// <param name="login">The user to check.</param>
public IObservable<TeamMembershipDetails> GetMembershipDetails(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");
return _client.GetMembershipDetails(id, login).ToObservable();
}
/// <summary>
/// Returns all team's repositories.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The team's repositories</returns>
public IObservable<Repository> GetAllRepositories(int id)
{
return GetAllRepositories(id, ApiOptions.None);
}
/// <summary>
/// Returns all team's repositories.
/// </summary>
/// <param name="id">Team Id.</param>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The team's repositories</returns>
public IObservable<Repository> GetAllRepositories(int id, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.TeamRepositories(id), null, AcceptHeaders.NestedTeamsPreview, options);
}
/// <summary>
/// Adds a <see cref="Repository"/> to a <see cref="Team"/>.
/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="organization">Org to associate the repo with.</param>
/// <param name="repoName">Name of the repo.</param>
/// <exception cref="ApiValidationException">Thrown if you attempt to add a repository to a team that is not owned by the organization.</exception>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository was added to the team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> AddRepository(int id, string organization, string repoName)
{
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");
return _client.AddRepository(id, organization, repoName).ToObservable();
}
/// <summary>
/// Adds a <see cref="Repository"/> to a <see cref="Team"/>.
/// </summary>
/// <param name="id">The team identifier.</param>
/// <param name="organization">Org to associate the repo with.</param>
/// <param name="repoName">Name of the repo.</param>
/// <param name="permission">The permission to grant the team on this repository.</param>
/// <exception cref="ApiValidationException">Thrown if you attempt to add a repository to a team that is not owned by the organization.</exception>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#add-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository was added to the team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> AddRepository(int id, string organization, string repoName, RepositoryPermissionRequest permission)
{
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");
return _client.AddRepository(id, organization, repoName, permission).ToObservable();
}
/// <summary>
/// Remove a repository from the team
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
public IObservable<bool> RemoveRepository(int id, string organization, string repoName)
{
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");
return _client.RemoveRepository(id, organization, repoName).ToObservable();
}
/// <summary>
/// Gets whether or not the given repository is managed by the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <param name="owner">Owner of the org the team is associated with.</param>
/// <param name="repo">Name of the repo.</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#get-team-repo">API documentation</a> for more information.
/// </remarks>
/// <returns><see langword="true"/> if the repository is managed by the given team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> IsRepositoryManagedByTeam(int id, string owner, string repo)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
return _client.IsRepositoryManagedByTeam(id, owner, repo).ToObservable();
}
/// <summary>
/// List all pending invitations for the given team.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="id">The team identifier</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(int id)
{
Ensure.ArgumentNotNull(id, nameof(id));
return GetAllPendingInvitations(id, ApiOptions.None);
}
/// <summary>
/// List all pending invitations for the given team.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/orgs/teams/#list-pending-team-invitations">API Documentation</a>
/// for more information.
/// </remarks>
/// <param name="id">The team identifier</param>
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
public IObservable<OrganizationMembershipInvitation> GetAllPendingInvitations(int id, ApiOptions options)
{
Ensure.ArgumentNotNull(id, nameof(id));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages<OrganizationMembershipInvitation>(ApiUrls.TeamPendingInvitations(id), null, AcceptHeaders.OrganizationMembershipPreview, options);
}
}
}