diff --git a/Octokit.Reactive/Clients/IObservableCommitCommentReactionsClient.cs b/Octokit.Reactive/Clients/IObservableCommitCommentReactionsClient.cs index 174863fa..5d837b70 100644 --- a/Octokit.Reactive/Clients/IObservableCommitCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/IObservableCommitCommentReactionsClient.cs @@ -2,6 +2,12 @@ namespace Octokit.Reactive { + /// + /// A client for GitHub's Reactions API. + /// + /// + /// See the Reactions API documentation for more information. + /// public interface IObservableCommitCommentReactionsClient { /// @@ -15,6 +21,16 @@ namespace Octokit.Reactive /// IObservable Create(string owner, string name, int number, NewReaction reaction); + /// + /// Creates a reaction for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment + /// The ID of the repository + /// The comment id + /// The reaction to create + /// + IObservable Create(int repositoryId, int number, NewReaction reaction); + /// /// List reactions for a specified Commit Comment /// @@ -24,5 +40,14 @@ namespace Octokit.Reactive /// The comment id /// IObservable GetAll(string owner, string name, int number); + + /// + /// List reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// + IObservable GetAll(int repositoryId, int number); } } diff --git a/Octokit.Reactive/Clients/ObservableCommitCommentReactionsClient.cs b/Octokit.Reactive/Clients/ObservableCommitCommentReactionsClient.cs index e3d172ee..7b138355 100644 --- a/Octokit.Reactive/Clients/ObservableCommitCommentReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservableCommitCommentReactionsClient.cs @@ -4,6 +4,12 @@ using Octokit.Reactive.Internal; namespace Octokit.Reactive { + /// + /// A client for GitHub's Reactions API. + /// + /// + /// See the Reactions API documentation for more information. + /// public class ObservableCommitCommentReactionsClient : IObservableCommitCommentReactionsClient { readonly ICommitCommentReactionsClient _client; @@ -35,6 +41,21 @@ namespace Octokit.Reactive return _client.Create(owner, name, number, reaction).ToObservable(); } + /// + /// Creates a reaction for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment + /// The ID of the repository + /// The comment id + /// The reaction to create + /// + public IObservable Create(int repositoryId, int number, NewReaction reaction) + { + Ensure.ArgumentNotNull(reaction, "reaction"); + + return _client.Create(repositoryId, number, reaction).ToObservable(); + } + /// /// List reactions for a specified Commit Comment /// @@ -50,5 +71,17 @@ namespace Octokit.Reactive return _connection.GetAndFlattenAllPages(ApiUrls.CommitCommentReactions(owner, name, number), null, AcceptHeaders.ReactionsPreview); } + + /// + /// List reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// + public IObservable GetAll(int repositoryId, int number) + { + return _connection.GetAndFlattenAllPages(ApiUrls.CommitCommentReactions(repositoryId, number), null, AcceptHeaders.ReactionsPreview); + } } } diff --git a/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs b/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs index 679070a6..6c3e169c 100644 --- a/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/CommitCommentReactionsClientTests.cs @@ -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); + + Assert.Equal(ReactionType.Confused, reaction.Content); + + Assert.Equal(result.User.Id, reaction.User.Id); + } + public void Dispose() { _context.Dispose(); diff --git a/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs b/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs index aba818ca..0f55c0e8 100644 --- a/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs +++ b/Octokit.Tests/Clients/CommitCommentReactionsClientTests.cs @@ -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(); - 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(Arg.Is(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(); - var client = new ReactionsClient(connection); + var client = new CommitCommentReactionsClient(connection); - await Assert.ThrowsAsync(() => client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComment.Create("owner", "name", 1, null)); + await client.GetAll(1, 42); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview"); + } + + [Fact] + public async Task EnsuresNotNullArguments() + { + var connection = Substitute.For(); + var client = new CommitCommentReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1)); + await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1)); + + await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); } } @@ -51,11 +62,40 @@ namespace Octokit.Tests.Clients NewReaction newReaction = new NewReaction(ReactionType.Heart); var connection = Substitute.For(); - 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(Arg.Is(u => u.ToString() == "repos/fake/repo/comments/1/reactions"), Arg.Any(), "application/vnd.github.squirrel-girl-preview"); + connection.Received().Post(Arg.Is(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(); + var client = new CommitCommentReactionsClient(connection); + + client.Create(1, 1, newReaction); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/comments/1/reactions"), newReaction, "application/vnd.github.squirrel-girl-preview"); + } + + [Fact] + public async Task EnsuresNotNullArguments() + { + var connection = Substitute.For(); + var client = new CommitCommentReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Create("owner", "name", 1, null)); + + await Assert.ThrowsAsync(() => client.Create(1, 1, null)); + + await Assert.ThrowsAsync(() => client.Create("", "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); } } } diff --git a/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs b/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs index 221d950f..021e9f24 100644 --- a/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCommitCommentReactionsClientTests.cs @@ -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(); - _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(); + 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(); + var client = new ObservableCommitCommentReactionsClient(gitHubClient); - Assert.Throws(() => _client.CommitComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComment.Create("", "name", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _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(); + var client = new ObservableCommitCommentReactionsClient(gitHubClient); + + Assert.Throws(() => client.GetAll(null, "name", 1)); + Assert.Throws(() => client.GetAll("owner", null, 1)); + + Assert.Throws(() => client.GetAll("", "name", 1)); + Assert.Throws(() => client.GetAll("owner", "", 1)); } } @@ -54,12 +60,41 @@ namespace Octokit.Tests.Reactive public void RequestsCorrectUrl() { var githubClient = Substitute.For(); - 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(); + 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(); + var client = new ObservableCommitCommentReactionsClient(gitHubClient); + + Assert.Throws(() => client.Create(null, "name", 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => client.Create("owner", null, 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => client.Create("owner", "name", 1, null)); + + Assert.Throws(() => client.Create(1, 1, null)); + + Assert.Throws(() => client.Create("", "name", 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => client.Create("owner", "", 1, new NewReaction(ReactionType.Heart))); + } } } } diff --git a/Octokit/Clients/CommitCommentReactionsClient.cs b/Octokit/Clients/CommitCommentReactionsClient.cs index 000cddb5..34ff4edc 100644 --- a/Octokit/Clients/CommitCommentReactionsClient.cs +++ b/Octokit/Clients/CommitCommentReactionsClient.cs @@ -3,6 +3,12 @@ using System.Threading.Tasks; namespace Octokit { + /// + /// A client for GitHub's Reactions API. + /// + /// + /// See the Reactions API documentation for more information. + /// public class CommitCommentReactionsClient : ApiClient, ICommitCommentReactionsClient { public CommitCommentReactionsClient(IApiConnection apiConnection) @@ -28,6 +34,21 @@ namespace Octokit return ApiConnection.Post(ApiUrls.CommitCommentReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); } + /// + /// Creates a reaction for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// The reaction to create + /// + public Task Create(int repositoryId, int number, NewReaction reaction) + { + Ensure.ArgumentNotNull(reaction, "reaction"); + + return ApiConnection.Post(ApiUrls.CommitCommentReactions(repositoryId, number), reaction, AcceptHeaders.ReactionsPreview); + } + /// /// Get all reactions for a specified Commit Comment /// @@ -43,5 +64,17 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.CommitCommentReactions(owner, name, number), AcceptHeaders.ReactionsPreview); } + + /// + /// Get all reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// + public Task> GetAll(int repositoryId, int number) + { + return ApiConnection.GetAll(ApiUrls.CommitCommentReactions(repositoryId, number), AcceptHeaders.ReactionsPreview); + } } } diff --git a/Octokit/Clients/ICommitCommentReactionsClient.cs b/Octokit/Clients/ICommitCommentReactionsClient.cs index 7e1c73bf..241d4cce 100644 --- a/Octokit/Clients/ICommitCommentReactionsClient.cs +++ b/Octokit/Clients/ICommitCommentReactionsClient.cs @@ -3,6 +3,12 @@ using System.Threading.Tasks; namespace Octokit { + /// + /// A client for GitHub's Reactions API. + /// + /// + /// See the Reactions API documentation for more information. + /// public interface ICommitCommentReactionsClient { /// @@ -16,6 +22,16 @@ namespace Octokit /// Task Create(string owner, string name, int number, NewReaction reaction); + /// + /// Creates a reaction for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// The reaction to create + /// + Task Create(int repositoryId, int number, NewReaction reaction); + /// /// Get all reactions for a specified Commit Comment /// @@ -25,5 +41,14 @@ namespace Octokit /// The comment id /// Task> GetAll(string owner, string name, int number); + + /// + /// Get all reactions for a specified Commit Comment + /// + /// https://developer.github.com/v3/reactions/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The comment id + /// + Task> GetAll(int repositoryId, int number); } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index eee7ad36..2192aebd 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -446,6 +446,17 @@ namespace Octokit return "repos/{0}/{1}/comments/{2}/reactions".FormatUri(owner, name, number); } + /// + /// Returns the for the reaction of a specified commit comment. + /// + /// The ID of the repository + /// The comment number + /// + public static Uri CommitCommentReactions(int repositoryId, int number) + { + return "repositories/{0}/comments/{1}/reactions".FormatUri(repositoryId, number); + } + /// /// Returns the that returns all of the assignees to which issues may be assigned. ///