using System.Collections.Generic; using System.Net; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub's Pull Request Review Comments API. /// /// /// See the Review Comments API documentation for more information. /// 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 [ManualRoute("GET", "/repos/{owner}/{repo}/pulls/{pull_number}/comments")] public Task> GetAll(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return GetAll(owner, name, number, ApiOptions.None); } /// /// Gets review comments for a specified pull request. /// /// http://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request /// The Id of the repository /// The pull request number [ManualRoute("GET", "/repositories/{id}/pulls/{number}/comments")] public Task> GetAll(long repositoryId, int number) { return GetAll(repositoryId, number, ApiOptions.None); } /// /// 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 /// Options for changing the API response [ManualRoute("GET", "/repos/{owner}/{repo}/pulls/{pull_number}/comments")] [Preview("squirrel-girl")] public Task> GetAll(string owner, string name, int number, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(ApiUrls.PullRequestReviewComments(owner, name, number), null, AcceptHeaders.ReactionsPreview, options); } /// /// Gets review comments for a specified pull request. /// /// http://developer.github.com/v3/pulls/comments/#list-comments-on-a-pull-request /// The Id of the repository /// The pull request number /// Options for changing the API response [ManualRoute("GET", "/repositories/{id}/pulls/{number}/comments")] public Task> GetAll(long repositoryId, int number, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(ApiUrls.PullRequestReviewComments(repositoryId, number), options); } /// /// 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 [ManualRoute("GET", "/repos/{owner}/{repo}/pulls/comments")] public Task> GetAllForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return GetAllForRepository(owner, name, new PullRequestReviewCommentRequest(), ApiOptions.None); } /// /// 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 Id of the repository [ManualRoute("GET", "/repositories/{id}/pulls/comments")] public Task> GetAllForRepository(long repositoryId) { return GetAllForRepository(repositoryId, new PullRequestReviewCommentRequest(), ApiOptions.None); } /// /// 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 /// Options for changing the API response [ManualRoute("GET", "/repos/{owner}/{repo}/pulls/comments")] public Task> GetAllForRepository(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return GetAllForRepository(owner, name, new PullRequestReviewCommentRequest(), options); } /// /// 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 Id of the repository /// Options for changing the API response [ManualRoute("GET", "/repositories/{id}/pulls/comments")] public Task> GetAllForRepository(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return GetAllForRepository(repositoryId, new PullRequestReviewCommentRequest(), options); } /// /// 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 [ManualRoute("GET", "/repos/{owner}/{repo}/pulls/comments")] public Task> GetAllForRepository(string owner, string name, PullRequestReviewCommentRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForRepository(owner, name, request, ApiOptions.None); } /// /// 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 Id of the repository /// The sorting parameters [ManualRoute("GET", "/repositories/{id}/pulls/comments")] public Task> GetAllForRepository(long repositoryId, PullRequestReviewCommentRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForRepository(repositoryId, request, ApiOptions.None); } /// /// 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 /// Options for changing the API response [Preview("squirrel-girl")] [ManualRoute("GET", "/repos/{owner}/{repo}/pulls/comments")] public Task> GetAllForRepository(string owner, string name, PullRequestReviewCommentRequest 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.PullRequestReviewCommentsRepository(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// /// 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 Id of the repository /// The sorting parameters /// Options for changing the API response [Preview("squirrel-girl")] [ManualRoute("GET", "/repositories/{id}/pulls/comments")] public Task> GetAllForRepository(long repositoryId, PullRequestReviewCommentRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(ApiUrls.PullRequestReviewCommentsRepository(repositoryId), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, options); } /// /// 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 [Preview("squirrel-girl")] [ManualRoute("GET", "/repos/{owner}/{repo}/pulls/comments/{comment_id}")] public Task GetComment(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return ApiConnection.Get(ApiUrls.PullRequestReviewComment(owner, name, number), new Dictionary(), AcceptHeaders.ReactionsPreview); } /// /// Gets a single pull request review comment by number. /// /// http://developer.github.com/v3/pulls/comments/#get-a-single-comment /// The Id of the repository /// The pull request review comment number [ManualRoute("GET", "/repositories/{id}/pulls/comments/{number}")] public Task GetComment(long repositoryId, int number) { return ApiConnection.Get(ApiUrls.PullRequestReviewComment(repositoryId, 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 [ManualRoute("POST", "/repos/{owner}/{repo}/pulls/{pull_number}/comments")] public async Task Create(string owner, string name, int number, PullRequestReviewCommentCreate comment) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(comment, nameof(comment)); var endpoint = ApiUrls.PullRequestReviewComments(owner, name, number); var response = await ApiConnection.Connection.Post(endpoint, comment, null, null).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.Created) { throw new ApiException("Invalid Status Code returned. Expected a 201", response.HttpResponse.StatusCode); } return response.Body; } /// /// Creates a comment on a pull request review. /// /// http://developer.github.com/v3/pulls/comments/#create-a-comment /// The Id of the repository /// The Pull Request number /// The comment [ManualRoute("POST", "/repositories/{id}/pulls/{number}/comments")] public async Task Create(long repositoryId, int number, PullRequestReviewCommentCreate comment) { Ensure.ArgumentNotNull(comment, nameof(comment)); var endpoint = ApiUrls.PullRequestReviewComments(repositoryId, number); var response = await ApiConnection.Connection.Post(endpoint, comment, null, null).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.Created) { throw new ApiException("Invalid Status Code returned. Expected a 201", response.HttpResponse.StatusCode); } return response.Body; } /// /// 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 [ManualRoute("POST", "/repos/{owner}/{repo}/pulls/{pull_number}/comment")] public async Task CreateReply(string owner, string name, int number, PullRequestReviewCommentReplyCreate comment) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(comment, nameof(comment)); var endpoint = ApiUrls.PullRequestReviewComments(owner, name, number); var response = await ApiConnection.Connection.Post(endpoint, comment, null, null).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.Created) { throw new ApiException("Invalid Status Code returned. Expected a 201", response.HttpResponse.StatusCode); } return response.Body; } /// /// 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 Id of the repository /// The pull request number /// The comment [ManualRoute("POST", "/repositories/{id}/pulls/{number}/comments")] public async Task CreateReply(long repositoryId, int number, PullRequestReviewCommentReplyCreate comment) { Ensure.ArgumentNotNull(comment, nameof(comment)); var endpoint = ApiUrls.PullRequestReviewComments(repositoryId, number); var response = await ApiConnection.Connection.Post(endpoint, comment, null, null).ConfigureAwait(false); if (response.HttpResponse.StatusCode != HttpStatusCode.Created) { throw new ApiException("Invalid Status Code returned. Expected a 201", response.HttpResponse.StatusCode); } return response.Body; } /// /// 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 [ManualRoute("PATCH", "/repos/{owner}/{repo}/pulls/comments/{comment_id}")] public Task Edit(string owner, string name, int number, PullRequestReviewCommentEdit comment) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(comment, nameof(comment)); return ApiConnection.Patch(ApiUrls.PullRequestReviewComment(owner, name, number), comment); } /// /// Edits a comment on a pull request review. /// /// http://developer.github.com/v3/pulls/comments/#edit-a-comment /// The Id of the repository /// The pull request review comment number /// The edited comment [ManualRoute("PATCH", "/repositories/{id}/pulls/comments/{number}")] public Task Edit(long repositoryId, int number, PullRequestReviewCommentEdit comment) { Ensure.ArgumentNotNull(comment, nameof(comment)); return ApiConnection.Patch(ApiUrls.PullRequestReviewComment(repositoryId, 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 [ManualRoute("DELETE", "/repos/{owner}/{repo}/pulls/comments/{comment_id}")] public Task Delete(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return ApiConnection.Delete(ApiUrls.PullRequestReviewComment(owner, name, number)); } /// /// Deletes a comment on a pull request review. /// /// http://developer.github.com/v3/pulls/comments/#delete-a-comment /// The Id of the repository /// The pull request review comment number [ManualRoute("DELETE", "/repositories/{id}/pulls/comments/{number}")] public Task Delete(long repositoryId, int number) { return ApiConnection.Delete(ApiUrls.PullRequestReviewComment(repositoryId, number)); } } }