2020
2121package com .spotify .github .v3 .clients ;
2222
23- import static com .spotify .github .v3 .clients .GitHubClient .IGNORE_RESPONSE_CONSUMER ;
24- import static com .spotify .github .v3 .clients .GitHubClient .LIST_COMMIT_TYPE_REFERENCE ;
25- import static com .spotify .github .v3 .clients .GitHubClient .LIST_PR_TYPE_REFERENCE ;
26- import static com .spotify .github .v3 .clients .GitHubClient .LIST_REVIEW_REQUEST_TYPE_REFERENCE ;
27- import static com .spotify .github .v3 .clients .GitHubClient .LIST_REVIEW_TYPE_REFERENCE ;
28- import static java .util .Objects .isNull ;
29-
30- import com .google .common .base .Strings ;
31- import com .google .common .collect .ImmutableMap ;
32- import com .spotify .github .async .AsyncPage ;
33- import com .spotify .github .v3 .prs .*;
34- import com .spotify .github .v3 .prs .requests .PullRequestCreate ;
35- import com .spotify .github .v3 .prs .requests .PullRequestParameters ;
36- import com .spotify .github .v3 .prs .requests .PullRequestUpdate ;
37- import com .spotify .github .v3 .repos .CommitItem ;
38-
3923import java .io .InputStreamReader ;
4024import java .io .Reader ;
4125import java .lang .invoke .MethodHandles ;
4226import java .util .Iterator ;
4327import java .util .List ;
4428import java .util .Map ;
29+ import static java .util .Objects .isNull ;
4530import java .util .concurrent .CompletableFuture ;
31+
4632import javax .ws .rs .core .HttpHeaders ;
33+
4734import org .slf4j .Logger ;
4835import org .slf4j .LoggerFactory ;
4936
37+ import com .google .common .base .Strings ;
38+ import com .google .common .collect .ImmutableMap ;
39+ import com .spotify .github .async .AsyncPage ;
40+ import static com .spotify .github .v3 .clients .GitHubClient .IGNORE_RESPONSE_CONSUMER ;
41+ import static com .spotify .github .v3 .clients .GitHubClient .LIST_COMMIT_TYPE_REFERENCE ;
42+ import static com .spotify .github .v3 .clients .GitHubClient .LIST_PR_TYPE_REFERENCE ;
43+ import static com .spotify .github .v3 .clients .GitHubClient .LIST_REVIEW_REQUEST_TYPE_REFERENCE ;
44+ import static com .spotify .github .v3 .clients .GitHubClient .LIST_REVIEW_TYPE_REFERENCE ;
45+ import com .spotify .github .v3 .prs .Comment ;
46+ import com .spotify .github .v3 .prs .MergeParameters ;
47+ import com .spotify .github .v3 .prs .PullRequest ;
48+ import com .spotify .github .v3 .prs .PullRequestItem ;
49+ import com .spotify .github .v3 .prs .RequestReviewParameters ;
50+ import com .spotify .github .v3 .prs .Review ;
51+ import com .spotify .github .v3 .prs .ReviewParameters ;
52+ import com .spotify .github .v3 .prs .ReviewRequests ;
53+ import com .spotify .github .v3 .prs .requests .PullRequestCreate ;
54+ import com .spotify .github .v3 .prs .requests .PullRequestParameters ;
55+ import com .spotify .github .v3 .prs .requests .PullRequestUpdate ;
56+ import com .spotify .github .v3 .repos .CommitItem ;
57+
5058/** Pull call API client */
5159public class PullRequestClient {
5260
@@ -57,6 +65,8 @@ public class PullRequestClient {
5765 private static final String PR_REVIEWS_TEMPLATE = "/repos/%s/%s/pulls/%s/reviews" ;
5866 private static final String PR_REVIEW_REQUESTS_TEMPLATE =
5967 "/repos/%s/%s/pulls/%s/requested_reviewers" ;
68+ private static final String PR_COMMENT_REPLIES_TEMPLATE =
69+ "/repos/%s/%s/pulls/%s/comments/%s/replies" ;
6070
6171 private final GitHubClient github ;
6272 private final String owner ;
@@ -450,4 +460,23 @@ private CompletableFuture<List<PullRequestItem>> list(final String parameterPath
450460 log .debug ("Fetching pull requests from " + path );
451461 return github .request (path , LIST_PR_TYPE_REFERENCE );
452462 }
463+
464+ /**
465+ * Creates a reply to a pull request review comment.
466+ *
467+ * @param prNumber pull request number
468+ * @param commentId the ID of the comment to reply to
469+ * @param body the reply message
470+ * @return the created comment
471+ * @see "https://docs.github.com/en/rest/pulls/comments#create-a-reply-for-a-review-comment"
472+ */
473+ public CompletableFuture <Comment > createCommentReply (
474+ final long prNumber , final long commentId , final String body ) {
475+ final String path =
476+ String .format (PR_COMMENT_REPLIES_TEMPLATE , owner , repo , prNumber , commentId );
477+ final Map <String , String > payload = ImmutableMap .of ("body" , body );
478+ final String jsonPayload = github .json ().toJsonUnchecked (payload );
479+ log .debug ("Creating reply to PR comment: " + path );
480+ return github .post (path , jsonPayload , Comment .class );
481+ }
453482}
0 commit comments