Skip to content

Commit 49d8ed2

Browse files
authored
Merge pull request hub4j#1469 from kisaga/issue/enhance-pull-request-comment-model
added fields in GHPullRequestReviewComment which were missing
2 parents 24832b1 + 248e4f2 commit 49d8ed2

File tree

70 files changed

+2885
-1126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2885
-1126
lines changed

src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package org.kohsuke.github;
2525

2626
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
27+
import org.kohsuke.github.internal.EnumUtils;
2728

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

50+
private Long pull_request_review_id = -1L;
4951
private String body;
5052
private GHUser user;
5153
private String path;
5254
private String html_url;
55+
private String pull_request_url;
5356
private int position = -1;
5457
private int original_position = -1;
5558
private long in_reply_to_id = -1L;
59+
private Integer start_line = -1;
60+
private Integer original_start_line = -1;
61+
private String start_side;
62+
private int line = -1;
63+
private int original_line = -1;
64+
private String side;
5665
private String diff_hunk;
5766
private String commit_id;
5867
private String original_commit_id;
68+
private String body_html;
69+
private String body_text;
70+
private GHPullRequestReviewCommentReactions reactions;
5971
private GHCommentAuthorAssociation author_association;
6072

6173
/**
@@ -227,6 +239,130 @@ protected String getApiRoute(boolean includePullNumber) {
227239
+ (includePullNumber ? "/" + owner.getNumber() : "") + "/comments/" + getId();
228240
}
229241

242+
/**
243+
* Gets The first line of the range for a multi-line comment.
244+
*
245+
* @return the start line
246+
*/
247+
public int getStartLine() {
248+
return start_line != null ? start_line : -1;
249+
}
250+
251+
/**
252+
* Gets The first line of the range for a multi-line comment.
253+
*
254+
* @return the original start line
255+
*/
256+
public int getOriginalStartLine() {
257+
return original_start_line != null ? original_start_line : -1;
258+
}
259+
260+
/**
261+
* Gets The side of the first line of the range for a multi-line comment.
262+
*
263+
* @return {@link Side} the side of the first line
264+
*/
265+
public Side getStartSide() {
266+
return Side.from(start_side);
267+
}
268+
269+
/**
270+
* Gets The line of the blob to which the comment applies. The last line of the range for a multi-line comment.
271+
*
272+
* @return the line to which the comment applies
273+
*/
274+
public int getLine() {
275+
return line;
276+
}
277+
278+
/**
279+
* Gets The line of the blob to which the comment applies. The last line of the range for a multi-line comment.
280+
*
281+
* @return the line to which the comment applies
282+
*/
283+
public int getOriginalLine() {
284+
return original_line;
285+
}
286+
287+
/**
288+
* Gets The side of the diff to which the comment applies. The side of the last line of the range for a multi-line
289+
* comment
290+
*
291+
* @return {@link Side} the side if the diff to which the comment applies
292+
*/
293+
public Side getSide() {
294+
return Side.from(side);
295+
}
296+
297+
/**
298+
* Gets The ID of the pull request review to which the comment belongs.
299+
*
300+
* @return {@link Long} the ID of the pull request review
301+
*/
302+
public Long getPullRequestReviewId() {
303+
return pull_request_review_id != null ? pull_request_review_id : -1;
304+
}
305+
306+
/**
307+
* Gets URL for the pull request that the review comment belongs to.
308+
*
309+
* @return {@link URL} the URL of the pull request
310+
*/
311+
public URL getPullRequestUrl() {
312+
return GitHubClient.parseURL(pull_request_url);
313+
}
314+
315+
/**
316+
* Gets The body in html format.
317+
*
318+
* @return {@link String} the body in html format
319+
*/
320+
public String getBodyHtml() {
321+
return body_html;
322+
}
323+
324+
/**
325+
* Gets The body text.
326+
*
327+
* @return {@link String} the body text
328+
*/
329+
public String getBodyText() {
330+
return body_text;
331+
}
332+
333+
/**
334+
* Gets the Reaction Rollup
335+
*
336+
* @return {@link GHPullRequestReviewCommentReactions} the reaction rollup
337+
*/
338+
public GHPullRequestReviewCommentReactions getReactions() {
339+
return reactions;
340+
}
341+
342+
/**
343+
* The side of the diff to which the comment applies
344+
*/
345+
public static enum Side {
346+
/** Right side */
347+
RIGHT,
348+
/** Left side */
349+
LEFT,
350+
/** Unknown side */
351+
UNKNOWN;
352+
353+
/**
354+
* From.
355+
*
356+
* @param value
357+
* the value
358+
* @return the status
359+
*/
360+
public static Side from(String value) {
361+
return EnumUtils.getEnumOrDefault(Side.class, value, Side.UNKNOWN);
362+
}
363+
364+
}
365+
230366
/**
231367
* Updates the comment.
232368
*
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package org.kohsuke.github;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
5+
import java.net.URL;
6+
7+
/**
8+
* Reactions for a Pull Request Review comment.
9+
*
10+
* @author Vasilis Gakias
11+
* @see <a href="https://docs.github.com/en/rest/pulls/comments#get-a-review-comment-for-a-pull-request">API
12+
* documentation in the response schema</a>
13+
* @see GHPullRequestReviewComment
14+
*/
15+
public class GHPullRequestReviewCommentReactions {
16+
17+
private String url;
18+
19+
private int total_count = -1;
20+
@JsonProperty("+1")
21+
private int plus_one = -1;
22+
@JsonProperty("-1")
23+
private int minus_one = -1;
24+
private int laugh = -1;
25+
private int confused = -1;
26+
private int heart = -1;
27+
private int hooray = -1;
28+
private int eyes = -1;
29+
private int rocket = -1;
30+
31+
/**
32+
* Gets the URL of the comment's reactions
33+
*
34+
* @return the URL of the comment's reactions
35+
*/
36+
public URL getUrl() {
37+
return GitHubClient.parseURL(url);
38+
}
39+
40+
/**
41+
* Gets the total count of reactions
42+
*
43+
* @return the number of total reactions
44+
*/
45+
public int getTotalCount() {
46+
return total_count;
47+
}
48+
49+
/**
50+
* Gets the number of +1 reactions
51+
*
52+
* @return the number of +1 reactions
53+
*/
54+
public int getPlusOne() {
55+
return plus_one;
56+
}
57+
58+
/**
59+
* Gets the number of -1 reactions
60+
*
61+
* @return the number of -1 reactions
62+
*/
63+
public int getMinusOne() {
64+
return minus_one;
65+
}
66+
67+
/**
68+
* Gets the number of laugh reactions
69+
*
70+
* @return the number of laugh reactions
71+
*/
72+
public int getLaugh() {
73+
return laugh;
74+
}
75+
76+
/**
77+
* Gets the number of confused reactions
78+
*
79+
* @return the number of confused reactions
80+
*/
81+
public int getConfused() {
82+
return confused;
83+
}
84+
85+
/**
86+
* Gets the number of heart reactions
87+
*
88+
* @return the number of heart reactions
89+
*/
90+
public int getHeart() {
91+
return heart;
92+
}
93+
94+
/**
95+
* Gets the number of hooray reactions
96+
*
97+
* @return the number of hooray reactions
98+
*/
99+
public int getHooray() {
100+
return hooray;
101+
}
102+
103+
/**
104+
* Gets the number of eyes reactions
105+
*
106+
* @return the number of eyes reactions
107+
*/
108+
public int getEyes() {
109+
return eyes;
110+
}
111+
112+
/**
113+
* Gets the number of rocket reactions
114+
*
115+
* @return the number of rocket reactions
116+
*/
117+
public int getRocket() {
118+
return rocket;
119+
}
120+
}

