mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
Add null checks and fix CodeAnalysis errors.
I enabled code analysis to the Octokit.Reactive project and needed to fix things up.
This commit is contained in:
@@ -28,11 +28,15 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
public IObservable<Authorization> Update(long id, AuthorizationUpdate authorization)
|
||||
{
|
||||
Ensure.ArgumentNotNull(authorization, "authorization");
|
||||
|
||||
return client.Update(id, authorization).ToObservable();
|
||||
}
|
||||
|
||||
public IObservable<Authorization> Create(AuthorizationUpdate authorization)
|
||||
{
|
||||
Ensure.ArgumentNotNull(authorization, "authorization");
|
||||
|
||||
return client.Create(authorization).ToObservable();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
public IObservable<Organization> Get(string org)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
|
||||
return client.Get(org).ToObservable();
|
||||
}
|
||||
|
||||
@@ -27,6 +29,8 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
public IObservable<IReadOnlyCollection<Organization>> GetAll(string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return client.GetAll(user).ToObservable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,9 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
public IObservable<Repository> Get(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return client.Get(owner, name).ToObservable();
|
||||
}
|
||||
|
||||
@@ -27,16 +30,23 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
public IObservable<IReadOnlyCollection<Repository>> GetAllForUser(string login)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
||||
|
||||
return client.GetAllForUser(login).ToObservable();
|
||||
}
|
||||
|
||||
public IObservable<IReadOnlyCollection<Repository>> GetAllForOrg(string organization)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
|
||||
|
||||
return client.GetAllForOrg(organization).ToObservable();
|
||||
}
|
||||
|
||||
public IObservable<Readme> GetReadme(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return client.GetReadme(owner, name).ToObservable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
public IObservable<IReadOnlyCollection<SshKey>> GetAll(string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return client.GetAll(user).ToObservable();
|
||||
}
|
||||
|
||||
@@ -33,11 +35,15 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
public IObservable<SshKey> Create(SshKeyUpdate key)
|
||||
{
|
||||
Ensure.ArgumentNotNull(key, "key");
|
||||
|
||||
return client.Create(key).ToObservable();
|
||||
}
|
||||
|
||||
public IObservable<SshKey> Update(long id, SshKeyUpdate key)
|
||||
{
|
||||
Ensure.ArgumentNotNull(key, "key");
|
||||
|
||||
return client.Update(id, key).ToObservable();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
public IObservable<User> Get(string login)
|
||||
{
|
||||
Ensure.ArgumentNotNull(login, "login");
|
||||
|
||||
return client.Get(login).ToObservable();
|
||||
}
|
||||
|
||||
@@ -26,6 +28,8 @@ namespace Octokit.Reactive.Clients
|
||||
|
||||
public IObservable<User> Update(UserUpdate user)
|
||||
{
|
||||
Ensure.ArgumentNotNull(user, "user");
|
||||
|
||||
return client.Update(user).ToObservable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ namespace Octokit.Reactive
|
||||
string owner,
|
||||
string name)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return client.GetReadme(owner, name).SelectMany(r => r.GetHtmlContent().ToObservable());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,11 @@
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
<Link>CustomDictionary.xml</Link>
|
||||
</CodeAnalysisDictionary>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
@@ -16,6 +16,8 @@ namespace Octokit.Clients
|
||||
{
|
||||
public async Task<IReadOnlyCollection<T>> GetAllPages(Func<Task<IReadOnlyPagedCollection<T>>> getFirstPage)
|
||||
{
|
||||
Ensure.ArgumentNotNull(getFirstPage, "getFirstPage");
|
||||
|
||||
var page = await getFirstPage();
|
||||
var allItems = new List<T>(page);
|
||||
while ((page = await page.GetNextPage()) != null)
|
||||
|
||||
@@ -41,6 +41,8 @@ namespace Octokit.Clients
|
||||
/// <returns></returns>
|
||||
public async Task<Authorization> Update(long id, AuthorizationUpdate authorization)
|
||||
{
|
||||
Ensure.ArgumentNotNull(authorization, "authorization");
|
||||
|
||||
var endpoint = "/authorizations/{0}".FormatUri(id);
|
||||
return await Client.Update(endpoint, authorization);
|
||||
}
|
||||
@@ -52,6 +54,8 @@ namespace Octokit.Clients
|
||||
/// <returns></returns>
|
||||
public async Task<Authorization> Create(AuthorizationUpdate authorization)
|
||||
{
|
||||
Ensure.ArgumentNotNull(authorization, "authorization");
|
||||
|
||||
return await Client.Create(authorizationsEndpoint, authorization);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Octokit.Clients
|
||||
|
||||
public async Task<IReadOnlyCollection<Organization>> GetAll(string user)
|
||||
{
|
||||
Ensure.ArgumentNotNull(user, "user");
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
var endpoint = "/users/{0}/orgs".FormatUri(user);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace Octokit.Clients
|
||||
|
||||
public async Task<IReadOnlyCollection<Repository>> GetAllForUser(string login)
|
||||
{
|
||||
Ensure.ArgumentNotNull(login, "login");
|
||||
Ensure.ArgumentNotNullOrEmptyString(login, "login");
|
||||
|
||||
var endpoint = "/users/{0}/repos".FormatUri(login);
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Octokit.Clients
|
||||
|
||||
public async Task<IReadOnlyCollection<Repository>> GetAllForOrg(string organization)
|
||||
{
|
||||
Ensure.ArgumentNotNull(organization, "organization");
|
||||
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
|
||||
|
||||
var endpoint = "/orgs/{0}/repos".FormatUri(organization);
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace Octokit.Clients
|
||||
|
||||
public async Task<IReadOnlyCollection<SshKey>> GetAll(string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
var endpoint = "/users/{0}/keys".FormatUri(user);
|
||||
|
||||
return await Client.GetAll(endpoint);
|
||||
|
||||
@@ -6,6 +6,8 @@ namespace Octokit
|
||||
{
|
||||
public static TValue SafeGet<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> dictionary, TKey key)
|
||||
{
|
||||
Ensure.ArgumentNotNull(dictionary, "dictionary");
|
||||
|
||||
TValue value;
|
||||
return dictionary.TryGetValue(key, out value) ? value : default(TValue);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace Octokit
|
||||
|
||||
public static Uri FormatUri(this string pattern, params object[] args)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(pattern, "pattern");
|
||||
|
||||
return new Uri(string.Format(CultureInfo.InvariantCulture, pattern, args), UriKind.Relative);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,28 +26,39 @@ namespace Octokit.Http
|
||||
|
||||
public async Task<T> Get(Uri endpoint)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
return await GetItem<T>(endpoint);
|
||||
}
|
||||
|
||||
public async Task<TOther> GetItem<TOther>(Uri endpoint)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
var response = await Connection.GetAsync<TOther>(endpoint);
|
||||
return response.BodyAsObject;
|
||||
}
|
||||
|
||||
public async Task<string> GetHtml(Uri endpoint)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
var response = await Connection.GetHtml(endpoint);
|
||||
return response.Body;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<T>> GetAll(Uri endpoint)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
return await pagination.GetAllPages(async () => await GetPage(endpoint));
|
||||
}
|
||||
|
||||
public async Task<T> Create(Uri endpoint, object data)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
Ensure.ArgumentNotNull(data, "data");
|
||||
|
||||
var response = await Connection.PostAsync<T>(endpoint, data);
|
||||
|
||||
return response.BodyAsObject;
|
||||
@@ -55,6 +66,9 @@ namespace Octokit.Http
|
||||
|
||||
public async Task<T> Update(Uri endpoint, object data)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
Ensure.ArgumentNotNull(data, "data");
|
||||
|
||||
var response = await Connection.PatchAsync<T>(endpoint, data);
|
||||
|
||||
return response.BodyAsObject;
|
||||
@@ -62,11 +76,15 @@ namespace Octokit.Http
|
||||
|
||||
public async Task Delete(Uri endpoint)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
await Connection.DeleteAsync<T>(endpoint);
|
||||
}
|
||||
|
||||
async Task<IReadOnlyPagedCollection<T>> GetPage(Uri endpoint)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
var response = await Connection.GetAsync<List<T>>(endpoint);
|
||||
return new ReadOnlyPagedCollection<T>(response, Connection);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace Octokit.Http
|
||||
Ensure.ArgumentNotNull(credentialStore, "credentialStore");
|
||||
Ensure.ArgumentNotNull(httpClient, "httpClient");
|
||||
Ensure.ArgumentNotNull(serializer, "serializer");
|
||||
|
||||
if (!baseAddress.IsAbsoluteUri)
|
||||
{
|
||||
throw new ArgumentException(
|
||||
@@ -58,6 +59,8 @@ namespace Octokit.Http
|
||||
|
||||
public async Task<IResponse<T>> GetAsync<T>(Uri endpoint)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
return await Run<T>(new Request
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
@@ -68,6 +71,8 @@ namespace Octokit.Http
|
||||
|
||||
public async Task<IResponse<string>> GetHtml(Uri endpoint)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
return await GetHtml(new Request
|
||||
{
|
||||
Method = HttpMethod.Get,
|
||||
@@ -78,6 +83,9 @@ namespace Octokit.Http
|
||||
|
||||
public async Task<IResponse<T>> PatchAsync<T>(Uri endpoint, object body)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
Ensure.ArgumentNotNull(body, "body");
|
||||
|
||||
return await Run<T>(new Request
|
||||
{
|
||||
Method = HttpVerb.Patch,
|
||||
@@ -89,6 +97,9 @@ namespace Octokit.Http
|
||||
|
||||
public async Task<IResponse<T>> PostAsync<T>(Uri endpoint, object body)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
Ensure.ArgumentNotNull(body, "body");
|
||||
|
||||
return await Run<T>(new Request
|
||||
{
|
||||
Method = HttpMethod.Post,
|
||||
@@ -100,6 +111,8 @@ namespace Octokit.Http
|
||||
|
||||
public async Task DeleteAsync<T>(Uri endpoint)
|
||||
{
|
||||
Ensure.ArgumentNotNull(endpoint, "endpoint");
|
||||
|
||||
await Run<T>(new Request
|
||||
{
|
||||
Method = HttpMethod.Delete,
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Octokit.Http
|
||||
|
||||
protected async virtual Task<IResponse<T>> BuildResponse<T>(HttpResponseMessage responseMessage)
|
||||
{
|
||||
Ensure.ArgumentNotNull(responseMessage, "responseMessage");
|
||||
|
||||
var response = new ApiResponse<T>
|
||||
{
|
||||
Body = await responseMessage
|
||||
@@ -71,6 +73,8 @@ namespace Octokit.Http
|
||||
{
|
||||
public static HttpResponseMessage EnsureSuccess(this HttpResponseMessage response)
|
||||
{
|
||||
Ensure.ArgumentNotNull(response, "response");
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user