-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ProjectsClient.cs
324 lines (291 loc) · 15.6 KB
/
ProjectsClient.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
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Repository Projects API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/">Repository Projects API documentation</a> for more information.
/// </remarks>
public class ProjectsClient : ApiClient, IProjectsClient
{
public ProjectsClient(IApiConnection apiConnection) :
base(apiConnection)
{
Card = new ProjectCardsClient(apiConnection);
Column = new ProjectColumnsClient(apiConnection);
}
/// <summary>
/// Get all projects for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-repository-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
[ManualRoute("GET", "/repos/{owner}/{name}/projects")]
public Task<IReadOnlyList<Project>> GetAllForRepository(string owner, string name)
{
return GetAllForRepository(owner, name, ApiOptions.None);
}
/// <summary>
/// Get all projects for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-repository-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/repos/{owner}/{name}/projects")]
public Task<IReadOnlyList<Project>> GetAllForRepository(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll<Project>(ApiUrls.RepositoryProjects(owner, name), new Dictionary<string, string>(), AcceptHeaders.ProjectsApiPreview, options);
}
/// <summary>
/// Get all projects for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-repository-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">Used to filter the list of projects returned</param>
[ManualRoute("GET", "/repos/{owner}/{name}/projects")]
public Task<IReadOnlyList<Project>> GetAllForRepository(string owner, string name, ProjectRequest request)
{
return GetAllForRepository(owner, name, request, ApiOptions.None);
}
/// <summary>
/// Get all projects for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-repository-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">Used to filter the list of projects returned</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/repos/{owner}/{name}/projects")]
public Task<IReadOnlyList<Project>> GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll<Project>(ApiUrls.RepositoryProjects(owner, name), request.ToParametersDictionary(), AcceptHeaders.ProjectsApiPreview, options);
}
/// <summary>
/// Get all projects for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-repository-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
[ManualRoute("GET", "/repositories/{id}/projects")]
public Task<IReadOnlyList<Project>> GetAllForRepository(long repositoryId)
{
return GetAllForRepository(repositoryId, ApiOptions.None);
}
/// <summary>
/// Get all projects for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-repository-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/repositories/{id}/projects")]
public Task<IReadOnlyList<Project>> GetAllForRepository(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll<Project>(ApiUrls.RepositoryProjects(repositoryId), new Dictionary<string, string>(), AcceptHeaders.ProjectsApiPreview, options);
}
/// <summary>
/// Get all projects for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-repository-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="request">Used to filter the list of projects returned</param>
[ManualRoute("GET", "/repositories/{id}/projects")]
public Task<IReadOnlyList<Project>> GetAllForRepository(long repositoryId, ProjectRequest request)
{
return GetAllForRepository(repositoryId, request, ApiOptions.None);
}
/// <summary>
/// Get all projects for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-repository-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="request">Used to filter the list of projects returned</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/repositories/{id}/projects")]
public Task<IReadOnlyList<Project>> GetAllForRepository(long repositoryId, ProjectRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll<Project>(ApiUrls.RepositoryProjects(repositoryId), request.ToParametersDictionary(), AcceptHeaders.ProjectsApiPreview, options);
}
/// <summary>
/// Get all projects for the specified organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-organization-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="organization">The name of the organization</param>
[ManualRoute("GET", "/orgs/{org}/projects")]
public Task<IReadOnlyList<Project>> GetAllForOrganization(string organization)
{
return GetAllForOrganization(organization, ApiOptions.None);
}
/// <summary>
/// Get all projects for the specified organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-organization-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="organization">The name of the organization</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/orgs/{org}/projects")]
public Task<IReadOnlyList<Project>> GetAllForOrganization(string organization, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll<Project>(ApiUrls.OrganizationProjects(organization), new Dictionary<string, string>(), AcceptHeaders.ProjectsApiPreview, options);
}
/// <summary>
/// Get all projects for the specified organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-organization-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="organization">The name of the organization</param>
/// <param name="request">Used to filter the list of projects returned</param>
[ManualRoute("GET", "/orgs/{org}/projects")]
public Task<IReadOnlyList<Project>> GetAllForOrganization(string organization, ProjectRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
Ensure.ArgumentNotNull(request, nameof(request));
return GetAllForOrganization(organization, request, ApiOptions.None);
}
/// <summary>
/// Get all projects for the specified organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#list-organization-projects">API documentation</a> for more information.
/// </remarks>
/// <param name="organization">The name of the organization</param>
/// <param name="request">Used to filter the list of projects returned</param>
/// <param name="options">Options for changing the API response</param>
[ManualRoute("GET", "/orgs/{org}/projects")]
public Task<IReadOnlyList<Project>> GetAllForOrganization(string organization, ProjectRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll<Project>(ApiUrls.OrganizationProjects(organization), request.ToParametersDictionary(), AcceptHeaders.ProjectsApiPreview, options);
}
/// <summary>
/// Gets a single project for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/#get-a-project">API documentation</a> for more information.
/// </remarks>
/// <param name="id">The Id of the project</param>
[ManualRoute("GET", "/projects/{project_id}")]
public Task<Project> Get(int id)
{
return ApiConnection.Get<Project>(ApiUrls.Project(id), null, AcceptHeaders.ProjectsApiPreview);
}
// NOTE: I think we're missing a Task<Project> CreateForRepository(owner, name, newProject)
// Can we identify this programatically?
/// <summary>
/// Creates a project for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#create-a-repository-project">API documentation</a> for more information.
/// </remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="newProject">The new project to create for this repository</param>
[ManualRoute("POST", "/repositories/{id}/projects")]
public Task<Project> CreateForRepository(long repositoryId, NewProject newProject)
{
Ensure.ArgumentNotNull(newProject, nameof(newProject));
return ApiConnection.Post<Project>(ApiUrls.RepositoryProjects(repositoryId), newProject, AcceptHeaders.ProjectsApiPreview);
}
/// <summary>
/// Creates a project for the specified organization.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/projects/#create-an-organization-project">API documentation</a> for more information.
/// </remarks>
/// <param name="organization">The name of the organization</param>
/// <param name="newProject">The new project to create for this repository</param>
[ManualRoute("POST", "/orgs/{org}/projects")]
public Task<Project> CreateForOrganization(string organization, NewProject newProject)
{
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
Ensure.ArgumentNotNull(newProject, nameof(newProject));
return ApiConnection.Post<Project>(ApiUrls.OrganizationProjects(organization), newProject, AcceptHeaders.ProjectsApiPreview);
}
/// <summary>
/// Updates a project for this repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/#update-a-project">API documentation</a> for more information.
/// </remarks>
/// <param name="id">The Id of the project</param>
/// <param name="projectUpdate">The modified project</param>
[ManualRoute("PATCH", "/project/{project_id}")]
public Task<Project> Update(int id, ProjectUpdate projectUpdate)
{
Ensure.ArgumentNotNull(projectUpdate, nameof(projectUpdate));
return ApiConnection.Patch<Project>(ApiUrls.Project(id), projectUpdate, AcceptHeaders.ProjectsApiPreview);
}
/// <summary>
/// Deletes a project.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/#delete-a-project">API documentation</a> for more information.
/// </remarks>
/// <param name="id">The Id of the project</param>
[ManualRoute("DELETE", "/project/{project_id}")]
public async Task<bool> Delete(int id)
{
var endpoint = ApiUrls.Project(id);
try
{
var httpStatusCode = await Connection.Delete(endpoint, new object(), AcceptHeaders.ProjectsApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
/// <summary>
/// A client for GitHub's Project Cards API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/cards/">Repository Projects API documentation</a> for more information.
/// </remarks>
public IProjectCardsClient Card { get; private set; }
/// <summary>
/// A client for GitHub's Project Columns API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/columns/">Repository Projects API documentation</a> for more information.
/// </remarks>
public IProjectColumnsClient Column { get; private set; }
}
}