Skip to content
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

added fields in GHPullRequestReviewComment which were missing #1469

Merged
Merged
124 changes: 124 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package org.kohsuke.github;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.kohsuke.github.internal.EnumUtils;

import java.io.IOException;
import java.net.URL;
Expand All @@ -46,16 +47,27 @@ public class GHPullRequestReviewComment extends GHObject implements Reactable {
/** The owner. */
GHPullRequest owner;

private Long pull_request_review_id = -1L;
bitwiseman marked this conversation as resolved.
Show resolved Hide resolved
private String body;
private GHUser user;
private String path;
private String html_url;
private String pull_request_url;
private int position = -1;
private int original_position = -1;
private long in_reply_to_id = -1L;
private Integer start_line = -1;
private Integer original_start_line = -1;
private String start_side;
private int line = -1;
private int original_line = -1;
private String side;
private String diff_hunk;
private String commit_id;
private String original_commit_id;
private String body_html;
private String body_text;
private GHPullRequestReviewCommentReactions reactions;
private GHCommentAuthorAssociation author_association;

/**
Expand Down Expand Up @@ -227,6 +239,118 @@ protected String getApiRoute(boolean includePullNumber) {
+ (includePullNumber ? "/" + owner.getNumber() : "") + "/comments/" + getId();
}

/**
* Gets The first line of the range for a multi-line comment.
*
* @return the start line
*/
public int getStartLine() {
return start_line != null ? start_line : -1;
}

/**
* Gets The first line of the range for a multi-line comment.
*
* @return the original start line
*/
public int getOriginalStartLine() {
return original_start_line != null ? original_start_line : -1;
}

/**
* Gets The side of the first line of the range for a multi-line comment.
*
* @return {@link Side} the side of the first line
*/
public Side getStartSide() {
return Side.from(start_side);
}

/**
* 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
*/
public int getLine() {
return line;
}

/**
* 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
*/
public int getOriginalLine() {
return original_line;
}

/**
* 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
*
* @return {@link Side} the side if the diff to which the comment applies
*/
public Side getSide() {
return Side.from(side);
}

/**
* 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 pull_request_review_id != null ? pull_request_review_id : -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(pull_request_url);
}

/**
* Gets The body in html format.
*
* @return {@link String} the body in html format
*/
public String getBodyHtml() {
return body_html;
}

/**
* Gets The body text.
*
* @return {@link String} the body text
*/
public String getBodyText() {
return body_text;
}

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

/**
* The side of the diff to which the comment applies
*/
public static enum Side {
bitwiseman marked this conversation as resolved.
Show resolved Hide resolved
RIGHT, LEFT, UNKNOWN;

public static Side from(String value) {
return EnumUtils.getEnumOrDefault(Side.class, value, Side.UNKNOWN);
}
bitwiseman marked this conversation as resolved.
Show resolved Hide resolved

}

/**
* Updates the comment.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package org.kohsuke.github;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.net.URL;

/**
* Reactions for a Pull Request Review comment.
*
* @author Vasilis Gakias
* @see <a href="https://docs.github.com/en/rest/pulls/comments#get-a-review-comment-for-a-pull-request">API
* documentation in the response schema</a>
* @see GHPullRequestReviewComment
*/
public class GHPullRequestReviewCommentReactions {

private String url;

private int total_count = -1;
@JsonProperty("+1")
private int plus_one = -1;
@JsonProperty("-1")
private int minus_one = -1;
private int laugh = -1;
private int confused = -1;
private int heart = -1;
private int hooray = -1;
private int eyes = -1;
private int rocket = -1;

/**
* Gets the URL of the comment's reactions
*
* @return the URL of the comment's reactions
*/
public URL getUrl() {
return GitHubClient.parseURL(url);
}

/**
* Gets the total count of reactions
*
* @return the number of total reactions
*/
public int getTotalCount() {
return total_count;
}

/**
* Gets the number of +1 reactions
*
* @return the number of +1 reactions
*/
public int getPlusOne() {
return plus_one;
}

/**
* Gets the number of -1 reactions
*
* @return the number of -1 reactions
*/
public int getMinusOne() {
return minus_one;
}

/**
* Gets the number of laugh reactions
*
* @return the number of laugh reactions
*/
public int getLaugh() {
return laugh;
}

/**
* Gets the number of confused reactions
*
* @return the number of confused reactions
*/
public int getConfused() {
return confused;
}

/**
* Gets the number of heart reactions
*
* @return the number of heart reactions
*/
public int getHeart() {
return heart;
}

/**
* Gets the number of hooray reactions
*
* @return the number of hooray reactions
*/
public int getHooray() {
return hooray;
}

/**
* Gets the number of eyes reactions
*
* @return the number of eyes reactions
*/
public int getEyes() {
return eyes;
}

/**
* Gets the number of rocket reactions
*
* @return the number of rocket reactions
*/
public int getRocket() {
return rocket;
}
}
41 changes: 38 additions & 3 deletions src/test/java/org/kohsuke/github/GHPullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,24 +253,59 @@ public void pullRequestReviewComments() throws Exception {
assertThat(comment.getOriginalCommitId(), equalTo("07374fe73aff1c2024a8d4114b32406c7a8e89b7"));
assertThat(comment.getAuthorAssociation(), equalTo(GHCommentAuthorAssociation.MEMBER));
assertThat(comment.getUser(), notNullValue());
assertThat(comment.getStartLine(), equalTo(-1));
assertThat(comment.getOriginalStartLine(), equalTo(-1));
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.getPullRequestUrl(), notNullValue());
assertThat(comment.getPullRequestUrl().toString(), containsString("hub4j-test-org/github-api/pulls/"));
assertThat(comment.getBodyHtml(), nullValue());
assertThat(comment.getBodyText(), nullValue());
// Assert htmlUrl is not null
assertThat(comment.getHtmlUrl(), notNullValue());
assertThat(comment.getHtmlUrl().toString(),
containsString("hub4j-test-org/github-api/pull/" + p.getNumber()));

comment.createReaction(ReactionContent.EYES);
GHReaction toBeRemoved = comment.createReaction(ReactionContent.CONFUSED);
comment.createReaction(ReactionContent.ROCKET);
comment.createReaction(ReactionContent.HOORAY);
comment.createReaction(ReactionContent.HEART);
comment.createReaction(ReactionContent.MINUS_ONE);
comment.createReaction(ReactionContent.PLUS_ONE);
comment.createReaction(ReactionContent.LAUGH);
GHPullRequestReviewCommentReactions commentReactions = p.listReviewComments()
.toList()
.get(0)
.getReactions();
assertThat(commentReactions.getUrl().toString(), equalTo(comment.getUrl().toString().concat("/reactions")));
assertThat(commentReactions.getTotalCount(), equalTo(8));
assertThat(commentReactions.getPlusOne(), equalTo(1));
assertThat(commentReactions.getMinusOne(), equalTo(1));
assertThat(commentReactions.getLaugh(), equalTo(1));
assertThat(commentReactions.getHooray(), equalTo(1));
assertThat(commentReactions.getConfused(), equalTo(1));
assertThat(commentReactions.getHeart(), equalTo(1));
assertThat(commentReactions.getRocket(), equalTo(1));
assertThat(commentReactions.getEyes(), equalTo(1));

comment.deleteReaction(toBeRemoved);

List<GHReaction> reactions = comment.listReactions().toList();
assertThat(reactions, is(empty()));
assertThat(reactions.size(), equalTo(7));

GHReaction reaction = comment.createReaction(ReactionContent.CONFUSED);
assertThat(reaction.getContent(), equalTo(ReactionContent.CONFUSED));

reactions = comment.listReactions().toList();
assertThat(reactions.size(), equalTo(1));
assertThat(reactions.size(), equalTo(8));

comment.deleteReaction(reaction);

reactions = comment.listReactions().toList();
assertThat(reactions.size(), equalTo(0));
assertThat(reactions.size(), equalTo(7));

GHPullRequestReviewComment reply = comment.reply("This is a reply.");
assertThat(reply.getInReplyToId(), equalTo(comment.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 49,
"public_repos": 50,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/hub4j-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2020-06-04T05:56:10Z",
"type": "Organization",
"total_private_repos": 3,
"owned_private_repos": 3,
"total_private_repos": 4,
"owned_private_repos": 4,
"private_gists": 0,
"disk_usage": 11979,
"disk_usage": 11980,
"collaborators": 0,
"billing_email": "[email protected]",
"default_repository_permission": "none",
Expand All @@ -49,7 +49,7 @@
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 35,
"filled_seats": 38,
"seats": 3
}
}
Loading