From 18946fb03fac802ef5362e46494988ba50eec7b1 Mon Sep 17 00:00:00 2001 From: maddin2016 Date: Tue, 31 May 2016 14:28:41 +0200 Subject: [PATCH] add IssuesReactionsClient; some fixes --- ...bservableCommitCommentsReactionsClient.cs} | 4 +- .../IObservableIssuesReactionsClient.cs | 28 +++++++++ .../Clients/IObservableReactionsClient.cs | 4 +- ...ObservableCommitCommentsReactionClient.cs} | 12 ++-- .../ObservableIssuesReactionsClient.cs | 54 ++++++++++++++++ .../Clients/ObservableReactionsClient.cs | 11 +++- Octokit.Reactive/Octokit.Reactive-Mono.csproj | 4 ++ .../Octokit.Reactive-MonoAndroid.csproj | 4 ++ .../Octokit.Reactive-Monotouch.csproj | 4 ++ Octokit.Reactive/Octokit.Reactive.csproj | 6 +- ... => CommitCommentsReactionsClientTests.cs} | 18 +++--- .../Clients/IssuesReactionsClientTests.cs | 62 +++++++++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 3 +- ...ervableCommitCommentReactionClientTests.cs | 18 +++--- ...nt.cs => CommitCommentsReactionsClient.cs} | 10 +-- ...t.cs => ICommitCommentsReactionsClient.cs} | 4 +- Octokit/Clients/IIssuesReactionsClient.cs | 29 +++++++++ Octokit/Clients/IReactionsClient.cs | 12 +++- Octokit/Clients/IRepositoryCommentsClient.cs | 2 +- Octokit/Clients/IssuesReactionsClient.cs | 48 ++++++++++++++ Octokit/Clients/ReactionsClient.cs | 19 +++++- Octokit/Helpers/ApiUrls.cs | 14 ++++- Octokit/Octokit-Mono.csproj | 12 ++-- Octokit/Octokit-MonoAndroid.csproj | 10 +-- Octokit/Octokit-Monotouch.csproj | 10 +-- Octokit/Octokit-Portable.csproj | 10 +-- Octokit/Octokit-netcore45.csproj | 10 +-- Octokit/Octokit.csproj | 6 +- 28 files changed, 359 insertions(+), 69 deletions(-) rename Octokit.Reactive/Clients/{IObservableCommitCommentReactionClient.cs => IObservableCommitCommentsReactionsClient.cs} (89%) create mode 100644 Octokit.Reactive/Clients/IObservableIssuesReactionsClient.cs rename Octokit.Reactive/Clients/{ObservableCommitCommentReactionClient.cs => ObservableCommitCommentsReactionClient.cs} (82%) create mode 100644 Octokit.Reactive/Clients/ObservableIssuesReactionsClient.cs rename Octokit.Tests/Clients/{CommitCommentReactionClientTests.cs => CommitCommentsReactionsClientTests.cs} (76%) create mode 100644 Octokit.Tests/Clients/IssuesReactionsClientTests.cs rename Octokit/Clients/{CommitCommentReactionClient.cs => CommitCommentsReactionsClient.cs} (81%) rename Octokit/Clients/{ICommitCommentReactionClient.cs => ICommitCommentsReactionsClient.cs} (90%) create mode 100644 Octokit/Clients/IIssuesReactionsClient.cs create mode 100644 Octokit/Clients/IssuesReactionsClient.cs diff --git a/Octokit.Reactive/Clients/IObservableCommitCommentReactionClient.cs b/Octokit.Reactive/Clients/IObservableCommitCommentsReactionsClient.cs similarity index 89% rename from Octokit.Reactive/Clients/IObservableCommitCommentReactionClient.cs rename to Octokit.Reactive/Clients/IObservableCommitCommentsReactionsClient.cs index 967786cf..a2779000 100644 --- a/Octokit.Reactive/Clients/IObservableCommitCommentReactionClient.cs +++ b/Octokit.Reactive/Clients/IObservableCommitCommentsReactionsClient.cs @@ -2,7 +2,7 @@ namespace Octokit.Reactive { - public interface IObservableCommitCommentReactionClient + public interface IObservableCommitCommentsReactionsClient { /// /// Creates a reaction for an specified Commit Comment @@ -11,7 +11,7 @@ namespace Octokit.Reactive /// The owner of the repository /// The name of the repository /// The comment id - /// The reaction for + /// The reaction to create /// IObservable CreateReaction(string owner, string name, int number, NewReaction reaction); diff --git a/Octokit.Reactive/Clients/IObservableIssuesReactionsClient.cs b/Octokit.Reactive/Clients/IObservableIssuesReactionsClient.cs new file mode 100644 index 00000000..f4982598 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableIssuesReactionsClient.cs @@ -0,0 +1,28 @@ +using System; + +namespace Octokit.Reactive +{ + public interface IObservableIssuesReactionsClient + { + /// + /// Creates a reaction for an specified Commit Comment + /// + /// http://developer.github.com/v3/repos/comments/#create-reaction-for-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue id + /// The reaction to create + /// + IObservable CreateReaction(string owner, string name, int number, NewReaction reaction); + + /// + /// List reactions for a specified Commit Comment + /// + /// http://developer.github.com/v3/repos/comments/#list-reactions-for-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue id + /// + IObservable GetAll(string owner, string name, int number); + } +} diff --git a/Octokit.Reactive/Clients/IObservableReactionsClient.cs b/Octokit.Reactive/Clients/IObservableReactionsClient.cs index f10da108..4ac7125e 100644 --- a/Octokit.Reactive/Clients/IObservableReactionsClient.cs +++ b/Octokit.Reactive/Clients/IObservableReactionsClient.cs @@ -2,6 +2,8 @@ { public interface IObservableReactionsClient { - IObservableCommitCommentReactionClient CommitComments { get; } + IObservableCommitCommentsReactionsClient CommitComment { get; } + + IObservableIssuesReactionsClient Issue { get; } } } diff --git a/Octokit.Reactive/Clients/ObservableCommitCommentReactionClient.cs b/Octokit.Reactive/Clients/ObservableCommitCommentsReactionClient.cs similarity index 82% rename from Octokit.Reactive/Clients/ObservableCommitCommentReactionClient.cs rename to Octokit.Reactive/Clients/ObservableCommitCommentsReactionClient.cs index 6b632fce..8b319132 100644 --- a/Octokit.Reactive/Clients/ObservableCommitCommentReactionClient.cs +++ b/Octokit.Reactive/Clients/ObservableCommitCommentsReactionClient.cs @@ -4,16 +4,16 @@ using Octokit.Reactive.Internal; namespace Octokit.Reactive { - public class ObservableCommitCommentReactionClient : IObservableCommitCommentReactionClient + public class ObservableCommitCommentsReactionClient : IObservableCommitCommentsReactionsClient { - readonly ICommitCommentReactionClient _client; + readonly ICommitCommentsReactionsClient _client; readonly IConnection _connection; - public ObservableCommitCommentReactionClient(IGitHubClient client) + public ObservableCommitCommentsReactionClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); - _client = client.Reaction.CommitComments; + _client = client.Reaction.CommitComment; _connection = client.Connection; } @@ -24,7 +24,7 @@ namespace Octokit.Reactive /// The owner of the repository /// The name of the repository /// The comment id - /// The reaction for + /// The reaction to create /// public IObservable CreateReaction(string owner, string name, int number, NewReaction reaction) { @@ -48,7 +48,7 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return _connection.GetAndFlattenAllPages(ApiUrls.CommitCommentReaction(owner, name, number)); + return _connection.GetAndFlattenAllPages(ApiUrls.CommitCommentReactions(owner, name, number)); } } } diff --git a/Octokit.Reactive/Clients/ObservableIssuesReactionsClient.cs b/Octokit.Reactive/Clients/ObservableIssuesReactionsClient.cs new file mode 100644 index 00000000..04f21468 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableIssuesReactionsClient.cs @@ -0,0 +1,54 @@ +using Octokit.Reactive.Internal; +using System; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + public class ObservableIssuesReactionsClient : IObservableIssuesReactionsClient + { + readonly IIssuesReactionsClient _client; + readonly IConnection _connection; + + public ObservableIssuesReactionsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Reaction.Issue; + _connection = client.Connection; + } + + /// + /// Creates a reaction for a specified Issue + /// + /// http://developer.github.com/v3/repos/comments/#create-reaction-for-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue id + /// The reaction to create + /// + public IObservable CreateReaction(string owner, string name, int number, NewReaction reaction) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(reaction, "reaction"); + + return _client.CreateReaction(owner, name, number, reaction).ToObservable(); + } + + /// + /// List reactions for a specified Commit Comment + /// + /// http://developer.github.com/v3/repos/comments/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// + public IObservable GetAll(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssueReactions(owner, name, number)); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableReactionsClient.cs b/Octokit.Reactive/Clients/ObservableReactionsClient.cs index b94bc723..1f4ed3fb 100644 --- a/Octokit.Reactive/Clients/ObservableReactionsClient.cs +++ b/Octokit.Reactive/Clients/ObservableReactionsClient.cs @@ -1,4 +1,6 @@ -namespace Octokit.Reactive +using System; + +namespace Octokit.Reactive { public class ObservableReactionsClient : IObservableReactionsClient { @@ -6,9 +8,12 @@ { Ensure.ArgumentNotNull(client, "client"); - CommitComments = new ObservableCommitCommentReactionClient(client); + CommitComment = new ObservableCommitCommentsReactionClient(client); + Issue = new ObservableIssuesReactionsClient(client); } - public IObservableCommitCommentReactionClient CommitComments { get; private set; } + public IObservableCommitCommentsReactionsClient CommitComment { get; private set; } + + public IObservableIssuesReactionsClient Issue { get; private set; } } } diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index 08f0a67b..8c0e0bcf 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -186,6 +186,10 @@ + + + + diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index e2b2f8d5..fb339626 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -194,6 +194,10 @@ + + + + diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index 625fcdc1..6fb59a7a 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -190,6 +190,10 @@ + + + + diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index f3bfa18f..ab9b6c20 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -90,7 +90,8 @@ - + + @@ -101,7 +102,8 @@ - + + diff --git a/Octokit.Tests/Clients/CommitCommentReactionClientTests.cs b/Octokit.Tests/Clients/CommitCommentsReactionsClientTests.cs similarity index 76% rename from Octokit.Tests/Clients/CommitCommentReactionClientTests.cs rename to Octokit.Tests/Clients/CommitCommentsReactionsClientTests.cs index 8f7087a0..e8028b15 100644 --- a/Octokit.Tests/Clients/CommitCommentReactionClientTests.cs +++ b/Octokit.Tests/Clients/CommitCommentsReactionsClientTests.cs @@ -5,14 +5,14 @@ using Xunit; namespace Octokit.Tests.Clients { - public class CommitCommentReactionClientTests + public class CommitCommentsReactionsClientTests { public class TheCtor { [Fact] public void EnsuresNonNullArguments() { - Assert.Throws(() => new CommitCommentReactionClient(null)); + Assert.Throws(() => new CommitCommentsReactionsClient(null)); } } @@ -24,7 +24,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new ReactionsClient(connection); - client.CommitComments.GetAll("fake", "repo", 42); + client.CommitComment.GetAll("fake", "repo", 42); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/comments/1/reactions"), "application/vnd.github.squirrel-girl-preview"); } @@ -35,11 +35,11 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new ReactionsClient(connection); - await Assert.ThrowsAsync(() => client.CommitComments.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComments.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComments.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComments.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart))); - await Assert.ThrowsAsync(() => client.CommitComments.CreateReaction("owner", "name", 1, null)); + await Assert.ThrowsAsync(() => client.CommitComment.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.CommitComment.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.CommitComment.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.CommitComment.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.CommitComment.CreateReaction("owner", "name", 1, null)); } } @@ -53,7 +53,7 @@ namespace Octokit.Tests.Clients var connection = Substitute.For(); var client = new ReactionsClient(connection); - client.CommitComments.CreateReaction("fake", "repo", 1, newReaction); + client.CommitComment.CreateReaction("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"); } diff --git a/Octokit.Tests/Clients/IssuesReactionsClientTests.cs b/Octokit.Tests/Clients/IssuesReactionsClientTests.cs new file mode 100644 index 00000000..2a4c3c8e --- /dev/null +++ b/Octokit.Tests/Clients/IssuesReactionsClientTests.cs @@ -0,0 +1,62 @@ +using NSubstitute; +using System; +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class IssuesReactionsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new CommitCommentsReactionsClient(null)); + } + } + + public class TheGetAllMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new ReactionsClient(connection); + + client.CommitComment.GetAll("fake", "repo", 42); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/1/reactions"), "application/vnd.github.squirrel-girl-preview"); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new ReactionsClient(connection); + + await Assert.ThrowsAsync(() => client.Issue.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Issue.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Issue.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Issue.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart))); + await Assert.ThrowsAsync(() => client.Issue.CreateReaction("owner", "name", 1, null)); + } + } + + public class TheCreateMethod + { + [Fact] + public void RequestsCorrectUrl() + { + NewReaction newReaction = new NewReaction(ReactionType.Heart); + + var connection = Substitute.For(); + var client = new ReactionsClient(connection); + + client.CommitComment.CreateReaction("fake", "repo", 1, newReaction); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/1/reactions"), Arg.Any(), "application/vnd.github.squirrel-girl-preview"); + } + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 41c611c2..87c1ed5b 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -85,7 +85,8 @@ - + + diff --git a/Octokit.Tests/Reactive/ObservableCommitCommentReactionClientTests.cs b/Octokit.Tests/Reactive/ObservableCommitCommentReactionClientTests.cs index 3cbb86de..cd23ef15 100644 --- a/Octokit.Tests/Reactive/ObservableCommitCommentReactionClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableCommitCommentReactionClientTests.cs @@ -23,19 +23,19 @@ namespace Octokit.Tests.Reactive [Fact] public void RequestsCorrectUrl() { - _client.CommitComments.GetAll("fake", "repo", 42); - _githubClient.Received().Reaction.CommitComments.GetAll("fake", "repo", 42); + _client.CommitComment.GetAll("fake", "repo", 42); + _githubClient.Received().Reaction.CommitComment.GetAll("fake", "repo", 42); } [Fact] public void EnsuresArgumentsNotNull() { - Assert.Throws(() => _client.CommitComments.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComments.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComments.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComments.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart))); - Assert.Throws(() => _client.CommitComments.CreateReaction("owner", "name", 1, null)); + Assert.Throws(() => _client.CommitComment.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => _client.CommitComment.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => _client.CommitComment.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => _client.CommitComment.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart))); + Assert.Throws(() => _client.CommitComment.CreateReaction("owner", "name", 1, null)); } } @@ -48,8 +48,8 @@ namespace Octokit.Tests.Reactive var client = new ObservableReactionsClient(githubClient); var newReaction = new NewReaction(ReactionType.Confused); - client.CommitComments.CreateReaction("fake", "repo", 1, newReaction); - githubClient.Received().Reaction.CommitComments.CreateReaction("fake", "repo", 1, newReaction); + client.CommitComment.CreateReaction("fake", "repo", 1, newReaction); + githubClient.Received().Reaction.CommitComment.CreateReaction("fake", "repo", 1, newReaction); } } } diff --git a/Octokit/Clients/CommitCommentReactionClient.cs b/Octokit/Clients/CommitCommentsReactionsClient.cs similarity index 81% rename from Octokit/Clients/CommitCommentReactionClient.cs rename to Octokit/Clients/CommitCommentsReactionsClient.cs index 23511324..f81e960c 100644 --- a/Octokit/Clients/CommitCommentReactionClient.cs +++ b/Octokit/Clients/CommitCommentsReactionsClient.cs @@ -3,9 +3,9 @@ using System.Threading.Tasks; namespace Octokit { - public class CommitCommentReactionClient : ApiClient, ICommitCommentReactionClient + public class CommitCommentsReactionsClient : ApiClient, ICommitCommentsReactionsClient { - public CommitCommentReactionClient(IApiConnection apiConnection) + public CommitCommentsReactionsClient(IApiConnection apiConnection) : base(apiConnection) { } @@ -17,7 +17,7 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The comment id - /// The reaction for + /// The reaction to create /// public Task CreateReaction(string owner, string name, int number, NewReaction reaction) { @@ -25,7 +25,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(reaction, "reaction"); - return ApiConnection.Post(ApiUrls.CommitCommentReaction(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); + return ApiConnection.Post(ApiUrls.CommitCommentReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); } /// @@ -41,7 +41,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - return ApiConnection.GetAll(ApiUrls.CommitCommentReaction(owner, name, number), AcceptHeaders.ReactionsPreview); + return ApiConnection.GetAll(ApiUrls.CommitCommentReactions(owner, name, number), AcceptHeaders.ReactionsPreview); } } } diff --git a/Octokit/Clients/ICommitCommentReactionClient.cs b/Octokit/Clients/ICommitCommentsReactionsClient.cs similarity index 90% rename from Octokit/Clients/ICommitCommentReactionClient.cs rename to Octokit/Clients/ICommitCommentsReactionsClient.cs index c3865f10..52af4ed8 100644 --- a/Octokit/Clients/ICommitCommentReactionClient.cs +++ b/Octokit/Clients/ICommitCommentsReactionsClient.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; namespace Octokit { - public interface ICommitCommentReactionClient + public interface ICommitCommentsReactionsClient { /// /// Creates a reaction for an specified Commit Comment @@ -12,7 +12,7 @@ namespace Octokit /// The owner of the repository /// The name of the repository /// The comment id - /// The reaction for + /// The reaction to create /// Task CreateReaction(string owner, string name, int number, NewReaction reaction); diff --git a/Octokit/Clients/IIssuesReactionsClient.cs b/Octokit/Clients/IIssuesReactionsClient.cs new file mode 100644 index 00000000..d62a738c --- /dev/null +++ b/Octokit/Clients/IIssuesReactionsClient.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IIssuesReactionsClient + { + /// + /// Get all reactions for an specified Issue + /// + /// http://developer.github.com/v3/repos/comments/#list-reactions-for-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue id + /// + Task> GetAll(string owner, string name, int number); + + /// + /// Creates a reaction for an specified Issue + /// + /// http://developer.github.com/v3/repos/comments/#create-reaction-for-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue id + /// The reaction to create + /// + Task CreateReaction(string owner, string name, int number, NewReaction reaction); + } +} diff --git a/Octokit/Clients/IReactionsClient.cs b/Octokit/Clients/IReactionsClient.cs index c71a3496..ef610bcd 100644 --- a/Octokit/Clients/IReactionsClient.cs +++ b/Octokit/Clients/IReactionsClient.cs @@ -9,11 +9,19 @@ public interface IReactionsClient { /// - /// Access GitHub's Reactions API. + /// Access GitHub's Reactions API for Commit Comments. /// /// /// Refer to the API documentation for more information: https://developer.github.com/v3/reactions/ /// - ICommitCommentReactionClient CommitComments { get; } + ICommitCommentsReactionsClient CommitComment { get; } + + /// + /// Access GitHub's Reactions API for Issues. + /// + /// + /// Refer to the API documentation for more information: https://developer.github.com/v3/reactions/ + /// + IIssuesReactionsClient Issue { get; } } } diff --git a/Octokit/Clients/IRepositoryCommentsClient.cs b/Octokit/Clients/IRepositoryCommentsClient.cs index 840d36c2..f378dafe 100644 --- a/Octokit/Clients/IRepositoryCommentsClient.cs +++ b/Octokit/Clients/IRepositoryCommentsClient.cs @@ -94,6 +94,6 @@ namespace Octokit /// The name of the repository /// The comment id /// - Task Delete(string owner, string name, int number); + Task Delete(string owner, string name, int number); } } diff --git a/Octokit/Clients/IssuesReactionsClient.cs b/Octokit/Clients/IssuesReactionsClient.cs new file mode 100644 index 00000000..6d7e2d8d --- /dev/null +++ b/Octokit/Clients/IssuesReactionsClient.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public class IssuesReactionsClient : ApiClient, IIssuesReactionsClient + { + public IssuesReactionsClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Creates a reaction for an specified Issue + /// + /// http://developer.github.com/v3/repos/comments/#create-reaction-for-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The issue id + /// The reaction to create + /// + public Task CreateReaction(string owner, string name, int number, NewReaction reaction) + { + Ensure.ArgumentNotNull(owner, "owner"); + Ensure.ArgumentNotNull(name, "name"); + Ensure.ArgumentNotNull(reaction, "reaction"); + + return ApiConnection.Post(ApiUrls.IssueReactions(owner, name, number), reaction, AcceptHeaders.ReactionsPreview); + } + + /// + /// Get all reactions for an specified Issue + /// + /// http://developer.github.com/v3/repos/comments/#list-reactions-for-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The issue id + /// + public Task> GetAll(string owner, string name, int number) + { + Ensure.ArgumentNotNull(owner, "owner"); + Ensure.ArgumentNotNull(name, "name"); + + return ApiConnection.GetAll(ApiUrls.IssueReactions(owner, name, number), AcceptHeaders.ReactionsPreview); + } + } +} diff --git a/Octokit/Clients/ReactionsClient.cs b/Octokit/Clients/ReactionsClient.cs index 6924942e..8bd7c575 100644 --- a/Octokit/Clients/ReactionsClient.cs +++ b/Octokit/Clients/ReactionsClient.cs @@ -9,9 +9,24 @@ public ReactionsClient(IApiConnection apiConnection) : base(apiConnection) { - CommitComments = new CommitCommentReactionClient(apiConnection); + CommitComment = new CommitCommentsReactionsClient(apiConnection); + Issue = new IssuesReactionsClient(apiConnection); } - public ICommitCommentReactionClient CommitComments { get; private set; } + /// + /// Access GitHub's Reactions API for Commit Comments. + /// + /// + /// Refer to the API documentation for more information: https://developer.github.com/v3/reactions/ + /// + public ICommitCommentsReactionsClient CommitComment { get; private set; } + + /// + /// Access GitHub's Reactions API for Issues. + /// + /// + /// Refer to the API documentation for more information: https://developer.github.com/v3/reactions/ + /// + public IIssuesReactionsClient Issue { get; private set; } } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 20d730ae..c65aadb5 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -316,6 +316,18 @@ namespace Octokit return "repos/{0}/{1}/issues/{2}/lock".FormatUri(owner, name, number); } + /// + /// Returns the for the reaction of an specified issue. + /// + /// The owner of the repository + /// The name of the repository + /// The issue number + /// + public static Uri IssueReactions(string owner, string name, int number) + { + return "repos/{0}/{1}/issues/{2}/reactions".FormatUri(owner, name, number); + } + /// /// Returns the for the comments for all issues in a specific repo. /// @@ -393,7 +405,7 @@ namespace Octokit /// The name of the repository /// The comment number /// - public static Uri CommitCommentReaction(string owner, string name, int number) + public static Uri CommitCommentReactions(string owner, string name, int number) { return "repos/{0}/{1}/comments/{2}/reactions".FormatUri(owner, name, number); } diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index ae3e80f4..9911e5b2 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -467,11 +467,13 @@ - - - - - + + + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 9fb7fc9f..6fcb0cf6 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -479,10 +479,12 @@ - - - - + + + + + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 9b4e968a..214aae47 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -475,10 +475,12 @@ - - - - + + + + + + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index ab755f26..8d830ad5 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -465,10 +465,12 @@ - - - - + + + + + + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 91e377ed..b92c367d 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -471,11 +471,13 @@ - - + - - + + + + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index e3545ae9..c46b0aa7 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -58,7 +58,9 @@ Properties\SolutionInfo.cs - + + + @@ -86,7 +88,7 @@ - +