From 0b0661aa1e74aa84bed2c21d3a2abf1d0b3c7713 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 14 Nov 2013 12:44:02 +1100 Subject: [PATCH 01/64] add gist get --- Octokit.Tests.Integration/GistsClientTests.cs | 32 ++++++++++ .../Octokit.Tests.Integration.csproj | 1 + Octokit.Tests/Clients/GistsClientTests.cs | 33 ++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + Octokit.sln.DotSettings | 1 + Octokit/Clients/GistsClient.cs | 26 ++++++++ Octokit/Clients/IGistsClient.cs | 20 +++++++ Octokit/GitHubClient.cs | 2 + Octokit/Helpers/ApiUrls.cs | 9 +++ Octokit/IGitHubClient.cs | 1 + Octokit/Models/Response/Gist.cs | 60 +++++++++++++++++++ Octokit/Octokit-Mono.csproj | 3 + Octokit/Octokit-netcore45.csproj | 3 + Octokit/Octokit.csproj | 5 +- 14 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 Octokit.Tests.Integration/GistsClientTests.cs create mode 100644 Octokit.Tests/Clients/GistsClientTests.cs create mode 100644 Octokit/Clients/GistsClient.cs create mode 100644 Octokit/Clients/IGistsClient.cs create mode 100644 Octokit/Models/Response/Gist.cs diff --git a/Octokit.Tests.Integration/GistsClientTests.cs b/Octokit.Tests.Integration/GistsClientTests.cs new file mode 100644 index 00000000..855e6c58 --- /dev/null +++ b/Octokit.Tests.Integration/GistsClientTests.cs @@ -0,0 +1,32 @@ +using System; +using System.Linq; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration +{ + public class GistsClientTests + { + readonly IGitHubClient _gitHubClient; + readonly IGistsClient _gistsClient; + + public GistsClientTests() + { + this._gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + + this._gistsClient = this._gitHubClient.Gist; + } + + [IntegrationTest] + public async Task CanGetGist() + { + var retrieved = await this._gistsClient.Get(6305249); + Assert.NotNull(retrieved); + } + + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 205f8a4e..bc418d27 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -60,6 +60,7 @@ + diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs new file mode 100644 index 00000000..bd7b5f95 --- /dev/null +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using NSubstitute; +using Octokit; +using Xunit; + +public class GistsClientTests +{ + public class TheGetMethod + { + + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + client.Get(1); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/repo/git/commits/reference"), null); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new GistsClient(null)); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index cff9ef07..4ea2946d 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -62,6 +62,7 @@ + diff --git a/Octokit.sln.DotSettings b/Octokit.sln.DotSettings index 36aa1792..202116c9 100644 --- a/Octokit.sln.DotSettings +++ b/Octokit.sln.DotSettings @@ -262,4 +262,5 @@ II.2.12 <HandlesEvent /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + True \ No newline at end of file diff --git a/Octokit/Clients/GistsClient.cs b/Octokit/Clients/GistsClient.cs new file mode 100644 index 00000000..dc3a5099 --- /dev/null +++ b/Octokit/Clients/GistsClient.cs @@ -0,0 +1,26 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + public class GistsClient : ApiClient, IGistsClient + { + public GistsClient(IApiConnection apiConnection) : + base(apiConnection) + { + } + + /// + /// Gets a gist + /// + /// + /// http://developer.github.com/v3/gists/#get-a-single-gist + /// + /// The id of the gist + public Task Get(int id) + { + return ApiConnection.Get(ApiUrls.Gist(id)); + } + + + } +} \ No newline at end of file diff --git a/Octokit/Clients/IGistsClient.cs b/Octokit/Clients/IGistsClient.cs new file mode 100644 index 00000000..5137d71b --- /dev/null +++ b/Octokit/Clients/IGistsClient.cs @@ -0,0 +1,20 @@ +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IGistsClient + { + /// + /// Gets a gist + /// + /// + /// http://developer.github.com/v3/gists/#get-a-single-gist + /// + /// The id of the gidt + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + Task Get(int id); + + } +} \ No newline at end of file diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index 9bbcd384..e14a01d7 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -86,6 +86,7 @@ namespace Octokit Notification = new NotificationsClient(apiConnection); Organization = new OrganizationsClient(apiConnection); Repository = new RepositoriesClient(apiConnection); + Gist = new GistsClient(apiConnection); Release = new ReleasesClient(apiConnection); User = new UsersClient(apiConnection); SshKey = new SshKeysClient(apiConnection); @@ -132,6 +133,7 @@ namespace Octokit public IMiscellaneousClient Miscellaneous { get; private set; } public IOrganizationsClient Organization { get; private set; } public IRepositoriesClient Repository { get; private set; } + public IGistsClient Gist { get; private set; } public IReleasesClient Release { get; private set; } public ISshKeysClient SshKey { get; private set; } public IUsersClient User { get; private set; } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index be8ebd59..c3bcbe95 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -445,6 +445,15 @@ namespace Octokit return "events".FormatUri(); } + /// + /// Returns the for the specified commit. + /// + /// The id of the gist + public static Uri Gist(int id) + { + return "gists/{0}".FormatUri(id); + } + /// /// Returns the for the specified commit. /// diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index c8586208..64c08db5 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -12,6 +12,7 @@ namespace Octokit IMiscellaneousClient Miscellaneous { get; } IOrganizationsClient Organization { get; } IRepositoriesClient Repository { get; } + IGistsClient Gist { get; } IReleasesClient Release { get; } ISshKeysClient SshKey { get; } IUsersClient User { get; } diff --git a/Octokit/Models/Response/Gist.cs b/Octokit/Models/Response/Gist.cs new file mode 100644 index 00000000..e2735977 --- /dev/null +++ b/Octokit/Models/Response/Gist.cs @@ -0,0 +1,60 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace Octokit +{ + public class Gist + { + public string Url { get; set; } + public string Id { get; set; } + public string Description { get; set; } + public bool Public { get; set; } + public User User { get; set; } + [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public IDictionary Files { get; set; } + public int Comments { get; set; } + public string CommentsUrl { get; set; } + public string HtmlUrl { get; set; } + public string GitPullUrl { get; set; } + public string GitPushUrl { get; set; } + public DateTimeOffset CreatedAt { get; set; } + public DateTimeOffset UpdatedAt { get; set; } + [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public IList Forks { get; set; } + [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public IList History { get; set; } + } + + public class GistFork + { + public User User { get; set; } + public string Url { get; set; } + public string CreatedAt { get; set; } + } + public class GistFile + { + public int Size { get; set; } + [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] + public string Filename { get; set; } + [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] + public string Type { get; set; } + public string Language { get; set; } + public string Content { get; set; } + public string RawUrl { get; set; } + } + public class GistHistory + { + public string Url { get; set; } + public string Version { get; set; } + public User User { get; set; } + public GistChangeStatus ChangeStatus { get; set; } + public string CommittedAt { get; set; } + } + public class GistChangeStatus + { + public int Deletions { get; set; } + public int Additions { get; set; } + public int Total { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index b6d6d656..17d727c7 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -45,11 +45,13 @@ + + @@ -85,6 +87,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index fdd69ff7..41cbabc1 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -56,6 +56,7 @@ + @@ -63,6 +64,7 @@ + @@ -174,6 +176,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index b457bda0..8d51b968 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -53,6 +53,8 @@ Properties\SolutionInfo.cs + + @@ -95,6 +97,7 @@ + @@ -237,4 +240,4 @@ --> - + \ No newline at end of file From 470d289fa331bf64f410b33ac19d7b17da9f1419 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Wed, 13 Nov 2013 21:54:26 -0500 Subject: [PATCH 02/64] Add the observable starred client interface --- .../Clients/IObservableStarredClient.cs | 73 +++++++++++++++++++ Octokit.Reactive/Octokit.Reactive.csproj | 1 + 2 files changed, 74 insertions(+) create mode 100644 Octokit.Reactive/Clients/IObservableStarredClient.cs diff --git a/Octokit.Reactive/Clients/IObservableStarredClient.cs b/Octokit.Reactive/Clients/IObservableStarredClient.cs new file mode 100644 index 00000000..df4a269f --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableStarredClient.cs @@ -0,0 +1,73 @@ +using System; + +namespace Octokit.Reactive +{ + public interface IObservableStarredClient + { + /// + /// Retrieves all of the stargazers for the passed repository. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A of . + IObservable GetAllStargazers(string owner, string name); + + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Thrown if the client is not authenticated. + /// A of . + IObservable GetAllForCurrent(); + + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// A of . + IObservable GetAllForCurrent(StarredRequest request); + + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Thrown if the client is not authenticated. + /// A starred by the specified user. + IObservable GetAllForUser(string user); + + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// A starred by the specified user. + IObservable GetAllForUser(string user, StarredRequest request); + + /// + /// Check if a repository is starred by the current authenticated user. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A bool representing the success of the operation + IObservable CheckStarred(string owner, string name); + + /// + /// Stars a repository for the authenticated user. + /// + /// The owner of the repository to star + /// The name of the repository to star + /// A bool representing the success of starring + IObservable StarRepo(string owner, string name); + + /// + /// Unstars a repository for the authenticated user. + /// + /// The owner of the repository to unstar + /// The name of the repository to unstar + /// A bool representing the success of the operation + IObservable RemoveStarFromRepo(string owner, string name); + } +} diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 6561cf94..b9df22ed 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -76,6 +76,7 @@ + From cc779283ea9a482941c445fba919de1b17bfb220 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 14 Nov 2013 17:58:34 +1100 Subject: [PATCH 03/64] fix user mapping and add doco --- Octokit/Clients/IGistsClient.cs | 2 +- Octokit/Models/Response/Gist.cs | 98 ++++++++++++++------- Octokit/Models/Response/GistChangeStatus.cs | 23 +++++ Octokit/Models/Response/GistFile.cs | 40 +++++++++ Octokit/Models/Response/GistFork.cs | 23 +++++ Octokit/Models/Response/GistHistory.cs | 35 ++++++++ Octokit/Octokit-Mono.csproj | 4 + Octokit/Octokit-netcore45.csproj | 4 + Octokit/Octokit.csproj | 4 + 9 files changed, 198 insertions(+), 35 deletions(-) create mode 100644 Octokit/Models/Response/GistChangeStatus.cs create mode 100644 Octokit/Models/Response/GistFile.cs create mode 100644 Octokit/Models/Response/GistFork.cs create mode 100644 Octokit/Models/Response/GistHistory.cs diff --git a/Octokit/Clients/IGistsClient.cs b/Octokit/Clients/IGistsClient.cs index 5137d71b..40b68b60 100644 --- a/Octokit/Clients/IGistsClient.cs +++ b/Octokit/Clients/IGistsClient.cs @@ -11,7 +11,7 @@ namespace Octokit /// /// http://developer.github.com/v3/gists/#get-a-single-gist /// - /// The id of the gidt + /// The id of the gist [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] Task Get(int id); diff --git a/Octokit/Models/Response/Gist.cs b/Octokit/Models/Response/Gist.cs index e2735977..9224b6c7 100644 --- a/Octokit/Models/Response/Gist.cs +++ b/Octokit/Models/Response/Gist.cs @@ -4,57 +4,87 @@ using System.Diagnostics.CodeAnalysis; namespace Octokit { - public class Gist + public class Gist { + /// + /// The API URL for this . + /// public string Url { get; set; } + + /// + /// The Id of this . + /// + /// + /// Given a gist url of https://gist.github.com/UserName/1234 the Id would be '1234'. + /// public string Id { get; set; } + + /// + /// A description of the . + /// public string Description { get; set; } + + /// + /// Indicates if the is private or public. + /// public bool Public { get; set; } - public User User { get; set; } + + /// + /// The who owns this . + /// + /// + /// Given a gist url of https://gist.github.com/UserName/1234 the Owner would be 'UserName'. + /// + public User Owner { get; set; } + + /// + /// A containing all s in this . + /// [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public IDictionary Files { get; set; } + + /// + /// The number of comments on this . + /// public int Comments { get; set; } + + /// + /// A url to retrieve the comments for this . + /// public string CommentsUrl { get; set; } + public string HtmlUrl { get; set; } + + /// + /// The git url to pull from to retrieve the contents for this . + /// public string GitPullUrl { get; set; } + + /// + /// The git url to push to when changing this . + /// public string GitPushUrl { get; set; } + + /// + /// The for when this was created. + /// public DateTimeOffset CreatedAt { get; set; } + + /// + /// The for when this was last updated. + /// public DateTimeOffset UpdatedAt { get; set; } + + /// + /// A of all that exist for this . + /// [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public IList Forks { get; set; } + + /// + /// A of all containing the full history for this . + /// [SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public IList History { get; set; } } - - public class GistFork - { - public User User { get; set; } - public string Url { get; set; } - public string CreatedAt { get; set; } - } - public class GistFile - { - public int Size { get; set; } - [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] - public string Filename { get; set; } - [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] - public string Type { get; set; } - public string Language { get; set; } - public string Content { get; set; } - public string RawUrl { get; set; } - } - public class GistHistory - { - public string Url { get; set; } - public string Version { get; set; } - public User User { get; set; } - public GistChangeStatus ChangeStatus { get; set; } - public string CommittedAt { get; set; } - } - public class GistChangeStatus - { - public int Deletions { get; set; } - public int Additions { get; set; } - public int Total { get; set; } - } } \ No newline at end of file diff --git a/Octokit/Models/Response/GistChangeStatus.cs b/Octokit/Models/Response/GistChangeStatus.cs new file mode 100644 index 00000000..4b790347 --- /dev/null +++ b/Octokit/Models/Response/GistChangeStatus.cs @@ -0,0 +1,23 @@ +namespace Octokit +{ + /// + /// User by to indicate the level of change. + /// + public class GistChangeStatus + { + /// + /// The number of deletions that occurred as part of this change. + /// + public int Deletions { get; set; } + + /// + /// The number of additions that occurred as part of this change. + /// + public int Additions { get; set; } + + /// + /// The total number of changes. + /// + public int Total { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/GistFile.cs b/Octokit/Models/Response/GistFile.cs new file mode 100644 index 00000000..24379516 --- /dev/null +++ b/Octokit/Models/Response/GistFile.cs @@ -0,0 +1,40 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Octokit +{ + public class GistFile + { + + /// + /// The size in bytes of the file. + /// + public int Size { get; set; } + + /// + /// The name of the file + /// + [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")] + public string Filename { get; set; } + + /// + /// The mime type of the file + /// + [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")] + public string Type { get; set; } + + /// + /// The programming language of the file, if any. + /// + public string Language { get; set; } + + /// + /// The text content of the file. + /// + public string Content { get; set; } + + /// + /// The url to download the file. + /// + public string RawUrl { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/GistFork.cs b/Octokit/Models/Response/GistFork.cs new file mode 100644 index 00000000..869b10bb --- /dev/null +++ b/Octokit/Models/Response/GistFork.cs @@ -0,0 +1,23 @@ +using System; + +namespace Octokit +{ + public class GistFork + { + + /// + /// The that created this + /// + public User User { get; set; } + + /// + /// The API URL for this . + /// + public string Url { get; set; } + + /// + /// The for when this was created. + /// + public DateTimeOffset CreatedAt { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/GistHistory.cs b/Octokit/Models/Response/GistHistory.cs new file mode 100644 index 00000000..0ea5fe32 --- /dev/null +++ b/Octokit/Models/Response/GistHistory.cs @@ -0,0 +1,35 @@ +using System; + +namespace Octokit +{ + /// + /// A historical version of a + /// + public class GistHistory + { + /// + /// The url that can be used by the API to retrieve this version of the . + /// + public string Url { get; set; } + + /// + /// A git sha representing the version. + /// + public string Version { get; set; } + + /// + /// The who create this version. + /// + public User User { get; set; } + + /// + /// A that represents the level of change for this . + /// + public GistChangeStatus ChangeStatus { get; set; } + + /// + /// The the version was created. + /// + public DateTimeOffset CommittedAt { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 17d727c7..b7403388 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -88,6 +88,10 @@ + + + + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 41cbabc1..5bc5567a 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -177,6 +177,10 @@ + + + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 8d51b968..f49c12a0 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -98,6 +98,10 @@ + + + + From dd5db1e401192b730f70c568cec5a962fc42c4f2 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Thu, 14 Nov 2013 13:28:35 -0500 Subject: [PATCH 04/64] Implement the observable starred interface --- .../Clients/ObservableStarredClient.cs | 132 ++++++++++++++++++ Octokit.Reactive/Octokit.Reactive.csproj | 1 + 2 files changed, 133 insertions(+) create mode 100644 Octokit.Reactive/Clients/ObservableStarredClient.cs diff --git a/Octokit.Reactive/Clients/ObservableStarredClient.cs b/Octokit.Reactive/Clients/ObservableStarredClient.cs new file mode 100644 index 00000000..7d9db561 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableStarredClient.cs @@ -0,0 +1,132 @@ +using System; +using System.Reactive; +using System.Reactive.Threading.Tasks; +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive +{ + public class ObservableStarredClient + { + private IStarredClient _client; + private IConnection _connection; + + public ObservableStarredClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Activity.Starring; + _connection = client.Connection; + } + + /// + /// Retrieves all of the stargazers for the passed repository. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A of . + public IObservable GetAllStargazers(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Stargazers(owner, name)); + } + + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Thrown if the client is not authenticated. + /// A of . + public IObservable GetAllForCurrent() + { + return _connection.GetAndFlattenAllPages(ApiUrls.Starred()); + } + + /// + /// Retrieves all of the starred (ies) for the current user. + /// + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// A of . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + public IObservable GetAllForCurrent(StarredRequest request) + { + Ensure.ArgumentNotNull(request, "request"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Starred(), request.ToParametersDictionary()); + } + + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Thrown if the client is not authenticated. + /// A starred by the specified user. + public IObservable GetAllForUser(string user) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + + return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user)); + } + + /// + /// Retrieves all of the (ies) starred by the specified user. + /// + /// The login of the user + /// Star-specific request parameters that sort the results + /// Thrown if the client is not authenticated. + /// A starred by the specified user. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] + public IObservable GetAllForUser(string user, StarredRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(user, "user"); + Ensure.ArgumentNotNull(request, "request"); + + return _connection.GetAndFlattenAllPages(ApiUrls.StarredByUser(user), request.ToParametersDictionary()); + } + + /// + /// Check if a repository is starred by the current authenticated user. + /// + /// The owner of the repository + /// The name of the repository + /// Thrown if the client is not authenticated. + /// A bool representing the success of the operation + public IObservable CheckStarred(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.CheckStarred(owner, name).ToObservable(); + } + + /// + /// Stars a repository for the authenticated user. + /// + /// The owner of the repository to star + /// The name of the repository to star + /// A bool representing the success of starring + public IObservable StarRepo(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.StarRepo(owner, name).ToObservable(); + } + + /// + /// Unstars a repository for the authenticated user. + /// + /// The owner of the repository to unstar + /// The name of the repository to unstar + /// A bool representing the success of the operation + public IObservable RemoveStarFromRepo(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.RemoveStarFromRepo(owner, name).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index b9df22ed..7f2f6fef 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -103,6 +103,7 @@ + From f0ea90bb5f0fbe3da34fa81b520c5d770ee9e308 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 15 Nov 2013 08:19:40 +1100 Subject: [PATCH 05/64] fix gist test and remove some whitespace --- Octokit.Tests.Integration/GistsClientTests.cs | 1 - Octokit.Tests/Clients/GistsClientTests.cs | 5 +---- Octokit/Clients/GistsClient.cs | 2 -- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Octokit.Tests.Integration/GistsClientTests.cs b/Octokit.Tests.Integration/GistsClientTests.cs index 855e6c58..124ee8cc 100644 --- a/Octokit.Tests.Integration/GistsClientTests.cs +++ b/Octokit.Tests.Integration/GistsClientTests.cs @@ -27,6 +27,5 @@ namespace Octokit.Tests.Integration var retrieved = await this._gistsClient.Get(6305249); Assert.NotNull(retrieved); } - } } \ No newline at end of file diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index bd7b5f95..e2b025ba 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; using NSubstitute; using Octokit; using Xunit; @@ -9,7 +7,6 @@ public class GistsClientTests { public class TheGetMethod { - [Fact] public void RequestsCorrectUrl() { @@ -18,7 +15,7 @@ public class GistsClientTests client.Get(1); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/repo/git/commits/reference"), null); + connection.Received().Get(Arg.Is(u => u.ToString() == "gists/1"), null); } } diff --git a/Octokit/Clients/GistsClient.cs b/Octokit/Clients/GistsClient.cs index dc3a5099..19e4a7ec 100644 --- a/Octokit/Clients/GistsClient.cs +++ b/Octokit/Clients/GistsClient.cs @@ -20,7 +20,5 @@ namespace Octokit { return ApiConnection.Get(ApiUrls.Gist(id)); } - - } } \ No newline at end of file From b68a98d12fba97244714ea0586d08c0b09ee2f0e Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Thu, 14 Nov 2013 20:14:07 -0500 Subject: [PATCH 06/64] Namespacing! --- Octokit.Reactive/Clients/ObservableStarredClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Reactive/Clients/ObservableStarredClient.cs b/Octokit.Reactive/Clients/ObservableStarredClient.cs index 7d9db561..3f2e4afc 100644 --- a/Octokit.Reactive/Clients/ObservableStarredClient.cs +++ b/Octokit.Reactive/Clients/ObservableStarredClient.cs @@ -3,7 +3,7 @@ using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; -namespace Octokit.Reactive +namespace Octokit.Reactive.Clients { public class ObservableStarredClient { From ae34ccd4ae7aa59b67f4a35abaf85fcc00e5e539 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 15 Nov 2013 17:36:06 +1100 Subject: [PATCH 07/64] gist id can be a string --- Octokit.Tests.Integration/GistsClientTests.cs | 2 +- Octokit.Tests/Clients/GistsClientTests.cs | 2 +- Octokit/Clients/GistsClient.cs | 2 +- Octokit/Clients/IGistsClient.cs | 2 +- Octokit/Helpers/ApiUrls.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests.Integration/GistsClientTests.cs b/Octokit.Tests.Integration/GistsClientTests.cs index 124ee8cc..e9de24ae 100644 --- a/Octokit.Tests.Integration/GistsClientTests.cs +++ b/Octokit.Tests.Integration/GistsClientTests.cs @@ -24,7 +24,7 @@ namespace Octokit.Tests.Integration [IntegrationTest] public async Task CanGetGist() { - var retrieved = await this._gistsClient.Get(6305249); + var retrieved = await this._gistsClient.Get("6305249"); Assert.NotNull(retrieved); } } diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index e2b025ba..5765cc6d 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -13,7 +13,7 @@ public class GistsClientTests var connection = Substitute.For(); var client = new GistsClient(connection); - client.Get(1); + client.Get("1"); connection.Received().Get(Arg.Is(u => u.ToString() == "gists/1"), null); } diff --git a/Octokit/Clients/GistsClient.cs b/Octokit/Clients/GistsClient.cs index 19e4a7ec..c2897f59 100644 --- a/Octokit/Clients/GistsClient.cs +++ b/Octokit/Clients/GistsClient.cs @@ -16,7 +16,7 @@ namespace Octokit /// http://developer.github.com/v3/gists/#get-a-single-gist /// /// The id of the gist - public Task Get(int id) + public Task Get(string id) { return ApiConnection.Get(ApiUrls.Gist(id)); } diff --git a/Octokit/Clients/IGistsClient.cs b/Octokit/Clients/IGistsClient.cs index 40b68b60..1f3abb48 100644 --- a/Octokit/Clients/IGistsClient.cs +++ b/Octokit/Clients/IGistsClient.cs @@ -14,7 +14,7 @@ namespace Octokit /// The id of the gist [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] - Task Get(int id); + Task Get(string id); } } \ No newline at end of file diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index c3bcbe95..eedfed9a 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -449,7 +449,7 @@ namespace Octokit /// Returns the for the specified commit. /// /// The id of the gist - public static Uri Gist(int id) + public static Uri Gist(string id) { return "gists/{0}".FormatUri(id); } From 343fc35a03ad2398f740e8f40507679e1f64c2e0 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 16 Nov 2013 11:02:09 -0500 Subject: [PATCH 08/64] Replace "repo" with "name" in the Uri helpers --- Octokit/Helpers/ApiUrls.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index ff1e3e78..455eb6ed 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -381,9 +381,11 @@ namespace Octokit /// /// Returns the that lists the starred repositories for the authenticated user. /// - public static Uri Stargazers(string owner, string repo) + /// The owner of the repository + /// The name of the repository + public static Uri Stargazers(string owner, string name) { - return "repos/{0}/{1}/stargazers".FormatUri(owner, repo); + return "repos/{0}/{1}/stargazers".FormatUri(owner, name); } /// @@ -407,11 +409,11 @@ namespace Octokit /// Returns the that shows whether the repo is starred by the current user. /// /// The owner of the repository - /// The name of the repository + /// The name of the repository /// - public static Uri Starred(string owner, string repo) + public static Uri Starred(string owner, string name) { - return "user/starred/{0}/{1}".FormatUri(owner, repo); + return "user/starred/{0}/{1}".FormatUri(owner, name); } /// Returns the for the specified tag. From 71fc7e76f839f92ba9487de3c7eec1e5b1829389 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 16 Nov 2013 11:52:29 -0500 Subject: [PATCH 09/64] Add tests for `ObservableStarredClient` --- Octokit.Tests/Octokit.Tests.csproj | 1 + .../Reactive/ObservableStarredClientTests.cs | 146 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 Octokit.Tests/Reactive/ObservableStarredClientTests.cs diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index cff9ef07..7220fc92 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -123,6 +123,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableStarredClientTests.cs b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs new file mode 100644 index 00000000..6b1c7dfd --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs @@ -0,0 +1,146 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Linq; +using System.Threading.Tasks; +using NSubstitute; +using Octokit; +using Octokit.Internal; +using Octokit.Reactive.Clients; +using Octokit.Reactive.Internal; +using Octokit.Tests.Helpers; +using Xunit; +using Xunit.Extensions; + +namespace Octokit.Tests.Reactive +{ + public class ObservableStarredClientTests + { + public class TheGetAllStargazersMethod + { + [Fact] + public async Task EnsuresArguments() + { + var client = new ObservableStarredClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.GetAllStargazers(null, "name")); + await AssertEx.Throws(async () => await client.GetAllStargazers("owner", null)); + } + + [Fact] + public void GetsStargazersFromClient() + { + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + client.GetAllStargazers("jugglingnutcase", "katiejamie"); + connection.Received().GetAsync>(ApiUrls.Stargazers("jugglingnutcase", "katiejamie"), null, null); + } + } + + public class TheGetAllForCurrentMethod + { + [Fact] + public void GetsStarsForCurrent() + { + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + client.GetAllForCurrent(); + connection.Received().GetAsync>(ApiUrls.Starred(), null, null); + } + } + + public class TheGetAllForUserMethod + { + [Fact] + public async Task EnsuresArguments() + { + var client = new ObservableStarredClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.GetAllForUser(null)); + } + + [Fact] + public void GetsStarsForUser() + { + var connection = Substitute.For(); + var gitHubClient = Substitute.For(); + gitHubClient.Connection.Returns(connection); + var client = new ObservableStarredClient(gitHubClient); + + client.GetAllForUser("jugglingnutcase"); + connection.Received().GetAsync>(ApiUrls.StarredByUser("jugglingnutcase"), null, null); + } + } + + public class TheCheckStarredMethod + { + [Fact] + public async Task EnsuresArguments() + { + var client = new ObservableStarredClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.CheckStarred(null, "james")); + await AssertEx.Throws(async () => await client.CheckStarred("james", null)); + } + + [Fact] + public async Task ChecksStarredForUser() + { + var gitHubClient = Substitute.For(); + var client = new ObservableStarredClient(gitHubClient); + + client.CheckStarred("jugglingnutcase", "katiejamie"); + gitHubClient.Activity.Starring.Received().CheckStarred("jugglingnutcase", "katiejamie"); + } + } + + public class TheStarRepoMethod + { + [Fact] + public async Task EnsuresArguments() + { + var client = new ObservableStarredClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.StarRepo(null, "james")); + await AssertEx.Throws(async () => await client.StarRepo("james", null)); + } + + [Fact] + public async Task ChecksStarredForUser() + { + var gitHubClient = Substitute.For(); + var client = new ObservableStarredClient(gitHubClient); + + client.StarRepo("jugglingnutcase", "katiejamie"); + gitHubClient.Activity.Starring.Received().StarRepo("jugglingnutcase", "katiejamie"); + } + } + + public class TheRemoveStarFromRepoMethod + { + [Fact] + public async Task EnsuresArguments() + { + var client = new ObservableStarredClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.RemoveStarFromRepo(null, "james")); + await AssertEx.Throws(async () => await client.RemoveStarFromRepo("james", null)); + } + + [Fact] + public async Task ChecksStarredForUser() + { + var gitHubClient = Substitute.For(); + var client = new ObservableStarredClient(gitHubClient); + + client.RemoveStarFromRepo("jugglingnutcase", "katiejamie"); + gitHubClient.Activity.Starring.Received().RemoveStarFromRepo("jugglingnutcase", "katiejamie"); + } + } + } +} \ No newline at end of file From 97233cce768184ed0d71dd6753ebcb6494a9b433 Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 16 Nov 2013 14:22:53 -0500 Subject: [PATCH 10/64] Fix up starred xml documentation Wherein i edit some of the language and then declare war against the period. --- .../Clients/IObservableStarredClient.cs | 41 +++++++++------- .../Clients/ObservableStarredClient.cs | 34 +++++++------- Octokit/Clients/IStarredClient.cs | 15 ++++-- Octokit/Clients/StarredClient.cs | 47 ++++++++++--------- 4 files changed, 77 insertions(+), 60 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableStarredClient.cs b/Octokit.Reactive/Clients/IObservableStarredClient.cs index df4a269f..382260c9 100644 --- a/Octokit.Reactive/Clients/IObservableStarredClient.cs +++ b/Octokit.Reactive/Clients/IObservableStarredClient.cs @@ -5,48 +5,53 @@ namespace Octokit.Reactive public interface IObservableStarredClient { /// - /// Retrieves all of the stargazers for the passed repository. + /// Retrieves all of the stargazers for the passed repository /// /// The owner of the repository /// The name of the repository - /// Thrown if the client is not authenticated. - /// A of . + /// Thrown if the client is not authenticated + /// A of starring the passed repository IObservable GetAllStargazers(string owner, string name); /// - /// Retrieves all of the starred (ies) for the current user. + /// Retrieves all of the starred (ies) for the current user /// - /// Thrown if the client is not authenticated. - /// A of . + /// Thrown if the client is not authenticated + /// + /// A of (ies) starred by the current user + /// IObservable GetAllForCurrent(); /// - /// Retrieves all of the starred (ies) for the current user. + /// Retrieves all of the starred (ies) for the current user /// /// Star-specific request parameters that sort the results - /// Thrown if the client is not authenticated. - /// A of . + /// Thrown if the client is not authenticated + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters + /// IObservable GetAllForCurrent(StarredRequest request); /// - /// Retrieves all of the (ies) starred by the specified user. + /// Retrieves all of the (ies) starred by the specified user /// /// The login of the user - /// Thrown if the client is not authenticated. - /// A starred by the specified user. + /// Thrown if the client is not authenticated + /// A starred by the specified user IObservable GetAllForUser(string user); /// - /// Retrieves all of the (ies) starred by the specified user. + /// Retrieves all of the (ies) starred by the specified user /// /// The login of the user /// Star-specific request parameters that sort the results - /// Thrown if the client is not authenticated. - /// A starred by the specified user. + /// Thrown if the client is not authenticated + /// A starred by the specified user IObservable GetAllForUser(string user, StarredRequest request); /// - /// Check if a repository is starred by the current authenticated user. + /// Check if a repository is starred by the current authenticated user /// /// The owner of the repository /// The name of the repository @@ -55,7 +60,7 @@ namespace Octokit.Reactive IObservable CheckStarred(string owner, string name); /// - /// Stars a repository for the authenticated user. + /// Stars a repository for the authenticated user /// /// The owner of the repository to star /// The name of the repository to star @@ -63,7 +68,7 @@ namespace Octokit.Reactive IObservable StarRepo(string owner, string name); /// - /// Unstars a repository for the authenticated user. + /// Unstars a repository for the authenticated user /// /// The owner of the repository to unstar /// The name of the repository to unstar diff --git a/Octokit.Reactive/Clients/ObservableStarredClient.cs b/Octokit.Reactive/Clients/ObservableStarredClient.cs index 3f2e4afc..040170e9 100644 --- a/Octokit.Reactive/Clients/ObservableStarredClient.cs +++ b/Octokit.Reactive/Clients/ObservableStarredClient.cs @@ -19,12 +19,12 @@ namespace Octokit.Reactive.Clients } /// - /// Retrieves all of the stargazers for the passed repository. + /// Retrieves all of the stargazers for the passed repository /// /// The owner of the repository /// The name of the repository - /// Thrown if the client is not authenticated. - /// A of . + /// Thrown if the client is not authenticated + /// A of s starring the passed repository public IObservable GetAllStargazers(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -34,21 +34,21 @@ namespace Octokit.Reactive.Clients } /// - /// Retrieves all of the starred (ies) for the current user. + /// Retrieves all of the starred (ies) for the current user /// - /// Thrown if the client is not authenticated. - /// A of . + /// Thrown if the client is not authenticated + /// A of public IObservable GetAllForCurrent() { return _connection.GetAndFlattenAllPages(ApiUrls.Starred()); } /// - /// Retrieves all of the starred (ies) for the current user. + /// Retrieves all of the starred (ies) for the current user /// /// Star-specific request parameters that sort the results - /// Thrown if the client is not authenticated. - /// A of . + /// Thrown if the client is not authenticated + /// A of (ies) starred by the current user [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] public IObservable GetAllForCurrent(StarredRequest request) { @@ -58,11 +58,11 @@ namespace Octokit.Reactive.Clients } /// - /// Retrieves all of the (ies) starred by the specified user. + /// Retrieves all of the (ies) starred by the specified user /// /// The login of the user - /// Thrown if the client is not authenticated. - /// A starred by the specified user. + /// Thrown if the client is not authenticated + /// A starred by the specified user public IObservable GetAllForUser(string user) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); @@ -71,12 +71,12 @@ namespace Octokit.Reactive.Clients } /// - /// Retrieves all of the (ies) starred by the specified user. + /// Retrieves all of the (ies) starred by the specified user /// /// The login of the user /// Star-specific request parameters that sort the results - /// Thrown if the client is not authenticated. - /// A starred by the specified user. + /// Thrown if the client is not authenticated + /// A starred by the specified user [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] public IObservable GetAllForUser(string user, StarredRequest request) { @@ -87,11 +87,11 @@ namespace Octokit.Reactive.Clients } /// - /// Check if a repository is starred by the current authenticated user. + /// Check if a repository is starred by the current authenticated user /// /// The owner of the repository /// The name of the repository - /// Thrown if the client is not authenticated. + /// Thrown if the client is not authenticated /// A bool representing the success of the operation public IObservable CheckStarred(string owner, string name) { diff --git a/Octokit/Clients/IStarredClient.cs b/Octokit/Clients/IStarredClient.cs index ffb8695c..5dcbebfb 100644 --- a/Octokit/Clients/IStarredClient.cs +++ b/Octokit/Clients/IStarredClient.cs @@ -11,14 +11,16 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// Thrown if the client is not authenticated. - /// A of . + /// A of s starring the passed repository. Task> GetAllStargazers(string owner, string name); /// /// Retrieves all of the starred (ies) for the current user. /// /// Thrown if the client is not authenticated. - /// A of . + /// + /// A of (ies) starred by the current authenticated user. + /// Task> GetAllForCurrent(); /// @@ -26,7 +28,10 @@ namespace Octokit /// /// Star-specific request parameters that sort the results /// Thrown if the client is not authenticated. - /// A of . + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters. + /// Task> GetAllForCurrent(StarredRequest request); /// @@ -34,7 +39,9 @@ namespace Octokit /// /// The login of the user /// Thrown if the client is not authenticated. - /// A starred by the specified user. + /// + /// A (ies) starred by the specified user. + /// Task> GetAllForUser(string user); /// diff --git a/Octokit/Clients/StarredClient.cs b/Octokit/Clients/StarredClient.cs index 06e46c53..94ff2849 100644 --- a/Octokit/Clients/StarredClient.cs +++ b/Octokit/Clients/StarredClient.cs @@ -12,12 +12,12 @@ namespace Octokit } /// - /// Retrieves all of the stargazers for the passed repository. + /// Retrieves all of the stargazers for the passed repository /// /// The owner of the repository /// The name of the repository - /// Thrown if the client is not authenticated. - /// A of . + /// Thrown if the client is not authenticated + /// A of s starring the passed repository public Task> GetAllStargazers(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -27,21 +27,26 @@ namespace Octokit } /// - /// Retrieves all of the starred (ies) for the current user. + /// Retrieves all of the starred (ies) for the current user /// - /// Thrown if the client is not authenticated. - /// A of . + /// Thrown if the client is not authenticated + /// + /// A of (ies) starred by the current user + /// public Task> GetAllForCurrent() { return ApiConnection.GetAll(ApiUrls.Starred()); } /// - /// Retrieves all of the starred (ies) for the current user. + /// Retrieves all of the starred (ies) for the current user /// /// Star-specific request parameters that sort the results - /// Thrown if the client is not authenticated. - /// A of . + /// Thrown if the client is not authenticated + /// + /// A of (ies) starred by the current user, + /// sorted according to the passed request parameters + /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "But i think i do need star-specific request parameters")] public Task> GetAllForCurrent(StarredRequest request) @@ -52,11 +57,11 @@ namespace Octokit } /// - /// Retrieves all of the (ies) starred by the specified user. + /// Retrieves all of the (ies) starred by the specified user /// /// The login of the user - /// Thrown if the client is not authenticated. - /// A starred by the specified user. + /// Thrown if the client is not authenticated + /// A starred by the specified user public Task> GetAllForUser(string user) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); @@ -65,12 +70,12 @@ namespace Octokit } /// - /// Retrieves all of the (ies) starred by the specified user. + /// Retrieves all of the (ies) starred by the specified user /// /// The login of the user /// Star-specific request parameters that sort the results - /// Thrown if the client is not authenticated. - /// A starred by the specified user. + /// Thrown if the client is not authenticated + /// A starred by the specified user [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] public Task> GetAllForUser(string user, StarredRequest request) { @@ -81,11 +86,11 @@ namespace Octokit } /// - /// Check if a repository is starred by the current authenticated user. + /// Check if a repository is starred by the current authenticated user /// /// The owner of the repository /// The name of the repository - /// Thrown if the client is not authenticated. + /// Thrown if the client is not authenticated /// A bool representing the success of the operation public async Task CheckStarred(string owner, string name) { @@ -106,11 +111,11 @@ namespace Octokit } /// - /// Stars a repository for the authenticated user. + /// Stars a repository for the authenticated user /// /// The owner of the repository to star /// The name of the repository to star - /// A bool representing the success of starring the repository. + /// A bool representing the success of starring the repository public async Task StarRepo(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -130,11 +135,11 @@ namespace Octokit } /// - /// Unstars a repository for the authenticated user. + /// Unstars a repository for the authenticated user /// /// The owner of the repository to unstar /// The name of the repository to unstar - /// A bool representing the success of unstarring the repository. + /// A bool representing the success of unstarring the repository public async Task RemoveStarFromRepo(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); From a1d0a5e6a01d6df93a39a475e150c7132c9c19ca Mon Sep 17 00:00:00 2001 From: James R Sconfitto Date: Sat, 16 Nov 2013 14:26:12 -0500 Subject: [PATCH 11/64] Add files to mono projects --- Octokit.Reactive/Octokit.Reactive-Mono.csproj | 2 ++ Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj | 2 ++ Octokit.Reactive/Octokit.Reactive-Monotouch.csproj | 2 ++ 3 files changed, 6 insertions(+) diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index 5988045a..8a65ae6c 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -108,6 +108,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index ad8c40c4..da0f5738 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -117,6 +117,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index 677d1709..cd3bfee2 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -112,6 +112,8 @@ + + From 099919be4f1d9a351277cd8169790bc9c339bd9c Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Sun, 17 Nov 2013 08:56:30 +1100 Subject: [PATCH 12/64] The repo owner is octokit and not github --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 41ffb8b4..c03d26f4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ But first things first... * Fork the repository on GitHub by clicking on the "Clone in Windows" button or run the following command in a git shell. ``` -git clone git@github.com:github/Octokit.net.git Octokit +git clone git@github.com:octokit/Octokit.net.git Octokit ``` * Make sure the project builds and all tests pass on your machine by running the `build.cmd` script (this calls a [FAKE](https://github.com/fsharp/fake) script, `build.fsx`). From 5cf566b473609a57049f6527947fd177ef65a8ee Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Sun, 17 Nov 2013 10:02:55 +1100 Subject: [PATCH 13/64] The repo owner is octokit and not github --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b4652e84..ff705bed 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ To clone it locally click the "Clone in Windows" button above or run the following git commands. ``` -git clone git@github.com:github/Octokit.net.git Octokit +git clone git@github.com:octokit/Octokit.net.git Octokit cd Octokit .\build.cmd ``` From f7d8e012328bb68393e9b9f3d1c3479996d5f04b Mon Sep 17 00:00:00 2001 From: James Sconfitto Date: Sun, 17 Nov 2013 16:02:34 -0500 Subject: [PATCH 14/64] Fix xml docs in `NewAuthorization` --- Octokit/Models/Request/NewAuthorization.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit/Models/Request/NewAuthorization.cs b/Octokit/Models/Request/NewAuthorization.cs index 19a48e49..135e018c 100644 --- a/Octokit/Models/Request/NewAuthorization.cs +++ b/Octokit/Models/Request/NewAuthorization.cs @@ -18,8 +18,8 @@ namespace Octokit public string Note { get; set; } /// - // An optional URL to remind you what app the OAuth token is for. + /// An optional URL to remind you what app the OAuth token is for. /// public string NoteUrl { get; set; } } -} \ No newline at end of file +} From e53fd2c9f9e7cc6ec3811654118d9fad7a506c3d Mon Sep 17 00:00:00 2001 From: Phil Haack Date: Mon, 18 Nov 2013 09:21:47 -0800 Subject: [PATCH 15/64] Added note about project structure for contributors. --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index ff705bed..a523ecb5 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,18 @@ problem. Visit the [Contributor Guidelines](https://github.com/octokit/octokit.net/blob/master/CONTRIBUTING.md) for more details. +### A Note about project structure + +There are two primary projects in the solution: \Octokit.csproj\ and \Octokit.Reactive.csproj\. + +The first is the task-based library. The second is a wrapper that provides an Reactive Extensions (Rx) based library. + +The clients within a project are organized similarly to the endpoints in the [GitHub API documentation](http://developer.github.com/v3/) + +Some clients are "sub-clients". For example, when you navigate to the [Issues API](http://developer.github.com/v3/issues/) you'll notice there's an endpoint for issues. But in the right navbar, there are other APIs such as [Assignees](http://developer.github.com/v3/issues/assignees/) and [Milestones](http://developer.github.com/v3/issues/milestones/). + +We've tried to mirror this structure. So the `IObservableMilestoneClient` isn't a direct property of `IObservableGitHubClient`. Instead, it's a property of the `IObservableIssuesClient`. And thus you can get to it by going to `client.Issues.Milestones`. + ## Copyright and License Copyright 2013 GitHub, Inc. From 1313c5c63dd7dab999d11ae1a927bc9c8cb714a6 Mon Sep 17 00:00:00 2001 From: Phil Haack Date: Mon, 18 Nov 2013 09:23:47 -0800 Subject: [PATCH 16/64] Fix up backslashes. Not sure why that happened. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a523ecb5..e5f1dc0c 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ for more details. ### A Note about project structure -There are two primary projects in the solution: \Octokit.csproj\ and \Octokit.Reactive.csproj\. +There are two primary projects in the solution: `Octokit.csproj` and `Octokit.Reactive.csproj`. The first is the task-based library. The second is a wrapper that provides an Reactive Extensions (Rx) based library. From 602502a928e67bac38c82695165a5fd226cbd9cf Mon Sep 17 00:00:00 2001 From: Haacked Date: Tue, 19 Nov 2013 09:52:59 -0800 Subject: [PATCH 17/64] Release notes for 0.1.5 --- ReleaseNotes.md | 8 ++++++++ SolutionInfo.cs | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 0ab42142..33c8b71c 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,3 +1,11 @@ +### New in 0.1.5 (Released 2013/11/19) +* New client for starring repositories +* New client for retrieving commits +* New client for managing an organization's teams and members +* New client for managing blobs +* New client for retrieving and creating trees +* New client for managing collaborators of a repository + ### New in 0.1.4 (Released 2013/11/6) * New client for retrieving activity events * Fixed bug where concealing an org's member actually shows the member diff --git a/SolutionInfo.cs b/SolutionInfo.cs index 65f27551..358bd08a 100644 --- a/SolutionInfo.cs +++ b/SolutionInfo.cs @@ -3,11 +3,11 @@ using System.Reflection; using System.Runtime.InteropServices; [assembly: AssemblyProductAttribute("Octokit")] -[assembly: AssemblyVersionAttribute("0.1.4")] -[assembly: AssemblyFileVersionAttribute("0.1.4")] +[assembly: AssemblyVersionAttribute("0.1.5")] +[assembly: AssemblyFileVersionAttribute("0.1.5")] [assembly: ComVisibleAttribute(false)] namespace System { internal static class AssemblyVersionInformation { - internal const string Version = "0.1.4"; + internal const string Version = "0.1.5"; } } From 383ec596674e8500f582896997545659425b3856 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 21 Nov 2013 08:45:40 +1100 Subject: [PATCH 18/64] fixes for @shiftkey --- Octokit.sln.DotSettings | 1 - Octokit/Clients/IGistsClient.cs | 1 - Octokit/Models/Response/GistFile.cs | 1 - Octokit/Models/Response/GistFork.cs | 1 - 4 files changed, 4 deletions(-) diff --git a/Octokit.sln.DotSettings b/Octokit.sln.DotSettings index 202116c9..36aa1792 100644 --- a/Octokit.sln.DotSettings +++ b/Octokit.sln.DotSettings @@ -262,5 +262,4 @@ II.2.12 <HandlesEvent /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> - True \ No newline at end of file diff --git a/Octokit/Clients/IGistsClient.cs b/Octokit/Clients/IGistsClient.cs index 1f3abb48..93a44d50 100644 --- a/Octokit/Clients/IGistsClient.cs +++ b/Octokit/Clients/IGistsClient.cs @@ -15,6 +15,5 @@ namespace Octokit [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] Task Get(string id); - } } \ No newline at end of file diff --git a/Octokit/Models/Response/GistFile.cs b/Octokit/Models/Response/GistFile.cs index 24379516..64aad8b0 100644 --- a/Octokit/Models/Response/GistFile.cs +++ b/Octokit/Models/Response/GistFile.cs @@ -4,7 +4,6 @@ namespace Octokit { public class GistFile { - /// /// The size in bytes of the file. /// diff --git a/Octokit/Models/Response/GistFork.cs b/Octokit/Models/Response/GistFork.cs index 869b10bb..b6c3662c 100644 --- a/Octokit/Models/Response/GistFork.cs +++ b/Octokit/Models/Response/GistFork.cs @@ -4,7 +4,6 @@ namespace Octokit { public class GistFork { - /// /// The that created this /// From c7a1766bd73cff2ed455159f2fffcf151fdb2fdc Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 21 Nov 2013 08:58:07 +1100 Subject: [PATCH 19/64] fix merge issue --- Octokit/Octokit.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index bcebd9dd..9e0ab876 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -115,7 +115,6 @@ - From 9d12da169b116b690f857db893599498e88a097a Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 20 Nov 2013 17:14:57 -0800 Subject: [PATCH 20/64] do not block the build script from finishing --- build.cmd | 8 -------- 1 file changed, 8 deletions(-) diff --git a/build.cmd b/build.cmd index 431be99c..a73c6367 100644 --- a/build.cmd +++ b/build.cmd @@ -31,13 +31,5 @@ if defined TEAMCITY_PROJECT_NAME goto Quit rem Bail if we're running a MyGet build. if /i "%BuildRunner%"=="MyGet" goto Quit -rem Loop the build script. -set CHOICE=nothing -echo (Q)uit, (Enter) runs the build again -set /P CHOICE= -if /i "%CHOICE%"=="Q" goto :Quit - -GOTO Build - :Quit exit /b %errorlevel% From 04408885f8308e186bd29ba2c5e40dcc659f2bd4 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 21 Nov 2013 20:44:18 +1100 Subject: [PATCH 21/64] sync projects --- Octokit/Octokit-MonoAndroid.csproj | 7 +++++++ Octokit/Octokit-Monotouch.csproj | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 5fd88aec..4a3b0d7d 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -227,6 +227,13 @@ + + + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 755bcb74..3189e64f 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -222,6 +222,13 @@ + + + + + + + \ No newline at end of file From 6949f9a27e4b9fa6af9fbc73d949b11c55f7f92d Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Fri, 22 Nov 2013 14:41:13 -0800 Subject: [PATCH 22/64] Use FAKE 2.2 for build --- build.cmd | 13 +------------ script/cibuild.ps1 | 2 +- 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/build.cmd b/build.cmd index a73c6367..5255fee0 100644 --- a/build.cmd +++ b/build.cmd @@ -1,17 +1,6 @@ @echo off -SET MinimalFAKEVersion=639 -SET FAKEVersion=1 -cls - -if exist tools\FAKE.Core\tools\PatchVersion.txt ( - FOR /F "tokens=*" %%i in (tools\FAKE.Core\tools\PatchVersion.txt) DO (SET FAKEVersion=%%i) -) - -if %MinimalFAKEVersion% lss %FAKEVersion% goto Build -if %MinimalFAKEVersion%==%FAKEVersion% goto Build - -"tools\nuget\nuget.exe" "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-Prerelease" +"tools\nuget\nuget.exe" "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-version" "2.2.0" :Build cls diff --git a/script/cibuild.ps1 b/script/cibuild.ps1 index bddfe95a..51b10c97 100644 --- a/script/cibuild.ps1 +++ b/script/cibuild.ps1 @@ -76,7 +76,7 @@ if (Test-Path tools\FAKE.Core\tools\Fake.exe) { else { Write-Output "Installing FAKE..." Write-Output "" - .\tools\nuget\nuget.exe "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-Prerelease" + .\tools\nuget\nuget.exe "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-Version" "2.2.0" } Write-Output "Building Octokit..." From 54986a80aad1507815460cd815fbdb0b7244f3ee Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Fri, 22 Nov 2013 01:00:52 +0100 Subject: [PATCH 23/64] Added IReferenceClient and failing test --- Octokit.Tests/Clients/GitDatabaseClientTests.cs | 8 ++++++++ Octokit/Clients/GitDatabaseClient.cs | 1 + Octokit/Clients/IGitDatabaseClient.cs | 1 + Octokit/Clients/IReferencesClient.cs | 9 +++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 7 files changed, 22 insertions(+) create mode 100644 Octokit/Clients/IReferencesClient.cs diff --git a/Octokit.Tests/Clients/GitDatabaseClientTests.cs b/Octokit.Tests/Clients/GitDatabaseClientTests.cs index 93ee03bb..45544679 100644 --- a/Octokit.Tests/Clients/GitDatabaseClientTests.cs +++ b/Octokit.Tests/Clients/GitDatabaseClientTests.cs @@ -28,5 +28,13 @@ public class GitDatabaseClientTests var gitDatabaseClient = new GitDatabaseClient(apiConnection); Assert.NotNull(gitDatabaseClient.Commit); } + + [Fact] + public void SetReferencesClient() + { + var apiConnection = Substitute.For(); + var gitDatabaseClient = new GitDatabaseClient(apiConnection); + Assert.NotNull(gitDatabaseClient.Reference); + } } } \ No newline at end of file diff --git a/Octokit/Clients/GitDatabaseClient.cs b/Octokit/Clients/GitDatabaseClient.cs index 908f1ca0..b7495498 100644 --- a/Octokit/Clients/GitDatabaseClient.cs +++ b/Octokit/Clients/GitDatabaseClient.cs @@ -11,5 +11,6 @@ public ITagsClient Tag { get; set; } public ICommitsClient Commit { get; set; } + public IReferencesClient Reference { get; set; } } } \ No newline at end of file diff --git a/Octokit/Clients/IGitDatabaseClient.cs b/Octokit/Clients/IGitDatabaseClient.cs index 8c36b6bb..e4494306 100644 --- a/Octokit/Clients/IGitDatabaseClient.cs +++ b/Octokit/Clients/IGitDatabaseClient.cs @@ -7,5 +7,6 @@ { ITagsClient Tag { get; set; } ICommitsClient Commit { get; set; } + IReferencesClient Reference { get; set; } } } \ No newline at end of file diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs new file mode 100644 index 00000000..e21ffcdf --- /dev/null +++ b/Octokit/Clients/IReferencesClient.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IReferencesClient + { + Task Get(string owner, string repo, string reference); + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index e17ebc40..8943bcf4 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -58,6 +58,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 2f623f62..2b1d1bc1 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -76,6 +76,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 9e0ab876..dc8c49e7 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -55,6 +55,7 @@ + From d464b6ddaf93af66f63275713443722714d9d096 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Fri, 22 Nov 2013 01:05:00 +0100 Subject: [PATCH 24/64] Added implementation stub. Test is passing --- Octokit/Clients/GitDatabaseClient.cs | 1 + Octokit/Clients/ReferencesClient.cs | 15 +++++++++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 5 files changed, 19 insertions(+) create mode 100644 Octokit/Clients/ReferencesClient.cs diff --git a/Octokit/Clients/GitDatabaseClient.cs b/Octokit/Clients/GitDatabaseClient.cs index b7495498..d7738733 100644 --- a/Octokit/Clients/GitDatabaseClient.cs +++ b/Octokit/Clients/GitDatabaseClient.cs @@ -7,6 +7,7 @@ { Tag = new TagsClient(apiConnection); Commit = new CommitsClient(apiConnection); + Reference = new ReferencesClient(apiConnection); } public ITagsClient Tag { get; set; } diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs new file mode 100644 index 00000000..b0f0b819 --- /dev/null +++ b/Octokit/Clients/ReferencesClient.cs @@ -0,0 +1,15 @@ +using System; +using System.Threading.Tasks; + +namespace Octokit +{ + public class ReferencesClient : ApiClient, IReferencesClient + { + public ReferencesClient(IApiConnection apiConnection) : base(apiConnection) { } + + public Task Get(string owner, string repo, string reference) + { + throw new NotImplementedException(); + } + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 8943bcf4..7b4044ae 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -68,6 +68,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 2b1d1bc1..5547f28a 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -93,6 +93,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index dc8c49e7..76d7c1a9 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -56,6 +56,7 @@ + From 0971e3297dbd98ebcf9457e0be006f91cf3bfc32 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Fri, 22 Nov 2013 01:18:55 +0100 Subject: [PATCH 25/64] Added Reference Model --- Octokit/Clients/IReferencesClient.cs | 2 +- Octokit/Clients/ReferencesClient.cs | 18 ++++++++++++------ Octokit/Helpers/ApiUrls.cs | 12 ++++++++++++ Octokit/Models/Response/Reference.cs | 9 +++++++++ Octokit/Models/Response/TagObject.cs | 3 ++- Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 8 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 Octokit/Models/Response/Reference.cs diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs index e21ffcdf..1540fe64 100644 --- a/Octokit/Clients/IReferencesClient.cs +++ b/Octokit/Clients/IReferencesClient.cs @@ -4,6 +4,6 @@ namespace Octokit { public interface IReferencesClient { - Task Get(string owner, string repo, string reference); + Task Get(string owner, string name, string reference); } } \ No newline at end of file diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index b0f0b819..66e72319 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -1,15 +1,21 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Octokit { public class ReferencesClient : ApiClient, IReferencesClient { - public ReferencesClient(IApiConnection apiConnection) : base(apiConnection) { } - - public Task Get(string owner, string repo, string reference) + public ReferencesClient(IApiConnection apiConnection) : + base(apiConnection) { - throw new NotImplementedException(); + } + + public Task Get(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return ApiConnection.Get(ApiUrls.Reference(owner, name, reference)); } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 5ee72100..9dd7bff3 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -469,6 +469,18 @@ namespace Octokit return "repos/{0}/{1}/git/commits/{2}".FormatUri(owner, name, reference); } + /// + /// Returns the for the specified reference. + /// + /// The owner of the repository + /// The name of the repository + /// The reference name + /// + public static Uri Reference(string owner, string name, string reference) + { + return "repos/{0}/{1}/git/refs/{2}".FormatUri(owner, name, reference); + } + /// /// Returns the for creating a commit object. /// diff --git a/Octokit/Models/Response/Reference.cs b/Octokit/Models/Response/Reference.cs new file mode 100644 index 00000000..1fd8d08b --- /dev/null +++ b/Octokit/Models/Response/Reference.cs @@ -0,0 +1,9 @@ +namespace Octokit +{ + public class Reference + { + public string Ref { get; set; } + public string Url { get; set; } + public TagObject Object { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/TagObject.cs b/Octokit/Models/Response/TagObject.cs index b9c4b7cf..183f754f 100644 --- a/Octokit/Models/Response/TagObject.cs +++ b/Octokit/Models/Response/TagObject.cs @@ -14,6 +14,7 @@ { Commit, Blob, - Tree + Tree, + Tag } } \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 7b4044ae..a05062be 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -117,6 +117,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 5547f28a..eac6c575 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -206,6 +206,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 76d7c1a9..41c417c6 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -70,6 +70,7 @@ + From 776a0b845fc492d8e24af826cc30963c07b74cf9 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Fri, 22 Nov 2013 01:27:57 +0100 Subject: [PATCH 26/64] Added tests for the Get method --- .../Clients/ReferencesClientTests.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Octokit.Tests/Clients/ReferencesClientTests.cs diff --git a/Octokit.Tests/Clients/ReferencesClientTests.cs b/Octokit.Tests/Clients/ReferencesClientTests.cs new file mode 100644 index 00000000..fd922457 --- /dev/null +++ b/Octokit.Tests/Clients/ReferencesClientTests.cs @@ -0,0 +1,40 @@ +using System; + +using NSubstitute; + +using Octokit.Tests.Helpers; + +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class ReferencesClientTests + { + public class TheGetMethod + { + [Fact] + public async void EnsuresNonNullArguments() + { + var client = new ReferencesClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Get(null, "name", "heads/develop")); + await AssertEx.Throws(async () => await client.Get("owner", null, "heads/develop")); + await AssertEx.Throws(async () => await client.Get("owner", "name", null)); + await AssertEx.Throws(async () => await client.Get("", "name", "heads/develop")); + await AssertEx.Throws(async () => await client.Get("owner", "", "heads/develop")); + await AssertEx.Throws(async () => await client.Get("owner", "name", "")); + } + + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + client.Get("owner", "repo", "heads/develop"); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop"), null); + } + } + } +} \ No newline at end of file From 930537af53c3ff69d8bd5e39e86f6a8e0fc3bf41 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Fri, 22 Nov 2013 01:29:23 +0100 Subject: [PATCH 27/64] Added test for null argument in ctor --- Octokit.Tests/Clients/ReferencesClientTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Octokit.Tests/Clients/ReferencesClientTests.cs b/Octokit.Tests/Clients/ReferencesClientTests.cs index fd922457..c66c9ce9 100644 --- a/Octokit.Tests/Clients/ReferencesClientTests.cs +++ b/Octokit.Tests/Clients/ReferencesClientTests.cs @@ -12,6 +12,15 @@ namespace Octokit.Tests.Clients { public class TheGetMethod { + public class TheCtor + { + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new ReferencesClient(null)); + } + } + [Fact] public async void EnsuresNonNullArguments() { From 742ce856e88d9e4aea183fb5fb171e9ee3e5cb3a Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 24 Nov 2013 22:41:56 +0100 Subject: [PATCH 28/64] Added remaining methods on interface --- Octokit/Clients/IReferencesClient.cs | 11 ++++++++++- Octokit/Clients/ReferencesClient.cs | 23 ++++++++++++++++++++++- Octokit/Models/Request/NewReference.cs | 8 ++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 6 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 Octokit/Models/Request/NewReference.cs diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs index 1540fe64..9c367aba 100644 --- a/Octokit/Clients/IReferencesClient.cs +++ b/Octokit/Clients/IReferencesClient.cs @@ -1,9 +1,18 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Octokit { public interface IReferencesClient { Task Get(string owner, string name, string reference); + + Task> GetAll(string owner, string name, string subNamespace = null); + + Task Create(string owner, string name, NewReference reference); + + Task Update(string owner, string name, string reference, string sha, bool force = false); + + Task Delete(string owner, string name, string reference); } } \ No newline at end of file diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index 66e72319..a1953c43 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; namespace Octokit { @@ -17,5 +18,25 @@ namespace Octokit return ApiConnection.Get(ApiUrls.Reference(owner, name, reference)); } + + public Task> GetAll(string owner, string name, string subNamespace = null) + { + throw new System.NotImplementedException(); + } + + public Task Create(string owner, string name, NewReference reference) + { + throw new System.NotImplementedException(); + } + + public Task Update(string owner, string name, string reference, string sha, bool force = false) + { + throw new System.NotImplementedException(); + } + + public Task Delete(string owner, string name, string reference) + { + throw new System.NotImplementedException(); + } } } diff --git a/Octokit/Models/Request/NewReference.cs b/Octokit/Models/Request/NewReference.cs new file mode 100644 index 00000000..60386a7c --- /dev/null +++ b/Octokit/Models/Request/NewReference.cs @@ -0,0 +1,8 @@ +namespace Octokit +{ + public class NewReference + { + public string Ref { get; set; } + public string Sha { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index a05062be..f262d6e8 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -84,6 +84,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index eac6c575..2998c7a1 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -163,6 +163,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 41c417c6..590bdcb2 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -57,6 +57,7 @@ + From b9b60ed77c653432ab55e38dd085ab17cd6f3dc7 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 24 Nov 2013 23:20:11 +0100 Subject: [PATCH 29/64] Fleshed out most of the API methods --- .../Clients/ReferencesClientTests.cs | 77 ++++++++++++++++--- Octokit/Clients/IReferencesClient.cs | 2 +- Octokit/Clients/ReferencesClient.cs | 26 +++++-- Octokit/Helpers/ApiUrls.cs | 7 +- Octokit/Models/Request/ReferenceUpdate.cs | 14 ++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 8 files changed, 110 insertions(+), 19 deletions(-) create mode 100644 Octokit/Models/Request/ReferenceUpdate.cs diff --git a/Octokit.Tests/Clients/ReferencesClientTests.cs b/Octokit.Tests/Clients/ReferencesClientTests.cs index c66c9ce9..20f705ff 100644 --- a/Octokit.Tests/Clients/ReferencesClientTests.cs +++ b/Octokit.Tests/Clients/ReferencesClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using NSubstitute; @@ -10,19 +11,19 @@ namespace Octokit.Tests.Clients { public class ReferencesClientTests { + public class TheCtor + { + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new ReferencesClient(null)); + } + } + public class TheGetMethod { - public class TheCtor - { - [Fact] - public void EnsuresArgument() - { - Assert.Throws(() => new ReferencesClient(null)); - } - } - [Fact] - public async void EnsuresNonNullArguments() + public async Task EnsuresNonNullArguments() { var client = new ReferencesClient(Substitute.For()); @@ -35,15 +36,67 @@ namespace Octokit.Tests.Clients } [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new ReferencesClient(connection); - client.Get("owner", "repo", "heads/develop"); + await client.Get("owner", "repo", "heads/develop"); connection.Received().Get(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop"), null); } } + + public class TheGetAllMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ReferencesClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.GetAll(null, "name", "heads")); + await AssertEx.Throws(async () => await client.GetAll("owner", null, "heads")); + await AssertEx.Throws(async () => await client.GetAll("", "name", "heads")); + await AssertEx.Throws(async () => await client.GetAll("owner", "", "heads")); + } + + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.GetAll("owner", "repo", "heads"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads")); + } + } + + public class TheCreateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ReferencesClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Create(null, "name", new NewReference())); + await AssertEx.Throws(async () => await client.Create("owner", null, new NewReference())); + await AssertEx.Throws(async () => await client.Create("owner", "name", null)); + await AssertEx.Throws(async () => await client.Create("", "name", new NewReference())); + await AssertEx.Throws(async () => await client.Create("owner", "", new NewReference())); + } + + [Fact] + public async Task PostsToCorrectUrl() + { + var newReference = new NewReference(); + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.Create("owner", "repo", newReference); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs"), newReference); + } + } } } \ No newline at end of file diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs index 9c367aba..fa73e41c 100644 --- a/Octokit/Clients/IReferencesClient.cs +++ b/Octokit/Clients/IReferencesClient.cs @@ -11,7 +11,7 @@ namespace Octokit Task Create(string owner, string name, NewReference reference); - Task Update(string owner, string name, string reference, string sha, bool force = false); + Task Update(string owner, string name, string reference, ReferenceUpdate update); Task Delete(string owner, string name, string reference); } diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index a1953c43..b4d557ea 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -21,22 +21,38 @@ namespace Octokit public Task> GetAll(string owner, string name, string subNamespace = null) { - throw new System.NotImplementedException(); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.GetAll(ApiUrls.Reference(owner, name, subNamespace)); } public Task Create(string owner, string name, NewReference reference) { - throw new System.NotImplementedException(); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(reference, "reference"); + + return ApiConnection.Post(ApiUrls.Reference(owner, name), reference); } - public Task Update(string owner, string name, string reference, string sha, bool force = false) + public Task Update(string owner, string name, string reference, ReferenceUpdate update) { - throw new System.NotImplementedException(); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + Ensure.ArgumentNotNull(update, "update"); + + return ApiConnection.Patch(ApiUrls.Reference(owner, name, reference), update); } public Task Delete(string owner, string name, string reference) { - throw new System.NotImplementedException(); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return ApiConnection.Delete(ApiUrls.Reference(owner, name, reference)); } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 9dd7bff3..0b6cb37e 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -476,8 +476,13 @@ namespace Octokit /// The name of the repository /// The reference name /// - public static Uri Reference(string owner, string name, string reference) + public static Uri Reference(string owner, string name, string reference = null) { + if (string.IsNullOrEmpty(reference)) + { + return "repos/{0}/{1}/git/refs".FormatUri(owner, name); + } + return "repos/{0}/{1}/git/refs/{2}".FormatUri(owner, name, reference); } diff --git a/Octokit/Models/Request/ReferenceUpdate.cs b/Octokit/Models/Request/ReferenceUpdate.cs new file mode 100644 index 00000000..0b719cde --- /dev/null +++ b/Octokit/Models/Request/ReferenceUpdate.cs @@ -0,0 +1,14 @@ +namespace Octokit +{ + public class ReferenceUpdate + { + public ReferenceUpdate(string sha, bool force = false) + { + Sha = sha; + Force = force; + } + + public string Sha { get; set; } + public bool Force { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index f262d6e8..3eec02af 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -90,6 +90,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 2998c7a1..1e911000 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -170,6 +170,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 590bdcb2..229f056d 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -58,6 +58,7 @@ + From df0963c8489335a87ed94d7371532df15f2bae90 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 24 Nov 2013 23:44:30 +0100 Subject: [PATCH 30/64] Added missing tests --- .../Clients/ReferencesClientTests.cs | 66 +++++++++++++++++-- Octokit/Models/Request/NewReference.cs | 13 +++- Octokit/Models/Request/ReferenceUpdate.cs | 6 +- 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/Octokit.Tests/Clients/ReferencesClientTests.cs b/Octokit.Tests/Clients/ReferencesClientTests.cs index 20f705ff..bd914aea 100644 --- a/Octokit.Tests/Clients/ReferencesClientTests.cs +++ b/Octokit.Tests/Clients/ReferencesClientTests.cs @@ -79,17 +79,17 @@ namespace Octokit.Tests.Clients { var client = new ReferencesClient(Substitute.For()); - await AssertEx.Throws(async () => await client.Create(null, "name", new NewReference())); - await AssertEx.Throws(async () => await client.Create("owner", null, new NewReference())); + await AssertEx.Throws(async () => await client.Create(null, "name", new NewReference("heads/develop", "sha"))); + await AssertEx.Throws(async () => await client.Create("owner", null, new NewReference("heads/develop", "sha"))); await AssertEx.Throws(async () => await client.Create("owner", "name", null)); - await AssertEx.Throws(async () => await client.Create("", "name", new NewReference())); - await AssertEx.Throws(async () => await client.Create("owner", "", new NewReference())); + await AssertEx.Throws(async () => await client.Create("", "name", new NewReference("heads/develop", "sha"))); + await AssertEx.Throws(async () => await client.Create("owner", "", new NewReference("heads/develop", "sha"))); } [Fact] public async Task PostsToCorrectUrl() { - var newReference = new NewReference(); + var newReference = new NewReference("heads/develop", "sha"); var connection = Substitute.For(); var client = new ReferencesClient(connection); @@ -98,5 +98,61 @@ namespace Octokit.Tests.Clients connection.Received().Post(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs"), newReference); } } + + public class TheUpdateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ReferencesClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Update(null, "name", "heads/develop", new ReferenceUpdate("sha"))); + await AssertEx.Throws(async () => await client.Update("owner", null, "heads/develop", new ReferenceUpdate("sha"))); + await AssertEx.Throws(async () => await client.Update("owner", "name", null, new ReferenceUpdate("sha"))); + await AssertEx.Throws(async () => await client.Update("owner", "name", "heads/develop", null)); + await AssertEx.Throws(async () => await client.Update("", "name", "heads/develop", new ReferenceUpdate("sha"))); + await AssertEx.Throws(async () => await client.Update("owner", "", "heads/develop", new ReferenceUpdate("sha"))); + await AssertEx.Throws(async () => await client.Update("owner", "name", "", new ReferenceUpdate("sha"))); + } + + [Fact] + public async Task PostsToCorrectUrl() + { + var referenceUpdate = new ReferenceUpdate("sha"); + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.Update("owner", "repo", "heads/develop", referenceUpdate); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop"), referenceUpdate); + } + } + + public class TheDeleteMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ReferencesClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Delete(null, "name", "heads/develop")); + await AssertEx.Throws(async () => await client.Delete("owner", null, "heads/develop")); + await AssertEx.Throws(async () => await client.Delete("owner", "name", null)); + await AssertEx.Throws(async () => await client.Delete("", "name", "heads/develop")); + await AssertEx.Throws(async () => await client.Delete("owner", "", "heads/develop")); + await AssertEx.Throws(async () => await client.Delete("owner", "name", "")); + } + + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.Delete("owner", "repo", "heads/develop"); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads/develop")); + } + } } } \ No newline at end of file diff --git a/Octokit/Models/Request/NewReference.cs b/Octokit/Models/Request/NewReference.cs index 60386a7c..d6c58ab9 100644 --- a/Octokit/Models/Request/NewReference.cs +++ b/Octokit/Models/Request/NewReference.cs @@ -2,7 +2,16 @@ { public class NewReference { - public string Ref { get; set; } - public string Sha { get; set; } + public NewReference(string @ref, string sha) + { + Ensure.ArgumentNotNullOrEmptyString(@ref, "ref"); + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + + Ref = @ref; + Sha = sha; + } + + public string Ref { get; private set; } + public string Sha { get; private set; } } } \ No newline at end of file diff --git a/Octokit/Models/Request/ReferenceUpdate.cs b/Octokit/Models/Request/ReferenceUpdate.cs index 0b719cde..b2bf7442 100644 --- a/Octokit/Models/Request/ReferenceUpdate.cs +++ b/Octokit/Models/Request/ReferenceUpdate.cs @@ -4,11 +4,13 @@ { public ReferenceUpdate(string sha, bool force = false) { + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + Sha = sha; Force = force; } - public string Sha { get; set; } - public bool Force { get; set; } + public string Sha { get; private set; } + public bool Force { get; private set; } } } \ No newline at end of file From 25308e5f5ee0fada36e2789f4065522d5eb2ae84 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 00:20:22 +0100 Subject: [PATCH 31/64] Fixed code analysis errors --- Octokit/Clients/IReferencesClient.cs | 9 +++++++-- Octokit/Clients/ReferencesClient.cs | 17 +++++++++++++---- Octokit/Helpers/ApiUrls.cs | 20 +++++++++++++------- Octokit/Models/Request/ReferenceUpdate.cs | 6 +++++- Octokit/Octokit-MonoAndroid.csproj | 5 +++++ Octokit/Octokit-Monotouch.csproj | 5 +++++ 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs index fa73e41c..b07ab5fc 100644 --- a/Octokit/Clients/IReferencesClient.cs +++ b/Octokit/Clients/IReferencesClient.cs @@ -1,17 +1,22 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; namespace Octokit { public interface IReferencesClient { + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] Task Get(string owner, string name, string reference); - Task> GetAll(string owner, string name, string subNamespace = null); + Task> GetAll(string owner, string name); + + Task> GetAll(string owner, string name, string subNamespace); Task Create(string owner, string name, NewReference reference); - Task Update(string owner, string name, string reference, ReferenceUpdate update); + Task Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate); Task Delete(string owner, string name, string reference); } diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index b4d557ea..0e73210e 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -19,11 +19,20 @@ namespace Octokit return ApiConnection.Get(ApiUrls.Reference(owner, name, reference)); } - public Task> GetAll(string owner, string name, string subNamespace = null) + public Task> GetAll(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); + return ApiConnection.GetAll(ApiUrls.Reference(owner, name)); + } + + public Task> GetAll(string owner, string name, string subNamespace) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(subNamespace, "subNamespace"); + return ApiConnection.GetAll(ApiUrls.Reference(owner, name, subNamespace)); } @@ -36,14 +45,14 @@ namespace Octokit return ApiConnection.Post(ApiUrls.Reference(owner, name), reference); } - public Task Update(string owner, string name, string reference, ReferenceUpdate update) + public Task Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); - Ensure.ArgumentNotNull(update, "update"); + Ensure.ArgumentNotNull(referenceUpdate, "update"); - return ApiConnection.Patch(ApiUrls.Reference(owner, name, reference), update); + return ApiConnection.Patch(ApiUrls.Reference(owner, name, reference), referenceUpdate); } public Task Delete(string owner, string name, string reference) diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 0b6cb37e..6e9b2c2b 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -474,16 +474,22 @@ namespace Octokit /// /// The owner of the repository /// The name of the repository - /// The reference name /// - public static Uri Reference(string owner, string name, string reference = null) + public static Uri Reference(string owner, string name) { - if (string.IsNullOrEmpty(reference)) - { - return "repos/{0}/{1}/git/refs".FormatUri(owner, name); - } + return "repos/{0}/{1}/git/refs".FormatUri(owner, name); + } - return "repos/{0}/{1}/git/refs/{2}".FormatUri(owner, name, reference); + /// + /// Returns the for the specified reference. + /// + /// The owner of the repository + /// The name of the repository + /// The reference name + /// + public static Uri Reference(string owner, string name, string referenceName) + { + return "repos/{0}/{1}/git/refs/{2}".FormatUri(owner, name, referenceName); } /// diff --git a/Octokit/Models/Request/ReferenceUpdate.cs b/Octokit/Models/Request/ReferenceUpdate.cs index b2bf7442..0b187397 100644 --- a/Octokit/Models/Request/ReferenceUpdate.cs +++ b/Octokit/Models/Request/ReferenceUpdate.cs @@ -2,7 +2,11 @@ { public class ReferenceUpdate { - public ReferenceUpdate(string sha, bool force = false) + public ReferenceUpdate(string sha) : this(sha, false) + { + } + + public ReferenceUpdate(string sha, bool force) { Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 4a3b0d7d..4e32d67f 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -234,6 +234,11 @@ + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 3189e64f..0704707f 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -229,6 +229,11 @@ + + + + + \ No newline at end of file From ca40a397d28ddea8b5b78a8ec4120edab8072c5a Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 00:40:23 +0100 Subject: [PATCH 32/64] Added XML documentation --- Octokit/Clients/IReferencesClient.cs | 60 ++++++++++++++++++++++++++++ Octokit/Clients/ReferencesClient.cs | 60 ++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs index b07ab5fc..b9ba29c8 100644 --- a/Octokit/Clients/IReferencesClient.cs +++ b/Octokit/Clients/IReferencesClient.cs @@ -6,18 +6,78 @@ namespace Octokit { public interface IReferencesClient { + /// + /// Gets a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#get-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// Tha name of the reference + /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] Task Get(string owner, string name, string reference); + /// + /// Gets all references for a given repository + /// + /// + /// http://developer.github.com/v3/git/refs/#get-all-references + /// + /// The owner of the repository + /// The name of the repository + /// Task> GetAll(string owner, string name); + /// + /// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads" + /// + /// + /// http://developer.github.com/v3/git/refs/#get-all-references + /// + /// The owner of the repository + /// The name of the repository + /// The sub-namespace to get references for + /// Task> GetAll(string owner, string name, string subNamespace); + /// + /// Creates a reference for a given repository + /// + /// + /// http://developer.github.com/v3/git/refs/#create-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The reference to create + /// Task Create(string owner, string name, NewReference reference); + /// + /// Updates a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#update-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The name of the reference + /// The updated reference data + /// Task Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate); + /// + /// Deletes a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#delete-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The name of the reference + /// Task Delete(string owner, string name, string reference); } } \ No newline at end of file diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index 0e73210e..c4be19ac 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -10,6 +10,16 @@ namespace Octokit { } + /// + /// Gets a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#get-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// Tha name of the reference + /// public Task Get(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -19,6 +29,15 @@ namespace Octokit return ApiConnection.Get(ApiUrls.Reference(owner, name, reference)); } + /// + /// Gets all references for a given repository + /// + /// + /// http://developer.github.com/v3/git/refs/#get-all-references + /// + /// The owner of the repository + /// The name of the repository + /// public Task> GetAll(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -27,6 +46,16 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Reference(owner, name)); } + /// + /// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads" + /// + /// + /// http://developer.github.com/v3/git/refs/#get-all-references + /// + /// The owner of the repository + /// The name of the repository + /// The sub-namespace to get references for + /// public Task> GetAll(string owner, string name, string subNamespace) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -36,6 +65,16 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.Reference(owner, name, subNamespace)); } + /// + /// Creates a reference for a given repository + /// + /// + /// http://developer.github.com/v3/git/refs/#create-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The reference to create + /// public Task Create(string owner, string name, NewReference reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -45,6 +84,17 @@ namespace Octokit return ApiConnection.Post(ApiUrls.Reference(owner, name), reference); } + /// + /// Updates a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#update-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The name of the reference + /// The updated reference data + /// public Task Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); @@ -55,6 +105,16 @@ namespace Octokit return ApiConnection.Patch(ApiUrls.Reference(owner, name, reference), referenceUpdate); } + /// + /// Deletes a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#delete-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The name of the reference + /// public Task Delete(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); From db7624a4ba9da84964ced895353b28d7999f7b90 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 00:57:45 +0100 Subject: [PATCH 33/64] Added reactive client --- .../Clients/IObservableGitDatabaseClient.cs | 1 + .../Clients/IObservableReferencesClient.cs | 83 +++++++++++ .../Clients/ObservableGitDatabaseClient.cs | 2 + .../Clients/ObservableReferencesClient.cs | 136 ++++++++++++++++++ Octokit.Reactive/Octokit.Reactive-Mono.csproj | 2 + .../Octokit.Reactive-MonoAndroid.csproj | 2 + .../Octokit.Reactive-Monotouch.csproj | 2 + Octokit.Reactive/Octokit.Reactive.csproj | 2 + 8 files changed, 230 insertions(+) create mode 100644 Octokit.Reactive/Clients/IObservableReferencesClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableReferencesClient.cs diff --git a/Octokit.Reactive/Clients/IObservableGitDatabaseClient.cs b/Octokit.Reactive/Clients/IObservableGitDatabaseClient.cs index d071c78a..14b8a369 100644 --- a/Octokit.Reactive/Clients/IObservableGitDatabaseClient.cs +++ b/Octokit.Reactive/Clients/IObservableGitDatabaseClient.cs @@ -7,5 +7,6 @@ { IObservableTagsClient Tag { get; set; } IObservableCommitsClient Commit { get; set; } + IObservableReferencesClient Reference { get; set; } } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/IObservableReferencesClient.cs b/Octokit.Reactive/Clients/IObservableReferencesClient.cs new file mode 100644 index 00000000..699b45bc --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableReferencesClient.cs @@ -0,0 +1,83 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Reactive; + +namespace Octokit.Reactive +{ + public interface IObservableReferencesClient + { + /// + /// Gets a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#get-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// Tha name of the reference + /// + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + IObservable Get(string owner, string name, string reference); + + /// + /// Gets all references for a given repository + /// + /// + /// http://developer.github.com/v3/git/refs/#get-all-references + /// + /// The owner of the repository + /// The name of the repository + /// + IObservable GetAll(string owner, string name); + + /// + /// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads" + /// + /// + /// http://developer.github.com/v3/git/refs/#get-all-references + /// + /// The owner of the repository + /// The name of the repository + /// The sub-namespace to get references for + /// + IObservable GetAll(string owner, string name, string subNamespace); + + /// + /// Creates a reference for a given repository + /// + /// + /// http://developer.github.com/v3/git/refs/#create-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The reference to create + /// + IObservable Create(string owner, string name, NewReference reference); + + /// + /// Updates a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#update-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The name of the reference + /// The updated reference data + /// + IObservable Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate); + + /// + /// Deletes a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#delete-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The name of the reference + /// + IObservable Delete(string owner, string name, string reference); + } +} \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableGitDatabaseClient.cs b/Octokit.Reactive/Clients/ObservableGitDatabaseClient.cs index 48a65d0a..2ea26302 100644 --- a/Octokit.Reactive/Clients/ObservableGitDatabaseClient.cs +++ b/Octokit.Reactive/Clients/ObservableGitDatabaseClient.cs @@ -6,9 +6,11 @@ { Tag = new ObservableTagsClient(client); Commit = new ObservableCommitsClient(client); + Reference = new ObservableReferencesClient(client); } public IObservableTagsClient Tag { get; set; } public IObservableCommitsClient Commit { get; set; } + public IObservableReferencesClient Reference { get; set; } } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableReferencesClient.cs b/Octokit.Reactive/Clients/ObservableReferencesClient.cs new file mode 100644 index 00000000..3537607c --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableReferencesClient.cs @@ -0,0 +1,136 @@ +using System; +using System.Reactive; +using System.Reactive.Threading.Tasks; + +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive +{ + public class ObservableReferencesClient : IObservableReferencesClient + { + readonly IReferencesClient _reference; + readonly IConnection _connection; + + public ObservableReferencesClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _reference = client.GitDatabase.Reference; + _connection = client.Connection; + } + + /// + /// Gets a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#get-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// Tha name of the reference + /// + public IObservable Get(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return _reference.Get(owner, name, reference).ToObservable(); + } + + /// + /// Gets all references for a given repository + /// + /// + /// http://developer.github.com/v3/git/refs/#get-all-references + /// + /// The owner of the repository + /// The name of the repository + /// + public IObservable GetAll(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Reference(owner, name)); + } + + /// + /// Gets references for a given repository by sub-namespace, i.e. "tags" or "heads" + /// + /// + /// http://developer.github.com/v3/git/refs/#get-all-references + /// + /// The owner of the repository + /// The name of the repository + /// The sub-namespace to get references for + /// + public IObservable GetAll(string owner, string name, string subNamespace) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(subNamespace, "subNamespace"); + + return _connection.GetAndFlattenAllPages(ApiUrls.Reference(owner, name, subNamespace)); + } + + /// + /// Creates a reference for a given repository + /// + /// + /// http://developer.github.com/v3/git/refs/#create-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The reference to create + /// + public IObservable Create(string owner, string name, NewReference reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(reference, "reference"); + + return _reference.Create(owner, name, reference).ToObservable(); + } + + /// + /// Updates a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#update-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The name of the reference + /// The updated reference data + /// + public IObservable Update(string owner, string name, string reference, ReferenceUpdate referenceUpdate) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + Ensure.ArgumentNotNull(referenceUpdate, "update"); + + return _reference.Update(owner, name, reference, referenceUpdate).ToObservable(); + } + + /// + /// Deletes a reference for a given repository by reference name + /// + /// + /// http://developer.github.com/v3/git/refs/#delete-a-reference + /// + /// The owner of the repository + /// The name of the repository + /// The name of the reference + /// + public IObservable Delete(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return _reference.Delete(owner, name, reference).ToObservable(); + } + } +} \ No newline at end of file diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index 8a65ae6c..331c8ca3 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -110,6 +110,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index da0f5738..92e7e2c2 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -119,6 +119,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index cd3bfee2..1c08e72f 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -114,6 +114,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 1c38caf5..1917158a 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -74,6 +74,8 @@ Properties\SolutionInfo.cs + + From 727429278ee8ad802fd59533884a39d57a827db7 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 12:45:34 +0100 Subject: [PATCH 34/64] Fixed some R# documentation analysis errors --- Octokit.Reactive/Clients/IObservableOrganizationTeamsClient.cs | 2 +- Octokit.Reactive/Clients/ObservableOrganizationTeamsClient.cs | 2 +- Octokit/Clients/IRepoCollaboratorsClient.cs | 2 +- Octokit/Clients/ITeamsClient.cs | 2 +- Octokit/Clients/RepoCollaboratorsClient.cs | 2 +- Octokit/Http/IHttpClient.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableOrganizationTeamsClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationTeamsClient.cs index a7911838..9c9dfc33 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationTeamsClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationTeamsClient.cs @@ -16,7 +16,7 @@ namespace Octokit.Reactive /// Returns all s for the current org. /// /// Thrown when a general API error occurs. - /// A list of the orgs's teams s. + /// A list of the orgs's teams s. IObservable GetAllTeams(string org); /// diff --git a/Octokit.Reactive/Clients/ObservableOrganizationTeamsClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationTeamsClient.cs index 609375cc..1888a2a4 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationTeamsClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationTeamsClient.cs @@ -25,7 +25,7 @@ namespace Octokit.Reactive /// Returns all s for the current org. /// /// Thrown when a general API error occurs. - /// A list of the orgs's teams s. + /// A list of the orgs's teams s. public IObservable GetAllTeams(string org) { Ensure.ArgumentNotNullOrEmptyString(org, "org"); diff --git a/Octokit/Clients/IRepoCollaboratorsClient.cs b/Octokit/Clients/IRepoCollaboratorsClient.cs index f94b0fe1..3c379ba0 100644 --- a/Octokit/Clients/IRepoCollaboratorsClient.cs +++ b/Octokit/Clients/IRepoCollaboratorsClient.cs @@ -31,7 +31,7 @@ namespace Octokit /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// True if user is a collaborator else false + /// True if user is a collaborator else false Task IsCollaborator(string owner, string repo, string user); /// diff --git a/Octokit/Clients/ITeamsClient.cs b/Octokit/Clients/ITeamsClient.cs index 06554128..31c02b70 100644 --- a/Octokit/Clients/ITeamsClient.cs +++ b/Octokit/Clients/ITeamsClient.cs @@ -18,7 +18,7 @@ namespace Octokit /// Returns all s for the current org. /// /// Thrown when a general API error occurs. - /// A list of the orgs's teams s. + /// A list of the orgs's teams s. Task> GetAllTeams(string org); /// diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 6fc52ca4..6b508b98 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -48,7 +48,7 @@ namespace Octokit /// See the API documentation for more information. /// /// Thrown when a general API error occurs. - /// True if user is a collaborator else false + /// True if user is a collaborator else false public async Task IsCollaborator(string owner, string repo, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); diff --git a/Octokit/Http/IHttpClient.cs b/Octokit/Http/IHttpClient.cs index 75c87a0c..4e699d31 100644 --- a/Octokit/Http/IHttpClient.cs +++ b/Octokit/Http/IHttpClient.cs @@ -15,7 +15,7 @@ namespace Octokit.Internal /// /// The type of data to send /// A that represents the HTTP request - /// A + /// A of Task> Send(IRequest request); } } From e5009598f731f262ef191c0c5b4b88c288f1db0c Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 13:42:27 +0100 Subject: [PATCH 35/64] Fixed typos and whitespace --- Octokit.Reactive/Clients/IObservableReferencesClient.cs | 2 +- Octokit.Reactive/Clients/ObservableReferencesClient.cs | 2 +- Octokit.Tests/Clients/AssigneesClientTests.cs | 3 +-- Octokit.Tests/Clients/CommitsClientTests.cs | 3 +-- Octokit/Clients/IReferencesClient.cs | 2 +- Octokit/Clients/ReferencesClient.cs | 2 +- 6 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservableReferencesClient.cs b/Octokit.Reactive/Clients/IObservableReferencesClient.cs index 699b45bc..86b7eb89 100644 --- a/Octokit.Reactive/Clients/IObservableReferencesClient.cs +++ b/Octokit.Reactive/Clients/IObservableReferencesClient.cs @@ -14,7 +14,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// Tha name of the reference + /// The name of the reference /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] diff --git a/Octokit.Reactive/Clients/ObservableReferencesClient.cs b/Octokit.Reactive/Clients/ObservableReferencesClient.cs index 3537607c..8ebb1373 100644 --- a/Octokit.Reactive/Clients/ObservableReferencesClient.cs +++ b/Octokit.Reactive/Clients/ObservableReferencesClient.cs @@ -27,7 +27,7 @@ namespace Octokit.Reactive /// /// The owner of the repository /// The name of the repository - /// Tha name of the reference + /// The name of the reference /// public IObservable Get(string owner, string name, string reference) { diff --git a/Octokit.Tests/Clients/AssigneesClientTests.cs b/Octokit.Tests/Clients/AssigneesClientTests.cs index 443a059b..6a422c34 100644 --- a/Octokit.Tests/Clients/AssigneesClientTests.cs +++ b/Octokit.Tests/Clients/AssigneesClientTests.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Net; using System.Threading.Tasks; using NSubstitute; -using Octokit; using Octokit.Internal; using Octokit.Tests.Helpers; using Xunit; @@ -97,4 +96,4 @@ namespace Octokit.Tests.Clients } } } -} \ No newline at end of file +} diff --git a/Octokit.Tests/Clients/CommitsClientTests.cs b/Octokit.Tests/Clients/CommitsClientTests.cs index c36cb9a4..981c1c7c 100644 --- a/Octokit.Tests/Clients/CommitsClientTests.cs +++ b/Octokit.Tests/Clients/CommitsClientTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using NSubstitute; -using Octokit; using Octokit.Tests.Helpers; using Xunit; @@ -75,4 +74,4 @@ public class CommitsClientTests Assert.Throws(() => new CommitsClient(null)); } } -} \ No newline at end of file +} diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs index b9ba29c8..a609b021 100644 --- a/Octokit/Clients/IReferencesClient.cs +++ b/Octokit/Clients/IReferencesClient.cs @@ -14,7 +14,7 @@ namespace Octokit /// /// The owner of the repository /// The name of the repository - /// Tha name of the reference + /// The name of the reference /// [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index c4be19ac..d4102ed0 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -18,7 +18,7 @@ namespace Octokit /// /// The owner of the repository /// The name of the repository - /// Tha name of the reference + /// The name of the reference /// public Task Get(string owner, string name, string reference) { From 786c7e50f3c2098ff8a21d6a010b8c6e7bf1b1b9 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 16:14:04 +0100 Subject: [PATCH 36/64] Renamed GetAll with sub-namespace to GetAllForSubNamespace and added test for the regular GetAll --- .../Clients/ReferencesClientTests.cs | 35 ++++++++++++++++--- Octokit/Clients/IReferencesClient.cs | 2 +- Octokit/Clients/ReferencesClient.cs | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests/Clients/ReferencesClientTests.cs b/Octokit.Tests/Clients/ReferencesClientTests.cs index bd914aea..cf7e7de0 100644 --- a/Octokit.Tests/Clients/ReferencesClientTests.cs +++ b/Octokit.Tests/Clients/ReferencesClientTests.cs @@ -54,10 +54,10 @@ namespace Octokit.Tests.Clients { var client = new ReferencesClient(Substitute.For()); - await AssertEx.Throws(async () => await client.GetAll(null, "name", "heads")); - await AssertEx.Throws(async () => await client.GetAll("owner", null, "heads")); - await AssertEx.Throws(async () => await client.GetAll("", "name", "heads")); - await AssertEx.Throws(async () => await client.GetAll("owner", "", "heads")); + await AssertEx.Throws(async () => await client.GetAll(null, "name")); + await AssertEx.Throws(async () => await client.GetAll("owner", null)); + await AssertEx.Throws(async () => await client.GetAll("", "name")); + await AssertEx.Throws(async () => await client.GetAll("owner", "")); } [Fact] @@ -66,7 +66,32 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new ReferencesClient(connection); - await client.GetAll("owner", "repo", "heads"); + await client.GetAll("owner", "repo"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs")); + } + } + + public class TheGetAllForSubNamespaceMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ReferencesClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.GetAllForSubNamespace(null, "name", "heads")); + await AssertEx.Throws(async () => await client.GetAllForSubNamespace("owner", null, "heads")); + await AssertEx.Throws(async () => await client.GetAllForSubNamespace("", "name", "heads")); + await AssertEx.Throws(async () => await client.GetAllForSubNamespace("owner", "", "heads")); + } + + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new ReferencesClient(connection); + + await client.GetAllForSubNamespace("owner", "repo", "heads"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/owner/repo/git/refs/heads")); } diff --git a/Octokit/Clients/IReferencesClient.cs b/Octokit/Clients/IReferencesClient.cs index a609b021..06aecfb8 100644 --- a/Octokit/Clients/IReferencesClient.cs +++ b/Octokit/Clients/IReferencesClient.cs @@ -41,7 +41,7 @@ namespace Octokit /// The name of the repository /// The sub-namespace to get references for /// - Task> GetAll(string owner, string name, string subNamespace); + Task> GetAllForSubNamespace(string owner, string name, string subNamespace); /// /// Creates a reference for a given repository diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index d4102ed0..c7cb657d 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -56,7 +56,7 @@ namespace Octokit /// The name of the repository /// The sub-namespace to get references for /// - public Task> GetAll(string owner, string name, string subNamespace) + public Task> GetAllForSubNamespace(string owner, string name, string subNamespace) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); From ace83587ba37429fa011e62c87239b31536a2e56 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 16:16:55 +0100 Subject: [PATCH 37/64] Removed more whitespace --- Octokit.Tests/Clients/GistsClientTests.cs | 3 +-- Octokit.Tests/Clients/GitDatabaseClientTests.cs | 3 +-- Octokit.Tests/Clients/IssueCommentsClientTests.cs | 1 - Octokit.Tests/Clients/IssuesClientTests.cs | 3 +-- Octokit.Tests/Clients/MilestonesClientTests.cs | 1 - 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index 5765cc6d..30c2f53a 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -1,6 +1,5 @@ using System; using NSubstitute; -using Octokit; using Xunit; public class GistsClientTests @@ -27,4 +26,4 @@ public class GistsClientTests Assert.Throws(() => new GistsClient(null)); } } -} \ No newline at end of file +} diff --git a/Octokit.Tests/Clients/GitDatabaseClientTests.cs b/Octokit.Tests/Clients/GitDatabaseClientTests.cs index 45544679..dfad5e3f 100644 --- a/Octokit.Tests/Clients/GitDatabaseClientTests.cs +++ b/Octokit.Tests/Clients/GitDatabaseClientTests.cs @@ -1,6 +1,5 @@ using System; using NSubstitute; -using Octokit; using Xunit; public class GitDatabaseClientTests @@ -37,4 +36,4 @@ public class GitDatabaseClientTests Assert.NotNull(gitDatabaseClient.Reference); } } -} \ No newline at end of file +} diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index 1bac6036..a336f6a0 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using NSubstitute; -using Octokit; using Octokit.Internal; using Octokit.Tests.Helpers; using Xunit; diff --git a/Octokit.Tests/Clients/IssuesClientTests.cs b/Octokit.Tests/Clients/IssuesClientTests.cs index da402574..632b37f8 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; -using Octokit; using Octokit.Internal; using Octokit.Tests; using Octokit.Tests.Helpers; @@ -254,4 +253,4 @@ namespace Octokit.Tests.Clients Assert.Equal(new Uri("https://github.com/octokit-net-test/public-repo-20131022050247078/issues/1"), response.BodyAsObject.HtmlUrl); } } -} \ No newline at end of file +} diff --git a/Octokit.Tests/Clients/MilestonesClientTests.cs b/Octokit.Tests/Clients/MilestonesClientTests.cs index 9b27b715..8897e77d 100644 --- a/Octokit.Tests/Clients/MilestonesClientTests.cs +++ b/Octokit.Tests/Clients/MilestonesClientTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; -using Octokit; using Octokit.Tests.Helpers; using Xunit; From 09dc5edc27931b5ebd8e9dd2da40cb2fbed7c8a6 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 19:27:44 +0100 Subject: [PATCH 38/64] Added TODO for handling 404 when sub-namespace cannot be found --- Octokit/Clients/ReferencesClient.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Octokit/Clients/ReferencesClient.cs b/Octokit/Clients/ReferencesClient.cs index c7cb657d..9ba48437 100644 --- a/Octokit/Clients/ReferencesClient.cs +++ b/Octokit/Clients/ReferencesClient.cs @@ -62,6 +62,8 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(subNamespace, "subNamespace"); + // TODO: Handle 404 when subNamespace cannot be found + return ApiConnection.GetAll(ApiUrls.Reference(owner, name, subNamespace)); } From 0d0cf18b2ef09a22b411bf6c2caf52d4f87d2ab1 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 22:22:31 +0100 Subject: [PATCH 39/64] Added validation when creating reference --- Octokit.Tests/Models/NewReferenceTests.cs | 25 ++++++++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + Octokit/Models/Request/NewReference.cs | 31 ++++++++++++++++++++--- 3 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 Octokit.Tests/Models/NewReferenceTests.cs diff --git a/Octokit.Tests/Models/NewReferenceTests.cs b/Octokit.Tests/Models/NewReferenceTests.cs new file mode 100644 index 00000000..c5e68adf --- /dev/null +++ b/Octokit.Tests/Models/NewReferenceTests.cs @@ -0,0 +1,25 @@ +using System; + +using Octokit; + +using Xunit; + +public class NewReferenceTests +{ + public class TheCtor + { + [Fact] + public void EnforcesRefsPrefix() + { + var create = new NewReference("heads/develop", "sha"); + + Assert.Equal(create.Ref, "refs/heads/develop"); + } + + [Fact] + public void ThrowsExceptionIfRefHasLessThanTwoSlashes() + { + Assert.Throws(() => new NewReference("refs/develop", "sha")); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index d2f2535b..b41260a2 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -111,6 +111,7 @@ + diff --git a/Octokit/Models/Request/NewReference.cs b/Octokit/Models/Request/NewReference.cs index d6c58ab9..47288583 100644 --- a/Octokit/Models/Request/NewReference.cs +++ b/Octokit/Models/Request/NewReference.cs @@ -1,17 +1,40 @@ -namespace Octokit +using System; +using System.Linq; + +namespace Octokit { public class NewReference { - public NewReference(string @ref, string sha) + const string _refsPrefix = "refs"; + + public NewReference(string reference, string sha) { - Ensure.ArgumentNotNullOrEmptyString(@ref, "ref"); + Ensure.ArgumentNotNullOrEmptyString(reference, "ref"); Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); - Ref = @ref; + Ref = GetReference(reference); Sha = sha; } public string Ref { get; private set; } public string Sha { get; private set; } + + static string GetReference(string reference) + { + var parts = reference.Split('/').ToList(); + + var refsPart = parts.FirstOrDefault(); + if (refsPart != null && refsPart != _refsPrefix) + { + parts.Insert(0, _refsPrefix); + } + + if (parts.Count < 3) + { + throw new FormatException("Reference must start with 'refs' and have at least two slashes."); + } + + return string.Join("/", parts); + } } } \ No newline at end of file From 88c5a9a703f1689d84faa22b560495b7d08df3a8 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Mon, 25 Nov 2013 23:48:42 +0100 Subject: [PATCH 40/64] Fixed some errors after merge --- Octokit.Reactive/Clients/ObservableReferencesClient.cs | 1 - Octokit.Tests/Clients/CommitsClientTests.cs | 1 + Octokit.Tests/Clients/GistsClientTests.cs | 1 + Octokit.Tests/Clients/GitDatabaseClientTests.cs | 1 + Octokit.Tests/Clients/IssueCommentsClientTests.cs | 1 + Octokit.Tests/Clients/ReferencesClientTests.cs | 3 --- Octokit.Tests/Models/NewReferenceTests.cs | 2 -- Octokit.Tests/Octokit.Tests.csproj | 1 + 8 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservableReferencesClient.cs b/Octokit.Reactive/Clients/ObservableReferencesClient.cs index 8ebb1373..4f578098 100644 --- a/Octokit.Reactive/Clients/ObservableReferencesClient.cs +++ b/Octokit.Reactive/Clients/ObservableReferencesClient.cs @@ -1,7 +1,6 @@ using System; using System.Reactive; using System.Reactive.Threading.Tasks; - using Octokit.Reactive.Internal; namespace Octokit.Reactive diff --git a/Octokit.Tests/Clients/CommitsClientTests.cs b/Octokit.Tests/Clients/CommitsClientTests.cs index 981c1c7c..1901322a 100644 --- a/Octokit.Tests/Clients/CommitsClientTests.cs +++ b/Octokit.Tests/Clients/CommitsClientTests.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using NSubstitute; +using Octokit; using Octokit.Tests.Helpers; using Xunit; diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index 30c2f53a..f83742cf 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -1,5 +1,6 @@ using System; using NSubstitute; +using Octokit; using Xunit; public class GistsClientTests diff --git a/Octokit.Tests/Clients/GitDatabaseClientTests.cs b/Octokit.Tests/Clients/GitDatabaseClientTests.cs index dfad5e3f..7c417981 100644 --- a/Octokit.Tests/Clients/GitDatabaseClientTests.cs +++ b/Octokit.Tests/Clients/GitDatabaseClientTests.cs @@ -1,5 +1,6 @@ using System; using NSubstitute; +using Octokit; using Xunit; public class GitDatabaseClientTests diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index a336f6a0..1bac6036 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using NSubstitute; +using Octokit; using Octokit.Internal; using Octokit.Tests.Helpers; using Xunit; diff --git a/Octokit.Tests/Clients/ReferencesClientTests.cs b/Octokit.Tests/Clients/ReferencesClientTests.cs index cf7e7de0..5ca39024 100644 --- a/Octokit.Tests/Clients/ReferencesClientTests.cs +++ b/Octokit.Tests/Clients/ReferencesClientTests.cs @@ -1,10 +1,7 @@ using System; using System.Threading.Tasks; - using NSubstitute; - using Octokit.Tests.Helpers; - using Xunit; namespace Octokit.Tests.Clients diff --git a/Octokit.Tests/Models/NewReferenceTests.cs b/Octokit.Tests/Models/NewReferenceTests.cs index c5e68adf..48cc90ca 100644 --- a/Octokit.Tests/Models/NewReferenceTests.cs +++ b/Octokit.Tests/Models/NewReferenceTests.cs @@ -1,7 +1,5 @@ using System; - using Octokit; - using Xunit; public class NewReferenceTests diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index b41260a2..6a7e72bc 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -64,6 +64,7 @@ + From 7c64e06bfcbc7e9ed07d97ffc3661bce9878d3cb Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Tue, 26 Nov 2013 14:39:16 -0800 Subject: [PATCH 41/64] refactoring scripts so the build server can run each in-step --- build.cmd | 13 +++++++++++++ build.fsx | 17 ++++++++++++----- script/cibuild.ps1 | 43 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/build.cmd b/build.cmd index 5255fee0..7c927e17 100644 --- a/build.cmd +++ b/build.cmd @@ -12,6 +12,19 @@ IF NOT [%1]==[] (set TARGET="%1") SET BUILDMODE="Release" IF NOT [%2]==[] (set BUILDMODE="%2") +:: because we want to run specific steps inline on qed +:: we need to break the dependency chain +:: this ensures we do a build before running any tests + +if TARGET=="Default" (SET RunBuild=1) +if TARGET=="RunUnitTests" (SET RunBuild=1) +if TARGET=="RunIntegrationTests" (SET RunBuild=1) +if TARGET=="CreatePackages" (SET RunBuild=1) + +if "%RunBuild%"=="" ( +"tools\FAKE.Core\tools\Fake.exe" "build.fsx" "target=BuildApp" "buildMode=%BUILDMODE%" +) + "tools\FAKE.Core\tools\Fake.exe" "build.fsx" "target=%TARGET%" "buildMode=%BUILDMODE%" rem Bail if we're running a TeamCity build. diff --git a/build.fsx b/build.fsx index 009dc883..3ed31657 100644 --- a/build.fsx +++ b/build.fsx @@ -131,14 +131,21 @@ Target "CreateOctokitReactivePackage" (fun _ -> Target "Default" DoNothing +Target "CreatePackages" DoNothing + "Clean" ==> "AssemblyInfo" ==> "CheckProjects" - ==> "BuildApp" - ==> "UnitTests" - ==> "IntegrationTests" - ==> "CreateOctokitPackage" - ==> "CreateOctokitReactivePackage" + ==> "BuildApp" + +"UnitTests" ==> "Default" +"IntegrationTests" + ==> "Default" + +"CreateOctokitPackage" +"CreateOctokitReactivePackage" + ==> "CreatePackages" + RunTargetOrDefault "Default" \ No newline at end of file diff --git a/script/cibuild.ps1 b/script/cibuild.ps1 index 51b10c97..5f479f26 100644 --- a/script/cibuild.ps1 +++ b/script/cibuild.ps1 @@ -35,6 +35,17 @@ function Die-WithOutput($exitCode, $output) { exit $exitCode } +function Dump-Error($output) { + $exitCode = $LastExitCode + + $errors = $output | Select-String ": error" + if ($errors) { + $output = "Likely errors:", $errors, "", "Full output:", $output + } + + Die-WithOutput $exitCode $output +} + function Run-Command([scriptblock]$Command, [switch]$Fatal, [switch]$Quiet) { $output = "" if ($Quiet) { @@ -81,16 +92,34 @@ else { Write-Output "Building Octokit..." Write-Output "" -$output = .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=Default" "buildMode=Release" +$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=BuildApp" "buildMode=Release" 2>&1 if ($LastExitCode -ne 0) { - $exitCode = $LastExitCode + Dump-Error($output) +} - $errors = $output | Select-String ": error" - if ($errors) { - $output = "Likely errors:", $errors, "", "Full output:", $output - } +Write-Output "Running unit tests..." +Write-Output "" +$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=UnitTests" "buildMode=Release" 2>&1 +if ($LastExitCode -ne 0) { + Dump-Error($output) +} - Die-WithOutput $exitCode $output +Write-Output "Running integration tests..." +Write-Output "" +$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=IntegrationTests" "buildMode=Release" 2>&1 +if ($LastExitCode -ne 0) { + Dump-Error($output) +} + +Write-Output "Creating NuGet packages..." +Write-Output "" +$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=CreateOctokitPackage" "buildMode=Release" 2>&1 +if ($LastExitCode -ne 0) { + Dump-Error($output) +} +$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=CreateOctokitReactivePackage" "buildMode=Release" 2>&1 +if ($LastExitCode -ne 0) { + Dump-Error($output) } $exitCode = 0 From 9fb83fba3ecc538972eef5466f607ce711f8a974 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 09:33:34 -0800 Subject: [PATCH 42/64] use the /silent output for xUnit tests --- build.fsx | 1 + 1 file changed, 1 insertion(+) diff --git a/build.fsx b/build.fsx index 3ed31657..a9419026 100644 --- a/build.fsx +++ b/build.fsx @@ -75,6 +75,7 @@ Target "IntegrationTests" (fun _ -> |> xUnit (fun p -> {p with XmlOutput = true + Verbose = false OutputDir = testResultsDir }) else "The integration tests were skipped because the OCTOKIT_GITHUBUSERNAME and OCTOKIT_GITHUBPASSWORD environment variables are not set. " + From 9da0254e774644a7d238987e09a5e6c13ee8f1b4 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 09:34:07 -0800 Subject: [PATCH 43/64] we don't need to log the error output, use CreatePackages meta-task --- script/cibuild.ps1 | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/script/cibuild.ps1 b/script/cibuild.ps1 index 5f479f26..62568b95 100644 --- a/script/cibuild.ps1 +++ b/script/cibuild.ps1 @@ -87,37 +87,33 @@ if (Test-Path tools\FAKE.Core\tools\Fake.exe) { else { Write-Output "Installing FAKE..." Write-Output "" - .\tools\nuget\nuget.exe "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-Version" "2.2.0" + .\tools\nuget\nuget.exe "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-Version" "2.2.1" } Write-Output "Building Octokit..." Write-Output "" -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=BuildApp" "buildMode=Release" 2>&1 +$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=BuildApp" "buildMode=Release" if ($LastExitCode -ne 0) { Dump-Error($output) } Write-Output "Running unit tests..." Write-Output "" -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=UnitTests" "buildMode=Release" 2>&1 +$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=UnitTests" "buildMode=Release" if ($LastExitCode -ne 0) { Dump-Error($output) } Write-Output "Running integration tests..." Write-Output "" -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=IntegrationTests" "buildMode=Release" 2>&1 +$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=IntegrationTests" "buildMode=Release" if ($LastExitCode -ne 0) { Dump-Error($output) } Write-Output "Creating NuGet packages..." Write-Output "" -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=CreateOctokitPackage" "buildMode=Release" 2>&1 -if ($LastExitCode -ne 0) { - Dump-Error($output) -} -$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=CreateOctokitReactivePackage" "buildMode=Release" 2>&1 +$output = & .\tools\FAKE.Core\tools\Fake.exe "build.fsx" "target=CreatePackages" "buildMode=Release" if ($LastExitCode -ne 0) { Dump-Error($output) } From 6cba426813245f81358ccc3112de66109c78c107 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 10:17:16 -0800 Subject: [PATCH 44/64] let's make the folder structure consistent --- .../{ => Clients}/AssigneesClientTests.cs | 0 .../{ => Clients}/CommitStatusClientTests.cs | 0 .../{ => Clients}/CommitsClientTests.cs | 0 .../{ => Clients}/GistsClientTests.cs | 0 .../{ => Clients}/IssuesClientTests.cs | 0 .../{ => Clients}/IssuesEventsClientTests.cs | 0 .../{ => Clients}/MilestonesClientTests.cs | 0 .../{ => Clients}/MiscellaneousClientTests.cs | 0 .../{ => Clients}/ReleasesClientTests.cs | 0 .../{ => Clients}/RepositoriesClientTests.cs | 0 .../{ => Clients}/UsersClientTests.cs | 0 .../Octokit.Tests.Integration.csproj | 22 +++++++++---------- 12 files changed, 11 insertions(+), 11 deletions(-) rename Octokit.Tests.Integration/{ => Clients}/AssigneesClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/CommitStatusClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/CommitsClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/GistsClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/IssuesClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/IssuesEventsClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/MilestonesClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/MiscellaneousClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/ReleasesClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/RepositoriesClientTests.cs (100%) rename Octokit.Tests.Integration/{ => Clients}/UsersClientTests.cs (100%) diff --git a/Octokit.Tests.Integration/AssigneesClientTests.cs b/Octokit.Tests.Integration/Clients/AssigneesClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/AssigneesClientTests.cs rename to Octokit.Tests.Integration/Clients/AssigneesClientTests.cs diff --git a/Octokit.Tests.Integration/CommitStatusClientTests.cs b/Octokit.Tests.Integration/Clients/CommitStatusClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/CommitStatusClientTests.cs rename to Octokit.Tests.Integration/Clients/CommitStatusClientTests.cs diff --git a/Octokit.Tests.Integration/CommitsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/CommitsClientTests.cs rename to Octokit.Tests.Integration/Clients/CommitsClientTests.cs diff --git a/Octokit.Tests.Integration/GistsClientTests.cs b/Octokit.Tests.Integration/Clients/GistsClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/GistsClientTests.cs rename to Octokit.Tests.Integration/Clients/GistsClientTests.cs diff --git a/Octokit.Tests.Integration/IssuesClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/IssuesClientTests.cs rename to Octokit.Tests.Integration/Clients/IssuesClientTests.cs diff --git a/Octokit.Tests.Integration/IssuesEventsClientTests.cs b/Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/IssuesEventsClientTests.cs rename to Octokit.Tests.Integration/Clients/IssuesEventsClientTests.cs diff --git a/Octokit.Tests.Integration/MilestonesClientTests.cs b/Octokit.Tests.Integration/Clients/MilestonesClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/MilestonesClientTests.cs rename to Octokit.Tests.Integration/Clients/MilestonesClientTests.cs diff --git a/Octokit.Tests.Integration/MiscellaneousClientTests.cs b/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/MiscellaneousClientTests.cs rename to Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs diff --git a/Octokit.Tests.Integration/ReleasesClientTests.cs b/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/ReleasesClientTests.cs rename to Octokit.Tests.Integration/Clients/ReleasesClientTests.cs diff --git a/Octokit.Tests.Integration/RepositoriesClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/RepositoriesClientTests.cs rename to Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs diff --git a/Octokit.Tests.Integration/UsersClientTests.cs b/Octokit.Tests.Integration/Clients/UsersClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/UsersClientTests.cs rename to Octokit.Tests.Integration/Clients/UsersClientTests.cs diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index bc418d27..75096189 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -57,23 +57,23 @@ - - - - - - + + + + + + - - + + - - + + - + From dc9a3576e6d40baa974f109c1f00ccdb957ec424 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 10:40:56 -0800 Subject: [PATCH 45/64] fleshed out some integration tests for references --- .../Clients/ReferencesClientTests.cs | 101 ++++++++++++++++++ .../Octokit.Tests.Integration.csproj | 1 + 2 files changed, 102 insertions(+) create mode 100644 Octokit.Tests.Integration/Clients/ReferencesClientTests.cs diff --git a/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs b/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs new file mode 100644 index 00000000..633d96a1 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs @@ -0,0 +1,101 @@ +using System; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Octokit; +using Octokit.Tests.Helpers; +using Octokit.Tests.Integration; +using Xunit; + +public class ReferencesClientTests +{ + readonly IReferencesClient _fixture; + + public ReferencesClientTests() + { + var client = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + _fixture = client.GitDatabase.Reference; + } + + [IntegrationTest] + public async Task CanGetAReference() + { + var @ref = await _fixture.Get("octokit", "octokit.net", "heads/master"); + + // validate the top-level properties + Assert.Equal("refs/heads/master", @ref.Ref); + Assert.Equal("https://api.github.com/repos/octokit/octokit.net/git/refs/heads/master", @ref.Url); + + // validate the git reference + Assert.Equal(TaggedType.Commit, @ref.Object.Type); + Assert.False(String.IsNullOrWhiteSpace(@ref.Object.Sha)); + } + + [IntegrationTest] + public async Task CanGetListOfReferences() + { + var list = await _fixture.GetAll("octokit", "octokit.net"); + Assert.NotEmpty(list); + } + + [IntegrationTest] + public async Task CanGetListOfReferencesInNamespace() + { + var list = await _fixture.GetAllForSubNamespace("octokit", "octokit.net", "heads"); + Assert.NotEmpty(list); + } + + [IntegrationTest(Skip="TODO")] + public async Task CanGetErrorForInvalidNamespace() + { + await AssertEx.Throws( + async () => { await _fixture.GetAllForSubNamespace("octokit", "octokit.net", "666"); }); + } + + [IntegrationTest(Skip = "TODO")] + public async Task CanCreateAReference() + { + // TODO: create a blob + // TODO: create a tree + // TODO: create a commit + // TODO: use the SHA to create a reference + var newReference = new NewReference("heads/develop", "sha"); + var result = await _fixture.Create("owner", "repo", newReference); + + Assert.NotNull(result); + } + + [IntegrationTest(Skip="TODO")] + public async Task CanUpdateAReference() + { + // TODO: create a blob + // TODO: create a tree + // TODO: create a commit + // TODO: use the SHA to create a reference + + var newReference = new NewReference("heads/develop", "sha"); + await _fixture.Create("owner", "repo", newReference); + + var referenceUpdate = new ReferenceUpdate("sha"); + + var result = await _fixture.Update("owner", "repo", "heads/develop", referenceUpdate); + + Assert.NotNull(result); + } + + [IntegrationTest(Skip="TODO")] + public async Task CanDeleteAReference() + { + // TODO: create a blob + // TODO: create a tree + // TODO: create a commit + // TODO: use the SHA to create a reference + + // TODO: can we validate the response here? + // TODO: otherwise, fire off a GetAll and validate it's not in the list + + await _fixture.Delete("owner", "repo", "heads/develop"); + } +} diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 75096189..3650e936 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -63,6 +63,7 @@ + From 6d433945a04a01c47a6d9a2b85a3be5872543f33 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 11:03:52 -0800 Subject: [PATCH 46/64] added Blob to IGitDatabaseClient, added integration tests --- .../Clients/BlobClientTests.cs | 66 +++++++++++++++++++ .../Octokit.Tests.Integration.csproj | 1 + Octokit/Clients/GitDatabaseClient.cs | 2 + Octokit/Clients/IGitDatabaseClient.cs | 1 + 4 files changed, 70 insertions(+) create mode 100644 Octokit.Tests.Integration/Clients/BlobClientTests.cs diff --git a/Octokit.Tests.Integration/Clients/BlobClientTests.cs b/Octokit.Tests.Integration/Clients/BlobClientTests.cs new file mode 100644 index 00000000..9dd20c12 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/BlobClientTests.cs @@ -0,0 +1,66 @@ +using System; +using System.Net.Http.Headers; +using Octokit; +using Octokit.Tests.Integration; +using System.Threading.Tasks; +using Xunit; +using System.Text; + +public class BlobClientTests : IDisposable +{ + readonly IBlobsClient _fixture; + readonly Repository _repository; + readonly string _owner; + + public BlobClientTests() + { + var client = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + _fixture = client.GitDatabase.Blob; + + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + _repository = client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; + _owner = _repository.Owner.Login; + } + + [IntegrationTest] + public async Task CanCreateABlob() + { + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + + var result = await _fixture.Create(_owner, _repository.Name, blob); + + Assert.False(String.IsNullOrWhiteSpace(result.Sha)); + } + + [IntegrationTest] + public async Task CanGetABlob() + { + var newBlob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + + var result = await _fixture.Create(_owner, _repository.Name, newBlob); + var blob = await _fixture.Get(_owner, _repository.Name, result.Sha); + + Assert.Equal(result.Sha, blob.Sha); + Assert.Equal(EncodingType.Base64, blob.Encoding); + + var contents = Encoding.UTF8.GetString(Convert.FromBase64String(blob.Content)); + + Assert.Equal("Hello World!", contents); + } + + public void Dispose() + { + Helper.DeleteRepo(_repository); + } +} diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 3650e936..63518c46 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -58,6 +58,7 @@ + diff --git a/Octokit/Clients/GitDatabaseClient.cs b/Octokit/Clients/GitDatabaseClient.cs index d7738733..51297036 100644 --- a/Octokit/Clients/GitDatabaseClient.cs +++ b/Octokit/Clients/GitDatabaseClient.cs @@ -5,11 +5,13 @@ public GitDatabaseClient(IApiConnection apiConnection) : base(apiConnection) { + Blob = new BlobsClient(apiConnection); Tag = new TagsClient(apiConnection); Commit = new CommitsClient(apiConnection); Reference = new ReferencesClient(apiConnection); } + public IBlobsClient Blob { get; set; } public ITagsClient Tag { get; set; } public ICommitsClient Commit { get; set; } public IReferencesClient Reference { get; set; } diff --git a/Octokit/Clients/IGitDatabaseClient.cs b/Octokit/Clients/IGitDatabaseClient.cs index e4494306..77da8040 100644 --- a/Octokit/Clients/IGitDatabaseClient.cs +++ b/Octokit/Clients/IGitDatabaseClient.cs @@ -5,6 +5,7 @@ /// public interface IGitDatabaseClient { + IBlobsClient Blob { get; set; } ITagsClient Tag { get; set; } ICommitsClient Commit { get; set; } IReferencesClient Reference { get; set; } From ff4640b25b883727df233d7cd004038562320c57 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 11:10:51 -0800 Subject: [PATCH 47/64] added some integration tests for the Base64 versions of Blob APIs --- .../Clients/BlobClientTests.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/BlobClientTests.cs b/Octokit.Tests.Integration/Clients/BlobClientTests.cs index 9dd20c12..72364dfe 100644 --- a/Octokit.Tests.Integration/Clients/BlobClientTests.cs +++ b/Octokit.Tests.Integration/Clients/BlobClientTests.cs @@ -39,6 +39,23 @@ public class BlobClientTests : IDisposable Assert.False(String.IsNullOrWhiteSpace(result.Sha)); } + [IntegrationTest] + public async Task CanCreateABlobWithBase64Contents() + { + var utf8Bytes = Encoding.UTF8.GetBytes("Hello World!"); + var base64String = Convert.ToBase64String(utf8Bytes); + + var blob = new NewBlob + { + Content = base64String, + Encoding = EncodingType.Base64 + }; + + var result = await _fixture.Create(_owner, _repository.Name, blob); + + Assert.False(String.IsNullOrWhiteSpace(result.Sha)); + } + [IntegrationTest] public async Task CanGetABlob() { @@ -59,6 +76,30 @@ public class BlobClientTests : IDisposable Assert.Equal("Hello World!", contents); } + [IntegrationTest] + public async Task CanGetABlobWithBase64Text() + { + var utf8Bytes = Encoding.UTF8.GetBytes("Hello World!"); + var base64String = Convert.ToBase64String(utf8Bytes); + + var newBlob = new NewBlob + { + Content = base64String, + Encoding = EncodingType.Base64 + }; + + var result = await _fixture.Create(_owner, _repository.Name, newBlob); + var blob = await _fixture.Get(_owner, _repository.Name, result.Sha); + + Assert.Equal(result.Sha, blob.Sha); + Assert.Equal(EncodingType.Base64, blob.Encoding); + + // NOTE: it looks like the blobs you get back from the GitHub API + // will have an additional \n on the end. :cool:! + var expectedOutput = base64String + "\n"; + Assert.Equal(expectedOutput, blob.Content); + } + public void Dispose() { Helper.DeleteRepo(_repository); From 607b024452093122788ab79d919230151cb19ab7 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 11:22:03 -0800 Subject: [PATCH 48/64] added Trees to the base GitDatabaseClient, added some initial tests --- .../Clients/TreeClientTests.cs | 47 +++++++++++++++++++ .../Octokit.Tests.Integration.csproj | 1 + Octokit/Clients/GitDatabaseClient.cs | 2 + Octokit/Clients/IGitDatabaseClient.cs | 1 + 4 files changed, 51 insertions(+) create mode 100644 Octokit.Tests.Integration/Clients/TreeClientTests.cs diff --git a/Octokit.Tests.Integration/Clients/TreeClientTests.cs b/Octokit.Tests.Integration/Clients/TreeClientTests.cs new file mode 100644 index 00000000..26be6589 --- /dev/null +++ b/Octokit.Tests.Integration/Clients/TreeClientTests.cs @@ -0,0 +1,47 @@ +using System; +using System.Net.Http.Headers; +using System.Threading.Tasks; +using Octokit; +using Octokit.Tests.Integration; +using Xunit; + +public class TreeClientTests : IDisposable +{ + ITreesClient _fixture; + Repository _repository; + string _owner; + + public TreeClientTests() + { + var client = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + _fixture = client.GitDatabase.Tree; + + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + _repository = client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; + _owner = _repository.Owner.Login; + } + + [IntegrationTest(Skip="TODO")] + public async Task CanCreateATree() + { + // TODO: create a blob + // TODO: create a tree + + } + + [IntegrationTest] + public async Task CanGetATree() + { + var tree = await _fixture.Get("octokit", "octokit.net", "master"); + + Assert.NotNull(tree); + } + + public void Dispose() + { + Helper.DeleteRepo(_repository); + } +} diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 63518c46..5c1824f2 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -65,6 +65,7 @@ + diff --git a/Octokit/Clients/GitDatabaseClient.cs b/Octokit/Clients/GitDatabaseClient.cs index 51297036..0b50317f 100644 --- a/Octokit/Clients/GitDatabaseClient.cs +++ b/Octokit/Clients/GitDatabaseClient.cs @@ -6,12 +6,14 @@ : base(apiConnection) { Blob = new BlobsClient(apiConnection); + Tree = new TreesClient(apiConnection); Tag = new TagsClient(apiConnection); Commit = new CommitsClient(apiConnection); Reference = new ReferencesClient(apiConnection); } public IBlobsClient Blob { get; set; } + public ITreesClient Tree { get; set; } public ITagsClient Tag { get; set; } public ICommitsClient Commit { get; set; } public IReferencesClient Reference { get; set; } diff --git a/Octokit/Clients/IGitDatabaseClient.cs b/Octokit/Clients/IGitDatabaseClient.cs index 77da8040..0516b36a 100644 --- a/Octokit/Clients/IGitDatabaseClient.cs +++ b/Octokit/Clients/IGitDatabaseClient.cs @@ -7,6 +7,7 @@ { IBlobsClient Blob { get; set; } ITagsClient Tag { get; set; } + ITreesClient Tree { get; set; } ICommitsClient Commit { get; set; } IReferencesClient Reference { get; set; } } From e9b8f5af256d871315a6edb1fa703a4c86236ab5 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 11:35:10 -0800 Subject: [PATCH 49/64] create the Tree collection to make Everything Less Terrible --- Octokit/Models/Request/NewTree.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Octokit/Models/Request/NewTree.cs b/Octokit/Models/Request/NewTree.cs index 35e6c400..78e18588 100644 --- a/Octokit/Models/Request/NewTree.cs +++ b/Octokit/Models/Request/NewTree.cs @@ -1,10 +1,16 @@ using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; namespace Octokit { public class NewTree { + public NewTree() + { + Tree = new Collection(); + } + /// /// The SHA1 of the tree you want to update with new data. /// From ae38cc3e3fe5bdf7ab43f7610e95fd30932e6a1d Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 11:35:39 -0800 Subject: [PATCH 50/64] refactoring and improving Trees tests --- .../Clients/TreeClientTests.cs | 67 ++++++++++++++++--- 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/TreeClientTests.cs b/Octokit.Tests.Integration/Clients/TreeClientTests.cs index 26be6589..1c18a4d3 100644 --- a/Octokit.Tests.Integration/Clients/TreeClientTests.cs +++ b/Octokit.Tests.Integration/Clients/TreeClientTests.cs @@ -7,37 +7,82 @@ using Xunit; public class TreeClientTests : IDisposable { - ITreesClient _fixture; - Repository _repository; - string _owner; + readonly ITreesClient _fixture; + readonly Repository _repository; + readonly string _owner; + readonly GitHubClient _client; public TreeClientTests() { - var client = new GitHubClient(new ProductHeaderValue("OctokitTests")) + _client = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; - _fixture = client.GitDatabase.Tree; + _fixture = _client.GitDatabase.Tree; var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; + _repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; _owner = _repository.Owner.Login; } - [IntegrationTest(Skip="TODO")] + [IntegrationTest] public async Task CanCreateATree() { - // TODO: create a blob - // TODO: create a tree + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + var createdBlob = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, blob); + + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem + { + Type = TreeType.Blob, + Path = "README.md", + Sha = createdBlob.Sha + }); + + var result = await _fixture.Create(_owner, _repository.Name, newTree); + + Assert.NotNull(result); } [IntegrationTest] public async Task CanGetATree() { - var tree = await _fixture.Get("octokit", "octokit.net", "master"); + var result = await _fixture.Get("octokit", "octokit.net", "master"); - Assert.NotNull(tree); + Assert.NotNull(result); + Assert.NotEmpty(result.Tree); + } + + [IntegrationTest] + public async Task CanGetACreatedTree() + { + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + + var blobResult = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, blob); + + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem + { + Type = TreeType.Blob, + Path = "README.md", + Sha = blobResult.Sha + }); + + var tree = await _fixture.Create(_owner, _repository.Name, newTree); + + var result = await _fixture.Get(_owner, _repository.Name, tree.Sha); + + Assert.NotNull(result); + Assert.Equal(1, result.Tree.Count); } public void Dispose() From c89ca5fc11daa41a7c2de5cd65c1525efecd02b4 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 12:27:35 -0800 Subject: [PATCH 51/64] include the FileMode values which are necessary to creating non-busted trees --- Octokit/Models/Response/TreeItem.cs | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Octokit/Models/Response/TreeItem.cs b/Octokit/Models/Response/TreeItem.cs index 96a118a8..0fff7f60 100644 --- a/Octokit/Models/Response/TreeItem.cs +++ b/Octokit/Models/Response/TreeItem.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; namespace Octokit { @@ -42,4 +43,33 @@ namespace Octokit Tree, Commit } + + /// + /// The file mode to associate with a tree item + /// + public static class FileMode + { + /// + /// Mark the tree item as a file (applicable to blobs only) + /// + public const string File = "100644"; + /// + /// Mark the tree item as an executable (applicable to blobs only) + /// + public const string Executable = "100755"; + /// + /// Mark the tree item as a subdirectory (applicable to trees only) + /// + public const string Subdirectory = "040000"; + /// + /// Mark the tree item as a submodule (applicable to commits only) + /// + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Submodule")] + public const string Submodule = "160000"; + /// + /// Mark the tree item as a symlink (applicable to blobs only) + /// + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Symlink")] + public const string Symlink = "120000"; + } } \ No newline at end of file From 06737995ed95fbe6fee65ca967cba106e0ff78f4 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 12:37:58 -0800 Subject: [PATCH 52/64] catch an obscure requirement when creating trees --- Octokit.Tests/Clients/TreesClientTests.cs | 13 +++++++++++++ Octokit/Clients/TreesClient.cs | 9 ++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests/Clients/TreesClientTests.cs b/Octokit.Tests/Clients/TreesClientTests.cs index 60a18e2a..28bcc1b4 100644 --- a/Octokit.Tests/Clients/TreesClientTests.cs +++ b/Octokit.Tests/Clients/TreesClientTests.cs @@ -62,6 +62,19 @@ namespace Octokit.Tests await AssertEx.Throws(async () => await client.Create("owner", null, new NewTree())); await AssertEx.Throws(async () => await client.Create("owner", "", new NewTree())); } + + [Fact] + public async Task EnsureExceptionIsThrownWhenModeIsNotProvided() + { + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem { Path = "README.md", Type = TreeType.Blob, Sha = "2e1a73d60f004fd842d4bad28aa42392d4f35d28" }); + + var connection = Substitute.For(); + var client = new TreesClient(connection); + + await AssertEx.Throws( + async () => await client.Create("fake", "repo", newTree)); + } } public class TheCtor diff --git a/Octokit/Clients/TreesClient.cs b/Octokit/Clients/TreesClient.cs index 085ee05a..3d109fa9 100644 --- a/Octokit/Clients/TreesClient.cs +++ b/Octokit/Clients/TreesClient.cs @@ -1,4 +1,6 @@ -using System.Threading.Tasks; +using System; +using System.Linq; +using System.Threading.Tasks; namespace Octokit { @@ -44,6 +46,11 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(newTree, "newTree"); + if (newTree.Tree.Any(t => String.IsNullOrWhiteSpace(t.Mode))) + { + throw new ArgumentException("You have specified items in the tree which do not have a Mode value set."); + } + return ApiConnection.Post(ApiUrls.Tree(owner, name), newTree); } } From 1429141b429bfdba4c4dbacc70c11cbdec4942b2 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Wed, 27 Nov 2013 12:40:26 -0800 Subject: [PATCH 53/64] updated the integration tests for createing a commit and a tree :dancers: --- .../Clients/CommitsClientTests.cs | 95 ++++++++++--------- .../Clients/ReferencesClientTests.cs | 53 ++++++++--- 2 files changed, 94 insertions(+), 54 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs index 9e89a608..b6c6340e 100644 --- a/Octokit.Tests.Integration/Clients/CommitsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitsClientTests.cs @@ -2,53 +2,62 @@ using System.Linq; using System.Net.Http.Headers; using System.Threading.Tasks; +using Octokit; +using Octokit.Tests.Integration; using Xunit; -namespace Octokit.Tests.Integration +public class CommitsClientTests : IDisposable { - public class CommitsClientTests : IDisposable + readonly IGitHubClient _client; + readonly Repository _repository; + readonly ICommitsClient _fixture; + readonly string _owner; + + public CommitsClientTests() { - readonly IGitHubClient _gitHubClient; - readonly Repository _repository; - readonly ICommitsClient _commitsClient; - - public CommitsClientTests() + _client = new GitHubClient(new ProductHeaderValue("OctokitTests")) { - this._gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) - { - Credentials = Helper.Credentials - }; + Credentials = Helper.Credentials + }; - var repoName = Helper.MakeNameWithTimestamp("public-repo"); - this._commitsClient = this._gitHubClient.GitDatabase.Commit; - this._repository = this._gitHubClient.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; - } - - [IntegrationTest(Skip = "Requires Tree Api implementation to create a commit")] - public async Task CanCreateAndRetrieveCommit() - { - string owner = this._repository.Owner.Login; - - var author = new Signature { Name = "author", Email = "test-author@example.com", Date = DateTime.UtcNow }; - var commiter = new Signature { Name = "commiter", Email = "test-commiter@example.com", Date = DateTime.Today }; - - var newCommit = new NewCommit("test-commit", "[Change this to tree sha]", Enumerable.Empty()) - { - Author = author, - Committer = commiter - }; - - var commit = await this._commitsClient.Create(owner, this._repository.Name, newCommit); - - Assert.NotNull(commit); - var retrieved = await this._commitsClient.Get(owner, this._repository.Name, commit.Sha); - Assert.NotNull(retrieved); - } - - - public void Dispose() - { - Helper.DeleteRepo(this._repository); - } + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + _fixture = _client.GitDatabase.Commit; + _repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; + _owner = _repository.Owner.Login; } -} \ No newline at end of file + + [IntegrationTest] + public async Task CanCreateAndRetrieveCommit() + { + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + var blobResult = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, blob); + + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem + { + Type = TreeType.Blob, + Mode = FileMode.File, + Path = "README.md", + Sha = blobResult.Sha + }); + + var treeResult = await _client.GitDatabase.Tree.Create(_owner, _repository.Name, newTree); + + var newCommit = new NewCommit("test-commit", treeResult.Sha, Enumerable.Empty()); + + var commit = await _fixture.Create(_owner, _repository.Name, newCommit); + Assert.NotNull(commit); + + var retrieved = await _fixture.Get(_owner, _repository.Name, commit.Sha); + Assert.NotNull(retrieved); + } + + public void Dispose() + { + Helper.DeleteRepo(_repository); + } +} diff --git a/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs b/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs index 633d96a1..64425a53 100644 --- a/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/ReferencesClientTests.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Net.Http.Headers; using System.Threading.Tasks; using Octokit; @@ -6,17 +7,24 @@ using Octokit.Tests.Helpers; using Octokit.Tests.Integration; using Xunit; -public class ReferencesClientTests +public class ReferencesClientTests : IDisposable { readonly IReferencesClient _fixture; + readonly Repository _repository; + readonly GitHubClient _client; + readonly string _owner; public ReferencesClientTests() { - var client = new GitHubClient(new ProductHeaderValue("OctokitTests")) + _client = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; - _fixture = client.GitDatabase.Reference; + _fixture = _client.GitDatabase.Reference; + + var repoName = Helper.MakeNameWithTimestamp("public-repo"); + _repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; + _owner = _repository.Owner.Login; } [IntegrationTest] @@ -47,22 +55,40 @@ public class ReferencesClientTests Assert.NotEmpty(list); } - [IntegrationTest(Skip="TODO")] + [IntegrationTest(Skip="See ")] public async Task CanGetErrorForInvalidNamespace() { await AssertEx.Throws( async () => { await _fixture.GetAllForSubNamespace("octokit", "octokit.net", "666"); }); } - [IntegrationTest(Skip = "TODO")] + [IntegrationTest(Skip = "Investigating a 'Server Error' API response when creating a commit")] public async Task CanCreateAReference() { - // TODO: create a blob - // TODO: create a tree - // TODO: create a commit - // TODO: use the SHA to create a reference - var newReference = new NewReference("heads/develop", "sha"); - var result = await _fixture.Create("owner", "repo", newReference); + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + var blobResult = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, blob); + + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem + { + Mode = FileMode.File, + Type = TreeType.Blob, + Path = "README.md", + Sha = blobResult.Sha + }); + + var treeResult = await _client.GitDatabase.Tree.Create(_owner, _repository.Name, newTree); + + var newCommit = new NewCommit("This is a new commit", treeResult.Sha, Enumerable.Empty()); + + var commitResult = await _client.GitDatabase.Commit.Create(_owner, _repository.Name, newCommit); + + var newReference = new NewReference("heads/develop", commitResult.Sha); + var result = await _fixture.Create(_owner, _repository.Name, newReference); Assert.NotNull(result); } @@ -98,4 +124,9 @@ public class ReferencesClientTests await _fixture.Delete("owner", "repo", "heads/develop"); } + + public void Dispose() + { + Helper.DeleteRepo(_repository); + } } From a84cbc3fac0f88c69683256cdc8aa0987e709ee9 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sat, 30 Nov 2013 14:27:34 -0800 Subject: [PATCH 54/64] we should build the project if RunBuild is not empty --- build.cmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cmd b/build.cmd index 7c927e17..f3c0c6a8 100644 --- a/build.cmd +++ b/build.cmd @@ -21,7 +21,7 @@ if TARGET=="RunUnitTests" (SET RunBuild=1) if TARGET=="RunIntegrationTests" (SET RunBuild=1) if TARGET=="CreatePackages" (SET RunBuild=1) -if "%RunBuild%"=="" ( +if NOT "%RunBuild%"=="" ( "tools\FAKE.Core\tools\Fake.exe" "build.fsx" "target=BuildApp" "buildMode=%BUILDMODE%" ) From 3b4acb2053031c57713ac4b9c45bc509e127ee48 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 21:41:09 +0100 Subject: [PATCH 55/64] Added missing observable clients to git database client --- Octokit.Reactive/Clients/IObservableGitDatabaseClient.cs | 2 ++ Octokit.Reactive/Clients/ObservableGitDatabaseClient.cs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Octokit.Reactive/Clients/IObservableGitDatabaseClient.cs b/Octokit.Reactive/Clients/IObservableGitDatabaseClient.cs index 14b8a369..9f38c345 100644 --- a/Octokit.Reactive/Clients/IObservableGitDatabaseClient.cs +++ b/Octokit.Reactive/Clients/IObservableGitDatabaseClient.cs @@ -5,7 +5,9 @@ /// public interface IObservableGitDatabaseClient { + IObservableBlobClient Blob { get; set; } IObservableTagsClient Tag { get; set; } + IObservableTreesClient Tree { get; set; } IObservableCommitsClient Commit { get; set; } IObservableReferencesClient Reference { get; set; } } diff --git a/Octokit.Reactive/Clients/ObservableGitDatabaseClient.cs b/Octokit.Reactive/Clients/ObservableGitDatabaseClient.cs index 2ea26302..c3b338ca 100644 --- a/Octokit.Reactive/Clients/ObservableGitDatabaseClient.cs +++ b/Octokit.Reactive/Clients/ObservableGitDatabaseClient.cs @@ -4,12 +4,16 @@ { public ObservableGitDatabaseClient(IGitHubClient client) { + Blob = new ObservableBlobClient(client); Tag = new ObservableTagsClient(client); + Tree = new ObservableTreesClient(client); Commit = new ObservableCommitsClient(client); Reference = new ObservableReferencesClient(client); } + public IObservableBlobClient Blob { get; set; } public IObservableTagsClient Tag { get; set; } + public IObservableTreesClient Tree { get; set; } public IObservableCommitsClient Commit { get; set; } public IObservableReferencesClient Reference { get; set; } } From 54cdb972a96bb430db30cca8bfe2ac3521a6cd52 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 22:00:11 +0100 Subject: [PATCH 56/64] Added stubs for IGistCommentsClient --- Octokit.Tests/Clients/GistsClientTests.cs | 8 +++++ Octokit/Clients/GistCommentsClient.cs | 41 +++++++++++++++++++++++ Octokit/Clients/GistsClient.cs | 3 ++ Octokit/Clients/IGistCommentsClient.cs | 17 ++++++++++ Octokit/Clients/IGistsClient.cs | 2 ++ Octokit/Models/Response/GistComment.cs | 7 ++++ Octokit/Octokit-Mono.csproj | 3 ++ Octokit/Octokit-MonoAndroid.csproj | 3 ++ Octokit/Octokit-Monotouch.csproj | 3 ++ Octokit/Octokit-netcore45.csproj | 3 ++ Octokit/Octokit.csproj | 3 ++ 11 files changed, 93 insertions(+) create mode 100644 Octokit/Clients/GistCommentsClient.cs create mode 100644 Octokit/Clients/IGistCommentsClient.cs create mode 100644 Octokit/Models/Response/GistComment.cs diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index f83742cf..ad3f6d76 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -26,5 +26,13 @@ public class GistsClientTests { Assert.Throws(() => new GistsClient(null)); } + + [Fact] + public void SetCommentsClient() + { + var apiConnection = Substitute.For(); + var client = new GistsClient(apiConnection); + Assert.NotNull(client.Comment); + } } } diff --git a/Octokit/Clients/GistCommentsClient.cs b/Octokit/Clients/GistCommentsClient.cs new file mode 100644 index 00000000..e204ba8e --- /dev/null +++ b/Octokit/Clients/GistCommentsClient.cs @@ -0,0 +1,41 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public class GistCommentsClient : ApiClient, IGistCommentsClient + { + public GistCommentsClient(IApiConnection apiConnection) : base(apiConnection) + { + } + + public Task Get(int gistId, int commentId) + { + throw new System.NotImplementedException(); + } + + public Task> GetForGist(int gistId) + { + throw new System.NotImplementedException(); + } + + public Task Create(int gistId, string comment) + { + Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); + + throw new System.NotImplementedException(); + } + + public Task Update(int gistId, int commentId, string comment) + { + Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); + + throw new System.NotImplementedException(); + } + + public Task Delete(int gistId, int commentId) + { + throw new System.NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/GistsClient.cs b/Octokit/Clients/GistsClient.cs index c2897f59..0a08b80f 100644 --- a/Octokit/Clients/GistsClient.cs +++ b/Octokit/Clients/GistsClient.cs @@ -7,8 +7,11 @@ namespace Octokit public GistsClient(IApiConnection apiConnection) : base(apiConnection) { + Comment = new GistCommentsClient(apiConnection); } + public IGistCommentsClient Comment { get; set; } + /// /// Gets a gist /// diff --git a/Octokit/Clients/IGistCommentsClient.cs b/Octokit/Clients/IGistCommentsClient.cs new file mode 100644 index 00000000..554a1bc3 --- /dev/null +++ b/Octokit/Clients/IGistCommentsClient.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IGistCommentsClient + { + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + Task Get(int gistId, int commentId); + Task> GetForGist(int gistId); + Task Create(int gistId, string comment); + Task Update(int gistId, int commentId, string comment); + Task Delete(int gistId, int commentId); + } +} diff --git a/Octokit/Clients/IGistsClient.cs b/Octokit/Clients/IGistsClient.cs index 93a44d50..a8a90fdb 100644 --- a/Octokit/Clients/IGistsClient.cs +++ b/Octokit/Clients/IGistsClient.cs @@ -5,6 +5,8 @@ namespace Octokit { public interface IGistsClient { + IGistCommentsClient Comment { get; set; } + /// /// Gets a gist /// diff --git a/Octokit/Models/Response/GistComment.cs b/Octokit/Models/Response/GistComment.cs new file mode 100644 index 00000000..6ad48f3d --- /dev/null +++ b/Octokit/Models/Response/GistComment.cs @@ -0,0 +1,7 @@ +namespace Octokit +{ + public class GistComment + { + + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 3eec02af..b4f5a9e2 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -229,6 +229,9 @@ + + + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 4e32d67f..f422fadc 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -239,6 +239,9 @@ + + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 0704707f..01144c1a 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -234,6 +234,9 @@ + + + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 1e911000..6a66cba1 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -227,6 +227,9 @@ + + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 229f056d..8eb92c0e 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -53,7 +53,9 @@ Properties\SolutionInfo.cs + + @@ -72,6 +74,7 @@ + From 4c533858d3f0632c5ed376f9072a0ad2f89c28e9 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 22:12:19 +0100 Subject: [PATCH 57/64] Added failing tests --- .../Clients/GistCommentsClientTests.cs | 113 ++++++++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + 2 files changed, 114 insertions(+) create mode 100644 Octokit.Tests/Clients/GistCommentsClientTests.cs diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs new file mode 100644 index 00000000..0407e428 --- /dev/null +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -0,0 +1,113 @@ +using System; +using System.Threading.Tasks; + +using NSubstitute; + +using Octokit.Tests.Helpers; + +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class GistCommentsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new GistCommentsClient(null)); + } + } + + public class TheGetMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Get(24, 1337); + + connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), null); + } + } + + public class TheGetForGistMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.GetForGist(24); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments"), null); + } + } + + public class TheCreateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Create(24, null)); + await AssertEx.Throws(async () => await client.Create(24, "")); + } + + [Fact] + public async Task PostsToCorrectUrl() + { + var comment = "This is a comment."; + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Create(24, comment); + + connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), comment); + } + } + + public class TheUpdateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Update(24, 1337, null)); + await AssertEx.Throws(async () => await client.Update(24, 1337, "")); + } + + [Fact] + public async Task PostsToCorrectUrl() + { + var comment = "This is a comment."; + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Update(24, 1337, comment); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), comment); + } + } + + public class TheDeleteMethod + { + [Fact] + public async Task PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Delete(24, 1337); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 6a7e72bc..ab7436b8 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -62,6 +62,7 @@ + From f96b3fdeeff94a096a8095b504441a7950c4489f Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 22:24:05 +0100 Subject: [PATCH 58/64] Added ApiUrls, updated gist- and comment id to be strings, added failing tests --- .../Clients/GistCommentsClientTests.cs | 55 ++++++++++++++++--- Octokit/Clients/GistCommentsClient.cs | 21 +++++-- Octokit/Clients/IGistCommentsClient.cs | 10 ++-- Octokit/Helpers/ApiUrls.cs | 19 +++++++ 4 files changed, 86 insertions(+), 19 deletions(-) diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs index 0407e428..80045b9b 100644 --- a/Octokit.Tests/Clients/GistCommentsClientTests.cs +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -22,13 +22,24 @@ namespace Octokit.Tests.Clients public class TheGetMethod { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Get(null, "1337")); + await AssertEx.Throws(async () => await client.Get("24", null)); + await AssertEx.Throws(async () => await client.Get("", "1337")); + await AssertEx.Throws(async () => await client.Get("24", "")); + } + [Fact] public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Get(24, 1337); + await client.Get("24", "1337"); connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), null); } @@ -36,13 +47,22 @@ namespace Octokit.Tests.Clients public class TheGetForGistMethod { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.GetForGist(null)); + await AssertEx.Throws(async () => await client.GetForGist("")); + } + [Fact] public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.GetForGist(24); + await client.GetForGist("24"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments"), null); } @@ -55,8 +75,10 @@ namespace Octokit.Tests.Clients { var client = new GistCommentsClient(Substitute.For()); - await AssertEx.Throws(async () => await client.Create(24, null)); - await AssertEx.Throws(async () => await client.Create(24, "")); + await AssertEx.Throws(async () => await client.Create(null, "Comment")); + await AssertEx.Throws(async () => await client.Create("24", null)); + await AssertEx.Throws(async () => await client.Create("", "Comment")); + await AssertEx.Throws(async () => await client.Create("24", "")); } [Fact] @@ -66,7 +88,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Create(24, comment); + await client.Create("24", comment); connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), comment); } @@ -79,8 +101,12 @@ namespace Octokit.Tests.Clients { var client = new GistCommentsClient(Substitute.For()); - await AssertEx.Throws(async () => await client.Update(24, 1337, null)); - await AssertEx.Throws(async () => await client.Update(24, 1337, "")); + await AssertEx.Throws(async () => await client.Update(null, "1337", "Comment")); + await AssertEx.Throws(async () => await client.Update("24", null, "Comment")); + await AssertEx.Throws(async () => await client.Update("24", "1337", null)); + await AssertEx.Throws(async () => await client.Update("", "1337", "Comment")); + await AssertEx.Throws(async () => await client.Update("24", "", "Comment")); + await AssertEx.Throws(async () => await client.Update("24", "1337", "")); } [Fact] @@ -90,7 +116,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Update(24, 1337, comment); + await client.Update("24", "1337", comment); connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), comment); } @@ -98,13 +124,24 @@ namespace Octokit.Tests.Clients public class TheDeleteMethod { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Delete(null, "1337")); + await AssertEx.Throws(async () => await client.Delete("24", null)); + await AssertEx.Throws(async () => await client.Delete("", "1337")); + await AssertEx.Throws(async () => await client.Delete("24", "")); + } + [Fact] public async Task PostsToCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Delete(24, 1337); + await client.Delete("24", "1337"); connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); } diff --git a/Octokit/Clients/GistCommentsClient.cs b/Octokit/Clients/GistCommentsClient.cs index e204ba8e..764c4065 100644 --- a/Octokit/Clients/GistCommentsClient.cs +++ b/Octokit/Clients/GistCommentsClient.cs @@ -9,32 +9,43 @@ namespace Octokit { } - public Task Get(int gistId, int commentId) + public Task Get(string gistId, string commentId) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); + throw new System.NotImplementedException(); } - public Task> GetForGist(int gistId) + public Task> GetForGist(string gistId) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + throw new System.NotImplementedException(); } - public Task Create(int gistId, string comment) + public Task Create(string gistId, string comment) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); throw new System.NotImplementedException(); } - public Task Update(int gistId, int commentId, string comment) + public Task Update(string gistId, string commentId, string comment) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); throw new System.NotImplementedException(); } - public Task Delete(int gistId, int commentId) + public Task Delete(string gistId, string commentId) { + Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); + Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); + throw new System.NotImplementedException(); } } diff --git a/Octokit/Clients/IGistCommentsClient.cs b/Octokit/Clients/IGistCommentsClient.cs index 554a1bc3..fbf0d55b 100644 --- a/Octokit/Clients/IGistCommentsClient.cs +++ b/Octokit/Clients/IGistCommentsClient.cs @@ -8,10 +8,10 @@ namespace Octokit { [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] - Task Get(int gistId, int commentId); - Task> GetForGist(int gistId); - Task Create(int gistId, string comment); - Task Update(int gistId, int commentId, string comment); - Task Delete(int gistId, int commentId); + Task Get(string gistId, string commentId); + Task> GetForGist(string gistId); + Task Create(string gistId, string comment); + Task Update(string gistId, string commentId, string comment); + Task Delete(string gistId, string commentId); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 6e9b2c2b..06f6a8e5 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -457,6 +457,25 @@ namespace Octokit return "gists/{0}".FormatUri(id); } + /// + /// Returns the for the comments for the specified gist. + /// + /// The id of the gist + public static Uri GistComments(string gistId) + { + return "gists/{0}/comments".FormatUri(gistId); + } + + /// + /// Returns the for a spesific comment for the specified commit. + /// + /// The id of the gist + /// The id of the comment + public static Uri GistComment(string gistId, string commentId) + { + return "gists/{0}/comments/{1}".FormatUri(gistId, commentId); + } + /// /// Returns the for the specified commit. /// From bcae7efddef11c241dfb88afcae5d625c41be032 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 22:30:40 +0100 Subject: [PATCH 59/64] Implemented all gist comment methods --- Octokit.Tests/Clients/GistCommentsClientTests.cs | 2 +- Octokit/Clients/GistCommentsClient.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs index 80045b9b..6a899355 100644 --- a/Octokit.Tests/Clients/GistCommentsClientTests.cs +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -64,7 +64,7 @@ namespace Octokit.Tests.Clients await client.GetForGist("24"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments"), null); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments")); } } diff --git a/Octokit/Clients/GistCommentsClient.cs b/Octokit/Clients/GistCommentsClient.cs index 764c4065..a9c705ef 100644 --- a/Octokit/Clients/GistCommentsClient.cs +++ b/Octokit/Clients/GistCommentsClient.cs @@ -14,14 +14,14 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); - throw new System.NotImplementedException(); + return ApiConnection.Get(ApiUrls.GistComment(gistId, commentId)); } public Task> GetForGist(string gistId) { Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); - throw new System.NotImplementedException(); + return ApiConnection.GetAll(ApiUrls.GistComments(gistId)); } public Task Create(string gistId, string comment) @@ -29,7 +29,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); - throw new System.NotImplementedException(); + return ApiConnection.Post(ApiUrls.GistComments(gistId), comment); } public Task Update(string gistId, string commentId, string comment) @@ -38,7 +38,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); - throw new System.NotImplementedException(); + return ApiConnection.Patch(ApiUrls.GistComment(gistId, commentId), comment); } public Task Delete(string gistId, string commentId) @@ -46,7 +46,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); - throw new System.NotImplementedException(); + return ApiConnection.Delete(ApiUrls.GistComment(gistId, commentId)); } } } \ No newline at end of file From 34756d99155207309b553054ec279cc0d6b7a6d4 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 22:36:47 +0100 Subject: [PATCH 60/64] Fleshed out the GistComment model --- Octokit/Models/Response/GistComment.cs | 34 ++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Octokit/Models/Response/GistComment.cs b/Octokit/Models/Response/GistComment.cs index 6ad48f3d..e23945ed 100644 --- a/Octokit/Models/Response/GistComment.cs +++ b/Octokit/Models/Response/GistComment.cs @@ -1,7 +1,37 @@ -namespace Octokit +using System; + +namespace Octokit { public class GistComment { - + /// + /// The gist comment id. + /// + public string Id { get; set; } + + /// + /// The URL for this gist comment. + /// + public Uri Url { get; set; } + + /// + /// The body of this gist comment. + /// + public string Body { get; set; } + + /// + /// The user that created this gist comment. + /// + public User User { get; set; } + + /// + /// The date this comment was created. + /// + public DateTimeOffset CreatedAt { get; set; } + + /// + /// The date this comment was last updated. + /// + public DateTimeOffset? UpdatedAt { get; set; } } } \ No newline at end of file From 9a9362df76fb6f6b2c34c4fd7b7f153f5812fe8a Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 22:46:00 +0100 Subject: [PATCH 61/64] Added XML documentation to public methods --- Octokit/Clients/GistCommentsClient.cs | 35 +++++++++++++++++++++++ Octokit/Clients/IGistCommentsClient.cs | 39 ++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/Octokit/Clients/GistCommentsClient.cs b/Octokit/Clients/GistCommentsClient.cs index a9c705ef..aa717cb6 100644 --- a/Octokit/Clients/GistCommentsClient.cs +++ b/Octokit/Clients/GistCommentsClient.cs @@ -9,6 +9,13 @@ namespace Octokit { } + /// + /// Gets a single comment by gist- and comment id. + /// + /// http://developer.github.com/v3/gists/comments/#get-a-single-comment + /// The id of the gist + /// The id of the comment + /// Task{GistComment}. public Task Get(string gistId, string commentId) { Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); @@ -17,6 +24,12 @@ namespace Octokit return ApiConnection.Get(ApiUrls.GistComment(gistId, commentId)); } + /// + /// Gets all comments for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist + /// The id of the gist + /// Task{IReadOnlyList{GistComment}}. public Task> GetForGist(string gistId) { Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); @@ -24,6 +37,13 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.GistComments(gistId)); } + /// + /// Creates a comment for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#create-a-comment + /// The id of the gist + /// The body of the comment + /// Task{GistComment}. public Task Create(string gistId, string comment) { Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); @@ -32,6 +52,14 @@ namespace Octokit return ApiConnection.Post(ApiUrls.GistComments(gistId), comment); } + /// + /// Updates the comment with the specified gist- and comment id. + /// + /// http://developer.github.com/v3/gists/comments/#edit-a-comment + /// The id of the gist + /// The id of the comment + /// The updated body of the comment + /// Task{GistComment}. public Task Update(string gistId, string commentId, string comment) { Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); @@ -41,6 +69,13 @@ namespace Octokit return ApiConnection.Patch(ApiUrls.GistComment(gistId, commentId), comment); } + /// + /// Deletes the comment with the specified gist- and comment id. + /// + /// http://developer.github.com/v3/gists/comments/#delete-a-comment + /// The id of the gist + /// The id of the comment + /// Task. public Task Delete(string gistId, string commentId) { Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); diff --git a/Octokit/Clients/IGistCommentsClient.cs b/Octokit/Clients/IGistCommentsClient.cs index fbf0d55b..49005986 100644 --- a/Octokit/Clients/IGistCommentsClient.cs +++ b/Octokit/Clients/IGistCommentsClient.cs @@ -6,12 +6,51 @@ namespace Octokit { public interface IGistCommentsClient { + /// + /// Gets a single comment by gist- and comment id. + /// + /// http://developer.github.com/v3/gists/comments/#get-a-single-comment + /// The id of the gist + /// The id of the comment + /// Task{GistComment}. [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] Task Get(string gistId, string commentId); + + /// + /// Gets all comments for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist + /// The id of the gist + /// Task{IReadOnlyList{GistComment}}. Task> GetForGist(string gistId); + + /// + /// Creates a comment for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#create-a-comment + /// The id of the gist + /// The body of the comment + /// Task{GistComment}. Task Create(string gistId, string comment); + + /// + /// Updates the comment with the specified gist- and comment id. + /// + /// http://developer.github.com/v3/gists/comments/#edit-a-comment + /// The id of the gist + /// The id of the comment + /// The updated body of the comment + /// Task{GistComment}. Task Update(string gistId, string commentId, string comment); + + /// + /// Deletes the comment with the specified gist- and comment id. + /// + /// http://developer.github.com/v3/gists/comments/#delete-a-comment + /// The id of the gist + /// The id of the comment + /// Task. Task Delete(string gistId, string commentId); } } From d1361ead6c9365c7f3dd0d07ad9301b3bb5c6b8b Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 23:06:43 +0100 Subject: [PATCH 62/64] Minor adjustments to the API methods --- .../Clients/GistCommentsClientTests.cs | 59 ++++--------------- Octokit.sln.DotSettings | 1 + Octokit/Clients/GistCommentsClient.cs | 25 +++----- Octokit/Clients/IGistCommentsClient.cs | 10 ++-- Octokit/Helpers/ApiUrls.cs | 4 +- Octokit/Models/Request/BodyWrapper.cs | 12 ++++ Octokit/Models/Response/GistComment.cs | 2 +- Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 12 files changed, 44 insertions(+), 74 deletions(-) create mode 100644 Octokit/Models/Request/BodyWrapper.cs diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs index 6a899355..6d7db2a9 100644 --- a/Octokit.Tests/Clients/GistCommentsClientTests.cs +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -22,24 +22,13 @@ namespace Octokit.Tests.Clients public class TheGetMethod { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); - - await AssertEx.Throws(async () => await client.Get(null, "1337")); - await AssertEx.Throws(async () => await client.Get("24", null)); - await AssertEx.Throws(async () => await client.Get("", "1337")); - await AssertEx.Throws(async () => await client.Get("24", "")); - } - [Fact] public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Get("24", "1337"); + await client.Get(24, 1337); connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), null); } @@ -47,22 +36,13 @@ namespace Octokit.Tests.Clients public class TheGetForGistMethod { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); - - await AssertEx.Throws(async () => await client.GetForGist(null)); - await AssertEx.Throws(async () => await client.GetForGist("")); - } - [Fact] public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.GetForGist("24"); + await client.GetForGist(24); connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments")); } @@ -75,10 +55,8 @@ namespace Octokit.Tests.Clients { var client = new GistCommentsClient(Substitute.For()); - await AssertEx.Throws(async () => await client.Create(null, "Comment")); - await AssertEx.Throws(async () => await client.Create("24", null)); - await AssertEx.Throws(async () => await client.Create("", "Comment")); - await AssertEx.Throws(async () => await client.Create("24", "")); + await AssertEx.Throws(async () => await client.Create(24, null)); + await AssertEx.Throws(async () => await client.Create(24, "")); } [Fact] @@ -88,9 +66,9 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Create("24", comment); + await client.Create(24, comment); - connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), comment); + connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), Arg.Is(x => x.Body == comment)); } } @@ -101,12 +79,8 @@ namespace Octokit.Tests.Clients { var client = new GistCommentsClient(Substitute.For()); - await AssertEx.Throws(async () => await client.Update(null, "1337", "Comment")); - await AssertEx.Throws(async () => await client.Update("24", null, "Comment")); - await AssertEx.Throws(async () => await client.Update("24", "1337", null)); - await AssertEx.Throws(async () => await client.Update("", "1337", "Comment")); - await AssertEx.Throws(async () => await client.Update("24", "", "Comment")); - await AssertEx.Throws(async () => await client.Update("24", "1337", "")); + await AssertEx.Throws(async () => await client.Update(24, 1337, null)); + await AssertEx.Throws(async () => await client.Update(24, 1337, "")); } [Fact] @@ -116,32 +90,21 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Update("24", "1337", comment); + await client.Update(24, 1337, comment); - connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), comment); + connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), Arg.Is(x => x.Body == comment)); } } public class TheDeleteMethod { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); - - await AssertEx.Throws(async () => await client.Delete(null, "1337")); - await AssertEx.Throws(async () => await client.Delete("24", null)); - await AssertEx.Throws(async () => await client.Delete("", "1337")); - await AssertEx.Throws(async () => await client.Delete("24", "")); - } - [Fact] public async Task PostsToCorrectUrl() { var connection = Substitute.For(); var client = new GistCommentsClient(connection); - await client.Delete("24", "1337"); + await client.Delete(24, 1337); connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); } diff --git a/Octokit.sln.DotSettings b/Octokit.sln.DotSettings index 36aa1792..202116c9 100644 --- a/Octokit.sln.DotSettings +++ b/Octokit.sln.DotSettings @@ -262,4 +262,5 @@ II.2.12 <HandlesEvent /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /> + True \ No newline at end of file diff --git a/Octokit/Clients/GistCommentsClient.cs b/Octokit/Clients/GistCommentsClient.cs index aa717cb6..1b708e43 100644 --- a/Octokit/Clients/GistCommentsClient.cs +++ b/Octokit/Clients/GistCommentsClient.cs @@ -16,11 +16,8 @@ namespace Octokit /// The id of the gist /// The id of the comment /// Task{GistComment}. - public Task Get(string gistId, string commentId) + public Task Get(int gistId, int commentId) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); - Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); - return ApiConnection.Get(ApiUrls.GistComment(gistId, commentId)); } @@ -30,10 +27,8 @@ namespace Octokit /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist /// The id of the gist /// Task{IReadOnlyList{GistComment}}. - public Task> GetForGist(string gistId) + public Task> GetForGist(int gistId) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); - return ApiConnection.GetAll(ApiUrls.GistComments(gistId)); } @@ -44,12 +39,11 @@ namespace Octokit /// The id of the gist /// The body of the comment /// Task{GistComment}. - public Task Create(string gistId, string comment) + public Task Create(int gistId, string comment) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); - return ApiConnection.Post(ApiUrls.GistComments(gistId), comment); + return ApiConnection.Post(ApiUrls.GistComments(gistId), new BodyWrapper(comment)); } /// @@ -60,13 +54,11 @@ namespace Octokit /// The id of the comment /// The updated body of the comment /// Task{GistComment}. - public Task Update(string gistId, string commentId, string comment) + public Task Update(int gistId, int commentId, string comment) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); - Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); - return ApiConnection.Patch(ApiUrls.GistComment(gistId, commentId), comment); + return ApiConnection.Patch(ApiUrls.GistComment(gistId, commentId), new BodyWrapper(comment)); } /// @@ -76,11 +68,8 @@ namespace Octokit /// The id of the gist /// The id of the comment /// Task. - public Task Delete(string gistId, string commentId) + public Task Delete(int gistId, int commentId) { - Ensure.ArgumentNotNullOrEmptyString(gistId, "gistId"); - Ensure.ArgumentNotNullOrEmptyString(commentId, "commentId"); - return ApiConnection.Delete(ApiUrls.GistComment(gistId, commentId)); } } diff --git a/Octokit/Clients/IGistCommentsClient.cs b/Octokit/Clients/IGistCommentsClient.cs index 49005986..a9a5aeb8 100644 --- a/Octokit/Clients/IGistCommentsClient.cs +++ b/Octokit/Clients/IGistCommentsClient.cs @@ -15,7 +15,7 @@ namespace Octokit /// Task{GistComment}. [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] - Task Get(string gistId, string commentId); + Task Get(int gistId, int commentId); /// /// Gets all comments for the gist with the specified id. @@ -23,7 +23,7 @@ namespace Octokit /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist /// The id of the gist /// Task{IReadOnlyList{GistComment}}. - Task> GetForGist(string gistId); + Task> GetForGist(int gistId); /// /// Creates a comment for the gist with the specified id. @@ -32,7 +32,7 @@ namespace Octokit /// The id of the gist /// The body of the comment /// Task{GistComment}. - Task Create(string gistId, string comment); + Task Create(int gistId, string comment); /// /// Updates the comment with the specified gist- and comment id. @@ -42,7 +42,7 @@ namespace Octokit /// The id of the comment /// The updated body of the comment /// Task{GistComment}. - Task Update(string gistId, string commentId, string comment); + Task Update(int gistId, int commentId, string comment); /// /// Deletes the comment with the specified gist- and comment id. @@ -51,6 +51,6 @@ namespace Octokit /// The id of the gist /// The id of the comment /// Task. - Task Delete(string gistId, string commentId); + Task Delete(int gistId, int commentId); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 06f6a8e5..78586961 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -461,7 +461,7 @@ namespace Octokit /// Returns the for the comments for the specified gist. /// /// The id of the gist - public static Uri GistComments(string gistId) + public static Uri GistComments(int gistId) { return "gists/{0}/comments".FormatUri(gistId); } @@ -471,7 +471,7 @@ namespace Octokit /// /// The id of the gist /// The id of the comment - public static Uri GistComment(string gistId, string commentId) + public static Uri GistComment(int gistId, int commentId) { return "gists/{0}/comments/{1}".FormatUri(gistId, commentId); } diff --git a/Octokit/Models/Request/BodyWrapper.cs b/Octokit/Models/Request/BodyWrapper.cs new file mode 100644 index 00000000..2c1d332f --- /dev/null +++ b/Octokit/Models/Request/BodyWrapper.cs @@ -0,0 +1,12 @@ +namespace Octokit +{ + public class BodyWrapper + { + public BodyWrapper(string body) + { + Body = body; + } + + public string Body { get; private set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/GistComment.cs b/Octokit/Models/Response/GistComment.cs index e23945ed..f37023e0 100644 --- a/Octokit/Models/Response/GistComment.cs +++ b/Octokit/Models/Response/GistComment.cs @@ -7,7 +7,7 @@ namespace Octokit /// /// The gist comment id. /// - public string Id { get; set; } + public int Id { get; set; } /// /// The URL for this gist comment. diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index b4f5a9e2..80d77f4e 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -232,6 +232,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index f422fadc..549a850c 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -242,6 +242,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 01144c1a..40a3ea02 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -237,6 +237,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 6a66cba1..f621cbd4 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -230,6 +230,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 8eb92c0e..e1c46319 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -59,6 +59,7 @@ + From c4f6c6d19df7c188c51b6289591113a69bd6477f Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 23:18:40 +0100 Subject: [PATCH 63/64] Added observable clients for gist and gist comments --- .../Clients/IObservableGistCommentsClient.cs | 56 +++++++++++ .../Clients/IObservableGistsClient.cs | 21 ++++ .../Clients/ObservableGistCommentsClient.cs | 96 +++++++++++++++++++ .../Clients/ObservableGistsClient.cs | 27 ++++++ Octokit.Reactive/IObservableGitHubClient.cs | 5 +- Octokit.Reactive/ObservableGitHubClient.cs | 2 + Octokit.Reactive/Octokit.Reactive.csproj | 4 + 7 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 Octokit.Reactive/Clients/IObservableGistCommentsClient.cs create mode 100644 Octokit.Reactive/Clients/IObservableGistsClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableGistCommentsClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableGistsClient.cs diff --git a/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs b/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs new file mode 100644 index 00000000..96746baa --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs @@ -0,0 +1,56 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Reactive; + +namespace Octokit.Reactive.Clients +{ + public interface IObservableGistCommentsClient + { + /// + /// Gets a single comment by gist- and comment id. + /// + /// http://developer.github.com/v3/gists/comments/#get-a-single-comment + /// The id of the gist + /// The id of the comment + /// Task{GistComment}. + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + IObservable Get(int gistId, int commentId); + + /// + /// Gets all comments for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist + /// The id of the gist + /// Task{IReadOnlyList{GistComment}}. + IObservable GetForGist(int gistId); + + /// + /// Creates a comment for the gist with the specified id. + /// + /// http://developer.github.com/v3/gists/comments/#create-a-comment + /// The id of the gist + /// The body of the comment + /// Task{GistComment}. + IObservable Create(int gistId, string comment); + + /// + /// Updates the comment with the specified gist- and comment id. + /// + /// http://developer.github.com/v3/gists/comments/#edit-a-comment + /// The id of the gist + /// The id of the comment + /// The updated body of the comment + /// Task{GistComment}. + IObservable Update(int gistId, int commentId, string comment); + + /// + /// Deletes the comment with the specified gist- and comment id. + /// + /// http://developer.github.com/v3/gists/comments/#delete-a-comment + /// The id of the gist + /// The id of the comment + /// Task. + IObservable Delete(int gistId, int commentId); + } +} \ No newline at end of file diff --git a/Octokit.Reactive/Clients/IObservableGistsClient.cs b/Octokit.Reactive/Clients/IObservableGistsClient.cs new file mode 100644 index 00000000..c8a568cc --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableGistsClient.cs @@ -0,0 +1,21 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace Octokit.Reactive.Clients +{ + public interface IObservableGistsClient + { + IObservableGistCommentsClient Comment { get; set; } + + /// + /// Gets a gist + /// + /// + /// http://developer.github.com/v3/gists/#get-a-single-gist + /// + /// The id of the gist + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + IObservable Get(string id); + } +} \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs b/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs new file mode 100644 index 00000000..ff3afe60 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs @@ -0,0 +1,96 @@ +using System; +using System.Reactive; +using System.Reactive.Threading.Tasks; + +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive.Clients +{ + public class ObservableGistCommentsClient : IObservableGistCommentsClient + { + readonly IGistCommentsClient _client; + readonly IConnection _connection; + + public ObservableGistCommentsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Gist.Comment; + _connection = client.Connection; + } + + /// + /// Gets a single comment by gist- and comment id. + /// + /// + /// http://developer.github.com/v3/gists/comments/#get-a-single-comment + /// + /// The id of the gist + /// The id of the comment + /// Task{GistComment}. + public IObservable Get(int gistId, int commentId) + { + return _client.Get(gistId, commentId).ToObservable(); + } + + /// + /// Gets all comments for the gist with the specified id. + /// + /// + /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist + /// + /// The id of the gist + /// Task{IReadOnlyList{GistComment}}. + public IObservable GetForGist(int gistId) + { + return _connection.GetAndFlattenAllPages(ApiUrls.GistComments(gistId)); + } + + /// + /// Creates a comment for the gist with the specified id. + /// + /// + /// http://developer.github.com/v3/gists/comments/#create-a-comment + /// + /// The id of the gist + /// The body of the comment + /// Task{GistComment}. + public IObservable Create(int gistId, string comment) + { + Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); + + return _client.Create(gistId, comment).ToObservable(); + } + + /// + /// Updates the comment with the specified gist- and comment id. + /// + /// + /// http://developer.github.com/v3/gists/comments/#edit-a-comment + /// + /// The id of the gist + /// The id of the comment + /// The updated body of the comment + /// Task{GistComment}. + public IObservable Update(int gistId, int commentId, string comment) + { + Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); + + return _client.Update(gistId, commentId, comment).ToObservable(); + } + + /// + /// Deletes the comment with the specified gist- and comment id. + /// + /// + /// http://developer.github.com/v3/gists/comments/#delete-a-comment + /// + /// The id of the gist + /// The id of the comment + /// Task. + public IObservable Delete(int gistId, int commentId) + { + return _client.Delete(gistId, commentId).ToObservable(); + } + } +} \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableGistsClient.cs b/Octokit.Reactive/Clients/ObservableGistsClient.cs new file mode 100644 index 00000000..f98cb891 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableGistsClient.cs @@ -0,0 +1,27 @@ +using System; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive.Clients +{ + public class ObservableGistsClient : IObservableGistsClient + { + readonly IGistsClient _client; + + public ObservableGistsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Gist; + Comment = new ObservableGistCommentsClient(client); + } + + public IObservableGistCommentsClient Comment { get; set; } + + public IObservable Get(string id) + { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + + return _client.Get(id).ToObservable(); + } + } +} \ No newline at end of file diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index f8b2531c..2879c2b7 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -1,4 +1,6 @@ -namespace Octokit.Reactive +using Octokit.Reactive.Clients; + +namespace Octokit.Reactive { public interface IObservableGitHubClient { @@ -14,5 +16,6 @@ IObservableUsersClient User { get; } IObservableGitDatabaseClient GitDatabase { get; } IObservableTreesClient Tree { get; } + IObservableGistsClient Gist { get; } } } \ No newline at end of file diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index 42e1f19b..edb59091 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -45,6 +45,7 @@ namespace Octokit.Reactive Release = new ObservableReleasesClient(gitHubClient); GitDatabase = new ObservableGitDatabaseClient(gitHubClient); Tree = new ObservableTreesClient(gitHubClient); + Gist = new ObservableGistsClient(gitHubClient); } public IConnection Connection @@ -64,5 +65,6 @@ namespace Octokit.Reactive public IObservableUsersClient User { get; private set; } public IObservableGitDatabaseClient GitDatabase { get; private set; } public IObservableTreesClient Tree { get; private set; } + public IObservableGistsClient Gist { get; private set; } } } diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 1917158a..f2dad469 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -74,7 +74,11 @@ Properties\SolutionInfo.cs + + + + From ae23a2ae7ad08f17da1e18b1843d7e2def4aa827 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 23:25:41 +0100 Subject: [PATCH 64/64] Fixed minor namespace and whitespace issues --- .../Clients/IObservableGistCommentsClient.cs | 12 +- .../Clients/IObservableGistsClient.cs | 2 +- .../Clients/IObservableIssuesEventsClient.cs | 6 +- .../Clients/IObservableMilestonesClient.cs | 3 +- .../Clients/ObservableGistCommentsClient.cs | 13 +- .../Clients/ObservableGistsClient.cs | 10 +- .../Clients/ObservableIssuesClient.cs | 2 - .../Clients/ObservableIssuesEventsClient.cs | 3 +- .../Clients/ObservableMilestonesClient.cs | 2 +- .../Clients/ObservableNotificationsClient.cs | 2 +- .../Clients/ObservableStarredClient.cs | 4 +- Octokit.Reactive/IObservableGitHubClient.cs | 4 +- Octokit.Reactive/ObservableGitHubClient.cs | 1 - .../Octokit.Reactive.csproj.DotSettings | 2 + .../ObservableMilestonesClientTests.cs | 2 +- .../Clients/GistCommentsClientTests.cs | 167 +++++++++--------- .../ObservableMilestonesClientTests.cs | 2 +- .../Reactive/ObservableStarredClientTests.cs | 2 +- 18 files changed, 116 insertions(+), 123 deletions(-) create mode 100644 Octokit.Reactive/Octokit.Reactive.csproj.DotSettings diff --git a/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs b/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs index 96746baa..2d7372a5 100644 --- a/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGistCommentsClient.cs @@ -2,7 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Reactive; -namespace Octokit.Reactive.Clients +namespace Octokit.Reactive { public interface IObservableGistCommentsClient { @@ -12,7 +12,7 @@ namespace Octokit.Reactive.Clients /// http://developer.github.com/v3/gists/comments/#get-a-single-comment /// The id of the gist /// The id of the comment - /// Task{GistComment}. + /// IObservable{GistComment}. [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", Justification = "Method makes a network request")] IObservable Get(int gistId, int commentId); @@ -22,7 +22,7 @@ namespace Octokit.Reactive.Clients /// /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist /// The id of the gist - /// Task{IReadOnlyList{GistComment}}. + /// IObservable{GistComment}. IObservable GetForGist(int gistId); /// @@ -31,7 +31,7 @@ namespace Octokit.Reactive.Clients /// http://developer.github.com/v3/gists/comments/#create-a-comment /// The id of the gist /// The body of the comment - /// Task{GistComment}. + /// IObservable{GistComment}. IObservable Create(int gistId, string comment); /// @@ -41,7 +41,7 @@ namespace Octokit.Reactive.Clients /// The id of the gist /// The id of the comment /// The updated body of the comment - /// Task{GistComment}. + /// IObservable{GistComment}. IObservable Update(int gistId, int commentId, string comment); /// @@ -50,7 +50,7 @@ namespace Octokit.Reactive.Clients /// http://developer.github.com/v3/gists/comments/#delete-a-comment /// The id of the gist /// The id of the comment - /// Task. + /// IObservable{Unit}. IObservable Delete(int gistId, int commentId); } } \ No newline at end of file diff --git a/Octokit.Reactive/Clients/IObservableGistsClient.cs b/Octokit.Reactive/Clients/IObservableGistsClient.cs index c8a568cc..5bb29ede 100644 --- a/Octokit.Reactive/Clients/IObservableGistsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGistsClient.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics.CodeAnalysis; -namespace Octokit.Reactive.Clients +namespace Octokit.Reactive { public interface IObservableGistsClient { diff --git a/Octokit.Reactive/Clients/IObservableIssuesEventsClient.cs b/Octokit.Reactive/Clients/IObservableIssuesEventsClient.cs index 58269a62..7dc0b2b6 100644 --- a/Octokit.Reactive/Clients/IObservableIssuesEventsClient.cs +++ b/Octokit.Reactive/Clients/IObservableIssuesEventsClient.cs @@ -1,11 +1,7 @@ using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace Octokit.Reactive.Clients +namespace Octokit.Reactive { public interface IObservableIssuesEventsClient { diff --git a/Octokit.Reactive/Clients/IObservableMilestonesClient.cs b/Octokit.Reactive/Clients/IObservableMilestonesClient.cs index 321790a1..f1ad38e3 100644 --- a/Octokit.Reactive/Clients/IObservableMilestonesClient.cs +++ b/Octokit.Reactive/Clients/IObservableMilestonesClient.cs @@ -1,9 +1,8 @@ using System; -using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Reactive; -namespace Octokit +namespace Octokit.Reactive { public interface IObservableMilestonesClient { diff --git a/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs b/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs index ff3afe60..e1e6f576 100644 --- a/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGistCommentsClient.cs @@ -1,10 +1,9 @@ using System; using System.Reactive; using System.Reactive.Threading.Tasks; - using Octokit.Reactive.Internal; -namespace Octokit.Reactive.Clients +namespace Octokit.Reactive { public class ObservableGistCommentsClient : IObservableGistCommentsClient { @@ -27,7 +26,7 @@ namespace Octokit.Reactive.Clients /// /// The id of the gist /// The id of the comment - /// Task{GistComment}. + /// IObservable{GistComment}. public IObservable Get(int gistId, int commentId) { return _client.Get(gistId, commentId).ToObservable(); @@ -40,7 +39,7 @@ namespace Octokit.Reactive.Clients /// http://developer.github.com/v3/gists/comments/#list-comments-on-a-gist /// /// The id of the gist - /// Task{IReadOnlyList{GistComment}}. + /// IObservable{GistComment}. public IObservable GetForGist(int gistId) { return _connection.GetAndFlattenAllPages(ApiUrls.GistComments(gistId)); @@ -54,7 +53,7 @@ namespace Octokit.Reactive.Clients /// /// The id of the gist /// The body of the comment - /// Task{GistComment}. + /// IObservable{GistComment}. public IObservable Create(int gistId, string comment) { Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); @@ -71,7 +70,7 @@ namespace Octokit.Reactive.Clients /// The id of the gist /// The id of the comment /// The updated body of the comment - /// Task{GistComment}. + /// IObservable{GistComment}. public IObservable Update(int gistId, int commentId, string comment) { Ensure.ArgumentNotNullOrEmptyString(comment, "comment"); @@ -87,7 +86,7 @@ namespace Octokit.Reactive.Clients /// /// The id of the gist /// The id of the comment - /// Task. + /// IObservable{Unit}. public IObservable Delete(int gistId, int commentId) { return _client.Delete(gistId, commentId).ToObservable(); diff --git a/Octokit.Reactive/Clients/ObservableGistsClient.cs b/Octokit.Reactive/Clients/ObservableGistsClient.cs index f98cb891..63c2e6b7 100644 --- a/Octokit.Reactive/Clients/ObservableGistsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGistsClient.cs @@ -1,7 +1,7 @@ using System; using System.Reactive.Threading.Tasks; -namespace Octokit.Reactive.Clients +namespace Octokit.Reactive { public class ObservableGistsClient : IObservableGistsClient { @@ -17,6 +17,14 @@ namespace Octokit.Reactive.Clients public IObservableGistCommentsClient Comment { get; set; } + /// + /// Gets a gist + /// + /// + /// http://developer.github.com/v3/gists/#get-a-single-gist + /// + /// The id of the gist + /// IObservable{Gist}. public IObservable Get(string id) { Ensure.ArgumentNotNullOrEmptyString(id, "id"); diff --git a/Octokit.Reactive/Clients/ObservableIssuesClient.cs b/Octokit.Reactive/Clients/ObservableIssuesClient.cs index 38db8211..c9042400 100644 --- a/Octokit.Reactive/Clients/ObservableIssuesClient.cs +++ b/Octokit.Reactive/Clients/ObservableIssuesClient.cs @@ -1,7 +1,5 @@ using System; -using System.Collections.Generic; using System.Reactive.Threading.Tasks; -using Octokit.Reactive.Clients; using Octokit.Reactive.Internal; namespace Octokit.Reactive diff --git a/Octokit.Reactive/Clients/ObservableIssuesEventsClient.cs b/Octokit.Reactive/Clients/ObservableIssuesEventsClient.cs index 50e54300..67ff9184 100644 --- a/Octokit.Reactive/Clients/ObservableIssuesEventsClient.cs +++ b/Octokit.Reactive/Clients/ObservableIssuesEventsClient.cs @@ -1,9 +1,8 @@ using System; -using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; -namespace Octokit.Reactive.Clients +namespace Octokit.Reactive { public class ObservableIssuesEventsClient : IObservableIssuesEventsClient { diff --git a/Octokit.Reactive/Clients/ObservableMilestonesClient.cs b/Octokit.Reactive/Clients/ObservableMilestonesClient.cs index bd33ad53..65dcaf86 100644 --- a/Octokit.Reactive/Clients/ObservableMilestonesClient.cs +++ b/Octokit.Reactive/Clients/ObservableMilestonesClient.cs @@ -3,7 +3,7 @@ using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; -namespace Octokit.Reactive.Clients +namespace Octokit.Reactive { public class ObservableMilestonesClient : IObservableMilestonesClient { diff --git a/Octokit.Reactive/Clients/ObservableNotificationsClient.cs b/Octokit.Reactive/Clients/ObservableNotificationsClient.cs index 40893408..f7a3889d 100644 --- a/Octokit.Reactive/Clients/ObservableNotificationsClient.cs +++ b/Octokit.Reactive/Clients/ObservableNotificationsClient.cs @@ -1,7 +1,7 @@ using System; using Octokit.Reactive.Internal; -namespace Octokit.Reactive.Clients +namespace Octokit.Reactive { public class ObservableNotificationsClient : IObservableNotificationsClient { diff --git a/Octokit.Reactive/Clients/ObservableStarredClient.cs b/Octokit.Reactive/Clients/ObservableStarredClient.cs index 040170e9..7439c111 100644 --- a/Octokit.Reactive/Clients/ObservableStarredClient.cs +++ b/Octokit.Reactive/Clients/ObservableStarredClient.cs @@ -1,9 +1,9 @@ using System; -using System.Reactive; using System.Reactive.Threading.Tasks; + using Octokit.Reactive.Internal; -namespace Octokit.Reactive.Clients +namespace Octokit.Reactive { public class ObservableStarredClient { diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index 2879c2b7..4f0cb79d 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -1,6 +1,4 @@ -using Octokit.Reactive.Clients; - -namespace Octokit.Reactive +namespace Octokit.Reactive { public interface IObservableGitHubClient { diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index edb59091..f5fad6f4 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -1,6 +1,5 @@ using System; using System.Net.Http.Headers; -using Octokit.Reactive.Clients; namespace Octokit.Reactive { diff --git a/Octokit.Reactive/Octokit.Reactive.csproj.DotSettings b/Octokit.Reactive/Octokit.Reactive.csproj.DotSettings new file mode 100644 index 00000000..a4f335fe --- /dev/null +++ b/Octokit.Reactive/Octokit.Reactive.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/Octokit.Tests.Integration/Reactive/ObservableMilestonesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableMilestonesClientTests.cs index ab7f232d..2eedd3b1 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableMilestonesClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableMilestonesClientTests.cs @@ -2,7 +2,7 @@ using System.Net.Http.Headers; using System.Reactive.Linq; using System.Threading.Tasks; -using Octokit.Reactive.Clients; +using Octokit.Reactive; using Xunit; namespace Octokit.Tests.Integration diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs index 6d7db2a9..8ca77c6e 100644 --- a/Octokit.Tests/Clients/GistCommentsClientTests.cs +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -1,113 +1,108 @@ using System; using System.Threading.Tasks; - using NSubstitute; - +using Octokit; using Octokit.Tests.Helpers; - using Xunit; -namespace Octokit.Tests.Clients +public class GistCommentsClientTests { - public class GistCommentsClientTests + public class TheCtor { - public class TheCtor + [Fact] + public void EnsuresArgument() { - [Fact] - public void EnsuresArgument() - { - Assert.Throws(() => new GistCommentsClient(null)); - } + Assert.Throws(() => new GistCommentsClient(null)); + } + } + + public class TheGetMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Get(24, 1337); + + connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), null); + } + } + + public class TheGetForGistMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.GetForGist(24); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments")); + } + } + + public class TheCreateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Create(24, null)); + await AssertEx.Throws(async () => await client.Create(24, "")); } - public class TheGetMethod + [Fact] + public async Task PostsToCorrectUrl() { - [Fact] - public async Task RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); + var comment = "This is a comment."; + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); - await client.Get(24, 1337); + await client.Create(24, comment); - connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), null); - } + connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), Arg.Is(x => x.Body == comment)); + } + } + + public class TheUpdateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Update(24, 1337, null)); + await AssertEx.Throws(async () => await client.Update(24, 1337, "")); } - public class TheGetForGistMethod + [Fact] + public async Task PostsToCorrectUrl() { - [Fact] - public async Task RequestsCorrectUrl() - { - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); + var comment = "This is a comment."; + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); - await client.GetForGist(24); + await client.Update(24, 1337, comment); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments")); - } + connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), Arg.Is(x => x.Body == comment)); } + } - public class TheCreateMethod + public class TheDeleteMethod + { + [Fact] + public async Task PostsToCorrectUrl() { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); - await AssertEx.Throws(async () => await client.Create(24, null)); - await AssertEx.Throws(async () => await client.Create(24, "")); - } + await client.Delete(24, 1337); - [Fact] - public async Task PostsToCorrectUrl() - { - var comment = "This is a comment."; - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); - - await client.Create(24, comment); - - connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), Arg.Is(x => x.Body == comment)); - } - } - - public class TheUpdateMethod - { - [Fact] - public async Task EnsuresNonNullArguments() - { - var client = new GistCommentsClient(Substitute.For()); - - await AssertEx.Throws(async () => await client.Update(24, 1337, null)); - await AssertEx.Throws(async () => await client.Update(24, 1337, "")); - } - - [Fact] - public async Task PostsToCorrectUrl() - { - var comment = "This is a comment."; - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); - - await client.Update(24, 1337, comment); - - connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), Arg.Is(x => x.Body == comment)); - } - } - - public class TheDeleteMethod - { - [Fact] - public async Task PostsToCorrectUrl() - { - var connection = Substitute.For(); - var client = new GistCommentsClient(connection); - - await client.Delete(24, 1337); - - connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); - } + connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); } } } \ No newline at end of file diff --git a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs index d0216d85..35b1666d 100644 --- a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using NSubstitute; using Octokit; using Octokit.Internal; -using Octokit.Reactive.Clients; +using Octokit.Reactive; using Octokit.Tests.Helpers; using Xunit; diff --git a/Octokit.Tests/Reactive/ObservableStarredClientTests.cs b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs index 6b1c7dfd..f8797c2f 100644 --- a/Octokit.Tests/Reactive/ObservableStarredClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableStarredClientTests.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; using NSubstitute; using Octokit; using Octokit.Internal; -using Octokit.Reactive.Clients; +using Octokit.Reactive; using Octokit.Reactive.Internal; using Octokit.Tests.Helpers; using Xunit;