From f172edef5bf43340922f116c2d28012d8f781b8c Mon Sep 17 00:00:00 2001 From: Timothy Haagenson Date: Mon, 21 Jul 2014 13:41:34 -0500 Subject: [PATCH 1/2] [WIP] Gists get Commits and Forks - [ ] Finish Gists API Implementation - [ ] [Add method to get gist commits](https://developer.github.com/v3/gists/#list-gist-commits) - [ ] [Add method to get gist forks](https://developer.github.com/v3/gists/#list-gist-forks) Fixes #328, Fixes #216 Added implementation for the remaining pieces of the Gists API. The others mentioned in #328 and #216 were completed through other PRs. --- .../Clients/IObservableGistsClient.cs | 18 ++++++ .../Clients/ObservableGistsClient.cs | 28 +++++++++ .../Clients/GistsClientTests.cs | 12 ++++ Octokit.Tests/Clients/GistsClientTests.cs | 38 +++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + .../Reactive/ObservableGistsTests.cs | 57 +++++++++++++++++++ Octokit/Clients/GistsClient.cs | 28 +++++++++ Octokit/Clients/IGistsClient.cs | 18 ++++++ Octokit/Helpers/ApiUrls.cs | 13 +++++ 9 files changed, 213 insertions(+) create mode 100644 Octokit.Tests/Reactive/ObservableGistsTests.cs diff --git a/Octokit.Reactive/Clients/IObservableGistsClient.cs b/Octokit.Reactive/Clients/IObservableGistsClient.cs index 31ea9da54c..88afc6276b 100644 --- a/Octokit.Reactive/Clients/IObservableGistsClient.cs +++ b/Octokit.Reactive/Clients/IObservableGistsClient.cs @@ -91,6 +91,24 @@ public interface IObservableGistsClient /// Only gists updated at or after this time are returned IObservable GetAllForUser(string user, DateTimeOffset since); + /// + /// List gist commits + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-commits + /// + /// The id of the gist + IObservable GetCommits(string id); + + /// + /// List gist forks + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-forks + /// + /// The id of the gist + IObservable GetForks(string id); + /// /// Creates a new gist /// diff --git a/Octokit.Reactive/Clients/ObservableGistsClient.cs b/Octokit.Reactive/Clients/ObservableGistsClient.cs index 3525b870c7..755417f09c 100644 --- a/Octokit.Reactive/Clients/ObservableGistsClient.cs +++ b/Octokit.Reactive/Clients/ObservableGistsClient.cs @@ -180,6 +180,34 @@ public IObservable GetAllForUser(string user, DateTimeOffset since) return _connection.GetAndFlattenAllPages(ApiUrls.UsersGists(user), request.ToParametersDictionary()); } + /// + /// List gist commits + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-commits + /// + /// The id of the gist + public IObservable GetCommits(string id) + { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + + return _connection.GetAndFlattenAllPages(ApiUrls.GistCommits(id)); + } + + /// + /// List gist forks + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-forks + /// + /// The id of the gist + public IObservable GetForks(string id) + { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + + return _connection.GetAndFlattenAllPages(ApiUrls.ForkGist(id)); + } + /// /// Edits a gist /// diff --git a/Octokit.Tests.Integration/Clients/GistsClientTests.cs b/Octokit.Tests.Integration/Clients/GistsClientTests.cs index b7d1f6bfe1..28be892efa 100644 --- a/Octokit.Tests.Integration/Clients/GistsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GistsClientTests.cs @@ -126,4 +126,16 @@ public async Task CanListGists() await _fixture.Delete(createdGist.Id); } + + [IntegrationTest] + public async Task CanGetGistChildren() + { + // Test History/Commits + var commits = await _fixture.GetCommits(testGistId); + Assert.NotNull(commits); + + // Test Forks + var forks = await _fixture.GetForks(testGistId); + Assert.NotNull(forks); + } } diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index 53c56a68d1..aa6dc80abd 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -124,6 +124,44 @@ public void RequestsCorrectGetGistsForAUserWithSinceUrl() } } + public class TheGetChildrenMethods + { + [Fact] + public void EnsureNonNullArguments() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + Assert.Throws(() => client.GetCommits(null)); + Assert.Throws(() => client.GetCommits("")); + + Assert.Throws(() => client.GetForks(null)); + Assert.Throws(() => client.GetForks("")); + } + + [Fact] + public void RequestsCorrectGetCommitsUrl() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + client.GetCommits("9257657"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/9257657/commits")); + } + + [Fact] + public void RequestsCorrectGetForksUrl() + { + var connection = Substitute.For(); + var client = new GistsClient(connection); + + client.GetForks("9257657"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/9257657/forks")); + } + } + public class TheCreateMethod { [Fact] diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index c3477890c5..f090987f4d 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -162,6 +162,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableGistsTests.cs b/Octokit.Tests/Reactive/ObservableGistsTests.cs new file mode 100644 index 0000000000..b4dadfb479 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableGistsTests.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Linq; +using System.Threading.Tasks; +using NSubstitute; +using Octokit; +using Octokit.Internal; +using Octokit.Reactive; +using Octokit.Reactive.Internal; +using Octokit.Tests.Helpers; +using Xunit; +using Xunit.Extensions; + +namespace Octokit.Tests.Reactive +{ + public class ObservableGistsTests + { + public class TheGetChildrenMethods + { + [Fact] + public async Task EnsureNonNullArguments() + { + var client = new ObservableGistsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.GetCommits(null)); + await AssertEx.Throws(async () => await client.GetCommits("")); + + await AssertEx.Throws(async () => await client.GetForks(null)); + await AssertEx.Throws(async () => await client.GetForks("")); + } + + [Fact] + public void RequestsCorrectGetCommitsUrl() + { + var github = Substitute.For(); + var client = new ObservableGistsClient(github); + var expected = new Uri("gists/9257657/commits", UriKind.Relative); + + client.GetCommits("9257657"); + + github.Connection.Received(1).Get>(expected, Arg.Any>(), null); + } + + [Fact] + public void RequestsCorrectGetForksUrl() + { + var github = Substitute.For(); + var client = new ObservableGistsClient(github); + var expected = new Uri("gists/9257657/forks", UriKind.Relative); + + client.GetForks("9257657"); + + github.Connection.Received(1).Get>(expected, Arg.Any>(), null); + } + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/GistsClient.cs b/Octokit/Clients/GistsClient.cs index fcafeb7917..124380d8c5 100644 --- a/Octokit/Clients/GistsClient.cs +++ b/Octokit/Clients/GistsClient.cs @@ -196,6 +196,34 @@ public Task> GetAllForUser(string user, DateTimeOffset since return ApiConnection.GetAll(ApiUrls.UsersGists(user), request.ToParametersDictionary()); } + /// + /// List gist commits + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-commits + /// + /// The id of the gist + public Task> GetCommits(string id) + { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + + return ApiConnection.GetAll(ApiUrls.GistCommits(id)); + } + + /// + /// List gist forks + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-forks + /// + /// The id of the gist + public Task> GetForks(string id) + { + Ensure.ArgumentNotNullOrEmptyString(id, "id"); + + return ApiConnection.GetAll(ApiUrls.ForkGist(id)); + } + /// /// Edits a gist /// diff --git a/Octokit/Clients/IGistsClient.cs b/Octokit/Clients/IGistsClient.cs index c344c5763e..476a1fb2e5 100644 --- a/Octokit/Clients/IGistsClient.cs +++ b/Octokit/Clients/IGistsClient.cs @@ -98,6 +98,24 @@ public interface IGistsClient /// Only gists updated at or after this time are returned Task> GetAllForUser(string user, DateTimeOffset since); + /// + /// List gist commits + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-commits + /// + /// The id of the gist + Task> GetCommits(string id); + + /// + /// List gist forks + /// + /// + /// http://developer.github.com/v3/gists/#list-gists-forks + /// + /// The id of the gist + Task> GetForks(string id); + /// /// Creates a new gist /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 925f40f194..929d905400 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -646,6 +646,10 @@ public static Uri Gist(string id) return "gists/{0}".FormatUri(id); } + /// + /// Returns the for the forks for the specified gist. + /// + /// The id of the gist public static Uri ForkGist(string id) { return "gists/{0}/forks".FormatUri(id); @@ -680,6 +684,15 @@ public static Uri GistComments(int gistId) return "gists/{0}/comments".FormatUri(gistId); } + /// + /// Returns the for the commits for the specified gist. + /// + /// The id of the gist + public static Uri GistCommits(string id) + { + return "gists/{0}/commits".FormatUri(id); + } + /// /// Returns the that returns the specified pull request. /// From e8d894c648f6d0e472ad324b73de37575b4c5466 Mon Sep 17 00:00:00 2001 From: Timothy Haagenson Date: Mon, 18 Aug 2014 17:15:31 -0400 Subject: [PATCH 2/2] small changes to make ready for master a few small fixes added debugger attributes to models being used and added back a missing newline at end of file fixed a quick typo on the documentation for GistChangeStatus --- Octokit.Tests/Reactive/ObservableGistsTests.cs | 2 +- Octokit/Models/Response/GistChangeStatus.cs | 2 +- Octokit/Models/Response/GistFork.cs | 11 +++++++++++ Octokit/Models/Response/GistHistory.cs | 11 +++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/Reactive/ObservableGistsTests.cs b/Octokit.Tests/Reactive/ObservableGistsTests.cs index b4dadfb479..c8519a4727 100644 --- a/Octokit.Tests/Reactive/ObservableGistsTests.cs +++ b/Octokit.Tests/Reactive/ObservableGistsTests.cs @@ -54,4 +54,4 @@ public void RequestsCorrectGetForksUrl() } } } -} \ No newline at end of file +} diff --git a/Octokit/Models/Response/GistChangeStatus.cs b/Octokit/Models/Response/GistChangeStatus.cs index 4b79034743..9601fd2eee 100644 --- a/Octokit/Models/Response/GistChangeStatus.cs +++ b/Octokit/Models/Response/GistChangeStatus.cs @@ -1,7 +1,7 @@ namespace Octokit { /// - /// User by to indicate the level of change. + /// Used by to indicate the level of change. /// public class GistChangeStatus { diff --git a/Octokit/Models/Response/GistFork.cs b/Octokit/Models/Response/GistFork.cs index b6c3662c40..84bf95cd0b 100644 --- a/Octokit/Models/Response/GistFork.cs +++ b/Octokit/Models/Response/GistFork.cs @@ -1,7 +1,10 @@ using System; +using System.Diagnostics; +using System.Globalization; namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class GistFork { /// @@ -18,5 +21,13 @@ public class GistFork /// The for when this was created. /// public DateTimeOffset CreatedAt { get; set; } + + internal string DebuggerDisplay + { + get + { + return String.Format(CultureInfo.InvariantCulture, "Url: {0}", Url); + } + } } } \ No newline at end of file diff --git a/Octokit/Models/Response/GistHistory.cs b/Octokit/Models/Response/GistHistory.cs index 0ea5fe32df..6218321a99 100644 --- a/Octokit/Models/Response/GistHistory.cs +++ b/Octokit/Models/Response/GistHistory.cs @@ -1,10 +1,13 @@ using System; +using System.Diagnostics; +using System.Globalization; namespace Octokit { /// /// A historical version of a /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class GistHistory { /// @@ -31,5 +34,13 @@ public class GistHistory /// The the version was created. /// public DateTimeOffset CommittedAt { get; set; } + + internal string DebuggerDisplay + { + get + { + return String.Format(CultureInfo.InvariantCulture, "Url: {0} | Version: {1}", Url, Version); + } + } } } \ No newline at end of file