Skip to content

Commit

Permalink
Merge pull request #1385 from dampir/add-repo-id-pull-request-review-…
Browse files Browse the repository at this point in the history
…comment-reactions-client

Add repositoryId overloads to methods on I(Observable)PullRequestReviewCommentReactionsClient
  • Loading branch information
shiftkey authored Jul 6, 2016
2 parents 79a4749 + 0c1a4e0 commit 3032c74
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
using System;
using System.Collections.Generic;

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 IObservablePullRequestReviewCommentReactionsClient
{
/// <summary>
/// Get all reactions for a specified Pull Request Review Comment.
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The comment id</param>
IObservable<Reaction> GetAll(string owner, string name, int number);

/// <summary>
/// Get all reactions for a specified Pull Request Review Comment.
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="number">The comment id</param>
IObservable<Reaction> GetAll(int repositoryId, int number);

/// <summary>
/// Creates a reaction for a specified Pull Request Review Comment.
/// </summary>
Expand All @@ -13,17 +35,15 @@ public interface IObservablePullRequestReviewCommentReactionsClient
/// <param name="name">The name of the repository</param>
/// <param name="number">The comment id</param>
/// <param name="reaction">The reaction to create</param>
/// <returns></returns>
IObservable<Reaction> Create(string owner, string name, int number, NewReaction reaction);

/// <summary>
/// Get all reactions for a specified Pull Request Review Comment.
/// Creates a reaction for a specified Pull Request Review Comment.
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The comment id</param>
/// <returns></returns>
IObservable<Reaction> GetAll(string owner, string name, int number);
/// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-a-pull-request-review-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>
IObservable<Reaction> Create(int repositoryId, int number, NewReaction reaction);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
using Octokit.Reactive.Internal;
using System;
using System.Collections.Generic;
using System;
using System.Reactive.Threading.Tasks;
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 ObservablePullRequestReviewCommentReactionsClient : IObservablePullRequestReviewCommentReactionsClient
{
readonly IPullRequestReviewCommentReactionsClient _client;
Expand All @@ -18,6 +23,32 @@ public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client)
_connection = client.Connection;
}

/// <summary>
/// Get all reactions for a specified Pull Request Review Comment.
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The comment id</param>
public IObservable<Reaction> GetAll(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return _connection.GetAndFlattenAllPages<Reaction>(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), null, AcceptHeaders.ReactionsPreview);
}

/// <summary>
/// Get all reactions for a specified Pull Request Review Comment.
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="number">The comment id</param>
public IObservable<Reaction> GetAll(int repositoryId, int number)
{
return _connection.GetAndFlattenAllPages<Reaction>(ApiUrls.PullRequestReviewCommentReaction(repositoryId, number), null, AcceptHeaders.ReactionsPreview);
}

/// <summary>
/// Creates a reaction for a specified Pull Request Review Comment.
/// </summary>
Expand All @@ -26,7 +57,6 @@ public ObservablePullRequestReviewCommentReactionsClient(IGitHubClient client)
/// <param name="name">The name 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(string owner, string name, int number, NewReaction reaction)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Expand All @@ -37,19 +67,17 @@ public IObservable<Reaction> Create(string owner, string name, int number, NewRe
}

/// <summary>
/// Get all reactions for a specified Pull Request Review Comment.
/// Creates a reaction for a specified Pull Request Review Comment.
/// </summary>
/// <remarks>https://developer.github.com/v3/reactions/#list-reactions-for-a-pull-request-review-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The comment id</param>
/// <returns></returns>
public IObservable<Reaction> GetAll(string owner, string name, int number)
/// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-a-pull-request-review-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>
public IObservable<Reaction> Create(int repositoryId, int number, NewReaction reaction)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(reaction, "reaction");

return _connection.GetAndFlattenAllPages<Reaction>(ApiUrls.PullRequestReviewCommentReaction(owner, name, number), null, AcceptHeaders.ReactionsPreview);
return _client.Create(repositoryId, number, reaction).ToObservable();
}
}
}
Original file line number Diff line number Diff line change
@@ -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 PullRequestReviewCommentReactionsClientTests : IDisposable
Expand All @@ -26,6 +26,52 @@ public PullRequestReviewCommentReactionsClientTests()
_context = _github.CreateRepositoryContext("test-repo").Result;
}

[IntegrationTest]
public async Task CanListReactions()
{
var pullRequest = await CreatePullRequest(_context);

const string body = "A review comment message";
const int position = 1;

var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number);

