|
| 1 | +/* |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2017, CloudBees, Inc. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | +package org.kohsuke.github; |
| 25 | + |
| 26 | +import java.io.IOException; |
| 27 | +import java.net.URL; |
| 28 | + |
| 29 | +/** |
| 30 | + * Review to the pull request |
| 31 | + * |
| 32 | + * @see GHPullRequest#listReviews() |
| 33 | + * @see GHPullRequest#createReview(String, GHPullRequestReviewState, GHPullRequestReviewComment...) |
| 34 | + */ |
| 35 | +public class GHPullRequestReview extends GHObject { |
| 36 | + GHPullRequest owner; |
| 37 | + |
| 38 | + private String body; |
| 39 | + private GHUser user; |
| 40 | + private String commit_id; |
| 41 | + private GHPullRequestReviewState state; |
| 42 | + |
| 43 | + /*package*/ GHPullRequestReview wrapUp(GHPullRequest owner) { |
| 44 | + this.owner = owner; |
| 45 | + return this; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Gets the pull request to which this review is associated. |
| 50 | + */ |
| 51 | + public GHPullRequest getParent() { |
| 52 | + return owner; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * The comment itself. |
| 57 | + */ |
| 58 | + public String getBody() { |
| 59 | + return body; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Gets the user who posted this review. |
| 64 | + */ |
| 65 | + public GHUser getUser() throws IOException { |
| 66 | + return owner.root.getUser(user.getLogin()); |
| 67 | + } |
| 68 | + |
| 69 | + public String getCommitId() { |
| 70 | + return commit_id; |
| 71 | + } |
| 72 | + |
| 73 | + public GHPullRequestReviewState getState() { |
| 74 | + return state; |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + public URL getHtmlUrl() { |
| 79 | + return null; |
| 80 | + } |
| 81 | + |
| 82 | + protected String getApiRoute() { |
| 83 | + return owner.getApiRoute()+"/reviews/"+id; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Updates the comment. |
| 88 | + */ |
| 89 | + @Preview |
| 90 | + @Deprecated |
| 91 | + public void submit(String body, GHPullRequestReviewState event) throws IOException { |
| 92 | + new Requester(owner.root).method("POST") |
| 93 | + .with("body", body) |
| 94 | + .with("event", event.action()) |
| 95 | + .withPreview("application/vnd.github.black-cat-preview+json") |
| 96 | + .to(getApiRoute()+"/events",this); |
| 97 | + this.body = body; |
| 98 | + this.state = event; |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Deletes this review. |
| 103 | + */ |
| 104 | + @Preview |
| 105 | + @Deprecated |
| 106 | + public void delete() throws IOException { |
| 107 | + new Requester(owner.root).method("DELETE") |
| 108 | + .withPreview("application/vnd.github.black-cat-preview+json") |
| 109 | + .to(getApiRoute()); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Dismisses this review. |
| 114 | + */ |
| 115 | + @Preview |
| 116 | + @Deprecated |
| 117 | + public void dismiss(String message) throws IOException { |
| 118 | + new Requester(owner.root).method("PUT") |
| 119 | + .with("message", message) |
| 120 | + .withPreview("application/vnd.github.black-cat-preview+json") |
| 121 | + .to(getApiRoute()+"/dismissals"); |
| 122 | + state = GHPullRequestReviewState.DISMISSED; |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Obtains all the review comments associated with this pull request review. |
| 127 | + */ |
| 128 | + @Preview |
| 129 | + @Deprecated |
| 130 | + public PagedIterable<GHPullRequestReviewComment> listReviewComments() throws IOException { |
| 131 | + return new PagedIterable<GHPullRequestReviewComment>() { |
| 132 | + public PagedIterator<GHPullRequestReviewComment> _iterator(int pageSize) { |
| 133 | + return new PagedIterator<GHPullRequestReviewComment>( |
| 134 | + owner.root.retrieve() |
| 135 | + .withPreview("application/vnd.github.black-cat-preview+json") |
| 136 | + .asIterator(getApiRoute() + "/comments", |
| 137 | + GHPullRequestReviewComment[].class, pageSize)) { |
| 138 | + protected void wrapUp(GHPullRequestReviewComment[] page) { |
| 139 | + for (GHPullRequestReviewComment c : page) |
| 140 | + c.wrapUp(owner); |
| 141 | + } |
| 142 | + }; |
| 143 | + } |
| 144 | + }; |
| 145 | + } |
| 146 | + |
| 147 | +} |
0 commit comments