2323 */
2424package org .kohsuke .github ;
2525
26- import javax .annotation .CheckForNull ;
2726import java .io .IOException ;
2827import java .net .URL ;
29- import java .util .ArrayList ;
30- import java .util .Arrays ;
3128import java .util .Collection ;
3229import java .util .Date ;
33- import java .util .List ;
34-
35- import static org .kohsuke .github .Previews .*;
3630
3731/**
3832 * A pull request.
39- *
33+ *
4034 * @author Kohsuke Kawaguchi
4135 * @see GHRepository#getPullRequest(int)
4236 */
4337@ SuppressWarnings ({"UnusedDeclaration" })
4438public class GHPullRequest extends GHIssue {
4539
40+ private static final String COMMENTS_ACTION = "/comments" ;
41+
4642 private String patch_url , diff_url , issue_url ;
4743 private GHCommitPointer base ;
4844 private String merged_at ;
@@ -91,7 +87,7 @@ protected String getApiRoute() {
9187 public URL getPatchUrl () {
9288 return GitHub .parseURL (patch_url );
9389 }
94-
90+
9591 /**
9692 * The URL of the patch file.
9793 * like https://github.com/jenkinsci/jenkins/pull/100.patch
@@ -114,7 +110,7 @@ public GHCommitPointer getBase() {
114110 public GHCommitPointer getHead () {
115111 return head ;
116112 }
117-
113+
118114 @ Deprecated
119115 public Date getIssueUpdatedAt () throws IOException {
120116 return super .getUpdatedAt ();
@@ -262,7 +258,6 @@ public PagedIterable<GHPullRequestReview> listReviews() {
262258 return new PagedIterable <GHPullRequestReview >() {
263259 public PagedIterator <GHPullRequestReview > _iterator (int pageSize ) {
264260 return new PagedIterator <GHPullRequestReview >(root .retrieve ()
265- .withPreview (BLACK_CAT )
266261 .asIterator (String .format ("%s/reviews" , getApiRoute ()),
267262 GHPullRequestReview [].class , pageSize )) {
268263 @ Override
@@ -282,7 +277,7 @@ protected void wrapUp(GHPullRequestReview[] page) {
282277 public PagedIterable <GHPullRequestReviewComment > listReviewComments () throws IOException {
283278 return new PagedIterable <GHPullRequestReviewComment >() {
284279 public PagedIterator <GHPullRequestReviewComment > _iterator (int pageSize ) {
285- return new PagedIterator <GHPullRequestReviewComment >(root .retrieve ().asIterator (getApiRoute () + "/comments" ,
280+ return new PagedIterator <GHPullRequestReviewComment >(root .retrieve ().asIterator (getApiRoute () + COMMENTS_ACTION ,
286281 GHPullRequestReviewComment [].class , pageSize )) {
287282 protected void wrapUp (GHPullRequestReviewComment [] page ) {
288283 for (GHPullRequestReviewComment c : page )
@@ -312,32 +307,8 @@ protected void wrapUp(GHPullRequestCommitDetail[] page) {
312307 };
313308 }
314309
315- @ Preview
316- @ Deprecated
317- public GHPullRequestReview createReview (String body , @ CheckForNull GHPullRequestReviewState event ,
318- GHPullRequestReviewComment ... comments )
319- throws IOException {
320- return createReview (body , event , Arrays .asList (comments ));
321- }
322-
323- @ Preview
324- @ Deprecated
325- public GHPullRequestReview createReview (String body , @ CheckForNull GHPullRequestReviewState event ,
326- List <GHPullRequestReviewComment > comments )
327- throws IOException {
328- // if (event == null) {
329- // event = GHPullRequestReviewState.PENDING;
330- // }
331- List <DraftReviewComment > draftComments = new ArrayList <DraftReviewComment >(comments .size ());
332- for (GHPullRequestReviewComment c : comments ) {
333- draftComments .add (new DraftReviewComment (c .getBody (), c .getPath (), c .getPosition ()));
334- }
335- return new Requester (root ).method ("POST" )
336- .with ("body" , body )
337- //.with("event", event.name())
338- ._with ("comments" , draftComments )
339- .withPreview (BLACK_CAT )
340- .to (getApiRoute () + "/reviews" , GHPullRequestReview .class ).wrapUp (this );
310+ public GHPullRequestReviewBuilder createReview () {
311+ return new GHPullRequestReviewBuilder (this );
341312 }
342313
343314 public GHPullRequestReviewComment createReviewComment (String body , String sha , String path , int position ) throws IOException {
@@ -346,7 +317,7 @@ public GHPullRequestReviewComment createReviewComment(String body, String sha, S
346317 .with ("commit_id" , sha )
347318 .with ("path" , path )
348319 .with ("position" , position )
349- .to (getApiRoute () + "/comments" , GHPullRequestReviewComment .class ).wrapUp (this );
320+ .to (getApiRoute () + COMMENTS_ACTION , GHPullRequestReviewComment .class ).wrapUp (this );
350321 }
351322
352323 /**
@@ -387,10 +358,10 @@ public void merge(String msg, String sha) throws IOException {
387358 */
388359 public void merge (String msg , String sha , MergeMethod method ) throws IOException {
389360 new Requester (root ).method ("PUT" )
390- .with ("commit_message" ,msg )
391- .with ("sha" ,sha )
392- .with ("merge_method" ,method )
393- .to (getApiRoute ()+ "/merge" );
361+ .with ("commit_message" , msg )
362+ .with ("sha" , sha )
363+ .with ("merge_method" , method )
364+ .to (getApiRoute () + "/merge" );
394365 }
395366
396367 public enum MergeMethod { MERGE , SQUASH , REBASE }
@@ -401,28 +372,4 @@ private void fetchIssue() throws IOException {
401372 fetchedIssueDetails = true ;
402373 }
403374 }
404-
405- private static class DraftReviewComment {
406- private String body ;
407- private String path ;
408- private int position ;
409-
410- public DraftReviewComment (String body , String path , int position ) {
411- this .body = body ;
412- this .path = path ;
413- this .position = position ;
414- }
415-
416- public String getBody () {
417- return body ;
418- }
419-
420- public String getPath () {
421- return path ;
422- }
423-
424- public int getPosition () {
425- return position ;
426- }
427- }
428375}
0 commit comments