Skip to content

Commit 7c72a8c

Browse files
Merge pull request #33 from brunodea/add-create-review
Add createReview action to PullRequestClient
2 parents e536832 + 27a77ca commit 7c72a8c

File tree

2 files changed

+79
-4
lines changed

2 files changed

+79
-4
lines changed

src/main/java/com/spotify/github/v3/clients/PullRequestClient.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727

2828
import com.google.common.base.Strings;
2929
import com.spotify.github.async.AsyncPage;
30-
import com.spotify.github.v3.prs.Review;
31-
import com.spotify.github.v3.prs.MergeParameters;
32-
import com.spotify.github.v3.prs.PullRequest;
33-
import com.spotify.github.v3.prs.PullRequestItem;
30+
import com.spotify.github.v3.prs.*;
3431
import com.spotify.github.v3.prs.requests.PullRequestCreate;
3532
import com.spotify.github.v3.prs.requests.PullRequestParameters;
3633
import com.spotify.github.v3.prs.requests.PullRequestUpdate;
@@ -162,6 +159,20 @@ public Iterator<AsyncPage<Review>> listReviews(final int number, final int items
162159
return new GithubPageIterator<>(new GithubPage<>(github, path, LIST_REVIEW_TYPE_REFERENCE));
163160
}
164161

162+
/**
163+
* Creates a review for a pull request.
164+
*
165+
* @param number pull request number
166+
* @param properties properties for reviewing the PR, such as sha, body and event
167+
* @see "https://developer.github.com/v3/pulls/reviews/#create-a-review-for-a-pull-request"
168+
*/
169+
public CompletableFuture<Review> createReview(final int number, final ReviewParameters properties) {
170+
final String path = String.format(PR_REVIEWS_TEMPLATE, owner, repo, number);
171+
final String jsonPayload = github.json().toJsonUnchecked(properties);
172+
log.debug("Creating review for PR: " + path);
173+
return github.post(path, jsonPayload, Review.class);
174+
}
175+
165176
/**
166177
* Merges a pull request.
167178
*
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*-
2+
* -\-\-
3+
* github-api
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
21+
package com.spotify.github.v3.prs;
22+
23+
import com.fasterxml.jackson.annotation.JsonInclude;
24+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
25+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
26+
import com.spotify.github.GithubStyle;
27+
import java.util.Optional;
28+
import org.immutables.value.Value;
29+
30+
/**
31+
* The parameters for creating a review for a Pull Request.
32+
*
33+
* @see "https://developer.github.com/v3/pulls/reviews/#input"
34+
*/
35+
@Value.Immutable
36+
@GithubStyle
37+
@JsonSerialize(as = ImmutableReviewParameters.class)
38+
@JsonDeserialize(as = ImmutableReviewParameters.class)
39+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
40+
public abstract class ReviewParameters {
41+
/**
42+
* SHA of the commit that needs a review. If not the latest, the review may be outdated.
43+
* Defaults to the most recent commit in the PR when you do not specify a value.
44+
*
45+
* @return the optional commitId.
46+
*/
47+
public abstract Optional<String> commitId();
48+
49+
/**
50+
* **required** when using REQUEST_CHANGES or COMMENT for the event.
51+
*
52+
* @return the optional body for REQUEST_CHANGES or COMMENT events.
53+
*/
54+
public abstract Optional<String> body();
55+
56+
/**
57+
* Review action you want to perform. Should be one of: APPROVE, REQUEST_CHANGES or COMMENT.
58+
*
59+
* @return the review action to perform.
60+
*/
61+
public abstract String event();
62+
63+
// FIXME: add the missing input for reviews: array of comment objects.
64+
}

0 commit comments

Comments
 (0)