mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 06:05:12 +00:00
[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.
This commit is contained in:
@@ -91,6 +91,24 @@ namespace Octokit.Reactive
|
||||
/// <param name="since">Only gists updated at or after this time are returned</param>
|
||||
IObservable<Gist> GetAllForUser(string user, DateTimeOffset since);
|
||||
|
||||
/// <summary>
|
||||
/// List gist commits
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/gists/#list-gists-commits
|
||||
/// </remarks>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
IObservable<GistHistory> GetCommits(string id);
|
||||
|
||||
/// <summary>
|
||||
/// List gist forks
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/gists/#list-gists-forks
|
||||
/// </remarks>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
IObservable<GistFork> GetForks(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new gist
|
||||
/// </summary>
|
||||
|
||||
@@ -180,6 +180,34 @@ namespace Octokit.Reactive
|
||||
return _connection.GetAndFlattenAllPages<Gist>(ApiUrls.UsersGists(user), request.ToParametersDictionary());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List gist commits
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/gists/#list-gists-commits
|
||||
/// </remarks>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
public IObservable<GistHistory> GetCommits(string id)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(id, "id");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<GistHistory>(ApiUrls.GistCommits(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List gist forks
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/gists/#list-gists-forks
|
||||
/// </remarks>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
public IObservable<GistFork> GetForks(string id)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(id, "id");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<GistFork>(ApiUrls.ForkGist(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edits a gist
|
||||
/// </summary>
|
||||
|
||||
@@ -126,4 +126,16 @@ public class GistsClientTests
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,6 +124,44 @@ public class GistsClientTests
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetChildrenMethods
|
||||
{
|
||||
[Fact]
|
||||
public void EnsureNonNullArguments()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistsClient(connection);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetCommits(null));
|
||||
Assert.Throws<ArgumentException>(() => client.GetCommits(""));
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.GetForks(null));
|
||||
Assert.Throws<ArgumentException>(() => client.GetForks(""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectGetCommitsUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistsClient(connection);
|
||||
|
||||
client.GetCommits("9257657");
|
||||
|
||||
connection.Received().GetAll<GistHistory>(Arg.Is<Uri>(u => u.ToString() == "gists/9257657/commits"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectGetForksUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new GistsClient(connection);
|
||||
|
||||
client.GetForks("9257657");
|
||||
|
||||
connection.Received().GetAll<GistFork>(Arg.Is<Uri>(u => u.ToString() == "gists/9257657/forks"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
|
||||
@@ -162,6 +162,7 @@
|
||||
<Compile Include="Reactive\ObservablePullRequestReviewCommentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoryDeployKeysClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableGistsTests.cs" />
|
||||
<Compile Include="Reactive\ObservableStarredClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
|
||||
|
||||
57
Octokit.Tests/Reactive/ObservableGistsTests.cs
Normal file
57
Octokit.Tests/Reactive/ObservableGistsTests.cs
Normal file
@@ -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<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetCommits(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetCommits(""));
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForks(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForks(""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectGetCommitsUrl()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableGistsClient(github);
|
||||
var expected = new Uri("gists/9257657/commits", UriKind.Relative);
|
||||
|
||||
client.GetCommits("9257657");
|
||||
|
||||
github.Connection.Received(1).Get<List<GistHistory>>(expected, Arg.Any<IDictionary<string, string>>(), null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RequestsCorrectGetForksUrl()
|
||||
{
|
||||
var github = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableGistsClient(github);
|
||||
var expected = new Uri("gists/9257657/forks", UriKind.Relative);
|
||||
|
||||
client.GetForks("9257657");
|
||||
|
||||
github.Connection.Received(1).Get<List<GistFork>>(expected, Arg.Any<IDictionary<string, string>>(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -196,6 +196,34 @@ namespace Octokit
|
||||
return ApiConnection.GetAll<Gist>(ApiUrls.UsersGists(user), request.ToParametersDictionary());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List gist commits
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/gists/#list-gists-commits
|
||||
/// </remarks>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
public Task<IReadOnlyList<GistHistory>> GetCommits(string id)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(id, "id");
|
||||
|
||||
return ApiConnection.GetAll<GistHistory>(ApiUrls.GistCommits(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List gist forks
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/gists/#list-gists-forks
|
||||
/// </remarks>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
public Task<IReadOnlyList<GistFork>> GetForks(string id)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(id, "id");
|
||||
|
||||
return ApiConnection.GetAll<GistFork>(ApiUrls.ForkGist(id));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edits a gist
|
||||
/// </summary>
|
||||
|
||||
@@ -98,6 +98,24 @@ namespace Octokit
|
||||
/// <param name="since">Only gists updated at or after this time are returned</param>
|
||||
Task<IReadOnlyList<Gist>> GetAllForUser(string user, DateTimeOffset since);
|
||||
|
||||
/// <summary>
|
||||
/// List gist commits
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/gists/#list-gists-commits
|
||||
/// </remarks>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
Task<IReadOnlyList<GistHistory>> GetCommits(string id);
|
||||
|
||||
/// <summary>
|
||||
/// List gist forks
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// http://developer.github.com/v3/gists/#list-gists-forks
|
||||
/// </remarks>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
Task<IReadOnlyList<GistFork>> GetForks(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new gist
|
||||
/// </summary>
|
||||
|
||||
@@ -646,6 +646,10 @@ namespace Octokit
|
||||
return "gists/{0}".FormatUri(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> for the forks for the specified gist.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
public static Uri ForkGist(string id)
|
||||
{
|
||||
return "gists/{0}/forks".FormatUri(id);
|
||||
@@ -680,6 +684,15 @@ namespace Octokit
|
||||
return "gists/{0}/comments".FormatUri(gistId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> for the commits for the specified gist.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the gist</param>
|
||||
public static Uri GistCommits(string id)
|
||||
{
|
||||
return "gists/{0}/commits".FormatUri(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns the specified pull request.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user