forked from hub4j/github-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for multiline review comments (hub4j#1833)
* Add support for multi-line review comments On review comments or during the creation of a new review, support single and multi-line comments using `line` and `start_line` attributes. See: https://docs.github.com/en/rest/pulls/comments?apiVersion=2022-11-28#create-a-review-comment-for-a-pull-request and https://docs.github.com/en/rest/pulls/reviews?apiVersion=2022-11-28#create-a-review-for-a-pull-request * Add tests for multi-line review comments * Fix tests for multi-line comments on pull requests * Add builder to create review comments * Improve PR review comments implementation * Update src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java * Update src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java * Update src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java * Fix code formatting * Update src/test/java/org/kohsuke/github/GHPullRequestTest.java * Update src/test/java/org/kohsuke/github/GHPullRequestTest.java --------- Co-authored-by: Maxime Wiewiora <[email protected]> Co-authored-by: Liam Newman <[email protected]>
- Loading branch information
1 parent
3e478c2
commit 068b4e6
Showing
148 changed files
with
5,459 additions
and
3,539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package org.kohsuke.github; | ||
|
||
import java.io.IOException; | ||
|
||
// TODO: Auto-generated Javadoc | ||
|
||
/** | ||
* Builds up a creation of new {@link GHPullRequestReviewComment}. | ||
* | ||
* @see GHPullRequest#createReviewComment() | ||
*/ | ||
public class GHPullRequestReviewCommentBuilder { | ||
private final GHPullRequest pr; | ||
private final Requester builder; | ||
|
||
/** | ||
* Instantiates a new GH pull request review comment builder. | ||
* | ||
* @param pr | ||
* the pr | ||
*/ | ||
GHPullRequestReviewCommentBuilder(GHPullRequest pr) { | ||
this.pr = pr; | ||
this.builder = pr.root().createRequest(); | ||
} | ||
|
||
/** | ||
* The SHA of the commit that needs a review. Not using the latest commit SHA may render your review comment | ||
* outdated if a subsequent commit modifies the line you specify as the position. Defaults to the most recent commit | ||
* in the pull request when you do not specify a value. | ||
* | ||
* @param commitId | ||
* the commit id | ||
* @return the gh pull request review comment builder | ||
*/ | ||
public GHPullRequestReviewCommentBuilder commitId(String commitId) { | ||
builder.with("commit_id", commitId); | ||
return this; | ||
} | ||
|
||
/** | ||
* The text of the pull request review comment. | ||
* | ||
* @param body | ||
* the body | ||
* @return the gh pull request review comment builder | ||
*/ | ||
public GHPullRequestReviewCommentBuilder body(String body) { | ||
builder.with("body", body); | ||
return this; | ||
} | ||
|
||
/** | ||
* The relative path to the file that necessitates a comment. | ||
* | ||
* @param path | ||
* the path | ||
* @return the gh pull request review comment builder | ||
*/ | ||
public GHPullRequestReviewCommentBuilder path(String path) { | ||
builder.with("path", path); | ||
return this; | ||
} | ||
|
||
/** | ||
* The position in the diff where you want to add a review comment. | ||
* | ||
* @param position | ||
* the position | ||
* @return the gh pull request review comment builder | ||
* @implNote As position is deprecated in GitHub API, only keep this for internal usage (for retro-compatibility | ||
* with {@link GHPullRequest#createReviewComment(String, String, String, int)}). | ||
*/ | ||
GHPullRequestReviewCommentBuilder position(int position) { | ||
builder.with("position", position); | ||
return this; | ||
} | ||
|
||
/** | ||
* A single line of the blob in the pull request diff that the comment applies to. | ||
* <p> | ||
* {@link #line(int)} and {@link #lines(int, int)} will overwrite each other's values. | ||
* </p> | ||
* | ||
* @param line | ||
* the line number | ||
* @return the gh pull request review comment builder | ||
*/ | ||
public GHPullRequestReviewCommentBuilder line(int line) { | ||
builder.with("line", line); | ||
builder.remove("start_line"); | ||
return this; | ||
} | ||
|
||
/** | ||
* The range of lines in the pull request diff that this comment applies to. | ||
* <p> | ||
* {@link #line(int)} and {@link #lines(int, int)} will overwrite each other's values. | ||
* </p> | ||
* | ||
* @param startLine | ||
* the start line number of the comment | ||
* @param endLine | ||
* the end line number of the comment | ||
* @return the gh pull request review comment builder | ||
*/ | ||
public GHPullRequestReviewCommentBuilder lines(int startLine, int endLine) { | ||
builder.with("start_line", startLine); | ||
builder.with("line", endLine); | ||
return this; | ||
} | ||
|
||
/** | ||
* Create gh pull request review comment. | ||
* | ||
* @return the gh pull request review comment builder | ||
* @throws IOException | ||
* the io exception | ||
*/ | ||
public GHPullRequestReviewComment create() throws IOException { | ||
return builder.method("POST") | ||
.withUrlPath(pr.getApiRoute() + "/comments") | ||
.fetch(GHPullRequestReviewComment.class) | ||
.wrapUp(pr); | ||
} | ||
|
||
} |
Oops, something went wrong.