+ * This is useful when the comment was obtained via {@link GHPullRequestReview#listReviewComments()}, which uses a + * GitHub API endpoint that does not return all fields. After calling this method, fields like {@link #getLine()}, + * {@link #getOriginalLine()}, {@link #getSide()}, etc. will return their actual values. + * + * @throws IOException + * if an I/O error occurs + * @see GHPullRequest#listReviewComments() + */ + @Override + public void refresh() throws IOException { + owner.root().createRequest().withUrlPath(getApiRoute()).fetchInto(this).wrapUp(getParent()); + } + /** * Create a new comment that replies to this comment. * @@ -419,7 +387,7 @@ public GHPullRequestReviewComment reply(String body) throws IOException { .with("body", body) .withUrlPath(getApiRoute(true) + "/replies") .fetch(GHPullRequestReviewComment.class) - .wrapUp(owner); + .wrapUp(getParent()); } /** @@ -430,6 +398,7 @@ public GHPullRequestReviewComment reply(String body) throws IOException { * @throws IOException * the io exception */ + @Override public void update(String body) throws IOException { owner.root().createRequest().method("PATCH").with("body", body).withUrlPath(getApiRoute()).fetchInto(this); this.body = body; @@ -460,12 +429,12 @@ protected String getApiRoute(boolean includePullNumber) { /** * Wrap up. * - * @param owner - * the owner + * @param pullRequest + * the pull request owner * @return the GH pull request review comment */ - GHPullRequestReviewComment wrapUp(GHPullRequest owner) { - this.owner = owner; + GHPullRequestReviewComment wrapUp(GHPullRequest pullRequest) { + this.owner = pullRequest; return this; } } diff --git a/src/test/java/org/kohsuke/github/GHPullRequestTest.java b/src/test/java/org/kohsuke/github/GHPullRequestTest.java index c451128a0b..aa1aa231f4 100644 --- a/src/test/java/org/kohsuke/github/GHPullRequestTest.java +++ b/src/test/java/org/kohsuke/github/GHPullRequestTest.java @@ -764,6 +764,9 @@ public void pullRequestReviews() throws Exception { GHPullRequestReviewComment fullComment = comments.get(0).readPullRequestReviewComment(); assertThat(fullComment.getBody(), equalTo("Some niggle")); assertThat(fullComment.getLine(), equalTo(1)); + assertThat(fullComment.getParent().getNumber(), equalTo(p.getNumber())); + fullComment.refresh(); + assertThat(fullComment.getLine(), equalTo(1)); draftReview = p.createReview().body("Some new review").comment("Some niggle", "README.md", 1).create(); draftReview.delete();