Skip to content

feat: Add auto_merge field to the PR class #226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/main/java/com/spotify/github/v3/prs/AutoMerge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*-
* -\-\-
* github-api
* --
* Copyright (C) 2016 - 2020 Spotify AB
* --
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* -/-/-
*/

package com.spotify.github.v3.prs;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.spotify.github.GithubStyle;
import com.spotify.github.v3.User;
import org.immutables.value.Value;

import javax.annotation.Nullable;

@Value.Immutable
@GithubStyle
@JsonSerialize(as = ImmutableAutoMerge.class)
@JsonDeserialize(as = ImmutableAutoMerge.class)
public interface AutoMerge {
// Who enabled the auto merge
User enabledBy();

// Merge Method chosen for the auto merge
String mergeMethod();

// The commit title to use when merging the pull request
@Nullable
String commitTitle();

// The commit message to use when merging the pull request
@Nullable
String commitMessage();
}
7 changes: 5 additions & 2 deletions src/main/java/com/spotify/github/v3/prs/PullRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -87,4 +87,7 @@ public interface PullRequest extends PullRequestItem {

@Nullable
List<Label> labels();

@Nullable
AutoMerge autoMerge();
}
32 changes: 32 additions & 0 deletions src/test/java/com/spotify/github/v3/prs/PullRequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import static java.nio.charset.Charset.defaultCharset;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

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

@Test
public void testSerializationAutoMergeDisabled() throws IOException {
String fixture =
Resources.toString(getResource(this.getClass(), "pull_request_automerge_disabled.json"), defaultCharset());
final PullRequest pr = Json.create().fromJson(fixture, PullRequest.class);

assertThat(pr.id(), is(2439836648L));
assertThat(pr.head().sha(), is("881ef333d1ffc01869b666f13d3b37d7af92b9a2"));
assertThat(pr.merged(), is(false));
assertThat(pr.mergeable().get(), is(true));
assertThat(pr.draft(), is(Optional.of(true)));
assertNull(pr.autoMerge());
}

@Test
public void testSerializationAutoMergeEnabled() throws IOException {
String fixture =
Resources.toString(getResource(this.getClass(), "pull_request_automerge_enabled.json"), defaultCharset());
final PullRequest pr = Json.create().fromJson(fixture, PullRequest.class);

assertThat(pr.id(), is(2439836648L));
assertThat(pr.head().sha(), is("881ef333d1ffc01869b666f13d3b37d7af92b9a2"));
assertThat(pr.merged(), is(false));
assertThat(pr.mergeable().get(), is(true));
assertThat(pr.draft(), is(Optional.of(false)));
assertNotNull(pr.autoMerge());
assertThat(pr.autoMerge().enabledBy().login(), is("octocat"));
assertThat(pr.autoMerge().mergeMethod(), is("squash"));
}

@Test
public void testDeserializationMergeParamsOmitsFields() throws IOException {
final MergeParameters params = ImmutableMergeParameters.builder()
Expand Down
Loading