Skip to content

Commit 29aace3

Browse files
authored
feat: Add auto_merge field to the PR class (#226)
1 parent 391d6f6 commit 29aace3

File tree

5 files changed

+829
-2
lines changed

5 files changed

+829
-2
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*-
2+
* -\-\-
3+
* github-api
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 com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
25+
import com.spotify.github.GithubStyle;
26+
import com.spotify.github.v3.User;
27+
import org.immutables.value.Value;
28+
29+
import javax.annotation.Nullable;
30+
31+
@Value.Immutable
32+
@GithubStyle
33+
@JsonSerialize(as = ImmutableAutoMerge.class)
34+
@JsonDeserialize(as = ImmutableAutoMerge.class)
35+
public interface AutoMerge {
36+
// Who enabled the auto merge
37+
User enabledBy();
38+
39+
// Merge Method chosen for the auto merge
40+
String mergeMethod();
41+
42+
// The commit title to use when merging the pull request
43+
@Nullable
44+
String commitTitle();
45+
46+
// The commit message to use when merging the pull request
47+
@Nullable
48+
String commitMessage();
49+
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -87,4 +87,7 @@ public interface PullRequest extends PullRequestItem {
8787

8888
@Nullable
8989
List<Label> labels();
90+
91+
@Nullable
92+
AutoMerge autoMerge();
9093
}

src/test/java/com/spotify/github/v3/prs/PullRequestTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import static java.nio.charset.Charset.defaultCharset;
2525
import static org.hamcrest.MatcherAssert.assertThat;
2626
import static org.hamcrest.core.Is.is;
27+
import static org.junit.jupiter.api.Assertions.assertNotNull;
28+
import static org.junit.jupiter.api.Assertions.assertNull;
2729

2830
import com.google.common.io.Resources;
2931
import com.spotify.github.jackson.Json;
@@ -85,6 +87,36 @@ public void testSerializationMergeParams() throws IOException {
8587
assertThat(params.mergeMethod(), is(MergeMethod.merge));
8688
}
8789

90+
@Test
91+
public void testSerializationAutoMergeDisabled() throws IOException {
92+
String fixture =
93+
Resources.toString(getResource(this.getClass(), "pull_request_automerge_disabled.json"), defaultCharset());
94+
final PullRequest pr = Json.create().fromJson(fixture, PullRequest.class);
95+
96+
assertThat(pr.id(), is(2439836648L));
97+
assertThat(pr.head().sha(), is("881ef333d1ffc01869b666f13d3b37d7af92b9a2"));
98+
assertThat(pr.merged(), is(false));
99+
assertThat(pr.mergeable().get(), is(true));
100+
assertThat(pr.draft(), is(Optional.of(true)));
101+
assertNull(pr.autoMerge());
102+
}
103+
104+
@Test
105+
public void testSerializationAutoMergeEnabled() throws IOException {
106+
String fixture =
107+
Resources.toString(getResource(this.getClass(), "pull_request_automerge_enabled.json"), defaultCharset());
108+
final PullRequest pr = Json.create().fromJson(fixture, PullRequest.class);
109+
110+
assertThat(pr.id(), is(2439836648L));
111+
assertThat(pr.head().sha(), is("881ef333d1ffc01869b666f13d3b37d7af92b9a2"));
112+
assertThat(pr.merged(), is(false));
113+
assertThat(pr.mergeable().get(), is(true));
114+
assertThat(pr.draft(), is(Optional.of(false)));
115+
assertNotNull(pr.autoMerge());
116+
assertThat(pr.autoMerge().enabledBy().login(), is("octocat"));
117+
assertThat(pr.autoMerge().mergeMethod(), is("squash"));
118+
}
119+
88120
@Test
89121
public void testDeserializationMergeParamsOmitsFields() throws IOException {
90122
final MergeParameters params = ImmutableMergeParameters.builder()

0 commit comments

Comments
 (0)