var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id);

AssertComment(commentFromGitHub, body, position);

var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id, new NewReaction(ReactionType.Heart));

var reactions = await _github.Reaction.PullRequestReviewComment.GetAll(_context.RepositoryOwner, _context.RepositoryName, commentFromGitHub.Id);

Assert.NotEmpty(reactions);
Assert.Equal(reaction.Id, reactions[0].Id);
Assert.Equal(reaction.Content, reactions[0].Content);
}

[IntegrationTest]
public async Task CanListReactionsWithRepositoryId()
{
var pullRequest = await CreatePullRequest(_context);

const string body = "A review comment message";
const int position = 1;

var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number);

var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id);

AssertComment(commentFromGitHub, body, position);

var reaction = await _github.Reaction.PullRequestReviewComment.Create(_context.Repository.Id, commentFromGitHub.Id, new NewReaction(ReactionType.Heart));

var reactions = await _github.Reaction.PullRequestReviewComment.GetAll(_context.Repository.Id, commentFromGitHub.Id);

Assert.NotEmpty(reactions);
Assert.Equal(reaction.Id, reactions[0].Id);
Assert.Equal(reaction.Content, reactions[0].Content);
}

[IntegrationTest]
public async Task CanCreateReaction()
{
Expand All @@ -52,6 +98,31 @@ public async Task CanCreateReaction()
}
}

[IntegrationTest]
public async Task CanCreateReactionWithRepositoryId()
{
var pullRequest = await CreatePullRequest(_context);

const string body = "A review comment message";
const int position = 1;

var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number);

var commentFromGitHub = await _client.GetComment(Helper.UserName, _context.RepositoryName, createdComment.Id);

AssertComment(commentFromGitHub, body, position);

var pullRequestReviewCommentReaction = await _github.Reaction.PullRequestReviewComment.Create(_context.Repository.Id, commentFromGitHub.Id, new NewReaction(ReactionType.Heart));

Assert.NotNull(pullRequestReviewCommentReaction);

Assert.IsType<Reaction>(pullRequestReviewCommentReaction);

Assert.Equal(ReactionType.Heart, pullRequestReviewCommentReaction.Content);

Assert.Equal(commentFromGitHub.User.Id, pullRequestReviewCommentReaction.User.Id);
}

/// <summary>
/// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request)
/// </summary>
Expand Down Expand Up @@ -155,4 +226,3 @@ class PullRequestData
public string Sha { get; set; }
}
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NSubstitute;
using System;
using System;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;

namespace Octokit.Tests.Clients
Expand All @@ -22,24 +22,35 @@ public class TheGetAllMethod
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new ReactionsClient(connection);
var client = new PullRequestReviewCommentReactionsClient(connection);

client.PullRequestReviewComment.GetAll("fake", "repo", 42);
await client.GetAll("fake", "repo", 42);

connection.Received().GetAll<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/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 PullRequestReviewCommentReactionsClient(connection);

await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequestReviewComment.Create(null, "name", 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentException>(() => client.PullRequestReviewComment.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequestReviewComment.Create("owner", null, 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentException>(() => client.PullRequestReviewComment.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.PullRequestReviewComment.Create("owner", "name", 1, null));
await client.GetAll(1, 42);

connection.Received().GetAll<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/comments/42/reactions"), "application/vnd.github.squirrel-girl-preview");
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestReviewCommentReactionsClient(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));
}
}

Expand All @@ -51,11 +62,40 @@ public void RequestsCorrectUrl()
NewReaction newReaction = new NewReaction(ReactionType.Heart);

var connection = Substitute.For<IApiConnection>();
var client = new ReactionsClient(connection);
var client = new PullRequestReviewCommentReactionsClient(connection);

client.Create("fake", "repo", 1, newReaction);

connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/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 PullRequestReviewCommentReactionsClient(connection);

client.Create(1, 1, newReaction);

connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/comments/1/reactions"), newReaction, "application/vnd.github.squirrel-girl-preview");
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new PullRequestReviewCommentReactionsClient(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));

client.PullRequestReviewComment.Create("fake", "repo", 1, newReaction);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, 1, null));

connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/comments/1/reactions"), Arg.Any<object>(), "application/vnd.github.squirrel-girl-preview");
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", 1, new NewReaction(ReactionType.Heart)));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", 1, new NewReaction(ReactionType.Heart)));
}
}
}
Expand Down
Loading

0 comments on commit 3032c74

Please sign in to comment.