Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,13 @@ public PagedIterable<GHPullRequestFileDetail> listFiles() {
/**
* Obtains all the review comments associated with this pull request.
*
* <p>
* Unlike {@link GHPullRequestReview#listReviewComments()}, this method returns full
* {@link GHPullRequestReviewComment} objects including line-related fields such as
* {@link GHPullRequestReviewComment#getLine() line}, {@link GHPullRequestReviewComment#getSide() side}, etc.
*
* @return the paged iterable
* @see GHPullRequestReview#listReviewComments()
*/
public PagedIterable<GHPullRequestReviewComment> listReviewComments() {
return root().createRequest()
Expand Down
197 changes: 194 additions & 3 deletions src/main/java/org/kohsuke/github/GHPullRequestReview.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,190 @@
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
public class GHPullRequestReview extends GHObject {

/**
* Represents a review comment as returned by the review comments endpoint. This is a limited view that does not
* include line-related fields such as {@code line}, {@code originalLine}, {@code side}, etc.
*
* <p>
* To obtain the full {@link GHPullRequestReviewComment} with all fields, call
* {@link #readPullRequestReviewComment()}.
*
* @see GHPullRequest#listReviewComments()
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API")
public static class ReviewComment extends GHObject {

private GHCommentAuthorAssociation authorAssociation;
private String body;
private String commitId;
private String diffHunk;
private String htmlUrl;
private String originalCommitId;
private int originalPosition = -1;
private String path;
private int position = -1;
private Long pullRequestReviewId = -1L;
private String pullRequestUrl;
private GHPullRequestReviewCommentReactions reactions;
private GHUser user;

GHPullRequest owner;

/**
* Create default ReviewComment instance
*/
public ReviewComment() {
}

/**
* Gets the author association to the project.
*
* @return the author association to the project
*/
public GHCommentAuthorAssociation getAuthorAssociation() {
return authorAssociation;
}

/**
* The comment itself.
*
* @return the body
*/
public String getBody() {
return body;
}

/**
* Gets commit id.
*
* @return the commit id
*/
public String getCommitId() {
return commitId;
}

/**
* Gets diff hunk.
*
* @return the diff hunk
*/
public String getDiffHunk() {
return diffHunk;
}

/**
* Gets the html url.
*
* @return the html url
*/
public URL getHtmlUrl() {
return GitHubClient.parseURL(htmlUrl);
}

/**
* Gets commit id.
*
* @return the original commit id
*/
public String getOriginalCommitId() {
return originalCommitId;
}

/**
* Gets original position.
*
* @return the original position
*/
public int getOriginalPosition() {
return originalPosition;
}

/**
* Gets path.
*
* @return the path
*/
public String getPath() {
return path;
}

/**
* Gets position.
*
* @return the position
*/
public int getPosition() {
return position;
}

/**
* Gets The ID of the pull request review to which the comment belongs.
*
* @return {@link Long} the ID of the pull request review
*/
public Long getPullRequestReviewId() {
return pullRequestReviewId != null ? pullRequestReviewId : -1;
}

/**
* Gets URL for the pull request that the review comment belongs to.
*
* @return {@link URL} the URL of the pull request
*/
public URL getPullRequestUrl() {
return GitHubClient.parseURL(pullRequestUrl);
}

/**
* Gets the Reaction Rollup.
*
* @return {@link GHPullRequestReviewCommentReactions} the reaction rollup
*/
public GHPullRequestReviewCommentReactions getReactions() {
return reactions;
}

/**
* Gets the user who posted this comment.
*
* @return the user
* @throws IOException
* the io exception
*/
public GHUser getUser() throws IOException {
return owner.root().getUser(user.getLogin());
}

/**
* Fetches the full {@link GHPullRequestReviewComment} from the API, which includes all fields such as
* {@link GHPullRequestReviewComment#getLine() line}, {@link GHPullRequestReviewComment#getOriginalLine()
* originalLine}, {@link GHPullRequestReviewComment#getSide() side}, etc.
*
* @return the full {@link GHPullRequestReviewComment}
* @throws IOException
* if an I/O error occurs
*/
public GHPullRequestReviewComment readPullRequestReviewComment() throws IOException {
return owner.root()
.createRequest()
.withUrlPath("/repos/" + owner.getRepository().getFullName() + "/pulls/comments/" + getId())
.fetch(GHPullRequestReviewComment.class)
.wrapUp(owner);
}

/**
* Wrap up.
*
* @param owner
* the owner
* @return the review comment
*/
ReviewComment wrapUp(GHPullRequest owner) {
this.owner = owner;
return this;
}
}

private String body;

private String commitId;
Expand Down Expand Up @@ -174,13 +358,20 @@ public GHUser getUser() throws IOException {
/**
* Obtains all the review comments associated with this pull request review.
*
* @return the paged iterable
* <p>
* The GitHub API endpoint used by this method returns a limited set of fields. To obtain full comment data
* including line numbers, use {@link ReviewComment#readPullRequestReviewComment()} on individual comments, or use
* {@link GHPullRequest#listReviewComments()} instead.
*
* @return the paged iterable of {@link ReviewComment} objects
* @see GHPullRequest#listReviewComments()
* @see ReviewComment#readPullRequestReviewComment()
*/
public PagedIterable<GHPullRequestReviewComment> listReviewComments() {
public PagedIterable<ReviewComment> listReviewComments() {
return owner.root()
.createRequest()
.withUrlPath(getApiRoute() + "/comments")
.toIterable(GHPullRequestReviewComment[].class, item -> item.wrapUp(owner));
.toIterable(ReviewComment[].class, item -> item.wrapUp(owner));
}

/**
Expand Down
50 changes: 43 additions & 7 deletions src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,13 @@ public long getInReplyToId() {
/**
* Gets The line of the blob to which the comment applies. The last line of the range for a multi-line comment.
*
* @return the line to which the comment applies
* <p>
* This field is not available on {@link GHPullRequestReview.ReviewComment} objects returned by
* {@link GHPullRequestReview#listReviewComments()}. Use
* {@link GHPullRequestReview.ReviewComment#readPullRequestReviewComment()} or
* {@link GHPullRequest#listReviewComments()} to obtain this value.
*
* @return the line to which the comment applies, or -1 if not available
*/
public int getLine() {
return line;
Expand All @@ -236,7 +242,13 @@ public String getOriginalCommitId() {
/**
* Gets The line of the blob to which the comment applies. The last line of the range for a multi-line comment.
*
* @return the line to which the comment applies
* <p>
* This field is not available on {@link GHPullRequestReview.ReviewComment} objects returned by
* {@link GHPullRequestReview#listReviewComments()}. Use
* {@link GHPullRequestReview.ReviewComment#readPullRequestReviewComment()} or
* {@link GHPullRequest#listReviewComments()} to obtain this value.
*
* @return the line to which the comment applies, or -1 if not available
*/
public int getOriginalLine() {
return originalLine;
Expand All @@ -254,7 +266,13 @@ public int getOriginalPosition() {
/**
* Gets The first line of the range for a multi-line comment.
*
* @return the original start line
* <p>
* This field is not available on {@link GHPullRequestReview.ReviewComment} objects returned by
* {@link GHPullRequestReview#listReviewComments()}. Use
* {@link GHPullRequestReview.ReviewComment#readPullRequestReviewComment()} or
* {@link GHPullRequest#listReviewComments()} to obtain this value.
*
* @return the original start line, or -1 if not available or not a multi-line comment
*/
public int getOriginalStartLine() {
return originalStartLine != null ? originalStartLine : -1;
Expand Down Expand Up @@ -318,9 +336,15 @@ public GHPullRequestReviewCommentReactions getReactions() {

/**
* Gets The side of the diff to which the comment applies. The side of the last line of the range for a multi-line
* comment
* comment.
*
* @return {@link Side} the side if the diff to which the comment applies
* <p>
* This field is not available on {@link GHPullRequestReview.ReviewComment} objects returned by
* {@link GHPullRequestReview#listReviewComments()}. Use
* {@link GHPullRequestReview.ReviewComment#readPullRequestReviewComment()} or
* {@link GHPullRequest#listReviewComments()} to obtain this value.
*
* @return {@link Side} the side of the diff to which the comment applies, or {@link Side#UNKNOWN} if not available
*/
public Side getSide() {
return Side.from(side);
Expand All @@ -329,7 +353,13 @@ public Side getSide() {
/**
* Gets The first line of the range for a multi-line comment.
*
* @return the start line
* <p>
* This field is not available on {@link GHPullRequestReview.ReviewComment} objects returned by
* {@link GHPullRequestReview#listReviewComments()}. Use
* {@link GHPullRequestReview.ReviewComment#readPullRequestReviewComment()} or
* {@link GHPullRequest#listReviewComments()} to obtain this value.
*
* @return the start line, or -1 if not available or not a multi-line comment
*/
public int getStartLine() {
return startLine != null ? startLine : -1;
Expand All @@ -338,7 +368,13 @@ public int getStartLine() {
/**
* Gets The side of the first line of the range for a multi-line comment.
*
* @return {@link Side} the side of the first line
* <p>
* This field is not available on {@link GHPullRequestReview.ReviewComment} objects returned by
* {@link GHPullRequestReview#listReviewComments()}. Use
* {@link GHPullRequestReview.ReviewComment#readPullRequestReviewComment()} or
* {@link GHPullRequest#listReviewComments()} to obtain this value.
*
* @return {@link Side} the side of the first line, or {@link Side#UNKNOWN} if not available
*/
public Side getStartSide() {
return Side.from(startSide);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4334,6 +4334,21 @@
"allPublicClasses": true,
"allDeclaredClasses": true
},
{
"name": "org.kohsuke.github.GHPullRequestReview$ReviewComment",
"allPublicFields": true,
"allDeclaredFields": true,
"queryAllPublicConstructors": true,
"queryAllDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredConstructors": true,
"queryAllPublicMethods": true,
"queryAllDeclaredMethods": true,
"allPublicMethods": true,
"allDeclaredMethods": true,
"allPublicClasses": true,
"allDeclaredClasses": true
},
{
"name": "org.kohsuke.github.GHPullRequestReviewBuilder",
"allPublicFields": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@
{
"name": "org.kohsuke.github.GHPullRequestReview"
},
{
"name": "org.kohsuke.github.GHPullRequestReview$ReviewComment"
},
{
"name": "org.kohsuke.github.GHPullRequestReviewBuilder"
},
Expand Down
20 changes: 18 additions & 2 deletions src/test/java/org/kohsuke/github/GHPullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -739,16 +739,32 @@ public void pullRequestReviews() throws Exception {
assertThat(review.getBody(), is("Some draft review"));
assertThat(review.getCommitId(), notNullValue());
draftReview.submit("Some review comment", GHPullRequestReviewEvent.COMMENT);
List<GHPullRequestReviewComment> comments = review.listReviewComments().toList();
List<GHPullRequestReview.ReviewComment> comments = review.listReviewComments().toList();
assertThat(comments.size(), equalTo(3));
GHPullRequestReviewComment comment = comments.get(0);
GHPullRequestReview.ReviewComment comment = comments.get(0);
assertThat(comment.getBody(), equalTo("Some niggle"));
assertThat(comment.getPath(), equalTo("README.md"));
assertThat(comment.getCommitId(), equalTo("07374fe73aff1c2024a8d4114b32406c7a8e89b7"));
assertThat(comment.getOriginalCommitId(), equalTo("07374fe73aff1c2024a8d4114b32406c7a8e89b7"));
assertThat(comment.getDiffHunk(), notNullValue());
assertThat(comment.getAuthorAssociation(), equalTo(GHCommentAuthorAssociation.MEMBER));
assertThat(comment.getOriginalPosition(), equalTo(1));
assertThat(comment.getHtmlUrl(), notNullValue());
assertThat(comment.getPullRequestReviewId(), equalTo(2121304234L));
assertThat(comment.getPullRequestUrl(), notNullValue());
assertThat(comment.getReactions(), notNullValue());
comment = comments.get(1);
assertThat(comment.getBody(), equalTo("A single line comment"));
assertThat(comment.getPosition(), equalTo(4));
comment = comments.get(2);
assertThat(comment.getBody(), equalTo("A multiline comment"));
assertThat(comment.getPosition(), equalTo(5));

// Verify that readPullRequestReviewComment() fetches the full comment with line data
GHPullRequestReviewComment fullComment = comments.get(0).readPullRequestReviewComment();
assertThat(fullComment.getBody(), equalTo("Some niggle"));
assertThat(fullComment.getLine(), equalTo(1));

draftReview = p.createReview().body("Some new review").comment("Some niggle", "README.md", 1).create();
draftReview.delete();
}
Expand Down
Loading
Loading