From b57a0796a3adf09716393b85493db4cbb9579193 Mon Sep 17 00:00:00 2001 From: Johnathan Gilday Date: Fri, 21 Mar 2025 13:34:38 -0400 Subject: [PATCH 1/3] Add side and start_side Parameters to Create Review Comment Follows existing pattern from line and start_line --- .../GHPullRequestReviewCommentBuilder.java | 37 +++++++++++++++++++ .../org/kohsuke/github/GHPullRequestTest.java | 9 ++++- .../mappings/7-r_h_g_pulls_484_comments.json | 4 +- .../mappings/8-r_h_g_pulls_484_comments.json | 4 +- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java index a3b267c9f9..0d2834bdbe 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java @@ -110,6 +110,43 @@ public GHPullRequestReviewCommentBuilder lines(int startLine, int endLine) { return this; } + /** + * The side of the diff in the pull request that the comment applies to. + *

+ * {@link #side(GHPullRequestReviewComment.Side)} and + * {@link #sides(GHPullRequestReviewComment.Side, GHPullRequestReviewComment.Side)} will overwrite each other's + * values. + * + * @param side + * side of the diff to which the comment applies + * @return the gh pull request review comment builder + */ + public GHPullRequestReviewCommentBuilder side(GHPullRequestReviewComment.Side side) { + builder.with("side", side.toString().toLowerCase()); + builder.remove("start_side"); + return this; + } + + /** + * The sides of the diff in the pull request that the comment applies to. + *

+ * {@link #side(GHPullRequestReviewComment.Side)} and + * {@link #sides(GHPullRequestReviewComment.Side, GHPullRequestReviewComment.Side)} will overwrite each other's + * values. + * + * @param startSide + * side of the diff to which the start of the comment applies + * @param endSide + * side of the diff to which the end of the comment applies + * @return the gh pull request review comment builder + */ + public GHPullRequestReviewCommentBuilder sides(GHPullRequestReviewComment.Side startSide, + GHPullRequestReviewComment.Side endSide) { + builder.with("start_side", startSide.toString().toLowerCase()); + builder.with("side", endSide.toString().toLowerCase()); + return this; + } + /** * Create gh pull request review comment. * diff --git a/src/test/java/org/kohsuke/github/GHPullRequestTest.java b/src/test/java/org/kohsuke/github/GHPullRequestTest.java index ba43195755..3beddb2769 100644 --- a/src/test/java/org/kohsuke/github/GHPullRequestTest.java +++ b/src/test/java/org/kohsuke/github/GHPullRequestTest.java @@ -25,6 +25,8 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; +import static org.kohsuke.github.GHPullRequestReviewComment.Side.LEFT; +import static org.kohsuke.github.GHPullRequestReviewComment.Side.RIGHT; // TODO: Auto-generated Javadoc /** @@ -337,12 +339,14 @@ public void pullRequestReviewComments() throws Exception { .body("A single line review comment") .path("README.md") .line(2) + .side(RIGHT) .create(); p.createReviewComment() .commitId(p.getHead().getSha()) .body("A multiline review comment") .path("README.md") .lines(2, 3) + .sides(RIGHT, RIGHT) .create(); List comments = p.listReviewComments().toList(); assertThat(comments.size(), equalTo(3)); @@ -362,7 +366,7 @@ public void pullRequestReviewComments() throws Exception { assertThat(comment.getStartSide(), equalTo(GHPullRequestReviewComment.Side.UNKNOWN)); assertThat(comment.getLine(), equalTo(1)); assertThat(comment.getOriginalLine(), equalTo(1)); - assertThat(comment.getSide(), equalTo(GHPullRequestReviewComment.Side.LEFT)); + assertThat(comment.getSide(), equalTo(LEFT)); assertThat(comment.getPullRequestUrl(), notNullValue()); assertThat(comment.getPullRequestUrl().toString(), containsString("hub4j-test-org/github-api/pulls/")); assertThat(comment.getBodyHtml(), nullValue()); @@ -375,11 +379,14 @@ public void pullRequestReviewComments() throws Exception { comment = comments.get(1); assertThat(comment.getBody(), equalTo("A single line review comment")); assertThat(comment.getLine(), equalTo(2)); + assertThat(comment.getSide(), equalTo(RIGHT)); comment = comments.get(2); assertThat(comment.getBody(), equalTo("A multiline review comment")); assertThat(comment.getStartLine(), equalTo(2)); assertThat(comment.getLine(), equalTo(3)); + assertThat(comment.getStartSide(), equalTo(RIGHT)); + assertThat(comment.getSide(), equalTo(RIGHT)); comment.createReaction(ReactionContent.EYES); GHReaction toBeRemoved = comment.createReaction(ReactionContent.CONFUSED); diff --git a/src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/mappings/7-r_h_g_pulls_484_comments.json b/src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/mappings/7-r_h_g_pulls_484_comments.json index c62816d287..94ea535e21 100644 --- a/src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/mappings/7-r_h_g_pulls_484_comments.json +++ b/src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/mappings/7-r_h_g_pulls_484_comments.json @@ -11,7 +11,7 @@ }, "bodyPatterns": [ { - "equalToJson": "{\"path\":\"README.md\",\"line\":2,\"body\":\"A single line review comment\",\"commit_id\":\"07374fe73aff1c2024a8d4114b32406c7a8e89b7\"}", + "equalToJson": "{\"path\":\"README.md\",\"side\":\"right\",\"line\":2,\"body\":\"A single line review comment\",\"commit_id\":\"07374fe73aff1c2024a8d4114b32406c7a8e89b7\"}", "ignoreArrayOrder": true, "ignoreExtraElements": false } @@ -55,4 +55,4 @@ "uuid": "43f15589-cf59-4ed5-a2b8-8f6b7ebae791", "persistent": true, "insertionIndex": 7 -} \ No newline at end of file +} diff --git a/src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/mappings/8-r_h_g_pulls_484_comments.json b/src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/mappings/8-r_h_g_pulls_484_comments.json index 2b80fe4f36..f335232943 100644 --- a/src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/mappings/8-r_h_g_pulls_484_comments.json +++ b/src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/mappings/8-r_h_g_pulls_484_comments.json @@ -11,7 +11,7 @@ }, "bodyPatterns": [ { - "equalToJson": "{\"path\":\"README.md\",\"line\":3,\"start_line\":2,\"body\":\"A multiline review comment\",\"commit_id\":\"07374fe73aff1c2024a8d4114b32406c7a8e89b7\"}", + "equalToJson": "{\"path\":\"README.md\",\"side\":\"right\",\"start_side\":\"right\",\"line\":3,\"start_line\":2,\"body\":\"A multiline review comment\",\"commit_id\":\"07374fe73aff1c2024a8d4114b32406c7a8e89b7\"}", "ignoreArrayOrder": true, "ignoreExtraElements": false } @@ -55,4 +55,4 @@ "uuid": "efe94b1b-7f9c-4bba-9af2-0a7a59a498ab", "persistent": true, "insertionIndex": 8 -} \ No newline at end of file +} From 64f1332a77a1bb4ac15d15e63864d799dfe37e90 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 25 Mar 2025 00:25:31 -0700 Subject: [PATCH 2/3] Update src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java --- .../org/kohsuke/github/GHPullRequestReviewCommentBuilder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java index 0d2834bdbe..61110e6467 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java @@ -142,8 +142,8 @@ public GHPullRequestReviewCommentBuilder side(GHPullRequestReviewComment.Side si */ public GHPullRequestReviewCommentBuilder sides(GHPullRequestReviewComment.Side startSide, GHPullRequestReviewComment.Side endSide) { - builder.with("start_side", startSide.toString().toLowerCase()); - builder.with("side", endSide.toString().toLowerCase()); + builder.with("start_side", startSide); + builder.with("side", endSide); return this; } From b4e11d4bd0f2168173725b7e629c8b3c9ef237f2 Mon Sep 17 00:00:00 2001 From: Liam Newman Date: Tue, 25 Mar 2025 00:26:50 -0700 Subject: [PATCH 3/3] Update src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java --- .../org/kohsuke/github/GHPullRequestReviewCommentBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java index 61110e6467..98709f6e8f 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java @@ -122,7 +122,7 @@ public GHPullRequestReviewCommentBuilder lines(int startLine, int endLine) { * @return the gh pull request review comment builder */ public GHPullRequestReviewCommentBuilder side(GHPullRequestReviewComment.Side side) { - builder.with("side", side.toString().toLowerCase()); + builder.with("side", side); builder.remove("start_side"); return this; }