Merge pull request #1382 from dampir/add-repo-id-commit-comment-reactions-client

Add repositoryId overloads to methods on I(Observable)CommitCommentReactionsClient
This commit is contained in:
Brendan Forster
2016-07-06 11:39:12 +10:00
committed by GitHub
8 changed files with 310 additions and 38 deletions

View File

@@ -2,6 +2,12 @@
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Reactions API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/reactions">Reactions API documentation</a> for more information.
/// </remarks>
public interface IObservableCommitCommentReactionsClient
{
/// <summary>
@@ -15,6 +21,16 @@ namespace Octokit.Reactive
/// <returns></returns>
IObservable<Reaction> Create(string owner, string name, int number, NewReaction reaction);
/// <summary>
/// Creates a reaction for a specified Commit Comment
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="number">The comment id</param>
/// <param name="reaction">The reaction to create </param>
/// <returns></returns>
IObservable<Reaction> Create(int repositoryId, int number, NewReaction reaction);
/// <summary>
/// List reactions for a specified Commit Comment
/// </summary>
@@ -24,5 +40,14 @@ namespace Octokit.Reactive
/// <param name="number">The comment id</param>
/// <returns></returns>
IObservable<Reaction> GetAll(string owner, string name, int number);
/// <summary>
/// List reactions for a specified Commit Comment
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment</remarks>
/// <param name="repositoryId">The owner of the repository</param>
/// <param name="number">The comment id</param>
/// <returns></returns>
IObservable<Reaction> GetAll(int repositoryId, int number);
}
}

View File

@@ -4,6 +4,12 @@ using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Reactions API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/reactions">Reactions API documentation</a> for more information.
/// </remarks>
public class ObservableCommitCommentReactionsClient : IObservableCommitCommentReactionsClient
{
readonly ICommitCommentReactionsClient _client;
@@ -35,6 +41,21 @@ namespace Octokit.Reactive
return _client.Create(owner, name, number, reaction).ToObservable();
}
/// <summary>
/// Creates a reaction for a specified Commit Comment
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="number">The comment id</param>
/// <param name="reaction">The reaction to create </param>
/// <returns></returns>
public IObservable<Reaction> Create(int repositoryId, int number, NewReaction reaction)
{
Ensure.ArgumentNotNull(reaction, "reaction");
return _client.Create(repositoryId, number, reaction).ToObservable();
}
/// <summary>
/// List reactions for a specified Commit Comment
/// </summary>
@@ -50,5 +71,17 @@ namespace Octokit.Reactive
return _connection.GetAndFlattenAllPages<Reaction>(ApiUrls.CommitCommentReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview);
}
/// <summary>
/// List reactions for a specified Commit Comment
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment</remarks>
/// <param name="repositoryId">The owner of the repository</param>
/// <param name="number">The comment id</param>
/// <returns></returns>
public IObservable<Reaction> GetAll(int repositoryId, int number)
{
return _connection.GetAndFlattenAllPages<Reaction>(ApiUrls.CommitCommentReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview);
}
}
}

View File