src/test/java/org/kohsuke/github/GHPullRequestTest.java

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,24 +253,59 @@ public void pullRequestReviewComments() throws Exception {
253253
assertThat(comment.getOriginalCommitId(), equalTo("07374fe73aff1c2024a8d4114b32406c7a8e89b7"));
254254
assertThat(comment.getAuthorAssociation(), equalTo(GHCommentAuthorAssociation.MEMBER));
255255
assertThat(comment.getUser(), notNullValue());
256+
assertThat(comment.getStartLine(), equalTo(-1));
257+
assertThat(comment.getOriginalStartLine(), equalTo(-1));
258+
assertThat(comment.getStartSide(), equalTo(GHPullRequestReviewComment.Side.UNKNOWN));
259+
assertThat(comment.getLine(), equalTo(1));
260+
assertThat(comment.getOriginalLine(), equalTo(1));
261+
assertThat(comment.getSide(), equalTo(GHPullRequestReviewComment.Side.LEFT));
262+
assertThat(comment.getPullRequestUrl(), notNullValue());
263+
assertThat(comment.getPullRequestUrl().toString(), containsString("hub4j-test-org/github-api/pulls/"));
264+
assertThat(comment.getBodyHtml(), nullValue());
265+
assertThat(comment.getBodyText(), nullValue());
256266
// Assert htmlUrl is not null
257267
assertThat(comment.getHtmlUrl(), notNullValue());
258268
assertThat(comment.getHtmlUrl().toString(),
259269
containsString("hub4j-test-org/github-api/pull/" + p.getNumber()));
260270

271+
comment.createReaction(ReactionContent.EYES);
272+
GHReaction toBeRemoved = comment.createReaction(ReactionContent.CONFUSED);
273+
comment.createReaction(ReactionContent.ROCKET);
274+
comment.createReaction(ReactionContent.HOORAY);
275+
comment.createReaction(ReactionContent.HEART);
276+
comment.createReaction(ReactionContent.MINUS_ONE);
277+
comment.createReaction(ReactionContent.PLUS_ONE);
278+
comment.createReaction(ReactionContent.LAUGH);
279+
GHPullRequestReviewCommentReactions commentReactions = p.listReviewComments()
280+
.toList()
281+
.get(0)
282+
.getReactions();
283+
assertThat(commentReactions.getUrl().toString(), equalTo(comment.getUrl().toString().concat("/reactions")));
284+
assertThat(commentReactions.getTotalCount(), equalTo(8));
285+
assertThat(commentReactions.getPlusOne(), equalTo(1));
286+
assertThat(commentReactions.getMinusOne(), equalTo(1));
287+
assertThat(commentReactions.getLaugh(), equalTo(1));
288+
assertThat(commentReactions.getHooray(), equalTo(1));
289+
assertThat(commentReactions.getConfused(), equalTo(1));
290+
assertThat(commentReactions.getHeart(), equalTo(1));
291+
assertThat(commentReactions.getRocket(), equalTo(1));
292+
assertThat(commentReactions.getEyes(), equalTo(1));
293+
294+
comment.deleteReaction(toBeRemoved);
295+
261296
List<GHReaction> reactions = comment.listReactions().toList();
262-
assertThat(reactions, is(empty()));
297+
assertThat(reactions.size(), equalTo(7));
263298

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

267302
reactions = comment.listReactions().toList();
268-
assertThat(reactions.size(), equalTo(1));
303+
assertThat(reactions.size(), equalTo(8));
269304

270305
comment.deleteReaction(reaction);
271306

272307
reactions = comment.listReactions().toList();
273-
assertThat(reactions.size(), equalTo(0));
308+
assertThat(reactions.size(), equalTo(7));
274309

275310
GHPullRequestReviewComment reply = comment.reply("This is a reply.");
276311
assertThat(reply.getInReplyToId(), equalTo(comment.getId()));

src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/__files/orgs_hub4j-test-org-1.json renamed to src/test/resources/org/kohsuke/github/GHPullRequestTest/wiremock/pullRequestReviewComments/__files/orgs_hub4j-test-org-2.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@
2020
"is_verified": false,
2121
"has_organization_projects": true,
2222
"has_repository_projects": true,
23-
"public_repos": 49,
23+
"public_repos": 50,
2424
"public_gists": 0,
2525
"followers": 0,
2626
"following": 0,
2727
"html_url": "https://github.com/hub4j-test-org",
2828
"created_at": "2014-05-10T19:39:11Z",
2929
"updated_at": "2020-06-04T05:56:10Z",
3030
"type": "Organization",
31-
"total_private_repos": 3,
32-
"owned_private_repos": 3,
31+
"total_private_repos": 4,
32+
"owned_private_repos": 4,
3333
"private_gists": 0,
34-
"disk_usage": 11979,
34+
"disk_usage": 11980,
3535
"collaborators": 0,
3636
"billing_email": "kk@kohsuke.org",
3737
"default_repository_permission": "none",
@@ -49,7 +49,7 @@
4949
"name": "free",
5050
"space": 976562499,
5151
"private_repos": 10000,
52-
"filled_seats": 35,
52+
"filled_seats": 38,
5353
"seats": 3
5454
}
5555
}

0 commit comments

Comments
 (0)