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 GetAll(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"); 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"); 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"); 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(); } } }