From 15991fd2f763a40dd21c2a7715735abd87de9423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 30 Nov 2017 14:38:47 +0100 Subject: [PATCH] PullRequest review state and event do not have same values this fixes parsing of response of WS call submitting a review to fail when event of new review is REQUEST_CHANGES also, specifying event when creating a pending PR review is useless and providing it when submitting the review is enough --- .../org/kohsuke/github/GHPullRequest.java | 15 +++---- .../kohsuke/github/GHPullRequestReview.java | 7 ++-- .../github/GHPullRequestReviewEvent.java | 41 +++++++++++++++++++ .../github/GHPullRequestReviewState.java | 20 +++------ .../org/kohsuke/github/PullRequestTest.java | 2 +- 5 files changed, 56 insertions(+), 29 deletions(-) create mode 100644 src/main/java/org/kohsuke/github/GHPullRequestReviewEvent.java diff --git a/src/main/java/org/kohsuke/github/GHPullRequest.java b/src/main/java/org/kohsuke/github/GHPullRequest.java index 934262382..99db3bf32 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequest.java +++ b/src/main/java/org/kohsuke/github/GHPullRequest.java @@ -23,7 +23,6 @@ */ package org.kohsuke.github; -import javax.annotation.CheckForNull; import java.io.IOException; import java.net.URL; import java.util.ArrayList; @@ -298,23 +297,19 @@ public class GHPullRequest extends GHIssue { @Preview @Deprecated - public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event, - GHPullRequestReviewComment... comments) + public GHPullRequestReview createReview(String body, GHPullRequestReviewComment... comments) throws IOException { - return createReview(body, event, Arrays.asList(comments)); + return createReview(body, Arrays.asList(comments)); } @Preview @Deprecated - public GHPullRequestReview createReview(String body, @CheckForNull GHPullRequestReviewState event, - List comments) + public GHPullRequestReview createReview(String body, List comments) throws IOException { -// if (event == null) { -// event = GHPullRequestReviewState.PENDING; -// } List draftComments = new ArrayList(comments.size()); for (GHPullRequestReviewComment c : comments) { - draftComments.add(new DraftReviewComment(c.getBody(), c.getPath(), c.getPosition())); + Integer position = c.getPosition(); + draftComments.add(new DraftReviewComment(c.getBody(), c.getPath(), position == null ? 0 : position /*FIXME do not use GHPullRequestReviewComment for new comments*/)); } return new Requester(root).method("POST") .with("body", body) diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReview.java b/src/main/java/org/kohsuke/github/GHPullRequestReview.java index d7afe59aa..c96e8f149 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReview.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReview.java @@ -25,6 +25,7 @@ package org.kohsuke.github; import java.io.IOException; import java.net.URL; +import javax.annotation.CheckForNull; import static org.kohsuke.github.Previews.*; @@ -32,7 +33,7 @@ import static org.kohsuke.github.Previews.*; * Review to the pull request * * @see GHPullRequest#listReviews() - * @see GHPullRequest#createReview(String, GHPullRequestReviewState, GHPullRequestReviewComment...) + * @see GHPullRequest#createReview(String, GHPullRequestReviewComment...) */ public class GHPullRequestReview extends GHObject { GHPullRequest owner; @@ -72,6 +73,7 @@ public class GHPullRequestReview extends GHObject { return commit_id; } + @CheckForNull public GHPullRequestReviewState getState() { return state; } @@ -90,14 +92,13 @@ public class GHPullRequestReview extends GHObject { */ @Preview @Deprecated - public void submit(String body, GHPullRequestReviewState event) throws IOException { + public void submit(String body, GHPullRequestReviewEvent event) throws IOException { new Requester(owner.root).method("POST") .with("body", body) .with("event", event.action()) .withPreview("application/vnd.github.black-cat-preview+json") .to(getApiRoute()+"/events",this); this.body = body; - this.state = event; } /** diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewEvent.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewEvent.java new file mode 100644 index 000000000..4a5d66094 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewEvent.java @@ -0,0 +1,41 @@ +/* + * The MIT License + * + * Copyright (c) 2011, Eric Maupin + * + * 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; + +public enum GHPullRequestReviewEvent { + PENDING(null), + APPROVE("APPROVE"), + REQUEST_CHANGES("REQUEST_CHANGES"), + COMMENT("COMMENT"); + + private final String _action; + + GHPullRequestReviewEvent(String action) { + _action = action; + } + + public String action() { + return _action; + } +} diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewState.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewState.java index fca3fabfb..eff7fbf60 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewState.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewState.java @@ -1,19 +1,9 @@ package org.kohsuke.github; public enum GHPullRequestReviewState { - PENDING(null), - APPROVED("APPROVE"), - REQUEST_CHANGES("REQUEST_CHANGES"), - COMMENTED("COMMENT"), - DISMISSED(null); - - private final String _action; - - GHPullRequestReviewState(String action) { - _action = action; - } - - public String action() { - return _action; - } + PENDING, + APPROVED, + CHANGES_REQUESTED, + COMMENTED, + DISMISSED } diff --git a/src/test/java/org/kohsuke/github/PullRequestTest.java b/src/test/java/org/kohsuke/github/PullRequestTest.java index 5ea262830..bf45e35c4 100644 --- a/src/test/java/org/kohsuke/github/PullRequestTest.java +++ b/src/test/java/org/kohsuke/github/PullRequestTest.java @@ -45,7 +45,7 @@ public class PullRequestTest extends AbstractGitHubApiTestBase { assertThat(review.getState(), is(GHPullRequestReviewState.PENDING)); assertThat(review.getBody(), is("Some draft review")); assertThat(review.getCommitId(), notNullValue()); - review.submit("Some review comment", GHPullRequestReviewState.COMMENTED); + review.submit("Some review comment", GHPullRequestReviewEvent.COMMENT); List comments = review.listReviewComments().asList(); assertEquals(1, comments.size()); GHPullRequestReviewComment comment = comments.get(0);