Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for passing sort options to IssueCommentsClient.GetAllForRepository() #1501

Merged
merged 13 commits into from
Jan 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Octokit.Reactive/Clients/IObservableIssueCommentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@ public interface IObservableIssueCommentsClient
/// <param name="options">Options for changing the API response</param>
IObservable<IssueComment> GetAllForRepository(long repositoryId, ApiOptions options);

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
IObservable<IssueComment> GetAllForRepository(string owner, string name, IssueCommentRequest request);

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
IObservable<IssueComment> GetAllForRepository(long repositoryId, IssueCommentRequest request);

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
/// <param name="options">Options for changing the API response</param>
IObservable<IssueComment> GetAllForRepository(string owner, string name, IssueCommentRequest request, ApiOptions options);

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
/// <param name="options">Options for changing the API response</param>
IObservable<IssueComment> GetAllForRepository(long repositoryId, IssueCommentRequest request, ApiOptions options);

/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
Expand Down
66 changes: 64 additions & 2 deletions Octokit.Reactive/Clients/ObservableIssueCommentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public IObservable<IssueComment> GetAllForRepository(string owner, string name,
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(owner, name), null, AcceptHeaders.ReactionsPreview, options);
return GetAllForRepository(owner, name, new IssueCommentRequest(), options);
}

/// <summary>
Expand All @@ -100,7 +100,69 @@ public IObservable<IssueComment> GetAllForRepository(long repositoryId, ApiOptio
{
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(repositoryId), options);
return GetAllForRepository(repositoryId, new IssueCommentRequest(), options);
}

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
public IObservable<IssueComment> GetAllForRepository(string owner, string name, IssueCommentRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "request");

return GetAllForRepository(owner, name, request, ApiOptions.None);
}

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
public IObservable<IssueComment> GetAllForRepository(long repositoryId, IssueCommentRequest request)
{
Ensure.ArgumentNotNull(request, "request");

return GetAllForRepository(repositoryId, request, ApiOptions.None);
}

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
/// <param name="options">Options for changing the API response</param>
public IObservable<IssueComment> GetAllForRepository(string owner, string name, IssueCommentRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
/// <param name="options">Options for changing the API response</param>
public IObservable<IssueComment> GetAllForRepository(long repositoryId, IssueCommentRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(repositoryId), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options);
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions Octokit.Tests/Clients/IssueCommentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ public async Task EnsuresNonNullArguments()
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, "name", ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null, ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", options: null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None));

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, options: null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(1, null, ApiOptions.None));

await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("owner", ""));
Expand Down
44 changes: 34 additions & 10 deletions Octokit.Tests/Reactive/ObservableIssueCommentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void RequestsCorrectUrl()
client.GetAllForRepository("fake", "repo");

gitHubClient.Connection.Received(1).Get<List<IssueComment>>(
new Uri("repos/fake/repo/issues/comments", UriKind.Relative),
Args.EmptyDictionary,
new Uri("repos/fake/repo/issues/comments", UriKind.Relative),
Arg.Any<IDictionary<string, string>>(),
"application/vnd.github.squirrel-girl-preview");
}

Expand All @@ -71,7 +71,9 @@ public void RequestsCorrectUrlWithRepositoryId()
client.GetAllForRepository(1);

gitHubClient.Connection.Received(1).Get<List<IssueComment>>(
new Uri("repositories/1/issues/comments", UriKind.Relative), Args.EmptyDictionary, null);
new Uri("repositories/1/issues/comments", UriKind.Relative),
Arg.Any<IDictionary<string, string>>(),
"application/vnd.github.squirrel-girl-preview");
}

[Fact]
Expand All @@ -80,18 +82,27 @@ public void RequestsCorrectUrlWithApiOptions()
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableIssueCommentsClient(gitHubClient);

var request = new IssueCommentRequest()
{
Direction = SortDirection.Descending,
Since = new DateTimeOffset(2016, 11, 23, 11, 11, 11, 00, new TimeSpan()),
Sort = PullRequestReviewCommentSort.Updated
};
var options = new ApiOptions
{
StartPage = 1,
PageSize = 1,
PageCount = 1
};

client.GetAllForRepository("fake", "repo", options);
client.GetAllForRepository("fake", "repo", request, options);

gitHubClient.Connection.Received(1).Get<List<IssueComment>>(
new Uri("repos/fake/repo/issues/comments", UriKind.Relative),
Arg.Any<Dictionary<string, string>>(),
new Uri("repos/fake/repo/issues/comments", UriKind.Relative),
Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["direction"] == "desc"
&& d["since"] == "2016-11-23T11:11:11Z"
&& d["sort"] == "updated"),
"application/vnd.github.squirrel-girl-preview");
}

Expand All @@ -101,17 +112,28 @@ public void RequestsCorrectUrlWithRepositoryIdWithApiOptions()
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableIssueCommentsClient(gitHubClient);

var request = new IssueCommentRequest()
{
Direction = SortDirection.Descending,
Since = new DateTimeOffset(2016, 11, 23, 11, 11, 11, 00, new TimeSpan()),
Sort = PullRequestReviewCommentSort.Updated
};
var options = new ApiOptions
{
StartPage = 1,
PageSize = 1,
PageCount = 1
};

client.GetAllForRepository(1, options);
client.GetAllForRepository(1, request, options);

gitHubClient.Connection.Received(1).Get<List<IssueComment>>(
new Uri("repositories/1/issues/comments", UriKind.Relative), Arg.Is<IDictionary<string, string>>(d => d.Count == 2), null);
new Uri("repositories/1/issues/comments", UriKind.Relative),
Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["direction"] == "desc"
&& d["since"] == "2016-11-23T11:11:11Z"
&& d["sort"] == "updated"),
"application/vnd.github.squirrel-girl-preview");
}

[Fact]
Expand All @@ -124,9 +146,11 @@ public async Task EnsuresNonNullArguments()
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(null, "name", ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", request: null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", options: null));

Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, request: null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForRepository(1, options: null));

Assert.Throws<ArgumentException>(() => client.GetAllForRepository("", "name"));
Assert.Throws<ArgumentException>(() => client.GetAllForRepository("owner", ""));
Expand Down
36 changes: 36 additions & 0 deletions Octokit/Clients/IIssueCommentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,42 @@ public interface IIssueCommentsClient
/// <param name="options">Options for changing the API response</param>
Task<IReadOnlyList<IssueComment>> GetAllForRepository(long repositoryId, ApiOptions options);

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
Task<IReadOnlyList<IssueComment>> GetAllForRepository(string owner, string name, IssueCommentRequest request);

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
Task<IReadOnlyList<IssueComment>> GetAllForRepository(long repositoryId, IssueCommentRequest request);

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
/// <param name="options">Options for changing the API response</param>
Task<IReadOnlyList<IssueComment>> GetAllForRepository(string owner, string name, IssueCommentRequest request, ApiOptions options);

/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The Id of the repository</param>
/// <param name="request">The sorting <see cref="IssueCommentRequest">parameters</see></param>
/// <param name="options">Options for changing the API response</param>
Task<IReadOnlyList<IssueComment>> GetAllForRepository(long repositoryId, IssueCommentRequest request, ApiOptions options);

/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
Expand Down
Loading