diff --git a/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs b/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs index 9f0c2783e8..0744d57a17 100644 --- a/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs @@ -137,6 +137,46 @@ public interface IObservableIssueCommentsClient /// Options for changing the API response IObservable GetAllForIssue(long repositoryId, int number, ApiOptions options); + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// The sorting parameters + IObservable GetAllForIssue(string owner, string name, int number, IssueCommentRequest request); + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The Id of the repository + /// The issue number + /// The sorting parameters + IObservable GetAllForIssue(long repositoryId, int number, IssueCommentRequest request); + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// The sorting parameters + /// Options for changing the API response + IObservable GetAllForIssue(string owner, string name, int number, IssueCommentRequest request, ApiOptions options); + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The Id of the repository + /// The issue number + /// The sorting parameters + /// Options for changing the API response + IObservable GetAllForIssue(long repositoryId, int number, IssueCommentRequest request, ApiOptions options); + /// /// Creates a new Issue Comment for a specified Issue. /// diff --git a/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs b/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs index 5b21cedad9..e87c38bedd 100644 --- a/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs @@ -205,7 +205,7 @@ public IObservable GetAllForIssue(string owner, string name, int n Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); + return GetAllForIssue(owner, name, number, new IssueCommentRequest(), options); } /// @@ -219,7 +219,74 @@ public IObservable GetAllForIssue(long repositoryId, int number, A { Ensure.ArgumentNotNull(options, nameof(options)); - return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(repositoryId, number), options); + return GetAllForIssue(repositoryId, number, new IssueCommentRequest(), options); + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// The sorting parameters + public IObservable GetAllForIssue(string owner, string name, int number, IssueCommentRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(request, nameof(request)); + + return GetAllForIssue(owner, name, number, request, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The Id of the repository + /// The issue number + /// The sorting parameters + public IObservable GetAllForIssue(long repositoryId, int number, IssueCommentRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return GetAllForIssue(repositoryId, number, request, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// The sorting parameters + /// Options for changing the API response + public IObservable GetAllForIssue(string owner, string name, int number, IssueCommentRequest request, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(owner, name, number), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); + + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The Id of the repository + /// The issue number + /// The sorting parameters + /// Options for changing the API response + public IObservable GetAllForIssue(long repositoryId, int number, IssueCommentRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return _connection.GetAndFlattenAllPages(ApiUrls.IssueComments(repositoryId, number), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// diff --git a/Octokit.Tests/Clients/IssueCommentsClientTests.cs b/Octokit.Tests/Clients/IssueCommentsClientTests.cs index ff5a5ef9f3..34801f2e34 100644 --- a/Octokit.Tests/Clients/IssueCommentsClientTests.cs +++ b/Octokit.Tests/Clients/IssueCommentsClientTests.cs @@ -180,6 +180,45 @@ public async Task RequestsCorrectUrlWithRepositoryId() Args.ApiOptions); } + [Fact] + public async Task RequestsCorrectUrlWithIssueCommentRequest() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + var request = new IssueCommentRequest() + { + Since = new DateTimeOffset(2016, 11, 23, 11, 11, 11, 00, new TimeSpan()), + }; + + await client.GetAllForIssue("fake", "repo", 3, request); + + connection.Received().GetAll( + Arg.Is(u => u.ToString() == "repos/fake/repo/issues/3/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithIssueCommentRequest() + { + var connection = Substitute.For(); + var client = new IssueCommentsClient(connection); + + var request = new IssueCommentRequest() + { + Since = new DateTimeOffset(2016, 11, 23, 11, 11, 11, 00, new TimeSpan()), + }; + + await client.GetAllForIssue(1, 3, request); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/3/comments"), + Arg.Any>(), + "application/vnd.github.squirrel-girl-preview", + Args.ApiOptions); + } + [Fact] public async Task RequestsCorrectUrlWithApiOptions() { @@ -233,9 +272,13 @@ public async Task EnsuresNonNullArguments() await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1)); await Assert.ThrowsAsync(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, null)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, options: null)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, request: null)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, null, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForIssue(1, 1, null)); + await Assert.ThrowsAsync(() => client.GetAllForIssue(1, 1, options: null)); + await Assert.ThrowsAsync(() => client.GetAllForIssue(1, 1, request: null)); + await Assert.ThrowsAsync(() => client.GetAllForIssue(1, 1, null, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1)); await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1)); diff --git a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs index e420a4ffe9..f59c8bf0ca 100644 --- a/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs @@ -171,7 +171,7 @@ public void RequestsCorrectUrl() gitHubClient.Connection.Received(1).Get>( new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), - Args.EmptyDictionary, + Arg.Any>(), "application/vnd.github.squirrel-girl-preview"); } @@ -184,7 +184,47 @@ public void RequestsCorrectUrlWithRepositoryId() client.GetAllForIssue(1, 3); gitHubClient.Connection.Received(1).Get>( - new Uri("repositories/1/issues/3/comments", UriKind.Relative), Args.EmptyDictionary, null); + new Uri("repositories/1/issues/3/comments", UriKind.Relative), Arg.Any>(), "application/vnd.github.squirrel-girl-preview"); + } + + [Fact] + public void RequestsCorrectUrlWithIssueCommentRequest() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentsClient(gitHubClient); + + var request = new IssueCommentRequest() + { + Since = new DateTimeOffset(2016, 11, 23, 11, 11, 11, 00, new TimeSpan()), + }; + + client.GetAllForIssue("fake", "repo", 3, request); + + gitHubClient.Connection.Received(1).Get>( + new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), + Arg.Is>(d => d.Count == 3 + && d["since"] == "2016-11-23T11:11:11Z"), + "application/vnd.github.squirrel-girl-preview"); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryIdWithIssueCommentRequest() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssueCommentsClient(gitHubClient); + + var request = new IssueCommentRequest() + { + Since = new DateTimeOffset(2016, 11, 23, 11, 11, 11, 00, new TimeSpan()), + }; + + client.GetAllForIssue(1, 3, request); + + gitHubClient.Connection.Received(1).Get>( + new Uri("repositories/1/issues/3/comments", UriKind.Relative), + Arg.Is>(d => d.Count == 3 + && d["since"] == "2016-11-23T11:11:11Z"), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -203,7 +243,9 @@ public void RequestsCorrectUrlWithApiOptions() client.GetAllForIssue("fake", "repo", 3, options); gitHubClient.Connection.Received(1).Get>( - new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), Arg.Is>(d => d.Count == 2), "application/vnd.github.squirrel-girl-preview"); + new Uri("repos/fake/repo/issues/3/comments", UriKind.Relative), + Arg.Is>(d => d.Count == 4), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -222,7 +264,9 @@ public void RequestsCorrectUrlWithRepositoryIdWithApiOptions() client.GetAllForIssue(1, 3, options); gitHubClient.Connection.Received(1).Get>( - new Uri("repositories/1/issues/3/comments", UriKind.Relative), Arg.Is>(d => d.Count == 2), null); + new Uri("repositories/1/issues/3/comments", UriKind.Relative), + Arg.Is>(d => d.Count == 4), + "application/vnd.github.squirrel-girl-preview"); } [Fact] @@ -235,9 +279,13 @@ public async Task EnsuresNonNullArguments() Assert.Throws(() => client.GetAllForIssue("owner", null, 1)); Assert.Throws(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None)); Assert.Throws(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None)); - Assert.Throws(() => client.GetAllForIssue("owner", "name", 1, null)); + Assert.Throws(() => client.GetAllForIssue("owner", "name", 1, options: null)); + Assert.Throws(() => client.GetAllForIssue("owner", "name", 1, request: null)); + Assert.Throws(() => client.GetAllForIssue("owner", "name", 1, null, ApiOptions.None)); - Assert.Throws(() => client.GetAllForIssue(1, 1, null)); + Assert.Throws(() => client.GetAllForIssue(1, 1, options: null)); + Assert.Throws(() => client.GetAllForIssue(1, 1, request: null)); + Assert.Throws(() => client.GetAllForIssue(1, 1, null, ApiOptions.None)); Assert.Throws(() => client.GetAllForIssue("", "name", 1)); Assert.Throws(() => client.GetAllForIssue("owner", "", 1)); diff --git a/Octokit/Clients/IIssueCommentsClient.cs b/Octokit/Clients/IIssueCommentsClient.cs index 0f75296dec..bd1a05e93d 100644 --- a/Octokit/Clients/IIssueCommentsClient.cs +++ b/Octokit/Clients/IIssueCommentsClient.cs @@ -137,6 +137,46 @@ public interface IIssueCommentsClient /// Options for changing the API response Task> GetAllForIssue(long repositoryId, int number, ApiOptions options); + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// The sorting parameters + Task> GetAllForIssue(string owner, string name, int number, IssueCommentRequest request); + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The Id of the repository + /// The issue number + /// The sorting parameters + Task> GetAllForIssue(long repositoryId, int number, IssueCommentRequest request); + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// The sorting parameters + /// Options for changing the API response + Task> GetAllForIssue(string owner, string name, int number, IssueCommentRequest request, ApiOptions options); + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The Id of the repository + /// The issue number + /// The sorting parameters + /// Options for changing the API response + Task> GetAllForIssue(long repositoryId, int number, IssueCommentRequest request, ApiOptions options); + /// /// Creates a new Issue Comment for a specified Issue. /// diff --git a/Octokit/Clients/IssueCommentsClient.cs b/Octokit/Clients/IssueCommentsClient.cs index 1c527d4b23..8f582cd3c9 100644 --- a/Octokit/Clients/IssueCommentsClient.cs +++ b/Octokit/Clients/IssueCommentsClient.cs @@ -200,7 +200,7 @@ public Task> GetAllForIssue(string owner, string nam Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.IssueComments(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); + return GetAllForIssue(owner, name, number, new IssueCommentRequest(), options); } /// @@ -214,7 +214,73 @@ public Task> GetAllForIssue(long repositoryId, int n { Ensure.ArgumentNotNull(options, nameof(options)); - return ApiConnection.GetAll(ApiUrls.IssueComments(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options); + return GetAllForIssue(repositoryId, number, new IssueCommentRequest(), options); + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// The sorting parameters + public Task> GetAllForIssue(string owner, string name, int number, IssueCommentRequest request) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(request, nameof(request)); + + return GetAllForIssue(owner, name, number, request, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The Id of the repository + /// The issue number + /// The sorting parameters + public Task> GetAllForIssue(long repositoryId, int number, IssueCommentRequest request) + { + Ensure.ArgumentNotNull(request, nameof(request)); + + return GetAllForIssue(repositoryId, number, request, ApiOptions.None); + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The owner of the repository + /// The name of the repository + /// The issue number + /// The sorting parameters + /// Options for changing the API response + public Task> GetAllForIssue(string owner, string name, int number, IssueCommentRequest request, ApiOptions options) + { + Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); + Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.IssueComments(owner, name, number), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); + } + + /// + /// Gets Issue Comments for a specified Issue. + /// + /// http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue + /// The Id of the repository + /// The issue number + /// The sorting parameters + /// Options for changing the API response + public Task> GetAllForIssue(long repositoryId, int number, IssueCommentRequest request, ApiOptions options) + { + Ensure.ArgumentNotNull(request, nameof(request)); + Ensure.ArgumentNotNull(options, nameof(options)); + + return ApiConnection.GetAll(ApiUrls.IssueComments(repositoryId, number), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } ///