|
43 | 43 | @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") |
44 | 44 | public class GHPullRequestReview extends GHObject { |
45 | 45 |
|
| 46 | + /** |
| 47 | + * Represents a review comment as returned by the review comments endpoint. This is a limited view that does not |
| 48 | + * include line-related fields such as {@code line}, {@code originalLine}, {@code side}, etc. |
| 49 | + * |
| 50 | + * <p> |
| 51 | + * To obtain the full {@link GHPullRequestReviewComment} with all fields, call |
| 52 | + * {@link #readPullRequestReviewComment()}. |
| 53 | + * |
| 54 | + * @see GHPullRequest#listReviewComments() |
| 55 | + */ |
| 56 | + @SuppressFBWarnings(value = { "UWF_UNWRITTEN_FIELD" }, justification = "JSON API") |
| 57 | + public static class ReviewComment extends GHObject { |
| 58 | + |
| 59 | + private GHCommentAuthorAssociation authorAssociation; |
| 60 | + private String body; |
| 61 | + private String commitId; |
| 62 | + private String diffHunk; |
| 63 | + private String htmlUrl; |
| 64 | + private String originalCommitId; |
| 65 | + private int originalPosition = -1; |
| 66 | + private String path; |
| 67 | + private int position = -1; |
| 68 | + private Long pullRequestReviewId = -1L; |
| 69 | + private String pullRequestUrl; |
| 70 | + private GHPullRequestReviewCommentReactions reactions; |
| 71 | + private GHUser user; |
| 72 | + |
| 73 | + GHPullRequest owner; |
| 74 | + |
| 75 | + /** |
| 76 | + * Create default ReviewComment instance |
| 77 | + */ |
| 78 | + public ReviewComment() { |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Gets the author association to the project. |
| 83 | + * |
| 84 | + * @return the author association to the project |
| 85 | + */ |
| 86 | + public GHCommentAuthorAssociation getAuthorAssociation() { |
| 87 | + return authorAssociation; |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * The comment itself. |
| 92 | + * |
| 93 | + * @return the body |
| 94 | + */ |
| 95 | + public String getBody() { |
| 96 | + return body; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * Gets commit id. |
| 101 | + * |
| 102 | + * @return the commit id |
| 103 | + */ |
| 104 | + public String getCommitId() { |
| 105 | + return commitId; |
| 106 | + } |
| 107 | + |
| 108 | + /** |
| 109 | + * Gets diff hunk. |
| 110 | + * |
| 111 | + * @return the diff hunk |
| 112 | + */ |
| 113 | + public String getDiffHunk() { |
| 114 | + return diffHunk; |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Gets the html url. |
| 119 | + * |
| 120 | + * @return the html url |
| 121 | + */ |
| 122 | + public URL getHtmlUrl() { |
| 123 | + return GitHubClient.parseURL(htmlUrl); |
| 124 | + } |
| 125 | + |
| 126 | + /** |
| 127 | + * Gets commit id. |
| 128 | + * |
| 129 | + * @return the original commit id |
| 130 | + */ |
| 131 | + public String getOriginalCommitId() { |
| 132 | + return originalCommitId; |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Gets original position. |
| 137 | + * |
| 138 | + * @return the original position |
| 139 | + */ |
| 140 | + public int getOriginalPosition() { |
| 141 | + return originalPosition; |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Gets path. |
| 146 | + * |
| 147 | + * @return the path |
| 148 | + */ |
| 149 | + public String getPath() { |
| 150 | + return path; |
| 151 | + } |
| 152 | + |
| 153 | + /** |
| 154 | + * Gets position. |
| 155 | + * |
| 156 | + * @return the position |
| 157 | + */ |
| 158 | + public int getPosition() { |
| 159 | + return position; |
| 160 | + } |
| 161 | + |
| 162 | + /** |
| 163 | + * Gets The ID of the pull request review to which the comment belongs. |
| 164 | + * |
| 165 | + * @return {@link Long} the ID of the pull request review |
| 166 | + */ |
| 167 | + public Long getPullRequestReviewId() { |
| 168 | + return pullRequestReviewId != null ? pullRequestReviewId : -1; |
| 169 | + } |
| 170 | + |
| 171 | + /** |
| 172 | + * Gets URL for the pull request that the review comment belongs to. |
| 173 | + * |
| 174 | + * @return {@link URL} the URL of the pull request |
| 175 | + */ |
| 176 | + public URL getPullRequestUrl() { |
| 177 | + return GitHubClient.parseURL(pullRequestUrl); |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * Gets the Reaction Rollup. |
| 182 | + * |
| 183 | + * @return {@link GHPullRequestReviewCommentReactions} the reaction rollup |
| 184 | + */ |
| 185 | + public GHPullRequestReviewCommentReactions getReactions() { |
| 186 | + return reactions; |
| 187 | + } |
| 188 | + |
| 189 | + /** |
| 190 | + * Gets the user who posted this comment. |
| 191 | + * |
| 192 | + * @return the user |
| 193 | + * @throws IOException |
| 194 | + * the io exception |
| 195 | + */ |
| 196 | + public GHUser getUser() throws IOException { |
| 197 | + return owner.root().getUser(user.getLogin()); |
| 198 | + } |
| 199 | + |
| 200 | + /** |
| 201 | + * Fetches the full {@link GHPullRequestReviewComment} from the API, which includes all fields such as |
| 202 | + * {@link GHPullRequestReviewComment#getLine() line}, {@link GHPullRequestReviewComment#getOriginalLine() |
| 203 | + * originalLine}, {@link GHPullRequestReviewComment#getSide() side}, etc. |
| 204 | + * |
| 205 | + * @return the full {@link GHPullRequestReviewComment} |
| 206 | + * @throws IOException |
| 207 | + * if an I/O error occurs |
| 208 | + */ |
| 209 | + public GHPullRequestReviewComment readPullRequestReviewComment() throws IOException { |
| 210 | + return owner.root() |
| 211 | + .createRequest() |
| 212 | + .withUrlPath("/repos/" + owner.getRepository().getFullName() + "/pulls/comments/" + getId()) |
| 213 | + .fetch(GHPullRequestReviewComment.class) |
| 214 | + .wrapUp(owner); |
| 215 | + } |
| 216 | + |
| 217 | + /** |
| 218 | + * Wrap up. |
| 219 | + * |
| 220 | + * @param owner |
| 221 | + * the owner |
| 222 | + * @return the review comment |
| 223 | + */ |
| 224 | + ReviewComment wrapUp(GHPullRequest owner) { |
| 225 | + this.owner = owner; |
| 226 | + return this; |
| 227 | + } |
| 228 | + } |
| 229 | + |
46 | 230 | private String body; |
47 | 231 |
|
48 | 232 | private String commitId; |
@@ -171,13 +355,20 @@ public GHUser getUser() throws IOException { |
171 | 355 | /** |
172 | 356 | * Obtains all the review comments associated with this pull request review. |
173 | 357 | * |
174 | | - * @return the paged iterable |
| 358 | + * <p> |
| 359 | + * The GitHub API endpoint used by this method returns a limited set of fields. To obtain full comment data |
| 360 | + * including line numbers, use {@link ReviewComment#readPullRequestReviewComment()} on individual comments, or use |
| 361 | + * {@link GHPullRequest#listReviewComments()} instead. |
| 362 | + * |
| 363 | + * @return the paged iterable of {@link ReviewComment} objects |
| 364 | + * @see GHPullRequest#listReviewComments() |
| 365 | + * @see ReviewComment#readPullRequestReviewComment() |
175 | 366 | */ |
176 | | - public PagedIterable<GHPullRequestReviewComment> listReviewComments() { |
| 367 | + public PagedIterable<ReviewComment> listReviewComments() { |
177 | 368 | return owner.root() |
178 | 369 | .createRequest() |
179 | 370 | .withUrlPath(getApiRoute() + "/comments") |
180 | | - .toIterable(GHPullRequestReviewComment[].class, item -> item.wrapUp(owner)); |
| 371 | + .toIterable(ReviewComment[].class, item -> item.wrapUp(owner)); |
181 | 372 | } |
182 | 373 |
|
183 | 374 | /** |
|
0 commit comments