@@ -1,8 +1,8 @@
using Octokit;
using System;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
using Octokit.Tests.Integration.Helpers;
using System;
using System.Threading.Tasks;
using Xunit;
public class CommitCommentReactionsClientTests
@@ -44,6 +44,54 @@ public class CommitCommentReactionsClientTests
return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);
}
[IntegrationTest]
public async Task CanListReactions()
{
var commit = await SetupCommitForRepository(_github);
var comment = new NewCommitComment("test");
var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
commit.Sha, comment);
Assert.NotNull(result);
var newReaction = new NewReaction(ReactionType.Confused);
var reaction = await _github.Reaction.CommitComment.Create(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction);
var reactions = await _github.Reaction.CommitComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, result.Id);
Assert.NotEmpty(reactions);
Assert.Equal(reaction.Id, reactions[0].Id);
Assert.Equal(reaction.Content, reactions[0].Content);
}
[IntegrationTest]
public async Task CanListReactionsWithRepositoryId()
{
var commit = await SetupCommitForRepository(_github);
var comment = new NewCommitComment("test");
var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
commit.Sha, comment);
Assert.NotNull(result);
var newReaction = new NewReaction(ReactionType.Confused);
var reaction = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction);
var reactions = await _github.Reaction.CommitComment.GetAll(_context.Repository.Id, result.Id);
Assert.NotEmpty(reactions);
Assert.Equal(reaction.Id, reactions[0].Id);
Assert.Equal(reaction.Content, reactions[0].Content);
}
[IntegrationTest]
public async Task CanCreateReaction()
{
@@ -68,6 +116,28 @@ public class CommitCommentReactionsClientTests
}
}
[IntegrationTest]
public async Task CanCreateReactionWithRepositoryId()
{
var commit = await SetupCommitForRepository(_github);
var comment = new NewCommitComment("test");
var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
commit.Sha, comment);
Assert.NotNull(result);
var newReaction = new NewReaction(ReactionType.Confused);
var reaction = await _github.Reaction.CommitComment.Create(_context.Repository.Id, result.Id, newReaction);
Assert.IsType<Reaction>(reaction);
Assert.Equal(ReactionType.Confused, reaction.Content);
Assert.Equal(result.User.Id, reaction.User.Id);
}
public void Dispose()
{
_context.Dispose();

View File

@@ -1,6 +1,6 @@
using NSubstitute;
using System;
using System;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;
namespace Octokit.Tests.Clients
@@ -22,24 +22,35 @@ namespace Octokit.Tests.Clients
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new ReactionsClient(connection);
var client = new CommitCommentReactionsClient(connection);
client.CommitComment.GetAll("fake", "repo", 42);
await client.GetAll("fake", "repo", 42);
connection.Received().GetAll<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview");
}
[Fact]
public async Task EnsuresArgumentsNotNull()
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new ReactionsClient(connection);
var client = new CommitCommentReactionsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComment.Create("owner", "name", 1, null));
await client.GetAll(1, 42);
connection.Received().GetAll<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview");
}
[Fact]
public async Task EnsuresNotNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new CommitCommentReactionsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, "name", 1));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("owner", null, 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", "name", 1));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("owner", "", 1));
}
}
@@ -51,11 +62,40 @@ namespace Octokit.Tests.Clients
NewReaction newReaction = new NewReaction(ReactionType.Heart);
var connection = Substitute.For<IApiConnection>();
var client = new ReactionsClient(connection);
var client = new CommitCommentReactionsClient(connection);
client.CommitComment.Create("fake", "repo", 1, newReaction);
client.Create("fake", "repo", 1, newReaction);
connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/1/reactions"), Arg.Any<object>(), "application/vnd.github.squirrel-girl-preview");
connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/1/reactions"), newReaction, "application/vnd.github.squirrel-girl-preview");
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
NewReaction newReaction = new NewReaction(ReactionType.Heart);
var connection = Substitute.For<IApiConnection>();
var client = new CommitCommentReactionsClient(connection);
client.Create(1, 1, newReaction);
connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/comments/1/reactions"), newReaction, "application/vnd.github.squirrel-girl-preview");
}
[Fact]
public async Task EnsuresNotNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new CommitCommentReactionsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", 1, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, 1, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
}
}
}

View File

@@ -18,33 +18,39 @@ namespace Octokit.Tests.Reactive
public class TheGetAllMethod
{
private readonly IGitHubClient _githubClient;
private readonly IObservableReactionsClient _client;
private const string owner = "owner";
private const string name = "name";
public TheGetAllMethod()
{
_githubClient = Substitute.For<IGitHubClient>();
_client = new ObservableReactionsClient(_githubClient);
}
[Fact]
public void RequestsCorrectUrl()
{
_client.CommitComment.GetAll("fake", "repo", 42);
_githubClient.Received().Reaction.CommitComment.GetAll("fake", "repo", 42);
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableCommitCommentReactionsClient(gitHubClient);
client.GetAll("fake", "repo", 42);
gitHubClient.Received().Reaction.CommitComment.GetAll("fake", "repo", 42);
}
[Fact]
public void EnsuresArgumentsNotNull()
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableCommitCommentReactionsClient(gitHubClient);
Assert.Throws<ArgumentNullException>(() => _client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentException>(() => _client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentNullException>(() => _client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentException>(() => _client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentNullException>(() => _client.CommitComment.Create("owner", "name", 1, null));
client.GetAll(1, 42);
gitHubClient.Received().Reaction.CommitComment.GetAll(1, 42);
}
[Fact]
public void EnsuresNotNullArguments()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableCommitCommentReactionsClient(gitHubClient);
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "name", 1));
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null, 1));
Assert.Throws<ArgumentException>(() => client.GetAll("", "name", 1));
Assert.Throws<ArgumentException>(() => client.GetAll("owner", "", 1));
}
}
@@ -54,12 +60,41 @@ namespace Octokit.Tests.Reactive
public void RequestsCorrectUrl()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableReactionsClient(githubClient);
var client = new ObservableCommitCommentReactionsClient(githubClient);
var newReaction = new NewReaction(ReactionType.Confused);
client.CommitComment.Create("fake", "repo", 1, newReaction);
client.Create("fake", "repo", 1, newReaction);
githubClient.Received().Reaction.CommitComment.Create("fake", "repo", 1, newReaction);
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var githubClient = Substitute.For<IGitHubClient>();
var client = new ObservableCommitCommentReactionsClient(githubClient);
var newReaction = new NewReaction(ReactionType.Confused);
client.Create(1, 1, newReaction);
githubClient.Received().Reaction.CommitComment.Create(1, 1, newReaction);
}
[Fact]
public void EnsuresNotNullArguments()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableCommitCommentReactionsClient(gitHubClient);
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", 1, null));
Assert.Throws<ArgumentNullException>(() => client.Create(1, 1, null));
Assert.Throws<ArgumentException>(() => client.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
Assert.Throws<ArgumentException>(() => client.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
}
}
}
}

