Skip to content

Commit

Permalink
Add tests for multi-line review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Wiewiora committed Apr 19, 2024
1 parent 6cd648a commit b5f5551
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/main/java/org/kohsuke/github/GHPullRequest.java
Expand Up @@ -572,9 +572,11 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S
* @throws IOException
* the io exception
*/
public GHPullRequestReviewComment createReviewComment(String body, String sha, String path, Integer startLine,
Integer endLine)
throws IOException {
public GHPullRequestReviewComment createReviewComment(String body,
String sha,
String path,
Integer startLine,
Integer endLine) throws IOException {
return root().createRequest()
.method("POST")
.with("body", body)
Expand Down
25 changes: 23 additions & 2 deletions src/test/java/org/kohsuke/github/GHPullRequestTest.java
Expand Up @@ -234,6 +234,8 @@ public void pullRequestReviews() throws Exception {
GHPullRequestReview draftReview = p.createReview()
.body("Some draft review")
.comment("Some niggle", "README.md", 1)
.singleLineComment("A single line comment", "README.md", 2)
.multiLineComment("A multiline comment", "README.md", 2, 3)
.create();
assertThat(draftReview.getState(), is(GHPullRequestReviewState.PENDING));
assertThat(draftReview.getBody(), is("Some draft review"));
Expand All @@ -246,9 +248,16 @@ public void pullRequestReviews() throws Exception {
assertThat(review.getCommitId(), notNullValue());
draftReview.submit("Some review comment", GHPullRequestReviewEvent.COMMENT);
List<GHPullRequestReviewComment> comments = review.listReviewComments().toList();
assertThat(comments.size(), equalTo(1));
assertThat(comments.size(), equalTo(3));
GHPullRequestReviewComment comment = comments.get(0);
assertThat(comment.getBody(), equalTo("Some niggle"));
comment = comments.get(1);
assertThat(comment.getBody(), equalTo("A single line comment"));
assertThat(comment.getLine(), equalTo(2));
comment = comments.get(2);
assertThat(comment.getBody(), equalTo("A multiline comment"));
assertThat(comment.getStartLine(), equalTo(2));
assertThat(comment.getLine(), equalTo(3));
draftReview = p.createReview().body("Some new review").comment("Some niggle", "README.md", 1).create();
draftReview.delete();
}
Expand All @@ -267,8 +276,11 @@ public void pullRequestReviewComments() throws Exception {
// System.out.println(p.getUrl());
assertThat(p.listReviewComments().toList(), is(empty()));
p.createReviewComment("Sample review comment", p.getHead().getSha(), "README.md", 1);
p.createReviewComment("A single line review comment", p.getHead().getSha(), "README.md", 2, null);
p.createReviewComment("A multiline review comment", p.getHead().getSha(), "README.md", 2, 3);
List<GHPullRequestReviewComment> comments = p.listReviewComments().toList();
assertThat(comments.size(), equalTo(1));
assertThat(comments.size(), equalTo(3));

GHPullRequestReviewComment comment = comments.get(0);
assertThat(comment.getBody(), equalTo("Sample review comment"));
assertThat(comment.getInReplyToId(), equalTo(-1L));
Expand All @@ -294,6 +306,15 @@ public void pullRequestReviewComments() throws Exception {
assertThat(comment.getHtmlUrl().toString(),
containsString("hub4j-test-org/github-api/pull/" + p.getNumber()));

comment = comments.get(1);
assertThat(comment.getBody(), equalTo("A single line review comment"));
assertThat(comment.getLine(), equalTo(2));

comment = comments.get(2);
assertThat(comment.getBody(), equalTo("A multiline review comment"));
assertThat(comment.getStartLine(), equalTo(2));
assertThat(comment.getLine(), equalTo(3));

comment.createReaction(ReactionContent.EYES);
GHReaction toBeRemoved = comment.createReaction(ReactionContent.CONFUSED);
comment.createReaction(ReactionContent.ROCKET);
Expand Down

0 comments on commit b5f5551

Please sign in to comment.