Skip to content

Add side and start_side Parameters to Create Review Comment #2072

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <p>
* {@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.
* <p>
* {@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);
builder.with("side", endSide);
return this;
}

/**
* Create gh pull request review comment.
*
Expand Down
9 changes: 8 additions & 1 deletion src/test/java/org/kohsuke/github/GHPullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -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<GHPullRequestReviewComment> comments = p.listReviewComments().toList();
assertThat(comments.size(), equalTo(3));
Expand All @@ -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());
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -55,4 +55,4 @@
"uuid": "43f15589-cf59-4ed5-a2b8-8f6b7ebae791",
"persistent": true,
"insertionIndex": 7
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -55,4 +55,4 @@
"uuid": "efe94b1b-7f9c-4bba-9af2-0a7a59a498ab",
"persistent": true,
"insertionIndex": 8
}
}