View File

@@ -3,6 +3,12 @@ using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Reactions API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/reactions">Reactions API documentation</a> for more information.
/// </remarks>
public class CommitCommentReactionsClient : ApiClient, ICommitCommentReactionsClient
{
public CommitCommentReactionsClient(IApiConnection apiConnection)
@@ -28,6 +34,21 @@ namespace Octokit
return ApiConnection.Post<Reaction>(ApiUrls.CommitCommentReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview);
}
/// <summary>
/// Creates a reaction for a specified Commit Comment
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment</remarks>
/// <param name="repositoryId">The owner of the repository</param>
/// <param name="number">The comment id</param>
/// <param name="reaction">The reaction to create</param>
/// <returns></returns>
public Task<Reaction> Create(int repositoryId, int number, NewReaction reaction)
{
Ensure.ArgumentNotNull(reaction, "reaction");
return ApiConnection.Post<Reaction>(ApiUrls.CommitCommentReactions(repositoryId, number), reaction, AcceptHeaders.ReactionsPreview);
}
/// <summary>
/// Get all reactions for a specified Commit Comment
/// </summary>
@@ -43,5 +64,17 @@ namespace Octokit
return ApiConnection.GetAll<Reaction>(ApiUrls.CommitCommentReactions(owner, name, number), AcceptHeaders.ReactionsPreview);
}
/// <summary>
/// Get all reactions for a specified Commit Comment
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment</remarks>
/// <param name="repositoryId">The owner of the repository</param>
/// <param name="number">The comment id</param>
/// <returns></returns>
public Task<IReadOnlyList<Reaction>> GetAll(int repositoryId, int number)
{
return ApiConnection.GetAll<Reaction>(ApiUrls.CommitCommentReactions(repositoryId, number), AcceptHeaders.ReactionsPreview);
}
}
}

View File

@@ -3,6 +3,12 @@ using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Reactions API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/reactions">Reactions API documentation</a> for more information.
/// </remarks>
public interface ICommitCommentReactionsClient
{
/// <summary>
@@ -16,6 +22,16 @@ namespace Octokit
/// <returns></returns>
Task<Reaction> Create(string owner, string name, int number, NewReaction reaction);
/// <summary>
/// Creates a reaction for a specified Commit Comment
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment</remarks>
/// <param name="repositoryId">The owner of the repository</param>
/// <param name="number">The comment id</param>
/// <param name="reaction">The reaction to create</param>
/// <returns></returns>
Task<Reaction> Create(int repositoryId, int number, NewReaction reaction);
/// <summary>
/// Get all reactions for a specified Commit Comment
/// </summary>
@@ -25,5 +41,14 @@ namespace Octokit
/// <param name="number">The comment id</param>
/// <returns></returns>
Task<IReadOnlyList<Reaction>> GetAll(string owner, string name, int number);
/// <summary>
/// Get all reactions for a specified Commit Comment
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment</remarks>
/// <param name="repositoryId">The owner of the repository</param>
/// <param name="number">The comment id</param>
/// <returns></returns>
Task<IReadOnlyList<Reaction>> GetAll(int repositoryId, int number);
}
}

View File

@@ -446,6 +446,17 @@ namespace Octokit
return "repos/{0}/{1}/comments/{2}/reactions".FormatUri(owner, name, number);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the reaction of a specified commit comment.
/// </summary>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="number">The comment number</param>
/// <returns></returns>
public static Uri CommitCommentReactions(int repositoryId, int number)
{
return "repositories/{0}/comments/{1}/reactions".FormatUri(repositoryId, number);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the assignees to which issues may be assigned.
/// </summary>