1 /*
  2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 package org.openjdk.skara.host;
 24 
 25 import org.openjdk.skara.vcs.Hash;
 26 
 27 import java.net.URI;
 28 import java.time.ZonedDateTime;
 29 import java.util.*;
 30 
 31 public interface PullRequest {
 32 
 33     HostedRepository repository();
 34 
 35     /**
 36      * The repository-specific identifier.
 37      * @return
 38      */
 39     String getId();
 40 
 41     /**
 42      * The host-specific author name.
 43      * @return
 44      */
 45     HostUserDetails getAuthor();
 46 
 47     /**
 48      * List of reviews, in descending chronological order.
 49      * @return
 50      */
 51     List<Review> getReviews();
 52 
 53     /**
 54      * Adds a review with the given verdict.
 55      */
 56     void addReview(Review.Verdict verdict, String body);
 57 
 58     /**
 59      * Add a file specific comment.
 60      * @param hash
 61      * @param path
 62      * @param line
 63      * @param body
 64      * @return
 65      */
 66     ReviewComment addReviewComment(Hash base, Hash hash, String path, int line, String body);
 67 
 68     /**
 69      * Reply to a file specific comment.
 70      * @param parent
 71      * @param body
 72      * @return
 73      */
 74     ReviewComment addReviewCommentReply(ReviewComment parent, String body);
 75 
 76     /**
 77      * Get all file specific comments.
 78      * @return
 79      */
 80     List<ReviewComment> getReviewComments();
 81 
 82     /**
 83      * Hash of the current head of the request.
 84      * @return
 85      */
 86     Hash getHeadHash();
 87 
 88     /**
 89      * Returns the name of the ref the request is created from.
 90      * @return
 91      */
 92     String getSourceRef();
 93 
 94     /**
 95      * Returns the name of the ref the request is intended to be merged into.
 96      * @return
 97      */
 98     String getTargetRef();
 99 
100     /**
101      * Returns the current head of the ref the request is intended to be merged into.
102      * @return
103      */
104     Hash getTargetHash();
105 
106     /**
107      * Title of the request.
108      * @return
109      */
110     String getTitle();
111 
112     /**
113      * Update the title of the request.
114      * @param title
115      */
116     void setTitle(String title);
117 
118     /**
119      * The main body of the request.
120      * @return
121      */
122     String getBody();
123 
124     /**
125      * Update the main body of the request.
126      * @param body
127      */
128     void setBody(String body);
129 
130     /**
131      * All comments on the issue, in ascending creation time order.
132      * @return
133      */
134     List<Comment> getComments();
135 
136     /**
137      * Posts a new comment.
138      * @param body
139      */
140     Comment addComment(String body);
141 
142     /**
143      * Updates an existing comment.
144      * @param id
145      * @param body
146      */
147     Comment updateComment(String id, String body);
148 
149     /**
150      * When the request was created.
151      * @return
152      */
153     ZonedDateTime getCreated();
154 
155     /**
156      * When the request was last updated.
157      * @return
158      */
159     ZonedDateTime getUpdated();
160 
161     /**
162      * List of completed checks on the given hash.
163      * @return
164      */
165     Map<String, Check> getChecks(Hash hash);
166 
167     /**
168      * Creates a new check.
169      * @param check
170      */
171     void createCheck(Check check);
172 
173     /**
174      * Updates an existing check.
175      * @param check
176      */
177     void updateCheck(Check check);
178 
179     enum State {
180         OPEN,
181         CLOSED
182     }
183 
184     /**
185      * Set the state.
186      * @param state Desired state
187      */
188     void setState(State state);
189 
190     /**
191      * Adds the given label.
192      * @param label
193      */
194     void addLabel(String label);
195 
196     /**
197      * Removes the given label.
198      * @param label
199      */
200     void removeLabel(String label);
201 
202     /**
203      * Retrieves all the currently set labels.
204      * @return
205      */
206     List<String> getLabels();
207 
208     /**
209      * Returns a link that will lead to the PR.
210      */
211     URI getWebUrl();
212 
213     /**
214      * Returns all usernames assigned to the PR.
215      */
216     List<HostUserDetails> getAssignees();
217 
218     /**
219      * Update the list of assignees.
220      * @param assignees
221      */
222     void setAssignees(List<HostUserDetails> assignees);
223 }