-
Notifications
You must be signed in to change notification settings - Fork 752
Add support for multiline review comments #1833
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
bitwiseman
merged 16 commits into
hub4j:main
from
maximevw:add-support-for-multiline-review-comments
Jul 1, 2024
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6cd648a
Add support for multi-line review comments
b5f5551
Add tests for multi-line review comments
199227c
Merge branch 'main' into add-support-for-multiline-review-comments
maximevw eee743c
Fix tests for multi-line comments on pull requests
28a18ee
Merge branch 'main' into add-support-for-multiline-review-comments
bitwiseman 0200583
Merge remote-tracking branch 'upstream/main' into add-support-for-mul…
bitwiseman 4c1112c
Merge branch 'hub4j:main' into add-support-for-multiline-review-comments
maximevw 5e177d2
Add builder to create review comments
4df4cfe
Merge branch 'main' into add-support-for-multiline-review-comments
bitwiseman 1b25798
Improve PR review comments implementation
4627d34
Update src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBui…
bitwiseman fd6e0f8
Update src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBui…
bitwiseman e278227
Update src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBui…
bitwiseman 47170df
Fix code formatting
753f01b
Update src/test/java/org/kohsuke/github/GHPullRequestTest.java
bitwiseman 3df01bb
Update src/test/java/org/kohsuke/github/GHPullRequestTest.java
bitwiseman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
128 changes: 128 additions & 0 deletions
128
src/main/java/org/kohsuke/github/GHPullRequestReviewCommentBuilder.java
This file contains hidden or 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,128 @@ | ||
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); | ||
maximevw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return this; | ||
} | ||
|
||
/** | ||
* For a single line comment, the line of the blob in the pull request diff that the comment applies to. For a | ||
* multi-line comment, the last line of the range that your comment applies to (in this case, it's recommended to | ||
* use {@link #lines(int, int)} instead). | ||
* <p> | ||
* Be careful, this value can be overridden by {@link #lines(int, int)}. | ||
* </p> | ||
bitwiseman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @param line | ||
* the line number | ||
* @return the gh pull request review comment builder | ||
*/ | ||
public GHPullRequestReviewCommentBuilder line(int line) { | ||
builder.with("line", line); | ||
return this; | ||
bitwiseman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* The first line in the pull request diff that your multi-line comment applies to. | ||
* <p> | ||
* Be careful, the end line value can be overridden by {@link #line(int)} (usually used for single line comments). | ||
* </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 | ||
*/ | ||
bitwiseman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.