Skip to content

Commit

Permalink
PullRequest review state and event do not have same values
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sns-seb committed Jan 9, 2018
1 parent e25ae27 commit 15991fd
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 29 deletions.
15 changes: 5 additions & 10 deletions src/main/java/org/kohsuke/github/GHPullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package org.kohsuke.github;

import javax.annotation.CheckForNull;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -298,23 +297,19 @@ protected void wrapUp(GHPullRequestCommitDetail[] page) {

@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<GHPullRequestReviewComment> comments)
public GHPullRequestReview createReview(String body, List<GHPullRequestReviewComment> comments)
throws IOException {
// if (event == null) {
// event = GHPullRequestReviewState.PENDING;
// }
List<DraftReviewComment> draftComments = new ArrayList<DraftReviewComment>(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)
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/kohsuke/github/GHPullRequestReview.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@

import java.io.IOException;
import java.net.URL;
import javax.annotation.CheckForNull;

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;
Expand Down Expand Up @@ -72,6 +73,7 @@ public String getCommitId() {
return commit_id;
}

@CheckForNull
public GHPullRequestReviewState getState() {
return state;
}
Expand All @@ -90,14 +92,13 @@ protected String getApiRoute() {
*/
@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;
}

/**
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/org/kohsuke/github/GHPullRequestReviewEvent.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
20 changes: 5 additions & 15 deletions src/main/java/org/kohsuke/github/GHPullRequestReviewState.java
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion src/test/java/org/kohsuke/github/PullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testPullRequestReviews() throws Exception {
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<GHPullRequestReviewComment> comments = review.listReviewComments().asList();
assertEquals(1, comments.size());
GHPullRequestReviewComment comment = comments.get(0);
Expand Down

0 comments on commit 15991fd

Please sign in to comment.