mirror of
https://github.com/jlengrand/github-api.git
synced 2026-04-13 00:11:21 +00:00
- Restored binary compatibility. The draft API has changed in some significant way when it became public, and the PR took the liberty to delete removed constants and method signatures. I brought them back so that older clients can keep functioning. - Introduced a builder pattern to create PR review - replying to a review comment should be an instance method, not a static method. - GHPullRequestReview and GHPullRequestReviewDraft was not making sense to me, since GitHub API doesn't differentiate them. It creates a practical problem of not being able to submit a review comment unless you created the review comment in the same JVM session. That said, I don't understand the point of this two phase approach in the GitHub API to begin with!
149 lines
4.6 KiB
Java
149 lines
4.6 KiB
Java
/*
|
|
* The MIT License
|
|
*
|
|
* Copyright (c) 2017, CloudBees, Inc.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*/
|
|
package org.kohsuke.github;
|
|
|
|
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|
|
|
import javax.annotation.CheckForNull;
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
|
|
/**
|
|
* Review to a pull request.
|
|
*
|
|
* @see GHPullRequest#listReviews()
|
|
* @see GHPullRequestReviewBuilder
|
|
*/
|
|
@SuppressFBWarnings(value = {"UWF_UNWRITTEN_FIELD"}, justification = "JSON API")
|
|
public class GHPullRequestReview extends GHObject {
|
|
GHPullRequest owner;
|
|
|
|
private String body;
|
|
private GHUser user;
|
|
private String commit_id;
|
|
private GHPullRequestReviewState state;
|
|
|
|
/*package*/ GHPullRequestReview wrapUp(GHPullRequest owner) {
|
|
this.owner = owner;
|
|
return this;
|
|
}
|
|
|
|
/**
|
|
* Gets the pull request to which this review is associated.
|
|
*/
|
|
public GHPullRequest getParent() {
|
|
return owner;
|
|
}
|
|
|
|
/**
|
|
* The comment itself.
|
|
*/
|
|
public String getBody() {
|
|
return body;
|
|
}
|
|
|
|
/**
|
|
* Gets the user who posted this review.
|
|
*/
|
|
public GHUser getUser() throws IOException {
|
|
return owner.root.getUser(user.getLogin());
|
|
}
|
|
|
|
public String getCommitId() {
|
|
return commit_id;
|
|
}
|
|
|
|
@CheckForNull
|
|
public GHPullRequestReviewState getState() {
|
|
return state;
|
|
}
|
|
|
|
@Override
|
|
public URL getHtmlUrl() {
|
|
return null;
|
|
}
|
|
|
|
protected String getApiRoute() {
|
|
return owner.getApiRoute()+"/reviews/"+id;
|
|
}
|
|
|
|
/**
|
|
* @deprecated
|
|
* Former preview method that changed when it got public. Left here for backward compatibility.
|
|
* Use {@link #submit(String, GHPullRequestReviewEvent)}
|
|
*/
|
|
public void submit(String body, GHPullRequestReviewState state) throws IOException {
|
|
submit(body,state.toEvent());
|
|
}
|
|
|
|
/**
|
|
* Updates the comment.
|
|
*/
|
|
public void submit(String body, GHPullRequestReviewEvent event) throws IOException {
|
|
new Requester(owner.root).method("POST")
|
|
.with("body", body)
|
|
.with("event", event.action())
|
|
.to(getApiRoute()+"/events",this);
|
|
this.body = body;
|
|
this.state = event.toState();
|
|
}
|
|
|
|
/**
|
|
* Deletes this review.
|
|
*/
|
|
public void delete() throws IOException {
|
|
new Requester(owner.root).method("DELETE")
|
|
.to(getApiRoute());
|
|
}
|
|
|
|
/**
|
|
* Dismisses this review.
|
|
*/
|
|
public void dismiss(String message) throws IOException {
|
|
new Requester(owner.root).method("PUT")
|
|
.with("message", message)
|
|
.to(getApiRoute()+"/dismissals");
|
|
state = GHPullRequestReviewState.DISMISSED;
|
|
}
|
|
|
|
/**
|
|
* Obtains all the review comments associated with this pull request review.
|
|
*/
|
|
public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException {
|
|
return new PagedIterable<GHPullRequestReviewComment>() {
|
|
public PagedIterator<GHPullRequestReviewComment> _iterator(int pageSize) {
|
|
return new PagedIterator<GHPullRequestReviewComment>(
|
|
owner.root.retrieve()
|
|
.asIterator(getApiRoute() + "/comments",
|
|
GHPullRequestReviewComment[].class, pageSize)) {
|
|
protected void wrapUp(GHPullRequestReviewComment[] page) {
|
|
for (GHPullRequestReviewComment c : page)
|
|
c.wrapUp(owner);
|
|
}
|
|
};
|
|
}
|
|
};
|
|
}
|
|
}
|