From a01857ecd5b6e1b0acb9f51a8230375c87c03f51 Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Sun, 17 Nov 2013 08:34:23 +1100 Subject: [PATCH 01/23] Implemented pull request review comments API --- ...servablePullRequestReviewCommentsClient.cs | 90 ++++ ...servablePullRequestReviewCommentsClient.cs | 157 ++++++ Octokit.Reactive/Octokit.Reactive.csproj | 4 +- .../PullRequestReviewCommentsClientTests.cs | 312 ++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 2 + ...blePullRequestReviewCommentsClientTests.cs | 456 ++++++++++++++++++ .../IPullRequestReviewCommentsClient.cs | 90 ++++ Octokit/Clients/IPullRequestsClient.cs | 11 + .../PullRequestReviewCommentsClient.cs | 149 ++++++ Octokit/Clients/PullRequestsClient.cs | 16 + Octokit/GitHubClient.cs | 2 + Octokit/Helpers/ApiUrls.cs | 35 ++ Octokit/IGitHubClient.cs | 1 + .../Request/PullRequestReviewCommentCreate.cs | 28 ++ .../Request/PullRequestReviewCommentEdit.cs | 11 + .../PullRequestReviewCommentReplyCreate.cs | 18 + .../PullRequestReviewCommentRequest.cs | 31 ++ .../Response/PullRequestReviewComment.cs | 118 +++++ Octokit/Octokit-Mono.csproj | 9 + Octokit/Octokit-MonoAndroid.csproj | 9 + Octokit/Octokit-Monotouch.csproj | 9 + Octokit/Octokit-netcore45.csproj | 9 + Octokit/Octokit.csproj | 11 +- 23 files changed, 1576 insertions(+), 2 deletions(-) create mode 100644 Octokit.Reactive/Clients/IObservablePullRequestReviewCommentsClient.cs create mode 100644 Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs create mode 100644 Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs create mode 100644 Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs create mode 100644 Octokit/Clients/IPullRequestReviewCommentsClient.cs create mode 100644 Octokit/Clients/IPullRequestsClient.cs create mode 100644 Octokit/Clients/PullRequestReviewCommentsClient.cs create mode 100644 Octokit/Clients/PullRequestsClient.cs create mode 100644 Octokit/Models/Request/PullRequestReviewCommentCreate.cs create mode 100644 Octokit/Models/Request/PullRequestReviewCommentEdit.cs create mode 100644 Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs create mode 100644 Octokit/Models/Request/PullRequestReviewCommentRequest.cs create mode 100644 Octokit/Models/Response/PullRequestReviewComment.cs diff --git a/Octokit.Reactive/Clients/IObservablePullRequestReviewCommentsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestReviewCommentsClient.cs new file mode 100644 index 00000000..89526242 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservablePullRequestReviewCommentsClient.cs @@ -0,0 +1,90 @@ +using System; +using System.Reactive; + +namespace Octokit.Reactive +{ + public interface IObservablePullRequestReviewCommentsClient + { + /// + /// Gets review comments for a specified pull request. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The list of s for the specified pull request + IObservable GetForPullRequest(string owner, string name, int number); + + /// + /// Gets a list of the pull request review comments in a specified repository. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// The list of s for the specified repository + IObservable GetForRepository(string owner, string name); + + /// + /// Gets a list of the pull request review comments in a specified repository. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// The sorting parameters + /// The list of s for the specified repository + IObservable GetForRepository(string owner, string name, PullRequestReviewCommentRequest request); + + /// + /// Gets a single pull request review comment by number. + /// + /// http://developer.github.com/v3/pulls/comments/#get-a-single-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// The + IObservable GetComment(string owner, string name, int number); + + /// + /// Creates a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#create-a-comment + /// The owner of the repository + /// The name of the repository + /// The Pull Request number + /// The comment + /// The created + IObservable Create(string owner, string name, int number, PullRequestReviewCommentCreate comment); + + /// + /// Creates a comment on a pull request review as a reply to another comment. + /// + /// http://developer.github.com/v3/pulls/comments/#create-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The comment + /// The created + IObservable CreateReply(string owner, string name, int number, PullRequestReviewCommentReplyCreate comment); + + /// + /// Edits a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#edit-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// The edited comment + /// The edited + IObservable Edit(string owner, string name, int number, PullRequestReviewCommentEdit comment); + + /// + /// Deletes a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#delete-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// + IObservable Delete(string owner, string name, int number); + } +} diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs new file mode 100644 index 00000000..140bb5a7 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs @@ -0,0 +1,157 @@ +using System; +using System.Reactive; +using System.Reactive.Threading.Tasks; +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive +{ + public class ObservablePullRequestReviewCommentsClient : IObservablePullRequestReviewCommentsClient + { + readonly IPullRequestReviewCommentsClient _client; + readonly IConnection _connection; + + public ObservablePullRequestReviewCommentsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.PullRequest.Comment; + _connection = client.Connection; + } + + /// + /// Gets review comments for a specified pull request. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The list of s for the specified pull request + public IObservable GetForPullRequest(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewComments(owner, name, number)); + } + + /// + /// Gets a list of the pull request review comments in a specified repository. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// The list of s for the specified repository + public IObservable GetForRepository(string owner, string name) + { + return GetForRepository(owner, name, new PullRequestReviewCommentRequest()); + } + + /// + /// Gets a list of the pull request review comments in a specified repository. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// The sorting parameters + /// The list of s for the specified repository + public IObservable GetForRepository(string owner, string name, PullRequestReviewCommentRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(request, "request"); + + return _connection.GetAndFlattenAllPages(ApiUrls.PullRequestReviewCommentsRepository(owner, name), request.ToParametersDictionary()); + } + + /// + /// Gets a single pull request review comment by number. + /// + /// http://developer.github.com/v3/pulls/comments/#get-a-single-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// The + public IObservable GetComment(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.GetComment(owner, name, number).ToObservable(); + } + + /// + /// Creates a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#create-a-comment + /// The owner of the repository + /// The name of the repository + /// The Pull Request number + /// The comment + /// The created + public IObservable Create(string owner, string name, int number, PullRequestReviewCommentCreate comment) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(comment, "comment"); + Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); + Ensure.ArgumentNotNullOrEmptyString(comment.CommitId, "commitId"); + Ensure.ArgumentNotNullOrEmptyString(comment.Path, "path"); + + return _client.Create(owner, name, number, comment).ToObservable(); + } + + /// + /// Creates a comment on a pull request review as a reply to another comment. + /// + /// http://developer.github.com/v3/pulls/comments/#create-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The comment + /// The created + public IObservable CreateReply(string owner, string name, int number, PullRequestReviewCommentReplyCreate comment) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(comment, "comment"); + Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); + + return _client.CreateReply(owner, name, number, comment).ToObservable(); + } + + /// + /// Edits a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#edit-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// The edited comment + /// The edited + public IObservable Edit(string owner, string name, int number, PullRequestReviewCommentEdit comment) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(comment, "comment"); + Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); + + return _client.Edit(owner, name, number, comment).ToObservable(); + } + + /// + /// Deletes a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#delete-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// + public IObservable Delete(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.Delete(owner, name, number).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 2a05fe83..340def6a 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -74,6 +74,7 @@ Properties\SolutionInfo.cs + @@ -97,6 +98,7 @@ + @@ -143,4 +145,4 @@ --> - + \ No newline at end of file diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs new file mode 100644 index 00000000..70b0de76 --- /dev/null +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -0,0 +1,312 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using NSubstitute; +using Octokit; +using Octokit.Tests.Helpers; +using Xunit; + +public class PullRequestReviewCommentsClientTests +{ + public class TheGetForPullRequestMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + client.GetForPullRequest("fakeOwner", "fakeRepoName", 7); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments")); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + await AssertEx.Throws(async () => await client.GetForPullRequest(null, "name", 1)); + await AssertEx.Throws(async () => await client.GetForPullRequest("", "name", 1)); + await AssertEx.Throws(async () => await client.GetForPullRequest("owner", null, 1)); + await AssertEx.Throws(async () => await client.GetForPullRequest("owner", "", 1)); + } + } + + public class TheGetForRepositoryMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var request = new PullRequestReviewCommentRequest + { + Direction = SortDirection.Descending, + Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), + Sort = PullRequestReviewCommentSort.Updated, + }; + + client.GetForRepository("fakeOwner", "fakeRepoName", request); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments"), + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["since"] == "2013-11-15T11:43:01Z" + && d["sort"] == "updated")); + } + + [Fact] + public void RequestsCorrectUrlWithoutSelectedSortingArguments() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + client.GetForRepository("fakeOwner", "fakeRepoName"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments"), + Arg.Is>(d => d.Count == 2 + && d["direction"] == "asc" + && d["sort"] == "created")); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var client = new PullRequestReviewCommentsClient(Substitute.For()); + + var request = new PullRequestReviewCommentRequest(); + + await AssertEx.Throws(async () => await client.GetForRepository(null, "name", request)); + await AssertEx.Throws(async () => await client.GetForRepository("", "name", request)); + await AssertEx.Throws(async () => await client.GetForRepository("owner", null, request)); + await AssertEx.Throws(async () => await client.GetForRepository("owner", "", request)); + await AssertEx.Throws(async () => await client.GetForRepository("owner", "name", null)); + } + + [Fact] + public async Task EnsuresDefaultValues() + { + var request = new PullRequestReviewCommentRequest(); + + Assert.Equal(SortDirection.Ascending, request.Direction); + Assert.Null(request.Since); + Assert.Equal(PullRequestReviewCommentSort.Created, request.Sort); + } + } + + public class TheGetCommentMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + client.GetComment("fakeOwner", "fakeRepoName", 53); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/53"), + null); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var client = new PullRequestReviewCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.GetComment(null, "name", 1)); + await AssertEx.Throws(async () => await client.GetComment("", "name", 1)); + await AssertEx.Throws(async () => await client.GetComment("owner", null, 1)); + await AssertEx.Throws(async () => await client.GetComment("owner", "", 1)); + } + } + + public class TheCreateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var comment = new PullRequestReviewCommentCreate + { + Body = "Comment content", + CommitId = "qe3dsdsf6", + Path = "file.css", + Position = 7, + }; + + client.Create("fakeOwner", "fakeRepoName", 13, comment); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), + comment); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + string body = "Comment content"; + string commitId = "qe3dsdsf6"; + string path = "file.css"; + int position = 7; + + var comment = new PullRequestReviewCommentCreate + { + Body = body, + CommitId = commitId, + Path = path, + Position = position, + }; + + await AssertEx.Throws(async () => await client.Create(null, "fakeRepoName", 1, comment)); + await AssertEx.Throws(async () => await client.Create("", "fakeRepoName", 1, comment)); + await AssertEx.Throws(async () => await client.Create("fakeOwner", null, 1, comment)); + await AssertEx.Throws(async () => await client.Create("fakeOwner", "", 1, comment)); + await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, null)); + + comment.Body = null; + await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); + comment.Body = ""; + await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); + comment.Body = body; + + comment.CommitId = null; + await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); + comment.CommitId = ""; + await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); + comment.CommitId = commitId; + + comment.Path = null; + await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); + comment.Path = ""; + await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); + comment.Path = path; + } + } + + public class TheCreateReplyMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var comment = new PullRequestReviewCommentReplyCreate + { + Body = "Comment content", + InReplyTo = 5 + }; + + client.CreateReply("fakeOwner", "fakeRepoName", 13, comment); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), + comment); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + string body = "Comment content"; + int inReplyTo = 7; + + var comment = new PullRequestReviewCommentReplyCreate + { + Body = body, + InReplyTo = inReplyTo, + }; + + await AssertEx.Throws(async () => await client.CreateReply(null, "fakeRepoName", 1, comment)); + await AssertEx.Throws(async () => await client.CreateReply("", "fakeRepoName", 1, comment)); + await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", null, 1, comment)); + await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "", 1, comment)); + await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "fakeRepoName", 1, null)); + + comment.Body = null; + await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "fakeRepoName", 1, comment)); + comment.Body = ""; + await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "fakeRepoName", 1, comment)); + comment.Body = body; + } + } + + public class TheEditMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var comment = new PullRequestReviewCommentEdit + { + Body = "New comment content", + }; + + client.Edit("fakeOwner", "fakeRepoName", 13, comment); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/13"), comment); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + var body = "New comment content"; + + var comment = new PullRequestReviewCommentEdit + { + Body = body, + }; + + await AssertEx.Throws(async () => await client.Edit(null, "fakeRepoName", 1, comment)); + await AssertEx.Throws(async () => await client.Edit("", "fakeRepoName", 1, comment)); + await AssertEx.Throws(async () => await client.Edit("fakeOwner", null, 1, comment)); + await AssertEx.Throws(async () => await client.Edit("fakeOwner", "", 1, comment)); + await AssertEx.Throws(async () => await client.Edit("fakeOwner", null, 1, null)); + + comment.Body = null; + await AssertEx.Throws(async () => await client.Edit("fakeOwner", "fakeRepoName", 1, comment)); + comment.Body = ""; + await AssertEx.Throws(async () => await client.Edit("fakeOwner", "fakeRepoName", 1, comment)); + comment.Body = body; + } + } + + public class TheDeleteMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + client.Delete("fakeOwner", "fakeRepoName", 13); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/comments/13")); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var connection = Substitute.For(); + var client = new PullRequestReviewCommentsClient(connection); + + await AssertEx.Throws(async () => await client.Delete(null, "fakeRepoName", 1)); + await AssertEx.Throws(async () => await client.Delete("", "fakeRepoName", 1)); + await AssertEx.Throws(async () => await client.Delete("fakeOwner", null, 1)); + await AssertEx.Throws(async () => await client.Delete("fakeOwner", "", 1)); + } + } +} diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index cff9ef07..2450c067 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -66,6 +66,7 @@ + @@ -122,6 +123,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs new file mode 100644 index 00000000..6d1d3e98 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs @@ -0,0 +1,456 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Linq; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Internal; +using Octokit.Reactive; +using Octokit.Tests.Helpers; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservablePullRequestReviewCommentsClientTests + { + static ApiInfo CreateApiInfo(IDictionary links) + { + return new ApiInfo(links, new List(), new List(), "etag", new RateLimit(new Dictionary())); + } + + public class TheGetForPullRequestMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var firstPageUrl = new Uri("repos/fakeOwner/fakeRepoName/pulls/7/comments", UriKind.Relative); + var secondPageUrl = new Uri("https://example.com/page/2"); + var firstPageLinks = new Dictionary { { "next", secondPageUrl } }; + var firstPageResponse = new ApiResponse> + { + BodyAsObject = new List + { + new PullRequestReviewComment {Id = 1}, + new PullRequestReviewComment {Id = 2}, + new PullRequestReviewComment {Id = 3} + }, + ApiInfo = CreateApiInfo(firstPageLinks) + }; + var thirdPageUrl = new Uri("https://example.com/page/3"); + var secondPageLinks = new Dictionary { { "next", thirdPageUrl } }; + var secondPageResponse = new ApiResponse> + { + BodyAsObject = new List + { + new PullRequestReviewComment {Id = 4}, + new PullRequestReviewComment {Id = 5}, + new PullRequestReviewComment {Id = 6} + }, + ApiInfo = CreateApiInfo(secondPageLinks) + }; + var lastPageResponse = new ApiResponse> + { + BodyAsObject = new List + { + new PullRequestReviewComment {Id = 7} + }, + ApiInfo = CreateApiInfo(new Dictionary()) + }; + + var gitHubClient = Substitute.For(); + gitHubClient.Connection.GetAsync>(firstPageUrl) + .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + gitHubClient.Connection.GetAsync>(secondPageUrl) + .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + gitHubClient.Connection.GetAsync>(thirdPageUrl) + .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + var results = await client.GetForPullRequest("fakeOwner", "fakeRepoName", 7).ToArray(); + + Assert.Equal(7, results.Length); + gitHubClient.Connection.Received(1).GetAsync>(firstPageUrl, null, null); + gitHubClient.Connection.Received(1).GetAsync>(secondPageUrl, null, null); + gitHubClient.Connection.Received(1).GetAsync>(thirdPageUrl, null, null); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + await AssertEx.Throws(async () => await client.GetForPullRequest(null, "name", 1)); + await AssertEx.Throws(async () => await client.GetForPullRequest("", "name", 1)); + await AssertEx.Throws(async () => await client.GetForPullRequest("owner", null, 1)); + await AssertEx.Throws(async () => await client.GetForPullRequest("owner", "", 1)); + await AssertEx.Throws(async () => await client.GetForPullRequest(null, null, 1)); + await AssertEx.Throws(async () => await client.GetForPullRequest("", "", 1)); + } + } + + public class TheGetForRepositoryMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var firstPageUrl = new Uri("repos/fakeOwner/fakeRepoName/pulls/comments", UriKind.Relative); + var secondPageUrl = new Uri("https://example.com/page/2"); + var firstPageLinks = new Dictionary { { "next", secondPageUrl } }; + var firstPageResponse = new ApiResponse> + { + BodyAsObject = new List + { + new PullRequestReviewComment {Id = 1}, + new PullRequestReviewComment {Id = 2}, + new PullRequestReviewComment {Id = 3} + }, + ApiInfo = CreateApiInfo(firstPageLinks) + }; + var thirdPageUrl = new Uri("https://example.com/page/3"); + var secondPageLinks = new Dictionary { { "next", thirdPageUrl } }; + var secondPageResponse = new ApiResponse> + { + BodyAsObject = new List + { + new PullRequestReviewComment {Id = 4}, + new PullRequestReviewComment {Id = 5}, + new PullRequestReviewComment {Id = 6} + }, + ApiInfo = CreateApiInfo(secondPageLinks) + }; + var lastPageResponse = new ApiResponse> + { + BodyAsObject = new List + { + new PullRequestReviewComment {Id = 7}, + new PullRequestReviewComment {Id = 8}, + }, + ApiInfo = CreateApiInfo(new Dictionary()) + }; + + var gitHubClient = Substitute.For(); + + gitHubClient.Connection.GetAsync>(firstPageUrl, + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["since"] == "2013-11-15T11:43:01Z" + && d["sort"] == "updated"), null) + .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + gitHubClient.Connection.GetAsync>(secondPageUrl, null, null) + .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + gitHubClient.Connection.GetAsync>(thirdPageUrl, null, null) + .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + var request = new PullRequestReviewCommentRequest + { + Direction = SortDirection.Descending, + Since = new DateTimeOffset(2013, 11, 15, 11, 43, 01, 00, new TimeSpan()), + Sort = PullRequestReviewCommentSort.Updated, + }; + + var results = await client.GetForRepository("fakeOwner", "fakeRepoName", request).ToArray(); + + Assert.Equal(8, results.Length); + gitHubClient.Connection.Received(1).GetAsync>(firstPageUrl, + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["since"] == "2013-11-15T11:43:01Z" + && d["sort"] == "updated"), null); + gitHubClient.Connection.Received(1).GetAsync>(secondPageUrl, null, null); + gitHubClient.Connection.Received(1).GetAsync>(thirdPageUrl, null, null); + } + + [Fact] + public async Task RequestsCorrectUrlWithoutSelectedSortingArguments() + { + var firstPageUrl = new Uri("repos/fakeOwner/fakeRepoName/pulls/comments", UriKind.Relative); + var secondPageUrl = new Uri("https://example.com/page/2"); + var firstPageLinks = new Dictionary { { "next", secondPageUrl } }; + var firstPageResponse = new ApiResponse> + { + BodyAsObject = new List + { + new PullRequestReviewComment {Id = 1}, + new PullRequestReviewComment {Id = 2}, + new PullRequestReviewComment {Id = 3} + }, + ApiInfo = CreateApiInfo(firstPageLinks) + }; + var thirdPageUrl = new Uri("https://example.com/page/3"); + var secondPageLinks = new Dictionary { { "next", thirdPageUrl } }; + var secondPageResponse = new ApiResponse> + { + BodyAsObject = new List + { + new PullRequestReviewComment {Id = 4}, + new PullRequestReviewComment {Id = 5}, + new PullRequestReviewComment {Id = 6} + }, + ApiInfo = CreateApiInfo(secondPageLinks) + }; + var lastPageResponse = new ApiResponse> + { + BodyAsObject = new List + { + new PullRequestReviewComment {Id = 7}, + new PullRequestReviewComment {Id = 8}, + }, + ApiInfo = CreateApiInfo(new Dictionary()) + }; + + var gitHubClient = Substitute.For(); + + gitHubClient.Connection.GetAsync>(firstPageUrl, + Arg.Is>(d => d.Count == 2 + && d["direction"] == "asc" + && d["sort"] == "created"), null) + .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); + gitHubClient.Connection.GetAsync>(secondPageUrl, null, null) + .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); + gitHubClient.Connection.GetAsync>(thirdPageUrl, null, null) + .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); + + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + var results = await client.GetForRepository("fakeOwner", "fakeRepoName").ToArray(); + + Assert.Equal(8, results.Length); + gitHubClient.Connection.Received(1).GetAsync>(firstPageUrl, + Arg.Is>(d => d.Count == 2 + && d["direction"] == "asc" + && d["sort"] == "created"), null); + gitHubClient.Connection.Received(1).GetAsync>(secondPageUrl, null, null); + gitHubClient.Connection.Received(1).GetAsync>(thirdPageUrl, null, null); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var client = new ObservablePullRequestReviewCommentsClient(Substitute.For()); + + var request = new PullRequestReviewCommentRequest(); + + await AssertEx.Throws(async () => await client.GetForRepository(null, "name", request)); + await AssertEx.Throws(async () => await client.GetForRepository("", "name", request)); + await AssertEx.Throws(async () => await client.GetForRepository("owner", null, request)); + await AssertEx.Throws(async () => await client.GetForRepository("owner", "", request)); + await AssertEx.Throws(async () => await client.GetForRepository("owner", "name", null)); + } + } + + public class TheGetCommentMethod + { + [Fact] + public void GetsFromClientPullRequestComment() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + client.GetComment("fakeOwner", "fakeRepoName", 53); + + gitHubClient.PullRequest.Comment.Received().GetComment("fakeOwner", "fakeRepoName", 53); + } + + [Fact] + public async Task EnsuresArgumentsNonNull() + { + var client = new ObservablePullRequestReviewCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.GetComment(null, "name", 1)); + await AssertEx.Throws(async () => await client.GetComment("", "name", 1)); + await AssertEx.Throws(async () => await client.GetComment("owner", null, 1)); + await AssertEx.Throws(async () => await client.GetComment("owner", "", 1)); + await AssertEx.Throws(async () => await client.GetComment(null, null, 1)); + await AssertEx.Throws(async () => await client.GetComment("", "", 1)); + } + } + + public class TheCreateMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + var comment = new PullRequestReviewCommentCreate + { + Body = "Comment content", + CommitId = "qe3dsdsf6", + Path = "file.css", + Position = 7, + }; + + client.Create("fakeOwner", "fakeRepoName", 13, comment); + + gitHubClient.PullRequest.Comment.Received().Create("fakeOwner", "fakeRepoName", 13, comment); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + string body = "Comment content"; + string commitId = "qe3dsdsf6"; + string path = "file.css"; + int position = 7; + + var comment = new PullRequestReviewCommentCreate + { + Body = body, + CommitId = commitId, + Path = path, + Position = position, + }; + + await AssertEx.Throws(async () => await client.Create(null, "name", 1, comment)); + await AssertEx.Throws(async () => await client.Create("", "name", 1, comment)); + await AssertEx.Throws(async () => await client.Create("owner", null, 1, comment)); + await AssertEx.Throws(async () => await client.Create("owner", "", 1, comment)); + await AssertEx.Throws(async () => await client.Create("owner", "name", 1, null)); + + comment.Body = null; + await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); + comment.Body = ""; + await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); + comment.Body = body; + + comment.CommitId = null; + await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); + comment.CommitId = ""; + await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); + comment.CommitId = commitId; + + comment.Path = null; + await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); + comment.Path = ""; + await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); + comment.Path = path; + } + } + + public class TheCreateReplyMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + var comment = new PullRequestReviewCommentReplyCreate + { + Body = "Comment content", + InReplyTo = 9, + }; + + client.CreateReply("fakeOwner", "fakeRepoName", 13, comment); + + gitHubClient.PullRequest.Comment.Received().CreateReply("fakeOwner", "fakeRepoName", 13, comment); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + string body = "Comment content"; + int inReplyTo = 7; + + var comment = new PullRequestReviewCommentReplyCreate + { + Body = body, + InReplyTo = inReplyTo, + }; + + await AssertEx.Throws(async () => await client.CreateReply(null, "name", 1, comment)); + await AssertEx.Throws(async () => await client.CreateReply("", "name", 1, comment)); + await AssertEx.Throws(async () => await client.CreateReply("owner", null, 1, comment)); + await AssertEx.Throws(async () => await client.CreateReply("owner", "", 1, comment)); + await AssertEx.Throws(async () => await client.CreateReply("owner", "name", 1, null)); + + comment.Body = null; + await AssertEx.Throws(async () => await client.CreateReply("owner", "name", 1, comment)); + comment.Body = ""; + await AssertEx.Throws(async () => await client.CreateReply("owner", "name", 1, comment)); + comment.Body = body; + } + } + + public class TheEditMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + var comment = new PullRequestReviewCommentEdit + { + Body = "New comment content", + }; + + client.Edit("fakeOwner", "fakeRepoName", 13, comment); + + gitHubClient.PullRequest.Comment.Received().Edit("fakeOwner", "fakeRepoName", 13, comment); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + var body = "New comment content"; + + var comment = new PullRequestReviewCommentEdit + { + Body = body, + }; + + await AssertEx.Throws(async () => await client.Edit(null, "name", 1, comment)); + await AssertEx.Throws(async () => await client.Edit("", "name", 1, comment)); + await AssertEx.Throws(async () => await client.Edit("owner", null, 1, comment)); + await AssertEx.Throws(async () => await client.Edit("owner", "", 1, comment)); + await AssertEx.Throws(async () => await client.Edit("owner", "name", 1, null)); + + comment.Body = null; + await AssertEx.Throws(async () => await client.Edit("owner", "name", 1, comment)); + comment.Body = ""; + await AssertEx.Throws(async () => await client.Edit("owner", "name", 1, comment)); + comment.Body = body; + } + } + + public class TheDeleteMethod + { + [Fact] + public void PostsToCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + client.Delete("fakeOwner", "fakeRepoName", 13); + + gitHubClient.PullRequest.Comment.Received().Delete("fakeOwner", "fakeRepoName", 13); + } + + [Fact] + public async Task EnsuresArgumentsNotNull() + { + var gitHubClient = Substitute.For(); + var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); + + await AssertEx.Throws(async () => await client.Delete(null, "name", 1)); + await AssertEx.Throws(async () => await client.Delete("", "name", 1)); + await AssertEx.Throws(async () => await client.Delete("owner", null, 1)); + await AssertEx.Throws(async () => await client.Delete("owner", "", 1)); + } + } + } +} diff --git a/Octokit/Clients/IPullRequestReviewCommentsClient.cs b/Octokit/Clients/IPullRequestReviewCommentsClient.cs new file mode 100644 index 00000000..37cd15b4 --- /dev/null +++ b/Octokit/Clients/IPullRequestReviewCommentsClient.cs @@ -0,0 +1,90 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IPullRequestReviewCommentsClient + { + /// + /// Gets review comments for a specified pull request. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The list of s for the specified pull request + Task> GetForPullRequest(string owner, string name, int number); + + /// + /// Gets a list of the pull request review comments in a specified repository. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// The list of s for the specified repository + Task> GetForRepository(string owner, string name); + + /// + /// Gets a list of the pull request review comments in a specified repository. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// The sorting parameters + /// The list of s for the specified repository + Task> GetForRepository(string owner, string name, PullRequestReviewCommentRequest request); + + /// + /// Gets a single pull request review comment by number. + /// + /// http://developer.github.com/v3/pulls/comments/#get-a-single-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// The + Task GetComment(string owner, string name, int number); + + /// + /// Creates a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#create-a-comment + /// The owner of the repository + /// The name of the repository + /// The Pull Request number + /// The comment + /// The created + Task Create(string owner, string name, int number, PullRequestReviewCommentCreate comment); + + /// + /// Creates a comment on a pull request review as a reply to another comment. + /// + /// http://developer.github.com/v3/pulls/comments/#create-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The comment + /// The created + Task CreateReply(string owner, string name, int number, PullRequestReviewCommentReplyCreate comment); + + /// + /// Edits a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#edit-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// The edited comment + /// The edited + Task Edit(string owner, string name, int number, PullRequestReviewCommentEdit comment); + + /// + /// Deletes a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#delete-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// + Task Delete(string owner, string name, int number); + } +} diff --git a/Octokit/Clients/IPullRequestsClient.cs b/Octokit/Clients/IPullRequestsClient.cs new file mode 100644 index 00000000..1870c65b --- /dev/null +++ b/Octokit/Clients/IPullRequestsClient.cs @@ -0,0 +1,11 @@ + +namespace Octokit +{ + public interface IPullRequestsClient + { + /// + /// Client for managing comments. + /// + IPullRequestReviewCommentsClient Comment { get; } + } +} diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs new file mode 100644 index 00000000..6c049b19 --- /dev/null +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -0,0 +1,149 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + public class PullRequestReviewCommentsClient : ApiClient, IPullRequestReviewCommentsClient + { + public PullRequestReviewCommentsClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Gets review comments for a specified pull request. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The list of s for the specified pull request + public Task> GetForPullRequest(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.GetAll(ApiUrls.PullRequestReviewComments(owner, name, number)); + } + + /// + /// Gets a list of the pull request review comments in a specified repository. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// The list of s for the specified repository + public Task> GetForRepository(string owner, string name) + { + return GetForRepository(owner, name, new PullRequestReviewCommentRequest()); + } + + /// + /// Gets a list of the pull request review comments in a specified repository. + /// + /// http://developer.github.com/v3/pulls/comments/#list-comments-in-a-repository + /// The owner of the repository + /// The name of the repository + /// The sorting parameters + /// The list of s for the specified repository + public Task> GetForRepository(string owner, string name, PullRequestReviewCommentRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(request, "request"); + + return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentsRepository(owner, name), request.ToParametersDictionary()); + } + + /// + /// Gets a single pull request review comment by number. + /// + /// http://developer.github.com/v3/pulls/comments/#get-a-single-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// The + public Task GetComment(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.Get(ApiUrls.PullRequestReviewComment(owner, name, number)); + } + + /// + /// Creates a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#create-a-comment + /// The owner of the repository + /// The name of the repository + /// The Pull Request number + /// The comment + /// The created + public Task Create(string owner, string name, int number, PullRequestReviewCommentCreate comment) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(comment, "comment"); + Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); + Ensure.ArgumentNotNullOrEmptyString(comment.CommitId, "commitId"); + Ensure.ArgumentNotNullOrEmptyString(comment.Path, "path"); + + return ApiConnection.Post(ApiUrls.PullRequestReviewComments(owner, name, number), comment); + } + + /// + /// Creates a comment on a pull request review as a reply to another comment. + /// + /// http://developer.github.com/v3/pulls/comments/#create-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The comment + /// The created + public Task CreateReply(string owner, string name, int number, PullRequestReviewCommentReplyCreate comment) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(comment, "comment"); + Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); + + return ApiConnection.Post(ApiUrls.PullRequestReviewComments(owner, name, number), comment); + } + + /// + /// Edits a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#edit-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// The edited comment + /// The edited + public Task Edit(string owner, string name, int number, PullRequestReviewCommentEdit comment) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(comment, "comment"); + Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); + + return ApiConnection.Patch(ApiUrls.PullRequestReviewComment(owner, name, number), comment); + } + + /// + /// Deletes a comment on a pull request review. + /// + /// http://developer.github.com/v3/pulls/comments/#delete-a-comment + /// The owner of the repository + /// The name of the repository + /// The pull request review comment number + /// + public Task Delete(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.Delete(ApiUrls.PullRequestReviewComment(owner, name, number)); + } + } +} diff --git a/Octokit/Clients/PullRequestsClient.cs b/Octokit/Clients/PullRequestsClient.cs new file mode 100644 index 00000000..6e37d11c --- /dev/null +++ b/Octokit/Clients/PullRequestsClient.cs @@ -0,0 +1,16 @@ + +namespace Octokit +{ + public class PullRequestsClient : ApiClient, IPullRequestsClient + { + public PullRequestsClient(IApiConnection apiConnection) : base(apiConnection) + { + Comment = new PullRequestReviewCommentsClient(apiConnection); + } + + /// + /// Client for managing comments. + /// + public IPullRequestReviewCommentsClient Comment { get; private set; } + } +} diff --git a/Octokit/GitHubClient.cs b/Octokit/GitHubClient.cs index 9bbcd384..275d4074 100644 --- a/Octokit/GitHubClient.cs +++ b/Octokit/GitHubClient.cs @@ -85,6 +85,7 @@ namespace Octokit Miscellaneous = new MiscellaneousClient(connection); Notification = new NotificationsClient(apiConnection); Organization = new OrganizationsClient(apiConnection); + PullRequest = new PullRequestsClient(apiConnection); Repository = new RepositoriesClient(apiConnection); Release = new ReleasesClient(apiConnection); User = new UsersClient(apiConnection); @@ -131,6 +132,7 @@ namespace Octokit public IIssuesClient Issue { get; private set; } public IMiscellaneousClient Miscellaneous { get; private set; } public IOrganizationsClient Organization { get; private set; } + public IPullRequestsClient PullRequest { get; private set; } public IRepositoriesClient Repository { get; private set; } public IReleasesClient Release { get; private set; } public ISshKeysClient SshKey { get; private set; } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index be8ebd59..dbe30dfb 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -548,5 +548,40 @@ namespace Octokit { return "users/{0}/events/orgs/{1}".FormatUri(user, organization); } + + /// + /// Returns the for the comments of a specified pull request review. + /// + /// The owner of the repository + /// The name of the repository + /// The pull request number + /// The + public static Uri PullRequestReviewComments(string owner, string name, int number) + { + return "repos/{0}/{1}/pulls/{2}/comments".FormatUri(owner, name, number); + } + + /// + /// Returns the for the specified pull request review comment. + /// + /// The owner of the repository + /// The name of the repository + /// The comment number + /// The + public static Uri PullRequestReviewComment(string owner, string name, int number) + { + return "repos/{0}/{1}/pulls/comments/{2}".FormatUri(owner, name, number); + } + + /// + /// Returns the for the pull request review comments on a specified repository. + /// + /// The owner of the repository + /// The name of the repository + /// The + public static Uri PullRequestReviewCommentsRepository(string owner, string name) + { + return "repos/{0}/{1}/pulls/comments".FormatUri(owner, name); + } } } diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index c8586208..2e6b8ec0 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -11,6 +11,7 @@ namespace Octokit IIssuesClient Issue { get; } IMiscellaneousClient Miscellaneous { get; } IOrganizationsClient Organization { get; } + IPullRequestsClient PullRequest { get; } IRepositoriesClient Repository { get; } IReleasesClient Release { get; } ISshKeysClient SshKey { get; } diff --git a/Octokit/Models/Request/PullRequestReviewCommentCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs new file mode 100644 index 00000000..08e9e581 --- /dev/null +++ b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs @@ -0,0 +1,28 @@ +using Octokit.Internal; + +namespace Octokit +{ + public class PullRequestReviewCommentCreate : RequestParameters + { + /// + /// The text of the comment. + /// + public string Body { get; set; } + + /// + /// The SHA of the commit to comment on. + /// + [Parameter(Key = "commit_id")] + public string CommitId { get; set; } + + /// + /// The relative path of the file to comment on. + /// + public string Path { get; set; } + + /// + /// The line index in the diff to comment on. + /// + public int Position { get; set; } + } +} diff --git a/Octokit/Models/Request/PullRequestReviewCommentEdit.cs b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs new file mode 100644 index 00000000..1ad6f0ba --- /dev/null +++ b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs @@ -0,0 +1,11 @@ + +namespace Octokit +{ + public class PullRequestReviewCommentEdit : RequestParameters + { + /// + /// The text of the comment. + /// + public string Body { get; set; } + } +} diff --git a/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs new file mode 100644 index 00000000..a8e23599 --- /dev/null +++ b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs @@ -0,0 +1,18 @@ +using Octokit.Internal; + +namespace Octokit +{ + public class PullRequestReviewCommentReplyCreate : RequestParameters + { + /// + /// The text of the comment. + /// + public string Body { get; set; } + + /// + /// The comment Id to reply to. + /// + [Parameter(Key = "in_reply_to")] + public int InReplyTo { get; set; } + } +} diff --git a/Octokit/Models/Request/PullRequestReviewCommentRequest.cs b/Octokit/Models/Request/PullRequestReviewCommentRequest.cs new file mode 100644 index 00000000..125f8059 --- /dev/null +++ b/Octokit/Models/Request/PullRequestReviewCommentRequest.cs @@ -0,0 +1,31 @@ +using System; + +namespace Octokit +{ + public class PullRequestReviewCommentRequest : RequestParameters + { + public PullRequestReviewCommentRequest() + { + // Default arguments + + Sort = PullRequestReviewCommentSort.Created; + Direction = SortDirection.Ascending; + Since = null; + } + + /// + /// Can be either created or updated. Default: created. + /// + public PullRequestReviewCommentSort Sort { get; set; } + + /// + /// Can be either asc or desc. Default: asc. + /// + public SortDirection Direction { get; set; } + + /// + /// Only comments updated at or after this time are returned. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. + /// + public DateTimeOffset? Since { get; set; } + } +} diff --git a/Octokit/Models/Response/PullRequestReviewComment.cs b/Octokit/Models/Response/PullRequestReviewComment.cs new file mode 100644 index 00000000..734be9f2 --- /dev/null +++ b/Octokit/Models/Response/PullRequestReviewComment.cs @@ -0,0 +1,118 @@ +using System; + +namespace Octokit +{ + public class PullRequestReviewComment + { + /// + /// URL of the comment via the API. + /// + public Uri Url { get; set; } + + /// + /// The comment Id. + /// + public int Id { get; set; } + + /// + /// The diff hunk the comment is about. + /// + public string DiffHunk { get; set; } + + /// + /// The relative path of the file the comment is about. + /// + public string Path { get; set; } + + /// + /// The line index in the diff. + /// + public int? Position { get; set; } + + /// + /// The comment original position. + /// + public int? OriginalPosition { get; set; } + + /// + /// The commit Id the comment is associated with. + /// + public string CommitId { get; set; } + + /// + /// The original commit Id the comment is associated with. + /// + public string OriginalCommitId { get; set; } + + /// + /// The user that created the comment. + /// + public User User { get; set; } + + /// + /// The text of the comment. + /// + public string Body { get; set; } + + /// + /// The date the comment was created. + /// + public DateTimeOffset CreatedAt { get; set; } + + /// + /// The date the comment was last updated. + /// + public DateTimeOffset UpdatedAt { get; set; } + + /// + /// The URL for this comment on Github.com + /// + public Uri HtmlUrl { get; set; } + + /// + /// The URL for the pull request via the API. + /// + public Uri PullRequestUrl { get; set; } + + /// + /// Contains Url, HtmlUrl and PullRequestUrl + /// + public PullRequestReviewCommentLinks Links { get; set; } + } + + public class PullRequestReviewCommentLinks + { + /// + /// URL of the comment via the API. + /// + public PullRequestReviewCommentLink Self { get; set; } + + /// + /// The URL for this comment on Github.com + /// + public PullRequestReviewCommentLink Html { get; set; } + + /// + /// The URL for the pull request via the API. + /// + public PullRequestReviewCommentLink PullRequest { get; set; } + } + + public class PullRequestReviewCommentLink + { + public Uri Href { get; set; } + } + + public enum PullRequestReviewCommentSort + { + /// + /// Sort by create date (default) + /// + Created, + + /// + /// Sort by the date of the last update + /// + Updated, + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index b6d6d656..0d1ca16b 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -48,6 +48,14 @@ + + + + + + + + @@ -104,6 +112,7 @@ + diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 495049cd..1e97295a 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -58,6 +58,14 @@ + + + + + + + + @@ -103,6 +111,7 @@ + diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index eb9acc49..400e98aa 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -53,6 +53,14 @@ + + + + + + + + @@ -98,6 +106,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index fdd69ff7..db97e0ee 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -58,6 +58,10 @@ + + + + @@ -200,6 +204,11 @@ + + + + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index b457bda0..f981c584 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -55,6 +55,14 @@ + + + + + + + + @@ -95,6 +103,7 @@ + @@ -237,4 +246,4 @@ --> - + \ No newline at end of file From 6ad1192abd67ec7920268053bf1633b743fa1625 Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Thu, 21 Nov 2013 11:20:10 +1100 Subject: [PATCH 02/23] Removed _links field from review comment --- .../Response/PullRequestReviewComment.cs | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/Octokit/Models/Response/PullRequestReviewComment.cs b/Octokit/Models/Response/PullRequestReviewComment.cs index 734be9f2..14807e07 100644 --- a/Octokit/Models/Response/PullRequestReviewComment.cs +++ b/Octokit/Models/Response/PullRequestReviewComment.cs @@ -73,34 +73,6 @@ namespace Octokit /// The URL for the pull request via the API. /// public Uri PullRequestUrl { get; set; } - - /// - /// Contains Url, HtmlUrl and PullRequestUrl - /// - public PullRequestReviewCommentLinks Links { get; set; } - } - - public class PullRequestReviewCommentLinks - { - /// - /// URL of the comment via the API. - /// - public PullRequestReviewCommentLink Self { get; set; } - - /// - /// The URL for this comment on Github.com - /// - public PullRequestReviewCommentLink Html { get; set; } - - /// - /// The URL for the pull request via the API. - /// - public PullRequestReviewCommentLink PullRequest { get; set; } - } - - public class PullRequestReviewCommentLink - { - public Uri Href { get; set; } } public enum PullRequestReviewCommentSort From 090b078a1afd081c140cce47775d97e7ba2f4dfe Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Thu, 21 Nov 2013 16:48:49 +1100 Subject: [PATCH 03/23] Added basic integration testing for review comments client --- .../Octokit.Tests.Integration.csproj | 1 + .../PullRequestReviewCommentsClientTests.cs | 125 ++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 205f8a4e..4eb79e2f 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -65,6 +65,7 @@ + diff --git a/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs new file mode 100644 index 00000000..9651d29a --- /dev/null +++ b/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; +using Octokit; +using Octokit.Tests.Integration; +using Xunit; + +public class PullRequestReviewCommentsClientTests : IDisposable +{ + IGitHubClient _gitHubClient; + Repository _repository; + IPullRequestReviewCommentsClient _client; + + string _repoName; + string _ownerName; + + int _pullRequestNumber; + string _pullRequestCommitId; + string _path; + + public PullRequestReviewCommentsClientTests() + { + _gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + + // Creating a repository + + _repoName = Helper.MakeNameWithTimestamp("public-repo"); + _repository = _gitHubClient.Repository.Create(new NewRepository { Name = _repoName }).Result; + _ownerName = _repository.Owner.Name; + + // You can't for a repository that doesn't have any commit + + // Creating a blob + + // TODO Not Implemented: http://developer.github.com/v3/git/blobs/#create-a-blob + + // Creating a tree + + // TODO Not Implemented: http://developer.github.com/v3/git/trees/#create-a-tree + var treeSha = String.Empty; + + // Creating a commit + + var commit = new NewCommit("A nice commit message", treeSha, Enumerable.Empty()); + + var createdCommit = _gitHubClient.GitDatabase.Commit.Create(_ownerName, _repoName, commit).Result; + + // We can't fork our own repository so we need a second test user + // Using the second test user + + _gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + + // Creating a fork + + // TODO Not Implemented: http://developer.github.com/v3/repos/forks/#create-a-fork + + // Creating a blob + + // TODO Not Implemented: http://developer.github.com/v3/git/blobs/#create-a-blob + + // Creating a tree + + // TODO Not Implemented: http://developer.github.com/v3/git/trees/#create-a-tree + var pullRequestTreeSha = String.Empty; + _path = ""; + + // Creating a commit + + var pullRequestcommit = new NewCommit("A pull request commit message", pullRequestTreeSha, Enumerable.Empty()); + + var createdPullRequestCommit = _gitHubClient.GitDatabase.Commit.Create("second user name", _repoName, pullRequestcommit).Result; + _pullRequestCommitId = createdPullRequestCommit.Sha; + + // Creating a pull request + + // TODO Not Implemented: http://developer.github.com/v3/pulls/#create-a-pull-request + _pullRequestNumber = 0; + + // Using the first user again + + _gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + + _client = _gitHubClient.PullRequest.Comment; + } + + [IntegrationTest(Skip = "Requires Blob, Tree, Fork and Pull Request Api implementation")] + public async Task CanCreateAndRetrieveReviewComment() + { + var pullRequestReviewComment = new PullRequestReviewCommentCreate + { + Body = "A review comment message", + CommitId = _pullRequestCommitId, + Path = _path, + Position = 1, + }; + + var createdComment = await _client.Create(_ownerName, _repoName, _pullRequestNumber, pullRequestReviewComment); + + Assert.NotNull(createdComment); + Assert.Equal(pullRequestReviewComment.Body, createdComment.Body); + + var commentFromGitHub = await _client.GetComment(_ownerName, _repoName, createdComment.Id); + + Assert.NotNull(commentFromGitHub); + Assert.Equal(pullRequestReviewComment.Body, commentFromGitHub.Body); + } + + public void Dispose() + { + Helper.DeleteRepo(_repository); + // TODO Ensure that it deletes the forks too + } +} From ceb943c550fc9e17ac288325343dfdaef022f2a2 Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Fri, 22 Nov 2013 10:24:49 +1100 Subject: [PATCH 04/23] Checking that we are getting a Http Code 201 when creating a comment --- .../PullRequestReviewCommentsClientTests.cs | 8 +++---- .../PullRequestReviewCommentsClient.cs | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index 70b0de76..1788a95b 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -141,8 +141,8 @@ public class PullRequestReviewCommentsClientTests client.Create("fakeOwner", "fakeRepoName", 13, comment); - connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), - comment); + connection.Connection.Received().PostAsync(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), + comment, null, null); } [Fact] @@ -206,8 +206,8 @@ public class PullRequestReviewCommentsClientTests client.CreateReply("fakeOwner", "fakeRepoName", 13, comment); - connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), - comment); + connection.Connection.Received().PostAsync(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), + comment, null, null); } [Fact] diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs index 6c049b19..0df5eb3a 100644 --- a/Octokit/Clients/PullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Net; using System.Threading.Tasks; namespace Octokit @@ -80,7 +81,7 @@ namespace Octokit /// The Pull Request number /// The comment /// The created - public Task Create(string owner, string name, int number, PullRequestReviewCommentCreate comment) + public async Task Create(string owner, string name, int number, PullRequestReviewCommentCreate comment) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); @@ -89,7 +90,14 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(comment.CommitId, "commitId"); Ensure.ArgumentNotNullOrEmptyString(comment.Path, "path"); - return ApiConnection.Post(ApiUrls.PullRequestReviewComments(owner, name, number), comment); + var response = await ApiConnection.Connection.PostAsync(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); + + if (response.StatusCode != HttpStatusCode.Created) + { + throw new ApiException("Invalid Status Code returned. Expected a 201", response.StatusCode); + } + + return response.BodyAsObject; } /// @@ -101,14 +109,21 @@ namespace Octokit /// The pull request number /// The comment /// The created - public Task CreateReply(string owner, string name, int number, PullRequestReviewCommentReplyCreate comment) + public async Task CreateReply(string owner, string name, int number, PullRequestReviewCommentReplyCreate comment) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); - return ApiConnection.Post(ApiUrls.PullRequestReviewComments(owner, name, number), comment); + var response = await ApiConnection.Connection.PostAsync(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); + + if (response.StatusCode != HttpStatusCode.Created) + { + throw new ApiException("Invalid Status Code returned. Expected a 201", response.StatusCode); + } + + return response.BodyAsObject; } /// From 921353dd4ba2bcaf95215a5bcd53b85fa5b23996 Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Sun, 24 Nov 2013 19:06:59 +1100 Subject: [PATCH 05/23] Replaced public properties by readonly fields with a public getter and cleaned code --- ...servablePullRequestReviewCommentsClient.cs | 5 - .../PullRequestReviewCommentsClientTests.cs | 8 +- .../PullRequestReviewCommentsClientTests.cs | 141 ++++++++++-------- ...blePullRequestReviewCommentsClientTests.cs | 68 +-------- .../PullRequestReviewCommentsClient.cs | 5 - .../Request/PullRequestReviewCommentCreate.cs | 33 +++- .../Request/PullRequestReviewCommentEdit.cs | 15 +- .../PullRequestReviewCommentReplyCreate.cs | 21 ++- .../PullRequestReviewCommentRequest.cs | 1 - 9 files changed, 146 insertions(+), 151 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs index 140bb5a7..6c33ae3d 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs @@ -93,9 +93,6 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); - Ensure.ArgumentNotNullOrEmptyString(comment.CommitId, "commitId"); - Ensure.ArgumentNotNullOrEmptyString(comment.Path, "path"); return _client.Create(owner, name, number, comment).ToObservable(); } @@ -114,7 +111,6 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); return _client.CreateReply(owner, name, number, comment).ToObservable(); } @@ -133,7 +129,6 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); return _client.Edit(owner, name, number, comment).ToObservable(); } diff --git a/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs index 9651d29a..e1c28f97 100644 --- a/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs @@ -98,13 +98,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest(Skip = "Requires Blob, Tree, Fork and Pull Request Api implementation")] public async Task CanCreateAndRetrieveReviewComment() { - var pullRequestReviewComment = new PullRequestReviewCommentCreate - { - Body = "A review comment message", - CommitId = _pullRequestCommitId, - Path = _path, - Position = 1, - }; + var pullRequestReviewComment = new PullRequestReviewCommentCreate("A review comment message", _pullRequestCommitId, _path, 1); var createdComment = await _client.Create(_ownerName, _repoName, _pullRequestNumber, pullRequestReviewComment); diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index 1788a95b..fbdb9464 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -8,6 +8,79 @@ using Xunit; public class PullRequestReviewCommentsClientTests { + public class TheModelConstructors + { + [Fact] + public void PullRequestReviewCommentCreateEnsuresArgumentsValue() + { + string body = "body"; + string commitId = "sha"; + string path = "path"; + int position = 1; + + var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); + + Assert.Equal(body, comment.Body); + Assert.Equal(commitId, comment.CommitId); + Assert.Equal(path, comment.Path); + Assert.Equal(position, comment.Position); + } + + [Fact] + public void PullRequestReviewCommentCreateEnsuresArgumentsNotNull() + { + string body = "body"; + string commitId = "sha"; + string path = "path"; + int position = 1; + + Assert.Throws(() => new PullRequestReviewCommentCreate(null, commitId, path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate("", commitId, path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, null, path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, "", path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, commitId, null, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, commitId, "", position)); + } + + [Fact] + public void PullRequestReviewCommentEditEnsuresArgumentsValue() + { + string body = "body"; + + var comment = new PullRequestReviewCommentEdit(body); + + Assert.Equal(body, comment.Body); + } + + [Fact] + public void PullRequestReviewCommentEditEnsuresArgumentsNotNull() + { + Assert.Throws(() => new PullRequestReviewCommentEdit(null)); + Assert.Throws(() => new PullRequestReviewCommentEdit("")); + } + + [Fact] + public void PullRequestReviewCommentReplyCreateEnsuresArgumentsValue() + { + string body = "body"; + int inReplyTo = 1; + + var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); + + Assert.Equal(body, comment.Body); + Assert.Equal(inReplyTo, comment.InReplyTo); + } + + [Fact] + public void PullRequestReviewCommentReplyCreateEnsuresArgumentsNotNull() + { + int inReplyTo = 1; + + Assert.Throws(() => new PullRequestReviewCommentReplyCreate(null, inReplyTo)); + Assert.Throws(() => new PullRequestReviewCommentReplyCreate("", inReplyTo)); + } + } + public class TheGetForPullRequestMethod { [Fact] @@ -131,13 +204,7 @@ public class PullRequestReviewCommentsClientTests var connection = Substitute.For(); var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentCreate - { - Body = "Comment content", - CommitId = "qe3dsdsf6", - Path = "file.css", - Position = 7, - }; + var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7); client.Create("fakeOwner", "fakeRepoName", 13, comment); @@ -156,37 +223,13 @@ public class PullRequestReviewCommentsClientTests string path = "file.css"; int position = 7; - var comment = new PullRequestReviewCommentCreate - { - Body = body, - CommitId = commitId, - Path = path, - Position = position, - }; + var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); await AssertEx.Throws(async () => await client.Create(null, "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.Create("", "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.Create("fakeOwner", null, 1, comment)); await AssertEx.Throws(async () => await client.Create("fakeOwner", "", 1, comment)); await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = body; - - comment.CommitId = null; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.CommitId = ""; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.CommitId = commitId; - - comment.Path = null; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.Path = ""; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.Path = path; } } @@ -198,11 +241,7 @@ public class PullRequestReviewCommentsClientTests var connection = Substitute.For(); var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentReplyCreate - { - Body = "Comment content", - InReplyTo = 5 - }; + var comment = new PullRequestReviewCommentReplyCreate("Comment content", 5); client.CreateReply("fakeOwner", "fakeRepoName", 13, comment); @@ -219,23 +258,13 @@ public class PullRequestReviewCommentsClientTests string body = "Comment content"; int inReplyTo = 7; - var comment = new PullRequestReviewCommentReplyCreate - { - Body = body, - InReplyTo = inReplyTo, - }; + var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); await AssertEx.Throws(async () => await client.CreateReply(null, "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("", "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", null, 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "fakeRepoName", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = body; } } @@ -247,10 +276,7 @@ public class PullRequestReviewCommentsClientTests var connection = Substitute.For(); var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentEdit - { - Body = "New comment content", - }; + var comment = new PullRequestReviewCommentEdit("New comment content"); client.Edit("fakeOwner", "fakeRepoName", 13, comment); @@ -265,22 +291,13 @@ public class PullRequestReviewCommentsClientTests var body = "New comment content"; - var comment = new PullRequestReviewCommentEdit - { - Body = body, - }; + var comment = new PullRequestReviewCommentEdit(body); await AssertEx.Throws(async () => await client.Edit(null, "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.Edit("", "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.Edit("fakeOwner", null, 1, comment)); await AssertEx.Throws(async () => await client.Edit("fakeOwner", "", 1, comment)); await AssertEx.Throws(async () => await client.Edit("fakeOwner", null, 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.Edit("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.Edit("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = body; } } diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs index 6d1d3e98..dd47067e 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs @@ -276,13 +276,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); - var comment = new PullRequestReviewCommentCreate - { - Body = "Comment content", - CommitId = "qe3dsdsf6", - Path = "file.css", - Position = 7, - }; + var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7); client.Create("fakeOwner", "fakeRepoName", 13, comment); @@ -300,37 +294,13 @@ namespace Octokit.Tests.Reactive string path = "file.css"; int position = 7; - var comment = new PullRequestReviewCommentCreate - { - Body = body, - CommitId = commitId, - Path = path, - Position = position, - }; + var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); await AssertEx.Throws(async () => await client.Create(null, "name", 1, comment)); await AssertEx.Throws(async () => await client.Create("", "name", 1, comment)); await AssertEx.Throws(async () => await client.Create("owner", null, 1, comment)); await AssertEx.Throws(async () => await client.Create("owner", "", 1, comment)); await AssertEx.Throws(async () => await client.Create("owner", "name", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.Body = body; - - comment.CommitId = null; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.CommitId = ""; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.CommitId = commitId; - - comment.Path = null; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.Path = ""; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.Path = path; } } @@ -342,11 +312,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); - var comment = new PullRequestReviewCommentReplyCreate - { - Body = "Comment content", - InReplyTo = 9, - }; + var comment = new PullRequestReviewCommentReplyCreate("Comment content", 9); client.CreateReply("fakeOwner", "fakeRepoName", 13, comment); @@ -362,23 +328,13 @@ namespace Octokit.Tests.Reactive string body = "Comment content"; int inReplyTo = 7; - var comment = new PullRequestReviewCommentReplyCreate - { - Body = body, - InReplyTo = inReplyTo, - }; + var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); await AssertEx.Throws(async () => await client.CreateReply(null, "name", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("", "name", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("owner", null, 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("owner", "", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("owner", "name", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.CreateReply("owner", "name", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.CreateReply("owner", "name", 1, comment)); - comment.Body = body; } } @@ -390,10 +346,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); - var comment = new PullRequestReviewCommentEdit - { - Body = "New comment content", - }; + var comment = new PullRequestReviewCommentEdit("New comment content"); client.Edit("fakeOwner", "fakeRepoName", 13, comment); @@ -408,22 +361,13 @@ namespace Octokit.Tests.Reactive var body = "New comment content"; - var comment = new PullRequestReviewCommentEdit - { - Body = body, - }; + var comment = new PullRequestReviewCommentEdit(body); await AssertEx.Throws(async () => await client.Edit(null, "name", 1, comment)); await AssertEx.Throws(async () => await client.Edit("", "name", 1, comment)); await AssertEx.Throws(async () => await client.Edit("owner", null, 1, comment)); await AssertEx.Throws(async () => await client.Edit("owner", "", 1, comment)); await AssertEx.Throws(async () => await client.Edit("owner", "name", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.Edit("owner", "name", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.Edit("owner", "name", 1, comment)); - comment.Body = body; } } diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs index 0df5eb3a..280e5948 100644 --- a/Octokit/Clients/PullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -86,9 +86,6 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); - Ensure.ArgumentNotNullOrEmptyString(comment.CommitId, "commitId"); - Ensure.ArgumentNotNullOrEmptyString(comment.Path, "path"); var response = await ApiConnection.Connection.PostAsync(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); @@ -114,7 +111,6 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); var response = await ApiConnection.Connection.PostAsync(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); @@ -140,7 +136,6 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); return ApiConnection.Patch(ApiUrls.PullRequestReviewComment(owner, name, number), comment); } diff --git a/Octokit/Models/Request/PullRequestReviewCommentCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs index 08e9e581..b3f96441 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentCreate.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs @@ -4,25 +4,48 @@ namespace Octokit { public class PullRequestReviewCommentCreate : RequestParameters { + private readonly string _body; + private readonly string _commitId; + private readonly string _path; + private readonly int _position; + /// /// The text of the comment. /// - public string Body { get; set; } + public string Body { get { return _body; } } /// /// The SHA of the commit to comment on. /// - [Parameter(Key = "commit_id")] - public string CommitId { get; set; } + public string CommitId { get { return _commitId; } } /// /// The relative path of the file to comment on. /// - public string Path { get; set; } + public string Path { get { return _path; } } /// /// The line index in the diff to comment on. /// - public int Position { get; set; } + public int Position { get { return _position; } } + + /// + /// Creates a comment + /// + /// The text of the comment + /// The SHA of the commit to comment on + /// The relative path of the file to comment on + /// The line index in the diff to comment on + public PullRequestReviewCommentCreate(string body, string commitId, string path, int position) + { + Ensure.ArgumentNotNullOrEmptyString(body, "body"); + Ensure.ArgumentNotNullOrEmptyString(commitId, "commitId"); + Ensure.ArgumentNotNullOrEmptyString(path, "path"); + + _body = body; + _commitId = commitId; + _path = path; + _position = position; + } } } diff --git a/Octokit/Models/Request/PullRequestReviewCommentEdit.cs b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs index 1ad6f0ba..d257ebf1 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentEdit.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs @@ -3,9 +3,22 @@ namespace Octokit { public class PullRequestReviewCommentEdit : RequestParameters { + private readonly string _body; + /// /// The text of the comment. /// - public string Body { get; set; } + public string Body { get { return _body; }} + + /// + /// Creates an edit to a comment + /// + /// The text of the comment + public PullRequestReviewCommentEdit(string body) + { + Ensure.ArgumentNotNullOrEmptyString(body, "body"); + + _body = body; + } } } diff --git a/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs index a8e23599..90822c01 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs @@ -4,15 +4,30 @@ namespace Octokit { public class PullRequestReviewCommentReplyCreate : RequestParameters { + private readonly string _body; + private readonly int _inReplyTo; + /// /// The text of the comment. /// - public string Body { get; set; } + public string Body { get { return _body; } } /// /// The comment Id to reply to. /// - [Parameter(Key = "in_reply_to")] - public int InReplyTo { get; set; } + public int InReplyTo { get { return _inReplyTo; } } + + /// + /// Creates a comment that is replying to another comment. + /// + /// The text of the comment + /// The comment Id to reply to + public PullRequestReviewCommentReplyCreate(string body, int inReplyTo) + { + Ensure.ArgumentNotNullOrEmptyString(body, "body"); + + _body = body; + _inReplyTo = inReplyTo; + } } } diff --git a/Octokit/Models/Request/PullRequestReviewCommentRequest.cs b/Octokit/Models/Request/PullRequestReviewCommentRequest.cs index 125f8059..ada12064 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentRequest.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentRequest.cs @@ -7,7 +7,6 @@ namespace Octokit public PullRequestReviewCommentRequest() { // Default arguments - Sort = PullRequestReviewCommentSort.Created; Direction = SortDirection.Ascending; Since = null; From 9d5197524692b824da5d145293afd6b7e8c79e1f Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Sun, 24 Nov 2013 20:15:42 +1100 Subject: [PATCH 06/23] Fixed projects afer merge --- Octokit.Reactive/Octokit.Reactive-Mono.csproj | 2 ++ Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj | 2 ++ Octokit.Reactive/Octokit.Reactive-Monotouch.csproj | 2 ++ Octokit/Octokit-Mono.csproj | 12 ++++++++++-- Octokit/Octokit-MonoAndroid.csproj | 11 ++++++++++- Octokit/Octokit-Monotouch.csproj | 11 ++++++++++- Octokit/Octokit-netcore45.csproj | 10 +++++----- Octokit/Octokit.csproj | 11 ++++++++++- 8 files changed, 51 insertions(+), 10 deletions(-) diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index 5988045a..7ba1b53c 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -108,6 +108,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index ad8c40c4..908b2364 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -117,6 +117,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index 677d1709..b2499e14 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -112,6 +112,8 @@ + + diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 4125c986..a643db9b 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -113,7 +113,7 @@ - + @@ -218,6 +218,14 @@ + + + + + + + + - + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 624cb020..de9ae97a 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -227,6 +227,15 @@ + + + + + + + + + - + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 1cb2e203..6bf347b9 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -222,6 +222,15 @@ + + + + + + + + + - + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 41b36489..ccc85f2b 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -59,7 +59,7 @@ - + @@ -213,11 +213,11 @@ - - - + + + - + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index a5066b94..5fa3f190 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -53,6 +53,14 @@ Properties\SolutionInfo.cs + + + + + + + + @@ -66,6 +74,7 @@ + @@ -249,4 +258,4 @@ --> - + \ No newline at end of file From 6d29091266f8fd6fddf58ca787143e2baf82be1a Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Tue, 3 Dec 2013 09:43:50 +1100 Subject: [PATCH 07/23] Replaced read only fields by private setters in auto properties --- .../Request/PullRequestReviewCommentCreate.cs | 55 +++++++++---------- .../Request/PullRequestReviewCommentEdit.cs | 14 ++--- .../PullRequestReviewCommentReplyCreate.cs | 27 ++++----- 3 files changed, 44 insertions(+), 52 deletions(-) diff --git a/Octokit/Models/Request/PullRequestReviewCommentCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs index b3f96441..2a877a6f 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentCreate.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs @@ -4,31 +4,6 @@ namespace Octokit { public class PullRequestReviewCommentCreate : RequestParameters { - private readonly string _body; - private readonly string _commitId; - private readonly string _path; - private readonly int _position; - - /// - /// The text of the comment. - /// - public string Body { get { return _body; } } - - /// - /// The SHA of the commit to comment on. - /// - public string CommitId { get { return _commitId; } } - - /// - /// The relative path of the file to comment on. - /// - public string Path { get { return _path; } } - - /// - /// The line index in the diff to comment on. - /// - public int Position { get { return _position; } } - /// /// Creates a comment /// @@ -42,10 +17,32 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(commitId, "commitId"); Ensure.ArgumentNotNullOrEmptyString(path, "path"); - _body = body; - _commitId = commitId; - _path = path; - _position = position; + Body = body; + CommitId = commitId; + Path = path; + Position = position; } + + /// + /// The text of the comment. + /// + public string Body { get; private set; } + + /// + /// The SHA of the commit to comment on. + /// + public string CommitId { get; private set; } + + /// + /// The relative path of the file to comment on. + /// + public string Path { get; private set; } + + /// + /// The line index in the diff to comment on. + /// + public int Position { get; private set; } + + } } diff --git a/Octokit/Models/Request/PullRequestReviewCommentEdit.cs b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs index d257ebf1..933cafce 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentEdit.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs @@ -3,13 +3,6 @@ namespace Octokit { public class PullRequestReviewCommentEdit : RequestParameters { - private readonly string _body; - - /// - /// The text of the comment. - /// - public string Body { get { return _body; }} - /// /// Creates an edit to a comment /// @@ -18,7 +11,12 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(body, "body"); - _body = body; + Body = body; } + + /// + /// The text of the comment. + /// + public string Body { get; private set; } } } diff --git a/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs index 90822c01..342b5571 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs @@ -4,19 +4,6 @@ namespace Octokit { public class PullRequestReviewCommentReplyCreate : RequestParameters { - private readonly string _body; - private readonly int _inReplyTo; - - /// - /// The text of the comment. - /// - public string Body { get { return _body; } } - - /// - /// The comment Id to reply to. - /// - public int InReplyTo { get { return _inReplyTo; } } - /// /// Creates a comment that is replying to another comment. /// @@ -26,8 +13,18 @@ namespace Octokit { Ensure.ArgumentNotNullOrEmptyString(body, "body"); - _body = body; - _inReplyTo = inReplyTo; + Body = body; + InReplyTo = inReplyTo; } + + /// + /// The text of the comment. + /// + public string Body { get; private set; } + + /// + /// The comment Id to reply to. + /// + public int InReplyTo { get; private set; } } } From 895cfc116b84aa71552705d8e8476000ec6353d9 Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Mon, 9 Dec 2013 10:10:24 +1100 Subject: [PATCH 08/23] Fixed the Integration project that I broke --- .../{ => Clients}/PullRequestReviewCommentsClientTests.cs | 0 Octokit.Tests.Integration/Octokit.Tests.Integration.csproj | 7 +------ 2 files changed, 1 insertion(+), 6 deletions(-) rename Octokit.Tests.Integration/{ => Clients}/PullRequestReviewCommentsClientTests.cs (100%) diff --git a/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs similarity index 100% rename from Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs rename to Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 1eda978f..2d83eaa7 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -68,14 +68,9 @@ -<<<<<<< HEAD - - - -======= + ->>>>>>> master From 6590d227e3b70e99e0535f35ea6ed20ea3c8b50d Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Mon, 9 Dec 2013 10:34:32 +1100 Subject: [PATCH 09/23] Added blob and tree creation to review comments integration tests --- .../PullRequestReviewCommentsClientTests.cs | 60 +++++++++++++++---- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index e1c28f97..6d319a50 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -34,16 +34,32 @@ public class PullRequestReviewCommentsClientTests : IDisposable _repository = _gitHubClient.Repository.Create(new NewRepository { Name = _repoName }).Result; _ownerName = _repository.Owner.Name; - // You can't for a repository that doesn't have any commit + // You can't fork a repository that doesn't have any commit // Creating a blob - // TODO Not Implemented: http://developer.github.com/v3/git/blobs/#create-a-blob + var blob = new NewBlob + { + Content = "Hello World!", + Encoding = EncodingType.Utf8 + }; + + var createdBlob = _gitHubClient.GitDatabase.Blob.Create(_ownerName, _repoName, blob).Result; // Creating a tree - // TODO Not Implemented: http://developer.github.com/v3/git/trees/#create-a-tree - var treeSha = String.Empty; + var treeSha = createdBlob.Sha; + + var newTree = new NewTree(); + newTree.Tree.Add(new NewTreeItem + { + Type = TreeType.Blob, + Mode = FileMode.File, + Path = "README.md", + Sha = treeSha, + }); + + var createdTree = _gitHubClient.GitDatabase.Tree.Create(_ownerName, _repoName, newTree).Result; // Creating a commit @@ -52,7 +68,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable var createdCommit = _gitHubClient.GitDatabase.Commit.Create(_ownerName, _repoName, commit).Result; // We can't fork our own repository so we need a second test user - // Using the second test user + // TODO use the second test user + string secondUserName = "second user name"; + string forkRepoName = ""; _gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) { @@ -63,21 +81,37 @@ public class PullRequestReviewCommentsClientTests : IDisposable // TODO Not Implemented: http://developer.github.com/v3/repos/forks/#create-a-fork - // Creating a blob + // Creating a blob in the fork - // TODO Not Implemented: http://developer.github.com/v3/git/blobs/#create-a-blob + var pullRequestBlob = new NewBlob + { + Content = "Hello from the fork!", + Encoding = EncodingType.Utf8 + }; - // Creating a tree + var createdPullRequestBlob = _gitHubClient.GitDatabase.Blob.Create(secondUserName, forkRepoName, pullRequestBlob).Result; - // TODO Not Implemented: http://developer.github.com/v3/git/trees/#create-a-tree - var pullRequestTreeSha = String.Empty; - _path = ""; + // Creating a tree in the fork - // Creating a commit + var pullRequestTreeSha = createdPullRequestBlob.Sha; + _path = "CONTRIBUTING.md"; + + var pullRequestTree = new NewTree(); + pullRequestTree.Tree.Add(new NewTreeItem + { + Type = TreeType.Blob, + Mode = FileMode.File, + Path = _path, + Sha = pullRequestTreeSha, + }); + + var createdPullRequestTree = _gitHubClient.GitDatabase.Tree.Create(secondUserName, forkRepoName, pullRequestTree).Result; + + // Creating a commit in the fork var pullRequestcommit = new NewCommit("A pull request commit message", pullRequestTreeSha, Enumerable.Empty()); - var createdPullRequestCommit = _gitHubClient.GitDatabase.Commit.Create("second user name", _repoName, pullRequestcommit).Result; + var createdPullRequestCommit = _gitHubClient.GitDatabase.Commit.Create("second user name", forkRepoName, pullRequestcommit).Result; _pullRequestCommitId = createdPullRequestCommit.Sha; // Creating a pull request From 68aee77b180f85246af6edf121bfb3320550679a Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Mon, 30 Dec 2013 14:15:46 +1100 Subject: [PATCH 10/23] Replaced forking by branching --- .../PullRequestReviewCommentsClientTests.cs | 44 ++++++------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index 6d319a50..d5228664 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -14,8 +14,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable Repository _repository; IPullRequestReviewCommentsClient _client; - string _repoName; string _ownerName; + string _repoName; + string _branchName; int _pullRequestNumber; string _pullRequestCommitId; @@ -34,8 +35,6 @@ public class PullRequestReviewCommentsClientTests : IDisposable _repository = _gitHubClient.Repository.Create(new NewRepository { Name = _repoName }).Result; _ownerName = _repository.Owner.Name; - // You can't fork a repository that doesn't have any commit - // Creating a blob var blob = new NewBlob @@ -67,21 +66,13 @@ public class PullRequestReviewCommentsClientTests : IDisposable var createdCommit = _gitHubClient.GitDatabase.Commit.Create(_ownerName, _repoName, commit).Result; - // We can't fork our own repository so we need a second test user - // TODO use the second test user - string secondUserName = "second user name"; - string forkRepoName = ""; + // Creating a branch - _gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) - { - Credentials = Helper.Credentials - }; + var newBranch = new NewReference("refs/heads/new-branch", createdCommit.Sha); + var reference = _gitHubClient.GitDatabase.Reference.Create(_ownerName, _repoName, newBranch).Result; + _branchName = reference.Ref; - // Creating a fork - - // TODO Not Implemented: http://developer.github.com/v3/repos/forks/#create-a-fork - - // Creating a blob in the fork + // Creating a blob in the branch var pullRequestBlob = new NewBlob { @@ -89,9 +80,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable Encoding = EncodingType.Utf8 }; - var createdPullRequestBlob = _gitHubClient.GitDatabase.Blob.Create(secondUserName, forkRepoName, pullRequestBlob).Result; + var createdPullRequestBlob = _gitHubClient.GitDatabase.Blob.Create(_ownerName, _branchName, pullRequestBlob).Result; - // Creating a tree in the fork + // Creating a tree in the branch var pullRequestTreeSha = createdPullRequestBlob.Sha; _path = "CONTRIBUTING.md"; @@ -105,13 +96,13 @@ public class PullRequestReviewCommentsClientTests : IDisposable Sha = pullRequestTreeSha, }); - var createdPullRequestTree = _gitHubClient.GitDatabase.Tree.Create(secondUserName, forkRepoName, pullRequestTree).Result; + var createdPullRequestTree = _gitHubClient.GitDatabase.Tree.Create(_ownerName, _branchName, pullRequestTree).Result; - // Creating a commit in the fork + // Creating a commit in the branch var pullRequestcommit = new NewCommit("A pull request commit message", pullRequestTreeSha, Enumerable.Empty()); - var createdPullRequestCommit = _gitHubClient.GitDatabase.Commit.Create("second user name", forkRepoName, pullRequestcommit).Result; + var createdPullRequestCommit = _gitHubClient.GitDatabase.Commit.Create(_ownerName, _branchName, pullRequestcommit).Result; _pullRequestCommitId = createdPullRequestCommit.Sha; // Creating a pull request @@ -119,17 +110,10 @@ public class PullRequestReviewCommentsClientTests : IDisposable // TODO Not Implemented: http://developer.github.com/v3/pulls/#create-a-pull-request _pullRequestNumber = 0; - // Using the first user again - - _gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) - { - Credentials = Helper.Credentials - }; - _client = _gitHubClient.PullRequest.Comment; } - [IntegrationTest(Skip = "Requires Blob, Tree, Fork and Pull Request Api implementation")] + [IntegrationTest(Skip = "Requires Pull Request Api implementation")] public async Task CanCreateAndRetrieveReviewComment() { var pullRequestReviewComment = new PullRequestReviewCommentCreate("A review comment message", _pullRequestCommitId, _path, 1); @@ -148,6 +132,6 @@ public class PullRequestReviewCommentsClientTests : IDisposable public void Dispose() { Helper.DeleteRepo(_repository); - // TODO Ensure that it deletes the forks too + // TODO Ensure that it deletes the branch too } } From 7223518239a353597334ae5827e72ec4ed289521 Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Sat, 3 May 2014 11:56:36 +1000 Subject: [PATCH 11/23] Trying to get things to work again --- .../PullRequestReviewCommentsClientTests.cs | 2 +- .../PullRequestReviewCommentsClientTests.cs | 4 +-- ...blePullRequestReviewCommentsClientTests.cs | 36 +++++++++---------- Octokit/Clients/IPullRequestsClient.cs | 8 +---- .../PullRequestReviewCommentsClient.cs | 4 +-- Octokit/Clients/PullRequestsClient.cs | 12 ------- Octokit/Octokit-Mono.csproj | 2 -- Octokit/Octokit-MonoAndroid.csproj | 2 -- Octokit/Octokit-Monotouch.csproj | 2 -- Octokit/Octokit-Portable.csproj | 7 ++++ Octokit/Octokit-netcore45.csproj | 2 -- Octokit/Octokit.csproj | 3 -- 12 files changed, 31 insertions(+), 53 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index d5228664..a8cf2c14 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -24,7 +24,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable public PullRequestReviewCommentsClientTests() { - _gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) + _gitHubClient = new GitHubClient(new Octokit.ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index fbdb9464..3fd0480e 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -208,7 +208,7 @@ public class PullRequestReviewCommentsClientTests client.Create("fakeOwner", "fakeRepoName", 13, comment); - connection.Connection.Received().PostAsync(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), + connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), comment, null, null); } @@ -245,7 +245,7 @@ public class PullRequestReviewCommentsClientTests client.CreateReply("fakeOwner", "fakeRepoName", 13, comment); - connection.Connection.Received().PostAsync(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), + connection.Connection.Received().Post(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/13/comments"), comment, null, null); } diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs index dd47067e..5c7f2d93 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs @@ -57,11 +57,11 @@ namespace Octokit.Tests.Reactive }; var gitHubClient = Substitute.For(); - gitHubClient.Connection.GetAsync>(firstPageUrl) + gitHubClient.Connection.Get>(firstPageUrl, null, null) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.GetAsync>(secondPageUrl) + gitHubClient.Connection.Get>(secondPageUrl, null, null) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.GetAsync>(thirdPageUrl) + gitHubClient.Connection.Get>(thirdPageUrl, null, null) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -69,9 +69,9 @@ namespace Octokit.Tests.Reactive var results = await client.GetForPullRequest("fakeOwner", "fakeRepoName", 7).ToArray(); Assert.Equal(7, results.Length); - gitHubClient.Connection.Received(1).GetAsync>(firstPageUrl, null, null); - gitHubClient.Connection.Received(1).GetAsync>(secondPageUrl, null, null); - gitHubClient.Connection.Received(1).GetAsync>(thirdPageUrl, null, null); + gitHubClient.Connection.Received(1).Get>(firstPageUrl, null, null); + gitHubClient.Connection.Received(1).Get>(secondPageUrl, null, null); + gitHubClient.Connection.Received(1).Get>(thirdPageUrl, null, null); } [Fact] @@ -131,15 +131,15 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); - gitHubClient.Connection.GetAsync>(firstPageUrl, + gitHubClient.Connection.Get>(firstPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), null) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.GetAsync>(secondPageUrl, null, null) + gitHubClient.Connection.Get>(secondPageUrl, null, null) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.GetAsync>(thirdPageUrl, null, null) + gitHubClient.Connection.Get>(thirdPageUrl, null, null) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -154,13 +154,13 @@ namespace Octokit.Tests.Reactive var results = await client.GetForRepository("fakeOwner", "fakeRepoName", request).ToArray(); Assert.Equal(8, results.Length); - gitHubClient.Connection.Received(1).GetAsync>(firstPageUrl, + gitHubClient.Connection.Received(1).Get>(firstPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["since"] == "2013-11-15T11:43:01Z" && d["sort"] == "updated"), null); - gitHubClient.Connection.Received(1).GetAsync>(secondPageUrl, null, null); - gitHubClient.Connection.Received(1).GetAsync>(thirdPageUrl, null, null); + gitHubClient.Connection.Received(1).Get>(secondPageUrl, null, null); + gitHubClient.Connection.Received(1).Get>(thirdPageUrl, null, null); } [Fact] @@ -203,14 +203,14 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); - gitHubClient.Connection.GetAsync>(firstPageUrl, + gitHubClient.Connection.Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), null) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); - gitHubClient.Connection.GetAsync>(secondPageUrl, null, null) + gitHubClient.Connection.Get>(secondPageUrl, null, null) .Returns(Task.Factory.StartNew>>(() => secondPageResponse)); - gitHubClient.Connection.GetAsync>(thirdPageUrl, null, null) + gitHubClient.Connection.Get>(thirdPageUrl, null, null) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); @@ -218,12 +218,12 @@ namespace Octokit.Tests.Reactive var results = await client.GetForRepository("fakeOwner", "fakeRepoName").ToArray(); Assert.Equal(8, results.Length); - gitHubClient.Connection.Received(1).GetAsync>(firstPageUrl, + gitHubClient.Connection.Received(1).Get>(firstPageUrl, Arg.Is>(d => d.Count == 2 && d["direction"] == "asc" && d["sort"] == "created"), null); - gitHubClient.Connection.Received(1).GetAsync>(secondPageUrl, null, null); - gitHubClient.Connection.Received(1).GetAsync>(thirdPageUrl, null, null); + gitHubClient.Connection.Received(1).Get>(secondPageUrl, null, null); + gitHubClient.Connection.Received(1).Get>(thirdPageUrl, null, null); } [Fact] diff --git a/Octokit/Clients/IPullRequestsClient.cs b/Octokit/Clients/IPullRequestsClient.cs index 2b78ff29..940db5c0 100644 --- a/Octokit/Clients/IPullRequestsClient.cs +++ b/Octokit/Clients/IPullRequestsClient.cs @@ -1,21 +1,16 @@ -<<<<<<< HEAD - -======= using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; ->>>>>>> master namespace Octokit { public interface IPullRequestsClient { /// -<<<<<<< HEAD /// Client for managing comments. /// IPullRequestReviewCommentsClient Comment { get; } -======= + /// Get a pull request by number. /// /// @@ -101,6 +96,5 @@ namespace Octokit /// The pull request number /// A of s which are part of this pull request Task> Commits(string owner, string name, int number); ->>>>>>> master } } diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs index 280e5948..517afbc5 100644 --- a/Octokit/Clients/PullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -87,7 +87,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - var response = await ApiConnection.Connection.PostAsync(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); + var response = await ApiConnection.Connection.Post(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.Created) { @@ -112,7 +112,7 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - var response = await ApiConnection.Connection.PostAsync(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); + var response = await ApiConnection.Connection.Post(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.Created) { diff --git a/Octokit/Clients/PullRequestsClient.cs b/Octokit/Clients/PullRequestsClient.cs index 6e861087..bf2a026c 100644 --- a/Octokit/Clients/PullRequestsClient.cs +++ b/Octokit/Clients/PullRequestsClient.cs @@ -1,16 +1,11 @@ -<<<<<<< HEAD - -======= using System.Collections.Generic; using System.Net; using System.Threading.Tasks; ->>>>>>> master namespace Octokit { public class PullRequestsClient : ApiClient, IPullRequestsClient { -<<<<<<< HEAD public PullRequestsClient(IApiConnection apiConnection) : base(apiConnection) { Comment = new PullRequestReviewCommentsClient(apiConnection); @@ -20,13 +15,7 @@ namespace Octokit /// Client for managing comments. /// public IPullRequestReviewCommentsClient Comment { get; private set; } -======= - public PullRequestsClient(IApiConnection apiConnection) - : base(apiConnection) - { - } - /// /// Get a pull request by number. /// /// @@ -174,6 +163,5 @@ namespace Octokit return ApiConnection.GetAll(ApiUrls.PullRequestCommits(owner, name, number)); } ->>>>>>> master } } diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 5e6d3e34..f9c9577f 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -263,9 +263,7 @@ - - diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 56828454..5c62de62 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -242,9 +242,7 @@ - - diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 2398b22e..26636a29 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -237,9 +237,7 @@ - - diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index b1b9655c..99f2a4f6 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -317,6 +317,13 @@ + + + + + + + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 5ec6e94d..9db7edcd 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -89,7 +89,6 @@ - @@ -110,7 +109,6 @@ - diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 0c33b271..a8c19633 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -95,7 +95,6 @@ - @@ -182,7 +181,6 @@ - @@ -191,7 +189,6 @@ - From f23ddf81f9dc612d2c6d5d5bc66d1973edd55a3e Mon Sep 17 00:00:00 2001 From: Gabriel Weyer Date: Sun, 4 May 2014 10:46:35 +1000 Subject: [PATCH 12/23] Finalized integration testing for review comments --- .../Clients/IObservablePullRequestsClient.cs | 5 + .../Clients/ObservablePullRequestsClient.cs | 6 + Octokit.Reactive/IObservableGitHubClient.cs | 1 + Octokit.Reactive/ObservableGitHubClient.cs | 2 + .../PullRequestReviewCommentsClientTests.cs | 336 +++++++++++++----- .../Request/PullRequestReviewCommentCreate.cs | 6 +- .../Request/PullRequestReviewCommentEdit.cs | 4 +- .../PullRequestReviewCommentReplyCreate.cs | 4 +- .../PullRequestReviewCommentRequest.cs | 2 + .../Response/PullRequestReviewComment.cs | 2 + build.fsx | 2 +- 11 files changed, 279 insertions(+), 91 deletions(-) diff --git a/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs b/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs index 739793c8..7fd79c95 100644 --- a/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs +++ b/Octokit.Reactive/Clients/IObservablePullRequestsClient.cs @@ -5,6 +5,11 @@ namespace Octokit.Reactive { public interface IObservablePullRequestsClient { + /// + /// Client for managing comments. + /// + IObservablePullRequestReviewCommentsClient Comment { get; } + /// /// Gets a single Pull Request by number. /// diff --git a/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs index 33f749b2..ca8cd05d 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestsClient.cs @@ -9,12 +9,18 @@ namespace Octokit.Reactive readonly IPullRequestsClient _client; readonly IConnection _connection; + /// + /// Client for managing comments. + /// + public IObservablePullRequestReviewCommentsClient Comment { get; private set; } + public ObservablePullRequestsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Repository.PullRequest; _connection = client.Connection; + Comment = new ObservablePullRequestReviewCommentsClient(client); } /// diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index c8983ff8..e6374a0c 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -10,6 +10,7 @@ IObservableMiscellaneousClient Miscellaneous { get; } IObservableOauthClient Oauth { get; } IObservableOrganizationsClient Organization { get; } + IObservablePullRequestsClient PullRequest { get; } IObservableRepositoriesClient Repository { get; } IObservableGistsClient Gist { get; } IObservableReleasesClient Release { get; } diff --git a/Octokit.Reactive/ObservableGitHubClient.cs b/Octokit.Reactive/ObservableGitHubClient.cs index cba117f2..dc5c3d03 100644 --- a/Octokit.Reactive/ObservableGitHubClient.cs +++ b/Octokit.Reactive/ObservableGitHubClient.cs @@ -38,6 +38,7 @@ namespace Octokit.Reactive Notification = new ObservableNotificationsClient(gitHubClient); Oauth = new ObservableOauthClient(gitHubClient); Organization = new ObservableOrganizationsClient(gitHubClient); + PullRequest = new ObservablePullRequestsClient(gitHubClient); Repository = new ObservableRepositoriesClient(gitHubClient); SshKey = new ObservableSshKeysClient(gitHubClient); User = new ObservableUsersClient(gitHubClient); @@ -58,6 +59,7 @@ namespace Octokit.Reactive public IObservableMiscellaneousClient Miscellaneous { get; private set; } public IObservableOauthClient Oauth { get; private set; } public IObservableOrganizationsClient Organization { get; private set; } + public IObservablePullRequestsClient PullRequest { get; private set; } public IObservableRepositoriesClient Repository { get; private set; } public IObservableGistsClient Gist { get; private set; } public IObservableReleasesClient Release { get; private set; } diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index a8cf2c14..4cc6fd24 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -11,16 +11,15 @@ using Xunit; public class PullRequestReviewCommentsClientTests : IDisposable { IGitHubClient _gitHubClient; - Repository _repository; + List _repositoriesToDelete = new List(); IPullRequestReviewCommentsClient _client; - string _ownerName; - string _repoName; - string _branchName; + const string _branchName = "heads/new-branch"; + const string _path = "CONTRIBUTING.md"; + string _repoName; int _pullRequestNumber; string _pullRequestCommitId; - string _path; public PullRequestReviewCommentsClientTests() { @@ -29,109 +28,276 @@ public class PullRequestReviewCommentsClientTests : IDisposable Credentials = Helper.Credentials }; - // Creating a repository + _client = _gitHubClient.PullRequest.Comment; - _repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = _gitHubClient.Repository.Create(new NewRepository { Name = _repoName }).Result; - _ownerName = _repository.Owner.Name; + // We'll create a pull request that can be used by most tests + var pullRequestData = CreatePullRequest().Result; + + _repositoriesToDelete.Add(pullRequestData.Repository); + + _repoName = pullRequestData.RepoName; + _pullRequestNumber = pullRequestData.PullRequestNumber; + _pullRequestCommitId = pullRequestData.PullRequestCommitId; + } + + [IntegrationTest] + public async Task CanCreateAndRetrieveComment() + { + var body = "A review comment message"; + var position = 1; + + var createdCommentId = await CreateComment(body, position); + + var commentFromGitHub = await _client.GetComment(Helper.UserName, _repoName, createdCommentId); + + AssertComment(commentFromGitHub, body, position); + } + + [IntegrationTest] + public async Task CanEditComment() + { + var body = "A new review comment message"; + var position = 1; + + var createdCommentId = await CreateComment(body, position); + + var edit = new PullRequestReviewCommentEdit("Edited Comment"); + + var editedComment = await _client.Edit(Helper.UserName, _repoName, createdCommentId, edit); + + var commentFromGitHub = await _client.GetComment(Helper.UserName, _repoName, editedComment.Id); + + AssertComment(commentFromGitHub, edit.Body, position); + } + + [IntegrationTest] + public async Task CanDeleteComment() + { + var body = "A new review comment message"; + var position = 1; + + var createdCommentId = await CreateComment(body, position); + + var edit = new PullRequestReviewCommentEdit("Edited Comment"); + + Assert.DoesNotThrow(async () => { await _client.Delete(Helper.UserName, _repoName, createdCommentId); }); + } + + [IntegrationTest] + public async Task CanCreateReply() + { + var body = "Reply me!"; + var position = 1; + + var createdCommentId = await CreateComment(body, position); + + var reply = new PullRequestReviewCommentReplyCreate("Replied", createdCommentId); + var createdReply = await _client.CreateReply(Helper.UserName, _repoName, _pullRequestNumber, reply); + var createdReplyFromGitHub = await _client.GetComment(Helper.UserName, _repoName, createdReply.Id); + + AssertComment(createdReplyFromGitHub, reply.Body, position); + } + + [IntegrationTest] + public async Task CanGetForPullRequest() + { + var pullRequest = await CreatePullRequest(); + _repositoriesToDelete.Add(pullRequest.Repository); + + var position = 1; + List commentsToCreate = new List { "Comment 1", "Comment 2", "Comment 3" }; + + await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + + var pullRequestComments = await _client.GetForPullRequest(Helper.UserName, pullRequest.RepoName, pullRequest.PullRequestNumber); + + AssertComments(pullRequestComments, commentsToCreate, position); + } + + [IntegrationTest] + public async Task CanGetForRepository() + { + var pullRequest = await CreatePullRequest(); + _repositoriesToDelete.Add(pullRequest.Repository); + + var position = 1; + List commentsToCreate = new List { "Comment One", "Comment Two" }; + + await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + + var pullRequestComments = await _client.GetForRepository(Helper.UserName, pullRequest.RepoName); + + AssertComments(pullRequestComments, commentsToCreate, position); + } + + [IntegrationTest] + public async Task CanGetForRepositoryAscendingSort() + { + var pullRequest = await CreatePullRequest(); + _repositoriesToDelete.Add(pullRequest.Repository); + + var position = 1; + List commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; + + await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + + var pullRequestComments = await _client.GetForRepository(Helper.UserName, pullRequest.RepoName, new PullRequestReviewCommentRequest { Direction = SortDirection.Ascending }); + + AssertComments(pullRequestComments, commentsToCreate, position); + } + + [IntegrationTest] + public async Task CanGetForRepositoryDescendingSort() + { + var pullRequest = await CreatePullRequest(); + _repositoriesToDelete.Add(pullRequest.Repository); + + var position = 1; + List commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; + + await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + + var pullRequestComments = await _client.GetForRepository(Helper.UserName, pullRequest.RepoName, new PullRequestReviewCommentRequest { Direction = SortDirection.Descending }); + + commentsToCreate.Reverse(); + AssertComments(pullRequestComments, commentsToCreate, position); + } + + public void Dispose() + { + foreach (var repo in _repositoriesToDelete) + { + Helper.DeleteRepo(repo); + } + } + + private async Task CreateComment(string body, int position) + { + return await CreateComment(body, position, _repoName, _pullRequestCommitId, _pullRequestNumber); + } + + private async Task CreateComment(string body, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) + { + var comment = new PullRequestReviewCommentCreate(body, pullRequestCommitId, _path, position); + + var createdComment = await _client.Create(Helper.UserName, repoName, pullRequestNumber, comment); + + AssertComment(createdComment, body, position); + + return createdComment.Id; + } + + private async Task CreateComments(List comments, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) + { + foreach (var comment in comments) + { + await CreateComment(comment, position, repoName, pullRequestCommitId, pullRequestNumber); + } + } + + private void AssertComment(PullRequestReviewComment comment, string body, int position) + { + Assert.NotNull(comment); + Assert.Equal(body, comment.Body); + Assert.Equal(position, comment.Position); + } + + private void AssertComments(IReadOnlyList comments, List bodies, int position) + { + Assert.Equal(bodies.Count, comments.Count); + + for (int i = 0; i < bodies.Count; i = i + 1) + { + AssertComment(comments[i], bodies[i], position); + } + } + + private async Task CreateRepository(string repoName) + { + return await _gitHubClient.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }); + } + + /// + /// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request) + /// + /// + private async Task CreatePullRequest() + { + var repoName = Helper.MakeNameWithTimestamp("test-repo"); + var repository = await CreateRepository(repoName); + + // Creating a commit in master + + var createdCommitInMaster = await CreateCommit(repoName, "Hello World!", "README.md", "heads/master", "A master commit message"); + + // Creating a branch + + var newBranch = new NewReference("refs/" + _branchName, createdCommitInMaster.Sha); + var branchReference = await _gitHubClient.GitDatabase.Reference.Create(Helper.UserName, repoName, newBranch); + + // Creating a commit in the branch + + var createdCommitInBranch = await CreateCommit(repoName, "Hello from the fork!", _path, _branchName, "A branch commit message"); + + // Creating a pull request + + var pullRequest = new NewPullRequest("Nice title for the pull request", _branchName, "master"); + var createdPullRequest = await _gitHubClient.PullRequest.Create(Helper.UserName, repoName, pullRequest); + + var data = new PullRequestData + { + PullRequestCommitId = createdCommitInBranch.Sha, + PullRequestNumber = createdPullRequest.Number, + RepoName = repoName, + Repository = repository, + }; + + return data; + } + + private async Task CreateCommit(string repoName, string blobContent, string treePath, string reference, string commitMessage) + { // Creating a blob var blob = new NewBlob { - Content = "Hello World!", + Content = blobContent, Encoding = EncodingType.Utf8 }; - var createdBlob = _gitHubClient.GitDatabase.Blob.Create(_ownerName, _repoName, blob).Result; + var createdBlob = await _gitHubClient.GitDatabase.Blob.Create(Helper.UserName, repoName, blob); // Creating a tree - var treeSha = createdBlob.Sha; - var newTree = new NewTree(); newTree.Tree.Add(new NewTreeItem { Type = TreeType.Blob, Mode = FileMode.File, - Path = "README.md", - Sha = treeSha, + Path = treePath, + Sha = createdBlob.Sha, }); - var createdTree = _gitHubClient.GitDatabase.Tree.Create(_ownerName, _repoName, newTree).Result; + var createdTree = await _gitHubClient.GitDatabase.Tree.Create(Helper.UserName, repoName, newTree); + var treeSha = createdTree.Sha; // Creating a commit - var commit = new NewCommit("A nice commit message", treeSha, Enumerable.Empty()); + var parent = await _gitHubClient.GitDatabase.Reference.Get(Helper.UserName, repoName, reference); + var commit = new NewCommit(commitMessage, treeSha, parent.Object.Sha); - var createdCommit = _gitHubClient.GitDatabase.Commit.Create(_ownerName, _repoName, commit).Result; + var createdCommit = await _gitHubClient.GitDatabase.Commit.Create(Helper.UserName, repoName, commit); + await _gitHubClient.GitDatabase.Reference.Update(Helper.UserName, repoName, reference, new ReferenceUpdate(createdCommit.Sha)); - // Creating a branch - - var newBranch = new NewReference("refs/heads/new-branch", createdCommit.Sha); - var reference = _gitHubClient.GitDatabase.Reference.Create(_ownerName, _repoName, newBranch).Result; - _branchName = reference.Ref; - - // Creating a blob in the branch - - var pullRequestBlob = new NewBlob - { - Content = "Hello from the fork!", - Encoding = EncodingType.Utf8 - }; - - var createdPullRequestBlob = _gitHubClient.GitDatabase.Blob.Create(_ownerName, _branchName, pullRequestBlob).Result; - - // Creating a tree in the branch - - var pullRequestTreeSha = createdPullRequestBlob.Sha; - _path = "CONTRIBUTING.md"; - - var pullRequestTree = new NewTree(); - pullRequestTree.Tree.Add(new NewTreeItem - { - Type = TreeType.Blob, - Mode = FileMode.File, - Path = _path, - Sha = pullRequestTreeSha, - }); - - var createdPullRequestTree = _gitHubClient.GitDatabase.Tree.Create(_ownerName, _branchName, pullRequestTree).Result; - - // Creating a commit in the branch - - var pullRequestcommit = new NewCommit("A pull request commit message", pullRequestTreeSha, Enumerable.Empty()); - - var createdPullRequestCommit = _gitHubClient.GitDatabase.Commit.Create(_ownerName, _branchName, pullRequestcommit).Result; - _pullRequestCommitId = createdPullRequestCommit.Sha; - - // Creating a pull request - - // TODO Not Implemented: http://developer.github.com/v3/pulls/#create-a-pull-request - _pullRequestNumber = 0; - - _client = _gitHubClient.PullRequest.Comment; - } - - [IntegrationTest(Skip = "Requires Pull Request Api implementation")] - public async Task CanCreateAndRetrieveReviewComment() - { - var pullRequestReviewComment = new PullRequestReviewCommentCreate("A review comment message", _pullRequestCommitId, _path, 1); - - var createdComment = await _client.Create(_ownerName, _repoName, _pullRequestNumber, pullRequestReviewComment); - - Assert.NotNull(createdComment); - Assert.Equal(pullRequestReviewComment.Body, createdComment.Body); - - var commentFromGitHub = await _client.GetComment(_ownerName, _repoName, createdComment.Id); - - Assert.NotNull(commentFromGitHub); - Assert.Equal(pullRequestReviewComment.Body, commentFromGitHub.Body); - } - - public void Dispose() - { - Helper.DeleteRepo(_repository); - // TODO Ensure that it deletes the branch too + return createdCommit; } } + +class PullRequestData +{ + public Repository Repository { get; set; } + public int PullRequestNumber { get; set; } + public string PullRequestCommitId { get; set; } + public string RepoName { get; set; } +} \ No newline at end of file diff --git a/Octokit/Models/Request/PullRequestReviewCommentCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs index 2a877a6f..d9ae04b8 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentCreate.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs @@ -1,7 +1,9 @@ -using Octokit.Internal; +using System.Diagnostics; +using Octokit.Internal; namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class PullRequestReviewCommentCreate : RequestParameters { /// @@ -42,7 +44,5 @@ namespace Octokit /// The line index in the diff to comment on. /// public int Position { get; private set; } - - } } diff --git a/Octokit/Models/Request/PullRequestReviewCommentEdit.cs b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs index 933cafce..f8cc7ba1 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentEdit.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs @@ -1,6 +1,8 @@ - +using System.Diagnostics; + namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class PullRequestReviewCommentEdit : RequestParameters { /// diff --git a/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs index 342b5571..221ea677 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs @@ -1,7 +1,9 @@ -using Octokit.Internal; +using System.Diagnostics; +using Octokit.Internal; namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class PullRequestReviewCommentReplyCreate : RequestParameters { /// diff --git a/Octokit/Models/Request/PullRequestReviewCommentRequest.cs b/Octokit/Models/Request/PullRequestReviewCommentRequest.cs index ada12064..4bd22d0f 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentRequest.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentRequest.cs @@ -1,7 +1,9 @@ using System; +using System.Diagnostics; namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class PullRequestReviewCommentRequest : RequestParameters { public PullRequestReviewCommentRequest() diff --git a/Octokit/Models/Response/PullRequestReviewComment.cs b/Octokit/Models/Response/PullRequestReviewComment.cs index 14807e07..03e6b418 100644 --- a/Octokit/Models/Response/PullRequestReviewComment.cs +++ b/Octokit/Models/Response/PullRequestReviewComment.cs @@ -1,7 +1,9 @@ using System; +using System.Diagnostics; namespace Octokit { + [DebuggerDisplay("{DebuggerDisplay,nq}")] public class PullRequestReviewComment { /// diff --git a/build.fsx b/build.fsx index 7b914e33..21ab54b3 100644 --- a/build.fsx +++ b/build.fsx @@ -87,7 +87,7 @@ Target "IntegrationTests" (fun _ -> XmlOutput = true Verbose = false OutputDir = testResultsDir - TimeOut = TimeSpan.FromMinutes 10.0 }) + TimeOut = TimeSpan.FromMinutes 20.0 }) else "The integration tests were skipped because the OCTOKIT_GITHUBUSERNAME and OCTOKIT_GITHUBPASSWORD environment variables are not set. " + "Please configure these environment variables for a GitHub test account (DO NOT USE A \"REAL\" ACCOUNT)." From ae1f79688e30e71e6bdec91eb6aaa84d607d990e Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 13:49:40 +0930 Subject: [PATCH 13/23] :lipstick: tidy up test code a bit --- .../PullRequestReviewCommentsClientTests.cs | 84 +++++++++---------- 1 file changed, 38 insertions(+), 46 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index 4cc6fd24..c2ebdedf 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Net.Http.Headers; -using System.Text; using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; @@ -10,16 +7,16 @@ using Xunit; public class PullRequestReviewCommentsClientTests : IDisposable { - IGitHubClient _gitHubClient; - List _repositoriesToDelete = new List(); - IPullRequestReviewCommentsClient _client; + readonly IGitHubClient _gitHubClient; + readonly List _repositoriesToDelete = new List(); + readonly IPullRequestReviewCommentsClient _client; - const string _branchName = "heads/new-branch"; - const string _path = "CONTRIBUTING.md"; + const string branchName = "heads/new-branch"; + const string path = "CONTRIBUTING.md"; - string _repoName; - int _pullRequestNumber; - string _pullRequestCommitId; + readonly string _repoName; + readonly int _pullRequestNumber; + readonly string _pullRequestCommitId; public PullRequestReviewCommentsClientTests() { @@ -44,8 +41,8 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest] public async Task CanCreateAndRetrieveComment() { - var body = "A review comment message"; - var position = 1; + const string body = "A review comment message"; + const int position = 1; var createdCommentId = await CreateComment(body, position); @@ -57,8 +54,8 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest] public async Task CanEditComment() { - var body = "A new review comment message"; - var position = 1; + const string body = "A new review comment message"; + const int position = 1; var createdCommentId = await CreateComment(body, position); @@ -74,21 +71,19 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest] public async Task CanDeleteComment() { - var body = "A new review comment message"; - var position = 1; + const string body = "A new review comment message"; + const int position = 1; var createdCommentId = await CreateComment(body, position); - var edit = new PullRequestReviewCommentEdit("Edited Comment"); - Assert.DoesNotThrow(async () => { await _client.Delete(Helper.UserName, _repoName, createdCommentId); }); } [IntegrationTest] public async Task CanCreateReply() { - var body = "Reply me!"; - var position = 1; + const string body = "Reply me!"; + const int position = 1; var createdCommentId = await CreateComment(body, position); @@ -105,8 +100,8 @@ public class PullRequestReviewCommentsClientTests : IDisposable var pullRequest = await CreatePullRequest(); _repositoriesToDelete.Add(pullRequest.Repository); - var position = 1; - List commentsToCreate = new List { "Comment 1", "Comment 2", "Comment 3" }; + const int position = 1; + var commentsToCreate = new List { "Comment 1", "Comment 2", "Comment 3" }; await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); @@ -121,8 +116,8 @@ public class PullRequestReviewCommentsClientTests : IDisposable var pullRequest = await CreatePullRequest(); _repositoriesToDelete.Add(pullRequest.Repository); - var position = 1; - List commentsToCreate = new List { "Comment One", "Comment Two" }; + const int position = 1; + var commentsToCreate = new List { "Comment One", "Comment Two" }; await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); @@ -137,8 +132,8 @@ public class PullRequestReviewCommentsClientTests : IDisposable var pullRequest = await CreatePullRequest(); _repositoriesToDelete.Add(pullRequest.Repository); - var position = 1; - List commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; + const int position = 1; + var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); @@ -153,8 +148,8 @@ public class PullRequestReviewCommentsClientTests : IDisposable var pullRequest = await CreatePullRequest(); _repositoriesToDelete.Add(pullRequest.Repository); - var position = 1; - List commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; + const int position = 1; + var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); @@ -172,14 +167,14 @@ public class PullRequestReviewCommentsClientTests : IDisposable } } - private async Task CreateComment(string body, int position) + async Task CreateComment(string body, int position) { return await CreateComment(body, position, _repoName, _pullRequestCommitId, _pullRequestNumber); } - private async Task CreateComment(string body, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) + async Task CreateComment(string body, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) { - var comment = new PullRequestReviewCommentCreate(body, pullRequestCommitId, _path, position); + var comment = new PullRequestReviewCommentCreate(body, pullRequestCommitId, path, position); var createdComment = await _client.Create(Helper.UserName, repoName, pullRequestNumber, comment); @@ -188,7 +183,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable return createdComment.Id; } - private async Task CreateComments(List comments, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) + async Task CreateComments(IEnumerable comments, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) { foreach (var comment in comments) { @@ -196,24 +191,24 @@ public class PullRequestReviewCommentsClientTests : IDisposable } } - private void AssertComment(PullRequestReviewComment comment, string body, int position) + static void AssertComment(PullRequestReviewComment comment, string body, int position) { Assert.NotNull(comment); Assert.Equal(body, comment.Body); Assert.Equal(position, comment.Position); } - private void AssertComments(IReadOnlyList comments, List bodies, int position) + static void AssertComments(IReadOnlyList comments, List bodies, int position) { Assert.Equal(bodies.Count, comments.Count); - for (int i = 0; i < bodies.Count; i = i + 1) + for (var i = 0; i < bodies.Count; i = i + 1) { AssertComment(comments[i], bodies[i], position); } } - private async Task CreateRepository(string repoName) + async Task CreateRepository(string repoName) { return await _gitHubClient.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }); } @@ -222,7 +217,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable /// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request) /// /// - private async Task CreatePullRequest() + async Task CreatePullRequest() { var repoName = Helper.MakeNameWithTimestamp("test-repo"); var repository = await CreateRepository(repoName); @@ -233,16 +228,16 @@ public class PullRequestReviewCommentsClientTests : IDisposable // Creating a branch - var newBranch = new NewReference("refs/" + _branchName, createdCommitInMaster.Sha); - var branchReference = await _gitHubClient.GitDatabase.Reference.Create(Helper.UserName, repoName, newBranch); + var newBranch = new NewReference("refs/" + branchName, createdCommitInMaster.Sha); + await _gitHubClient.GitDatabase.Reference.Create(Helper.UserName, repoName, newBranch); // Creating a commit in the branch - var createdCommitInBranch = await CreateCommit(repoName, "Hello from the fork!", _path, _branchName, "A branch commit message"); + var createdCommitInBranch = await CreateCommit(repoName, "Hello from the fork!", path, branchName, "A branch commit message"); // Creating a pull request - var pullRequest = new NewPullRequest("Nice title for the pull request", _branchName, "master"); + var pullRequest = new NewPullRequest("Nice title for the pull request", branchName, "master"); var createdPullRequest = await _gitHubClient.PullRequest.Create(Helper.UserName, repoName, pullRequest); var data = new PullRequestData @@ -256,10 +251,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable return data; } - private async Task CreateCommit(string repoName, string blobContent, string treePath, string reference, string commitMessage) + async Task CreateCommit(string repoName, string blobContent, string treePath, string reference, string commitMessage) { // Creating a blob - var blob = new NewBlob { Content = blobContent, @@ -269,7 +263,6 @@ public class PullRequestReviewCommentsClientTests : IDisposable var createdBlob = await _gitHubClient.GitDatabase.Blob.Create(Helper.UserName, repoName, blob); // Creating a tree - var newTree = new NewTree(); newTree.Tree.Add(new NewTreeItem { @@ -283,7 +276,6 @@ public class PullRequestReviewCommentsClientTests : IDisposable var treeSha = createdTree.Sha; // Creating a commit - var parent = await _gitHubClient.GitDatabase.Reference.Get(Helper.UserName, repoName, reference); var commit = new NewCommit(commitMessage, treeSha, parent.Object.Sha); From 3da59c2150b528d7a3e460c2991a12fc29210551 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 14:14:37 +0930 Subject: [PATCH 14/23] simplify test setup and teardown --- .../PullRequestReviewCommentsClientTests.cs | 74 ++++++++----------- 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index c2ebdedf..da4ff427 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -8,19 +8,15 @@ using Xunit; public class PullRequestReviewCommentsClientTests : IDisposable { readonly IGitHubClient _gitHubClient; - readonly List _repositoriesToDelete = new List(); readonly IPullRequestReviewCommentsClient _client; + readonly Repository _repository; const string branchName = "heads/new-branch"; const string path = "CONTRIBUTING.md"; - readonly string _repoName; - readonly int _pullRequestNumber; - readonly string _pullRequestCommitId; - public PullRequestReviewCommentsClientTests() { - _gitHubClient = new GitHubClient(new Octokit.ProductHeaderValue("OctokitTests")) + _gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; @@ -28,25 +24,21 @@ public class PullRequestReviewCommentsClientTests : IDisposable _client = _gitHubClient.PullRequest.Comment; // We'll create a pull request that can be used by most tests - - var pullRequestData = CreatePullRequest().Result; - - _repositoriesToDelete.Add(pullRequestData.Repository); - - _repoName = pullRequestData.RepoName; - _pullRequestNumber = pullRequestData.PullRequestNumber; - _pullRequestCommitId = pullRequestData.PullRequestCommitId; + var repoName = Helper.MakeNameWithTimestamp("test-repo"); + _repository = CreateRepository(repoName).Result; } [IntegrationTest] public async Task CanCreateAndRetrieveComment() { + var pullRequest = await CreatePullRequest(_repository); + const string body = "A review comment message"; const int position = 1; - var createdCommentId = await CreateComment(body, position); + var createdCommentId = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - var commentFromGitHub = await _client.GetComment(Helper.UserName, _repoName, createdCommentId); + var commentFromGitHub = await _client.GetComment(Helper.UserName, _repository.Name, createdCommentId); AssertComment(commentFromGitHub, body, position); } @@ -54,16 +46,18 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest] public async Task CanEditComment() { + var pullRequest = await CreatePullRequest(_repository); + const string body = "A new review comment message"; const int position = 1; - var createdCommentId = await CreateComment(body, position); + var createdCommentId = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); var edit = new PullRequestReviewCommentEdit("Edited Comment"); - var editedComment = await _client.Edit(Helper.UserName, _repoName, createdCommentId, edit); + var editedComment = await _client.Edit(Helper.UserName, _repository.Name, createdCommentId, edit); - var commentFromGitHub = await _client.GetComment(Helper.UserName, _repoName, editedComment.Id); + var commentFromGitHub = await _client.GetComment(Helper.UserName, _repository.Name, editedComment.Id); AssertComment(commentFromGitHub, edit.Body, position); } @@ -71,25 +65,29 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest] public async Task CanDeleteComment() { + var pullRequest = await CreatePullRequest(_repository); + const string body = "A new review comment message"; const int position = 1; - var createdCommentId = await CreateComment(body, position); + var createdCommentId = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - Assert.DoesNotThrow(async () => { await _client.Delete(Helper.UserName, _repoName, createdCommentId); }); + Assert.DoesNotThrow(async () => { await _client.Delete(Helper.UserName, _repository.Name, createdCommentId); }); } [IntegrationTest] public async Task CanCreateReply() { + var pullRequest = await CreatePullRequest(_repository); + const string body = "Reply me!"; const int position = 1; - var createdCommentId = await CreateComment(body, position); + var createdCommentId = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); var reply = new PullRequestReviewCommentReplyCreate("Replied", createdCommentId); - var createdReply = await _client.CreateReply(Helper.UserName, _repoName, _pullRequestNumber, reply); - var createdReplyFromGitHub = await _client.GetComment(Helper.UserName, _repoName, createdReply.Id); + var createdReply = await _client.CreateReply(Helper.UserName, _repository.Name, pullRequest.PullRequestNumber, reply); + var createdReplyFromGitHub = await _client.GetComment(Helper.UserName, _repository.Name, createdReply.Id); AssertComment(createdReplyFromGitHub, reply.Body, position); } @@ -97,8 +95,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest] public async Task CanGetForPullRequest() { - var pullRequest = await CreatePullRequest(); - _repositoriesToDelete.Add(pullRequest.Repository); + var pullRequest = await CreatePullRequest(_repository); const int position = 1; var commentsToCreate = new List { "Comment 1", "Comment 2", "Comment 3" }; @@ -113,8 +110,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest] public async Task CanGetForRepository() { - var pullRequest = await CreatePullRequest(); - _repositoriesToDelete.Add(pullRequest.Repository); + var pullRequest = await CreatePullRequest(_repository); const int position = 1; var commentsToCreate = new List { "Comment One", "Comment Two" }; @@ -129,11 +125,10 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest] public async Task CanGetForRepositoryAscendingSort() { - var pullRequest = await CreatePullRequest(); - _repositoriesToDelete.Add(pullRequest.Repository); + var pullRequest = await CreatePullRequest(_repository); const int position = 1; - var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; + var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three" }; await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); @@ -145,8 +140,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest] public async Task CanGetForRepositoryDescendingSort() { - var pullRequest = await CreatePullRequest(); - _repositoriesToDelete.Add(pullRequest.Repository); + var pullRequest = await CreatePullRequest(_repository); const int position = 1; var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; @@ -161,15 +155,12 @@ public class PullRequestReviewCommentsClientTests : IDisposable public void Dispose() { - foreach (var repo in _repositoriesToDelete) - { - Helper.DeleteRepo(repo); - } + Helper.DeleteRepo(_repository); } - async Task CreateComment(string body, int position) + async Task CreateComment(string body, int position, string commitId, int number) { - return await CreateComment(body, position, _repoName, _pullRequestCommitId, _pullRequestNumber); + return await CreateComment(body, position, _repository.Name, commitId, number); } async Task CreateComment(string body, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) @@ -217,10 +208,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable /// Creates the base state for testing (creates a repo, a commit in master, a branch, a commit in the branch and a pull request) /// /// - async Task CreatePullRequest() + async Task CreatePullRequest(Repository repository) { - var repoName = Helper.MakeNameWithTimestamp("test-repo"); - var repository = await CreateRepository(repoName); + var repoName = repository.Name; // Creating a commit in master From 820ae69b71aab9066a3831aed674c56a0563ea4d Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 14:19:05 +0930 Subject: [PATCH 15/23] dropped mention of PullRequest to be consistent with other areas --- .../Clients/PullRequestReviewCommentsClientTests.cs | 2 +- .../Clients/PullRequestReviewCommentsClientTests.cs | 10 +++++----- Octokit/Clients/IPullRequestReviewCommentsClient.cs | 2 +- Octokit/Clients/PullRequestReviewCommentsClient.cs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index da4ff427..aaf735aa 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -102,7 +102,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - var pullRequestComments = await _client.GetForPullRequest(Helper.UserName, pullRequest.RepoName, pullRequest.PullRequestNumber); + var pullRequestComments = await _client.GetAll(Helper.UserName, pullRequest.RepoName, pullRequest.PullRequestNumber); AssertComments(pullRequestComments, commentsToCreate, position); } diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index 3fd0480e..70d38c37 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -89,7 +89,7 @@ public class PullRequestReviewCommentsClientTests var connection = Substitute.For(); var client = new PullRequestReviewCommentsClient(connection); - client.GetForPullRequest("fakeOwner", "fakeRepoName", 7); + client.GetAll("fakeOwner", "fakeRepoName", 7); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fakeOwner/fakeRepoName/pulls/7/comments")); } @@ -100,10 +100,10 @@ public class PullRequestReviewCommentsClientTests var connection = Substitute.For(); var client = new PullRequestReviewCommentsClient(connection); - await AssertEx.Throws(async () => await client.GetForPullRequest(null, "name", 1)); - await AssertEx.Throws(async () => await client.GetForPullRequest("", "name", 1)); - await AssertEx.Throws(async () => await client.GetForPullRequest("owner", null, 1)); - await AssertEx.Throws(async () => await client.GetForPullRequest("owner", "", 1)); + await AssertEx.Throws(async () => await client.GetAll(null, "name", 1)); + await AssertEx.Throws(async () => await client.GetAll("", "name", 1)); + await AssertEx.Throws(async () => await client.GetAll("owner", null, 1)); + await AssertEx.Throws(async () => await client.GetAll("owner", "", 1)); } } diff --git a/Octokit/Clients/IPullRequestReviewCommentsClient.cs b/Octokit/Clients/IPullRequestReviewCommentsClient.cs index 37cd15b4..e749effe 100644 --- a/Octokit/Clients/IPullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/IPullRequestReviewCommentsClient.cs @@ -13,7 +13,7 @@ namespace Octokit /// The name of the repository /// The pull request number /// The list of s for the specified pull request - Task> GetForPullRequest(string owner, string name, int number); + Task> GetAll(string owner, string name, int number); /// /// Gets a list of the pull request review comments in a specified repository. diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs index 517afbc5..fee2143c 100644 --- a/Octokit/Clients/PullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -19,7 +19,7 @@ namespace Octokit /// The name of the repository /// The pull request number /// The list of s for the specified pull request - public Task> GetForPullRequest(string owner, string name, int number) + public Task> GetAll(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); From 72db3f3ccd530b93af0cea9772ca74da7ba6e328 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 14:19:24 +0930 Subject: [PATCH 16/23] reverted build script change --- build.fsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.fsx b/build.fsx index eb56652a..416cb336 100644 --- a/build.fsx +++ b/build.fsx @@ -87,7 +87,7 @@ Target "IntegrationTests" (fun _ -> XmlOutput = true Verbose = false OutputDir = testResultsDir - TimeOut = TimeSpan.FromMinutes 20.0 }) + TimeOut = TimeSpan.FromMinutes 10.0 }) else "The integration tests were skipped because the OCTOKIT_GITHUBUSERNAME and OCTOKIT_GITHUBPASSWORD environment variables are not set. " + "Please configure these environment variables for a GitHub test account (DO NOT USE A \"REAL\" ACCOUNT)." From 12fca5f83d2d3ff70072378105b88c66ae344838 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 14:34:34 +0930 Subject: [PATCH 17/23] get to the created comment in the test --- .../PullRequestReviewCommentsClientTests.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index aaf735aa..4f69a358 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -36,9 +36,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable const string body = "A review comment message"; const int position = 1; - var createdCommentId = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - var commentFromGitHub = await _client.GetComment(Helper.UserName, _repository.Name, createdCommentId); + var commentFromGitHub = await _client.GetComment(Helper.UserName, _repository.Name, createdComment.Id); AssertComment(commentFromGitHub, body, position); } @@ -51,11 +51,11 @@ public class PullRequestReviewCommentsClientTests : IDisposable const string body = "A new review comment message"; const int position = 1; - var createdCommentId = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); var edit = new PullRequestReviewCommentEdit("Edited Comment"); - var editedComment = await _client.Edit(Helper.UserName, _repository.Name, createdCommentId, edit); + var editedComment = await _client.Edit(Helper.UserName, _repository.Name, createdComment.Id, edit); var commentFromGitHub = await _client.GetComment(Helper.UserName, _repository.Name, editedComment.Id); @@ -70,9 +70,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable const string body = "A new review comment message"; const int position = 1; - var createdCommentId = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - Assert.DoesNotThrow(async () => { await _client.Delete(Helper.UserName, _repository.Name, createdCommentId); }); + Assert.DoesNotThrow(async () => { await _client.Delete(Helper.UserName, _repository.Name, createdComment.Id); }); } [IntegrationTest] @@ -83,9 +83,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable const string body = "Reply me!"; const int position = 1; - var createdCommentId = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - var reply = new PullRequestReviewCommentReplyCreate("Replied", createdCommentId); + var reply = new PullRequestReviewCommentReplyCreate("Replied", createdComment.Id); var createdReply = await _client.CreateReply(Helper.UserName, _repository.Name, pullRequest.PullRequestNumber, reply); var createdReplyFromGitHub = await _client.GetComment(Helper.UserName, _repository.Name, createdReply.Id); @@ -158,12 +158,12 @@ public class PullRequestReviewCommentsClientTests : IDisposable Helper.DeleteRepo(_repository); } - async Task CreateComment(string body, int position, string commitId, int number) + async Task CreateComment(string body, int position, string commitId, int number) { return await CreateComment(body, position, _repository.Name, commitId, number); } - async Task CreateComment(string body, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) + async Task CreateComment(string body, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) { var comment = new PullRequestReviewCommentCreate(body, pullRequestCommitId, path, position); @@ -171,7 +171,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable AssertComment(createdComment, body, position); - return createdComment.Id; + return createdComment; } async Task CreateComments(IEnumerable comments, int position, string repoName, string pullRequestCommitId, int pullRequestNumber) From 5676b62e09924449db0823a40d0319ee39947225 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 14:38:58 +0930 Subject: [PATCH 18/23] added test around how timestamps work --- .../PullRequestReviewCommentsClientTests.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index 4f69a358..9a42d7c7 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -62,6 +62,25 @@ public class PullRequestReviewCommentsClientTests : IDisposable AssertComment(commentFromGitHub, edit.Body, position); } + [IntegrationTest] + public async Task TimestampsAreUpdated() + { + var pullRequest = await CreatePullRequest(_repository); + + const string body = "A new review comment message"; + const int position = 1; + + var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + + Assert.Equal(createdComment.UpdatedAt, createdComment.CreatedAt); + + var edit = new PullRequestReviewCommentEdit("Edited Comment"); + + var editedComment = await _client.Edit(Helper.UserName, _repository.Name, createdComment.Id, edit); + + Assert.NotEqual(editedComment.UpdatedAt, editedComment.CreatedAt); + } + [IntegrationTest] public async Task CanDeleteComment() { From ffebd59f62cdbaf9cb951ffd3fe08796b40d84c9 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 14:42:27 +0930 Subject: [PATCH 19/23] deprecate some properties --- .../PullRequestReviewCommentsClientTests.cs | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index 9a42d7c7..2ca52140 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -119,9 +119,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable const int position = 1; var commentsToCreate = new List { "Comment 1", "Comment 2", "Comment 3" }; - await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - var pullRequestComments = await _client.GetAll(Helper.UserName, pullRequest.RepoName, pullRequest.PullRequestNumber); + var pullRequestComments = await _client.GetAll(Helper.UserName, _repository.Name, pullRequest.PullRequestNumber); AssertComments(pullRequestComments, commentsToCreate, position); } @@ -134,9 +134,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable const int position = 1; var commentsToCreate = new List { "Comment One", "Comment Two" }; - await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - var pullRequestComments = await _client.GetForRepository(Helper.UserName, pullRequest.RepoName); + var pullRequestComments = await _client.GetForRepository(Helper.UserName, _repository.Name); AssertComments(pullRequestComments, commentsToCreate, position); } @@ -149,9 +149,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable const int position = 1; var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three" }; - await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - var pullRequestComments = await _client.GetForRepository(Helper.UserName, pullRequest.RepoName, new PullRequestReviewCommentRequest { Direction = SortDirection.Ascending }); + var pullRequestComments = await _client.GetForRepository(Helper.UserName, _repository.Name, new PullRequestReviewCommentRequest { Direction = SortDirection.Ascending }); AssertComments(pullRequestComments, commentsToCreate, position); } @@ -164,9 +164,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable const int position = 1; var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; - await CreateComments(commentsToCreate, position, pullRequest.RepoName, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); - var pullRequestComments = await _client.GetForRepository(Helper.UserName, pullRequest.RepoName, new PullRequestReviewCommentRequest { Direction = SortDirection.Descending }); + var pullRequestComments = await _client.GetForRepository(Helper.UserName, _repository.Name, new PullRequestReviewCommentRequest { Direction = SortDirection.Descending }); commentsToCreate.Reverse(); AssertComments(pullRequestComments, commentsToCreate, position); @@ -253,8 +253,6 @@ public class PullRequestReviewCommentsClientTests : IDisposable { PullRequestCommitId = createdCommitInBranch.Sha, PullRequestNumber = createdPullRequest.Number, - RepoName = repoName, - Repository = repository, }; return data; @@ -297,8 +295,8 @@ public class PullRequestReviewCommentsClientTests : IDisposable class PullRequestData { - public Repository Repository { get; set; } + [Obsolete] public int PullRequestNumber { get; set; } + [Obsolete] public string PullRequestCommitId { get; set; } - public string RepoName { get; set; } } \ No newline at end of file From 5ad166ac1a357a013b7ba0acaebd3cc175fc408c Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 14:45:45 +0930 Subject: [PATCH 20/23] making this an inner class --- .../PullRequestReviewCommentsClientTests.cs | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index 2ca52140..f31b183d 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -36,7 +36,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable const string body = "A review comment message"; const int position = 1; - var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); var commentFromGitHub = await _client.GetComment(Helper.UserName, _repository.Name, createdComment.Id); @@ -51,7 +51,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable const string body = "A new review comment message"; const int position = 1; - var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); var edit = new PullRequestReviewCommentEdit("Edited Comment"); @@ -70,7 +70,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable const string body = "A new review comment message"; const int position = 1; - var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); Assert.Equal(createdComment.UpdatedAt, createdComment.CreatedAt); @@ -89,7 +89,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable const string body = "A new review comment message"; const int position = 1; - var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); Assert.DoesNotThrow(async () => { await _client.Delete(Helper.UserName, _repository.Name, createdComment.Id); }); } @@ -102,10 +102,10 @@ public class PullRequestReviewCommentsClientTests : IDisposable const string body = "Reply me!"; const int position = 1; - var createdComment = await CreateComment(body, position, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + var createdComment = await CreateComment(body, position, pullRequest.Sha, pullRequest.Number); var reply = new PullRequestReviewCommentReplyCreate("Replied", createdComment.Id); - var createdReply = await _client.CreateReply(Helper.UserName, _repository.Name, pullRequest.PullRequestNumber, reply); + var createdReply = await _client.CreateReply(Helper.UserName, _repository.Name, pullRequest.Number, reply); var createdReplyFromGitHub = await _client.GetComment(Helper.UserName, _repository.Name, createdReply.Id); AssertComment(createdReplyFromGitHub, reply.Body, position); @@ -119,9 +119,9 @@ public class PullRequestReviewCommentsClientTests : IDisposable const int position = 1; var commentsToCreate = new List { "Comment 1", "Comment 2", "Comment 3" }; - await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.Sha, pullRequest.Number); - var pullRequestComments = await _client.GetAll(Helper.UserName, _repository.Name, pullRequest.PullRequestNumber); + var pullRequestComments = await _client.GetAll(Helper.UserName, _repository.Name, pullRequest.Number); AssertComments(pullRequestComments, commentsToCreate, position); } @@ -134,7 +134,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable const int position = 1; var commentsToCreate = new List { "Comment One", "Comment Two" }; - await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.Sha, pullRequest.Number); var pullRequestComments = await _client.GetForRepository(Helper.UserName, _repository.Name); @@ -149,7 +149,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable const int position = 1; var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three" }; - await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.Sha, pullRequest.Number); var pullRequestComments = await _client.GetForRepository(Helper.UserName, _repository.Name, new PullRequestReviewCommentRequest { Direction = SortDirection.Ascending }); @@ -164,7 +164,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable const int position = 1; var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; - await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.PullRequestCommitId, pullRequest.PullRequestNumber); + await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.Sha, pullRequest.Number); var pullRequestComments = await _client.GetForRepository(Helper.UserName, _repository.Name, new PullRequestReviewCommentRequest { Direction = SortDirection.Descending }); @@ -251,8 +251,8 @@ public class PullRequestReviewCommentsClientTests : IDisposable var data = new PullRequestData { - PullRequestCommitId = createdCommitInBranch.Sha, - PullRequestNumber = createdPullRequest.Number, + Sha = createdCommitInBranch.Sha, + Number = createdPullRequest.Number, }; return data; @@ -291,12 +291,10 @@ public class PullRequestReviewCommentsClientTests : IDisposable return createdCommit; } -} -class PullRequestData -{ - [Obsolete] - public int PullRequestNumber { get; set; } - [Obsolete] - public string PullRequestCommitId { get; set; } -} \ No newline at end of file + class PullRequestData + { + public int Number { get; set; } + public string Sha { get; set; } + } +} From 69bc413655a6de175e882f2bb503825a7ea24eb2 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 15:19:30 +0930 Subject: [PATCH 21/23] i hate myself --- .../Clients/PullRequestReviewCommentsClientTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index f31b183d..f3b8adac 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -74,6 +74,8 @@ public class PullRequestReviewCommentsClientTests : IDisposable Assert.Equal(createdComment.UpdatedAt, createdComment.CreatedAt); + await Task.Delay(TimeSpan.FromSeconds(2)); + var edit = new PullRequestReviewCommentEdit("Edited Comment"); var editedComment = await _client.Edit(Helper.UserName, _repository.Name, createdComment.Id, edit); From 9b8ed02f98bb48f8ba9790d7b1f3fb5de8c536f6 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 15:21:17 +0930 Subject: [PATCH 22/23] :lipstick: unused fields --- .../Clients/RepositoryDeployKeysClientTests.cs | 1 - .../Reactive/ObservableRespositoryDeployKeysClientTests.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/RepositoryDeployKeysClientTests.cs b/Octokit.Tests.Integration/Clients/RepositoryDeployKeysClientTests.cs index 99c49e23..802e96dd 100644 --- a/Octokit.Tests.Integration/Clients/RepositoryDeployKeysClientTests.cs +++ b/Octokit.Tests.Integration/Clients/RepositoryDeployKeysClientTests.cs @@ -11,7 +11,6 @@ public class RepositoryDeployKeysClientTests : IDisposable readonly IGitHubClient _client; IRepositoryDeployKeysClient _fixture; Repository _repository; - DeployKey _deployKey; string _owner; public RepositoryDeployKeysClientTests() diff --git a/Octokit.Tests.Integration/Reactive/ObservableRespositoryDeployKeysClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRespositoryDeployKeysClientTests.cs index 8e36b062..fda83a4c 100644 --- a/Octokit.Tests.Integration/Reactive/ObservableRespositoryDeployKeysClientTests.cs +++ b/Octokit.Tests.Integration/Reactive/ObservableRespositoryDeployKeysClientTests.cs @@ -13,7 +13,6 @@ public class ObservableRespositoryDeployKeysClientTests : IDisposable const string _keyTitle = "octokit@github"; ObservableRepositoryDeployKeysClient _client; Repository _repository; - DeployKey _deployKey; string _owner; public ObservableRespositoryDeployKeysClientTests() From e8cd8addc74c8481805c9f349e972ef3a744d262 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Thu, 10 Jul 2014 15:41:46 +0930 Subject: [PATCH 23/23] investigating why the order of these tests is weird --- .../Clients/PullRequestReviewCommentsClientTests.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs index f3b8adac..b3da09e9 100644 --- a/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/PullRequestReviewCommentsClientTests.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; @@ -149,13 +150,13 @@ public class PullRequestReviewCommentsClientTests : IDisposable var pullRequest = await CreatePullRequest(_repository); const int position = 1; - var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three" }; + var commentsToCreate = new [] { "Comment One", "Comment Two", "Comment Three" }; await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.Sha, pullRequest.Number); var pullRequestComments = await _client.GetForRepository(Helper.UserName, _repository.Name, new PullRequestReviewCommentRequest { Direction = SortDirection.Ascending }); - AssertComments(pullRequestComments, commentsToCreate, position); + Assert.Equal(pullRequestComments.Select(x => x.Body), commentsToCreate); } [IntegrationTest] @@ -164,14 +165,13 @@ public class PullRequestReviewCommentsClientTests : IDisposable var pullRequest = await CreatePullRequest(_repository); const int position = 1; - var commentsToCreate = new List { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; + var commentsToCreate = new [] { "Comment One", "Comment Two", "Comment Three", "Comment Four" }; await CreateComments(commentsToCreate, position, _repository.Name, pullRequest.Sha, pullRequest.Number); var pullRequestComments = await _client.GetForRepository(Helper.UserName, _repository.Name, new PullRequestReviewCommentRequest { Direction = SortDirection.Descending }); - commentsToCreate.Reverse(); - AssertComments(pullRequestComments, commentsToCreate, position); + Assert.Equal(pullRequestComments.Select(x => x.Body), commentsToCreate.Reverse()); } public void Dispose() @@ -200,6 +200,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable foreach (var comment in comments) { await CreateComment(comment, position, repoName, pullRequestCommitId, pullRequestNumber); + await Task.Delay(TimeSpan.FromSeconds(2)); } }