Skip to content

Commit 88ca933

Browse files
Make ReviewState a String (spotify#14)
the usage of this is inconsistent in github api
1 parent d358965 commit 88ca933

8 files changed

Lines changed: 152 additions & 14 deletions

File tree

src/main/java/com/spotify/github/v3/activity/events/PullRequestReviewEvent.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2525
import com.spotify.github.GithubStyle;
2626
import com.spotify.github.v3.prs.PullRequestItem;
27+
import com.spotify.github.v3.prs.Review;
2728
import javax.annotation.Nullable;
2829
import org.immutables.value.Value;
2930

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*-
2+
* -\-\-
3+
* github-client
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
21+
package com.spotify.github.v3.activity.events;
22+
23+
/**
24+
* Helpful constants for common Review states in reviews events.
25+
*
26+
* @see "https://developer.github.com/v3/activity/events/types/#pullrequestreviewevent"
27+
*/
28+
public class ReviewState {
29+
30+
public static final String PENDING = "pending";
31+
public static final String COMMENTED = "commented";
32+
public static final String APPROVED = "approved";
33+
public static final String REJECTED = "rejected";
34+
public static final String CHANGES_REQUESTED = "changes_requested";
35+
public static final String DISMISSED = "dismissed";
36+
37+
private ReviewState() {}
38+
}

src/main/java/com/spotify/github/v3/clients/GitHubClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
import com.fasterxml.jackson.core.type.TypeReference;
2727
import com.spotify.github.jackson.Json;
28-
import com.spotify.github.v3.activity.events.Review;
28+
import com.spotify.github.v3.prs.Review;
2929
import com.spotify.github.v3.checks.AccessToken;
3030
import com.spotify.github.v3.comment.Comment;
3131
import com.spotify.github.v3.exceptions.ReadOnlyRepositoryException;

src/main/java/com/spotify/github/v3/clients/PullRequestClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
import com.google.common.base.Strings;
2929
import com.spotify.github.async.AsyncPage;
30-
import com.spotify.github.v3.activity.events.Review;
30+
import com.spotify.github.v3.prs.Review;
3131
import com.spotify.github.v3.prs.MergeParameters;
3232
import com.spotify.github.v3.prs.PullRequest;
3333
import com.spotify.github.v3.prs.PullRequestItem;

src/main/java/com/spotify/github/v3/activity/events/Review.java renamed to src/main/java/com/spotify/github/v3/prs/Review.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
* -/-/-
1919
*/
2020

21-
package com.spotify.github.v3.activity.events;
21+
package com.spotify.github.v3.prs;
2222

2323
import com.fasterxml.jackson.annotation.JsonProperty;
2424
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
2525
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
2626
import com.spotify.github.GitHubInstant;
2727
import com.spotify.github.GithubStyle;
2828
import com.spotify.github.v3.User;
29-
import com.spotify.github.v3.prs.ReviewState;
29+
import com.spotify.github.v3.activity.events.ReviewLinks;
3030
import java.net.URI;
3131
import java.util.Optional;
3232
import javax.annotation.Nullable;
@@ -59,7 +59,7 @@ public interface Review {
5959

6060
/** State. */
6161
@Nullable
62-
ReviewState state();
62+
String state();
6363

6464
/** Html URL. */
6565
@Nullable

src/main/java/com/spotify/github/v3/prs/ReviewState.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*-
22
* -\-\-
3-
* github-api
3+
* github-client
44
* --
55
* Copyright (C) 2016 - 2020 Spotify AB
66
* --
@@ -20,12 +20,19 @@
2020

2121
package com.spotify.github.v3.prs;
2222

23-
/** Represents Review states. */
24-
public enum ReviewState {
25-
PENDING,
26-
COMMENTED,
27-
APPROVED,
28-
REJECTED,
29-
CHANGES_REQUESTED,
30-
DISMISSED
23+
/**
24+
* Helpful constants for common Review states in reviews.
25+
*
26+
* @see "https://developer.github.com/v3/pulls/reviews/#list-reviews-on-a-pull-request"
27+
*/
28+
public class ReviewState {
29+
30+
public static final String PENDING = "PENDING";
31+
public static final String COMMENTED = "COMMENTED";
32+
public static final String APPROVED = "APPROVED";
33+
public static final String REJECTED = "REJECTED";
34+
public static final String CHANGES_REQUESTED = "CHANGES_REQUESTED";
35+
public static final String DISMISSED = "DISMISSED";
36+
37+
private ReviewState() {}
3138
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*-
2+
* -\-\-
3+
* github-client
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
21+
package com.spotify.github.v3.activity.events;
22+
23+
import static com.google.common.io.Resources.getResource;
24+
import static java.nio.charset.Charset.defaultCharset;
25+
import static org.hamcrest.MatcherAssert.assertThat;
26+
import static org.hamcrest.core.Is.is;
27+
28+
import com.google.common.io.Resources;
29+
import com.spotify.github.jackson.Json;
30+
import java.io.IOException;
31+
import org.junit.Test;
32+
33+
public class PullRequestReviewEventTest {
34+
@Test
35+
public void testDeserialization() throws IOException {
36+
String fixture =
37+
Resources.toString(
38+
getResource(this.getClass(), "fixtures/pull_request_review_event.json"),
39+
defaultCharset());
40+
final PullRequestReviewEvent statusEvent =
41+
Json.create().fromJson(fixture, PullRequestReviewEvent.class);
42+
assertThat(statusEvent.action(), is("submitted"));
43+
assertThat(statusEvent.pullRequest().number(), is(8));
44+
assertThat(statusEvent.review().state(), is(ReviewState.APPROVED));
45+
}
46+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*-
2+
* -\-\-
3+
* github-client
4+
* --
5+
* Copyright (C) 2016 - 2020 Spotify AB
6+
* --
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* -/-/-
19+
*/
20+
21+
package com.spotify.github.v3.prs;
22+
23+
import static com.google.common.io.Resources.getResource;
24+
import static java.nio.charset.Charset.defaultCharset;
25+
import static org.hamcrest.MatcherAssert.assertThat;
26+
import static org.hamcrest.core.Is.is;
27+
28+
import com.google.common.io.Resources;
29+
import com.spotify.github.jackson.Json;
30+
import java.io.IOException;
31+
import org.junit.Test;
32+
33+
public class ReviewTest {
34+
@Test
35+
public void testDeserialization() throws IOException {
36+
String fixture =
37+
Resources.toString(
38+
getResource(this.getClass(), "review.json"),
39+
defaultCharset());
40+
final Review review =
41+
Json.create().fromJson(fixture, Review.class);
42+
assertThat(review.state(), is(ReviewState.APPROVED));
43+
assertThat(review.commitId(), is("ecdd80bb57125d7ba9641ffaa4d7d2c19d3f3091"));
44+
assertThat(review.id(), is(80));
45+
}
46+
}

0 commit comments

Comments
 (0)