diff --git a/src/main/java/com/spotify/github/v3/prs/ReviewComment.java b/src/main/java/com/spotify/github/v3/prs/ReviewComment.java new file mode 100644 index 00000000..d42854df --- /dev/null +++ b/src/main/java/com/spotify/github/v3/prs/ReviewComment.java @@ -0,0 +1,60 @@ +/*- + * -\-\- + * github-client + * -- + * Copyright (C) 2016 - 2020 Spotify AB + * -- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * -/-/- + */ + +package com.spotify.github.v3.prs; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.spotify.github.GithubStyle; +import org.immutables.value.Value; + +/** + * Comment parameters for a draft review. + * + * @see "https://developer.github.com/v3/pulls/reviews/#input" + */ +@Value.Immutable +@GithubStyle +@JsonSerialize(as = ImmutableReviewComment.class) +@JsonDeserialize(as = ImmutableReviewComment.class) +@JsonInclude(JsonInclude.Include.NON_ABSENT) +public abstract class ReviewComment { + /** + * Relative path to the file that necessitates a review comment. + * + * @return the path to the file. + */ + public abstract String path(); + + /** + * Position in the diff where you want to add a review comment. + * + * @return the position in the diff. + */ + public abstract int position(); + + /** + * Text of the review comment. + * + * @return the text of the review. + */ + public abstract String body(); +} diff --git a/src/main/java/com/spotify/github/v3/prs/ReviewParameters.java b/src/main/java/com/spotify/github/v3/prs/ReviewParameters.java index 279b59db..e058baae 100644 --- a/src/main/java/com/spotify/github/v3/prs/ReviewParameters.java +++ b/src/main/java/com/spotify/github/v3/prs/ReviewParameters.java @@ -24,6 +24,8 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.spotify.github.GithubStyle; + +import java.util.List; import java.util.Optional; import org.immutables.value.Value; @@ -60,5 +62,10 @@ public abstract class ReviewParameters { */ public abstract String event(); - // FIXME: add the missing input for reviews: array of comment objects. + /** + * List of comments for a non-approve review. + * + * @return the list of comments for the review. + */ + public abstract List comments(); } diff --git a/src/test/java/com/spotify/github/v3/prs/ReviewParametersTest.java b/src/test/java/com/spotify/github/v3/prs/ReviewParametersTest.java new file mode 100644 index 00000000..33d6e5f3 --- /dev/null +++ b/src/test/java/com/spotify/github/v3/prs/ReviewParametersTest.java @@ -0,0 +1,53 @@ +/*- + * -\-\- + * github-client + * -- + * Copyright (C) 2016 - 2020 Spotify AB + * -- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * -/-/- + */ + +package com.spotify.github.v3.prs; + +import com.google.common.io.Resources; +import com.spotify.github.jackson.Json; +import org.junit.Test; + +import java.io.IOException; + +import static com.google.common.io.Resources.getResource; +import static java.nio.charset.Charset.defaultCharset; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +public class ReviewParametersTest { + @Test + public void testDeserialization() throws IOException { + final String fixture = + Resources.toString( + getResource(this.getClass(), "create_review.json"), + defaultCharset()); + final ReviewParameters reviewParameters = + Json.create().fromJson(fixture, ReviewParameters.class); + assertThat(reviewParameters.event(), is("APPROVE")); + assertThat(reviewParameters.commitId().get(), is("some_commit_id")); + assertThat(reviewParameters.body().get(), is("some_approval_comment")); + assertThat(reviewParameters.comments().size(), is(1)); + + final ReviewComment reviewComment = reviewParameters.comments().get(0); + assertThat(reviewComment.path(), is("some_file.txt")); + assertThat(reviewComment.position(), is(2)); + assertThat(reviewComment.body(), is("some_comment_on_file.txt")); + } +} diff --git a/src/test/resources/com/spotify/github/v3/prs/create_review.json b/src/test/resources/com/spotify/github/v3/prs/create_review.json new file mode 100644 index 00000000..541afcde --- /dev/null +++ b/src/test/resources/com/spotify/github/v3/prs/create_review.json @@ -0,0 +1,12 @@ +{ + "commit_id": "some_commit_id", + "body": "some_approval_comment", + "event": "APPROVE", + "comments": [ + { + "path": "some_file.txt", + "position": 2, + "body": "some_comment_on_file.txt" + } + ] +} \ No newline at end of file