Skip to content

Commit 74bb1fc

Browse files
authored
Add ReviewComment attribute to ReviewParameters (#34)
1 parent ef7fc68 commit 74bb1fc

File tree

4 files changed

+133
-1
lines changed

4 files changed

+133
-1
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*-
2+
* -\-\-
3+
* github-client
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 org.immutables.value.Value;
28+
29+
/**
30+
* Comment parameters for a draft review.
31+
*
32+
* @see "https://developer.github.com/v3/pulls/reviews/#input"
33+
*/
34+
@Value.Immutable
35+
@GithubStyle
36+
@JsonSerialize(as = ImmutableReviewComment.class)
37+
@JsonDeserialize(as = ImmutableReviewComment.class)
38+
@JsonInclude(JsonInclude.Include.NON_ABSENT)
39+
public abstract class ReviewComment {
40+
/**
41+
* Relative path to the file that necessitates a review comment.
42+
*
43+
* @return the path to the file.
44+
*/
45+
public abstract String path();
46+
47+
/**
48+
* Position in the diff where you want to add a review comment.
49+
*
50+
* @return the position in the diff.
51+
*/
52+
public abstract int position();
53+
54+
/**
55+
* Text of the review comment.
56+
*
57+
* @return the text of the review.
58+
*/
59+
public abstract String body();
60+
}

src/main/java/com/spotify/github/v3/prs/ReviewParameters.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2525
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2626
import com.spotify.github.GithubStyle;
27+
28+
import java.util.List;
2729
import java.util.Optional;
2830
import org.immutables.value.Value;
2931

@@ -60,5 +62,10 @@ public abstract class ReviewParameters {
6062
*/
6163
public abstract String event();
6264

63-
// FIXME: add the missing input for reviews: array of comment objects.
65+
/**
66+
* List of comments for a non-approve review.
67+
*
68+
* @return the list of comments for the review.
69+
*/
70+
public abstract List<ReviewComment> comments();
6471
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*-
2+
* -\-\-
3+
* github-client
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.google.common.io.Resources;
24+
import com.spotify.github.jackson.Json;
25+
import org.junit.Test;
26+
27+
import java.io.IOException;
28+
29+
import static com.google.common.io.Resources.getResource;
30+
import static java.nio.charset.Charset.defaultCharset;
31+
import static org.hamcrest.MatcherAssert.assertThat;
32+
import static org.hamcrest.core.Is.is;
33+
34+
public class ReviewParametersTest {
35+
@Test
36+
public void testDeserialization() throws IOException {
37+
final String fixture =
38+
Resources.toString(
39+
getResource(this.getClass(), "create_review.json"),
40+
defaultCharset());
41+
final ReviewParameters reviewParameters =
42+
Json.create().fromJson(fixture, ReviewParameters.class);
43+
assertThat(reviewParameters.event(), is("APPROVE"));
44+
assertThat(reviewParameters.commitId().get(), is("some_commit_id"));
45+
assertThat(reviewParameters.body().get(), is("some_approval_comment"));
46+
assertThat(reviewParameters.comments().size(), is(1));
47+
48+
final ReviewComment reviewComment = reviewParameters.comments().get(0);
49+
assertThat(reviewComment.path(), is("some_file.txt"));
50+
assertThat(reviewComment.position(), is(2));
51+
assertThat(reviewComment.body(), is("some_comment_on_file.txt"));
52+
}
53+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"commit_id": "some_commit_id",
3+
"body": "some_approval_comment",
4+
"event": "APPROVE",
5+
"comments": [
6+
{
7+
"path": "some_file.txt",
8+
"position": 2,
9+
"body": "some_comment_on_file.txt"
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)