-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
GitHubClient.cs
287 lines (257 loc) · 11.6 KB
/
GitHubClient.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
using System;
using Octokit.Internal;
namespace Octokit
{
/// <summary>
/// A Client for the GitHub API v3. You can read more about the api here: http://developer.github.com.
/// </summary>
public class GitHubClient : IGitHubClient
{
/// <summary>
/// The base address for the GitHub API
/// </summary>
public static readonly Uri GitHubApiUrl = new Uri("https://api.github.com/");
internal static readonly Uri GitHubDotComUrl = new Uri("https://github.com/");
/// <summary>
/// Create a new instance of the GitHub API v3 client pointing to
/// https://api.github.com/
/// </summary>
/// <param name="productInformation">
/// The name (and optionally version) of the product using this library. This is sent to the server as part of
/// the user agent for analytics purposes.
/// </param>
public GitHubClient(ProductHeaderValue productInformation)
: this(new Connection(productInformation, GitHubApiUrl))
{
}
/// <summary>
/// Create a new instance of the GitHub API v3 client pointing to
/// https://api.github.com/
/// </summary>
/// <param name="productInformation">
/// The name (and optionally version) of the product using this library. This is sent to the server as part of
/// the user agent for analytics purposes.
/// </param>
/// <param name="credentialStore">Provides credentials to the client when making requests</param>
public GitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore)
: this(new Connection(productInformation, credentialStore))
{
}
/// <summary>
/// Create a new instance of the GitHub API v3 client pointing to the specified baseAddress.
/// </summary>
/// <param name="productInformation">
/// The name (and optionally version) of the product using this library. This is sent to the server as part of
/// the user agent for analytics purposes.
/// </param>
/// <param name="baseAddress">
/// The address to point this client to. Typically used for GitHub Enterprise
/// instances</param>
public GitHubClient(ProductHeaderValue productInformation, Uri baseAddress)
: this(new Connection(productInformation, FixUpBaseUri(baseAddress)))
{
}
/// <summary>
/// Create a new instance of the GitHub API v3 client pointing to the specified baseAddress.
/// </summary>
/// <param name="productInformation">
/// The name (and optionally version) of the product using this library. This is sent to the server as part of
/// the user agent for analytics purposes.
/// </param>
/// <param name="credentialStore">Provides credentials to the client when making requests</param>
/// <param name="baseAddress">
/// The address to point this client to. Typically used for GitHub Enterprise
/// instances</param>
public GitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore, Uri baseAddress)
: this(new Connection(productInformation, FixUpBaseUri(baseAddress), credentialStore))
{
}
/// <summary>
/// Create a new instance of the GitHub API v3 client using the specified connection.
/// </summary>
/// <param name="connection">The underlying <seealso cref="IConnection"/> used to make requests</param>
public GitHubClient(IConnection connection)
{
Ensure.ArgumentNotNull(connection, "connection");
Connection = connection;
var apiConnection = new ApiConnection(connection);
Activity = new ActivitiesClient(apiConnection);
Authorization = new AuthorizationsClient(apiConnection);
Deployment = new DeploymentsClient(apiConnection);
Enterprise = new EnterpriseClient(apiConnection);
Gist = new GistsClient(apiConnection);
Git = new GitDatabaseClient(apiConnection);
Issue = new IssuesClient(apiConnection);
Migration = new MigrationClient(apiConnection);
Miscellaneous = new MiscellaneousClient(connection);
Oauth = new OauthClient(connection);
Organization = new OrganizationsClient(apiConnection);
PullRequest = new PullRequestsClient(apiConnection);
Repository = new RepositoriesClient(apiConnection);
Search = new SearchClient(apiConnection);
User = new UsersClient(apiConnection);
Reaction = new ReactionsClient(apiConnection);
}
/// <summary>
/// Gets the latest API Info - this will be null if no API calls have been made
/// </summary>
/// <returns><seealso cref="ApiInfo"/> representing the information returned as part of an Api call</returns>
public ApiInfo GetLastApiInfo()
{
return Connection.GetLastApiInfo();
}
/// <summary>
/// Convenience property for getting and setting credentials.
/// </summary>
/// <remarks>
/// You can use this property if you only have a single hard-coded credential. Otherwise, pass in an
/// <see cref="ICredentialStore"/> to the constructor.
/// Setting this property will change the <see cref="ICredentialStore"/> to use
/// the default <see cref="InMemoryCredentialStore"/> with just these credentials.
/// </remarks>
public Credentials Credentials
{
get { return Connection.Credentials; }
// Note this is for convenience. We probably shouldn't allow this to be mutable.
set
{
Ensure.ArgumentNotNull(value, "value");
Connection.Credentials = value;
}
}
/// <summary>
/// The base address of the GitHub API. This defaults to https://api.github.com,
/// but you can change it if needed (to talk to a GitHub:Enterprise server for instance).
/// </summary>
public Uri BaseAddress
{
get { return Connection.BaseAddress; }
}
/// <summary>
/// Provides a client connection to make rest requests to HTTP endpoints.
/// </summary>
public IConnection Connection { get; private set; }
/// <summary>
/// Access GitHub's Authorization API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/oauth_authorizations/
/// </remarks>
public IAuthorizationsClient Authorization { get; private set; }
/// <summary>
/// Access GitHub's Activity API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/activity/
/// </remarks>
public IActivitiesClient Activity { get; private set; }
/// <summary>
/// Access GitHub's Issue API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/issues/
/// </remarks>
public IIssuesClient Issue { get; private set; }
/// <summary>
/// Access GitHub's Migration API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/migration/
/// </remarks>
public IMigrationClient Migration { get; private set; }
/// <summary>
/// Access GitHub's Miscellaneous API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/misc/
/// </remarks>
public IMiscellaneousClient Miscellaneous { get; private set; }
/// <summary>
/// Access GitHub's OAuth API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/oauth/
/// </remarks>
public IOauthClient Oauth { get; private set; }
/// <summary>
/// Access GitHub's Organizations API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/orgs/
/// </remarks>
public IOrganizationsClient Organization { get; private set; }
/// <summary>
/// Access GitHub's Pull Requests API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/pulls/
/// </remarks>
public IPullRequestsClient PullRequest { get; private set; }
/// <summary>
/// Access GitHub's Repositories API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/repos/
/// </remarks>
public IRepositoriesClient Repository { get; private set; }
/// <summary>
/// Access GitHub's Gists API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/gists/
/// </remarks>
public IGistsClient Gist { get; private set; }
/// <summary>
/// Access GitHub's Users API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/users/
/// </remarks>
public IUsersClient User { get; private set; }
/// <summary>
/// Access GitHub's Git Data API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/git/
/// </remarks>
public IGitDatabaseClient Git { get; private set; }
/// <summary>
/// Access GitHub's Search API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/search/
/// </remarks>
public ISearchClient Search { get; private set; }
// TODO: this should be under Repositories to align with the API docs
/// <summary>
/// Access GitHub's Deployments API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/repos/deployments/
/// </remarks>
public IDeploymentsClient Deployment { get; private set; }
/// <summary>
/// Access GitHub's Enterprise API.
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/enterprise/
/// </remarks>
public IEnterpriseClient Enterprise { get; private set; }
/// <summary>
/// Access GitHub's Reactions API
/// </summary>
/// <remarks>
/// Refer to the API documentation for more information: https://developer.github.com/v3/reactions/
/// </remarks>
public IReactionsClient Reaction { get; private set; }
static Uri FixUpBaseUri(Uri uri)
{
Ensure.ArgumentNotNull(uri, "uri");
if (uri.Host.Equals("github.com") || uri.Host.Equals("api.github.com"))
{
return GitHubApiUrl;
}
return new Uri(uri, new Uri("/api/v3/", UriKind.Relative));
}
}
}