Skip to content

Commit

Permalink
added fields in GHPullRequestReviewComment related which were missing
Browse files Browse the repository at this point in the history
  • Loading branch information
kisaga committed Jun 3, 2022
1 parent 4e103a6 commit af42287
Show file tree
Hide file tree
Showing 4 changed files with 275 additions and 10 deletions.
122 changes: 122 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
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;
import java.util.Locale;

import javax.annotation.CheckForNull;

Expand All @@ -43,16 +45,27 @@
public class GHPullRequestReviewComment extends GHObject implements Reactable {
GHPullRequest owner;

private Long pull_request_review_id = -1L;
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 @@ -212,6 +225,115 @@ 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;
}

public static enum Side {
RIGHT, LEFT, UNKNOWN;

public static Side from(String value) {
return EnumUtils.getEnumOrDefault(Side.class, value, Side.UNKNOWN);
}

}

/**
* 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</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;
}
}
23 changes: 23 additions & 0 deletions src/test/java/org/kohsuke/github/GHPullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,34 @@ public void pullRequestReviewComments() throws Exception {
assertThat(comment.getOriginalCommitId(), equalTo("07374fe73aff1c2024a8d4114b32406c7a8e89b7"));
assertThat(comment.getAuthorAssociation(), equalTo(GHCommentAuthorAssociation.MEMBER));
assertThat(comment.getUser(), notNullValue());
assertThat(comment.getStartLine(), equalTo(2));
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.getPullRequestReviewId(), equalTo(937124048L));
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()));

GHPullRequestReviewCommentReactions commentReactions = comment.getReactions();
assertThat(commentReactions.getUrl().toString(), equalTo(comment.getUrl().toString().concat("/reactions")));
assertThat(commentReactions.getTotalCount(), equalTo(30));
assertThat(commentReactions.getPlusOne(), equalTo(4));
assertThat(commentReactions.getMinusOne(), equalTo(3));
assertThat(commentReactions.getLaugh(), equalTo(3));
assertThat(commentReactions.getHooray(), equalTo(6));
assertThat(commentReactions.getConfused(), equalTo(7));
assertThat(commentReactions.getHeart(), equalTo(4));
assertThat(commentReactions.getRocket(), equalTo(4));
assertThat(commentReactions.getEyes(), equalTo(9));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@
},
"reactions": {
"url": "https://api.github.com/repos/hub4j-test-org/github-api/pulls/comments/846624633/reactions",
"total_count": 0,
"+1": 0,
"-1": 0,
"laugh": 0,
"hooray": 0,
"confused": 0,
"heart": 0,
"rocket": 0,
"eyes": 0
"total_count": 30,
"+1": 4,
"-1": 3,
"laugh": 3,
"hooray": 6,
"confused": 7,
"heart": 4,
"rocket": 4,
"eyes": 9
},
"start_line": null,
"start_line": 2,
"original_start_line": null,
"start_side": null,
"line": 1,
Expand Down

0 comments on commit af42287

Please sign in to comment.