2323import static com .spotify .github .v3 .clients .GitHubClient .IGNORE_RESPONSE_CONSUMER ;
2424import static com .spotify .github .v3 .clients .GitHubClient .LIST_COMMIT_TYPE_REFERENCE ;
2525import 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 ;
2627import static com .spotify .github .v3 .clients .GitHubClient .LIST_REVIEW_TYPE_REFERENCE ;
2728
2829import com .google .common .base .Strings ;
@@ -47,6 +48,7 @@ public class PullRequestClient {
4748 private static final String PR_NUMBER_TEMPLATE = "/repos/%s/%s/pulls/%s" ;
4849 private static final String PR_COMMITS_TEMPLATE = "/repos/%s/%s/pulls/%s/commits" ;
4950 private static final String PR_REVIEWS_TEMPLATE = "/repos/%s/%s/pulls/%s/reviews" ;
51+ private static final String PR_REVIEW_REQUESTS_TEMPLATE = "/repos/%s/%s/pulls/%s/requested_reviewers" ;
5052
5153 private final GitHubClient github ;
5254 private final String owner ;
@@ -173,6 +175,46 @@ public CompletableFuture<Review> createReview(final int number, final ReviewPara
173175 return github .post (path , jsonPayload , Review .class );
174176 }
175177
178+ /**
179+ * List pull request requested reviews.
180+ *
181+ * @param number pull request number
182+ * @return list of reviews
183+ */
184+ public CompletableFuture <ReviewRequests > listReviewRequests (final int number ) {
185+ final String path = String .format (PR_REVIEW_REQUESTS_TEMPLATE , owner , repo , number );
186+ log .debug ("Fetching pull request requested reviews from " + path );
187+ return github .request (path , LIST_REVIEW_REQUEST_TYPE_REFERENCE );
188+ }
189+
190+ /**
191+ * Requests a review for a pull request.
192+ *
193+ * @param number pull request number
194+ * @param properties properties for reviewing the PR, such as reviewers and team_reviewers.
195+ * @see "https://docs.github.com/en/rest/reference/pulls#request-reviewers-for-a-pull-request"
196+ */
197+ public CompletableFuture <PullRequest > requestReview (final int number , final RequestReviewParameters properties ) {
198+ final String path = String .format (PR_REVIEW_REQUESTS_TEMPLATE , owner , repo , number );
199+ final String jsonPayload = github .json ().toJsonUnchecked (properties );
200+ log .debug ("Requesting reviews for PR: " + path );
201+ return github .post (path , jsonPayload , PullRequest .class );
202+ }
203+
204+ /**
205+ * Remove a request for review for a pull request.
206+ *
207+ * @param number pull request number
208+ * @param properties properties for reviewing the PR, such as reviewers and team_reviewers.
209+ * @see "https://docs.github.com/en/rest/reference/pulls#request-reviewers-for-a-pull-request"
210+ */
211+ public CompletableFuture <Void > removeRequestedReview (final int number , final RequestReviewParameters properties ) {
212+ final String path = String .format (PR_REVIEW_REQUESTS_TEMPLATE , owner , repo , number );
213+ final String jsonPayload = github .json ().toJsonUnchecked (properties );
214+ log .debug ("Removing requested reviews for PR: " + path );
215+ return github .delete (path , jsonPayload ).thenAccept (IGNORE_RESPONSE_CONSUMER );
216+ }
217+
176218 /**
177219 * Merges a pull request.
178220 *
@@ -192,4 +234,5 @@ private CompletableFuture<List<PullRequestItem>> list(final String parameterPath
192234 log .debug ("Fetching pull requests from " + path );
193235 return github .request (path , LIST_PR_TYPE_REFERENCE );
194236 }
237+
195238}
0 commit comments