diff --git a/src/main/java/com/spotify/github/v3/repos/Branch.java b/src/main/java/com/spotify/github/v3/repos/Branch.java index 28701592..a0ce99a8 100644 --- a/src/main/java/com/spotify/github/v3/repos/Branch.java +++ b/src/main/java/com/spotify/github/v3/repos/Branch.java @@ -52,5 +52,6 @@ public interface Branch { /** Branch protection API URL */ @JsonDeserialize(using = BranchProtectionUrlDeserializer.class) Optional protectionUrl(); -} + Optional protection(); +} diff --git a/src/main/java/com/spotify/github/v3/repos/Protection.java b/src/main/java/com/spotify/github/v3/repos/Protection.java new file mode 100644 index 00000000..f4d6286e --- /dev/null +++ b/src/main/java/com/spotify/github/v3/repos/Protection.java @@ -0,0 +1,39 @@ +/*- + * -\-\- + * 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.repos; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.spotify.github.GithubStyle; +import org.immutables.value.Value; + +/** Branch resource */ +@Value.Immutable +@GithubStyle +@JsonSerialize(as = ImmutableProtection.class) +@JsonDeserialize(as = ImmutableProtection.class) +public interface Protection { + boolean enabled(); + + @JsonProperty("required_status_checks") + RequiredStatusChecks requiredStatusChecks(); +} diff --git a/src/main/java/com/spotify/github/v3/repos/RequiredStatusChecks.java b/src/main/java/com/spotify/github/v3/repos/RequiredStatusChecks.java new file mode 100644 index 00000000..3bbdd9b7 --- /dev/null +++ b/src/main/java/com/spotify/github/v3/repos/RequiredStatusChecks.java @@ -0,0 +1,45 @@ +/*- + * -\-\- + * 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.repos; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.spotify.github.GithubStyle; +import java.util.Collections; +import java.util.List; +import org.immutables.value.Value; +import org.immutables.value.Value.Default; + +/** Branch resource */ +@Value.Immutable +@GithubStyle +@JsonSerialize(as = ImmutableRequiredStatusChecks.class) +@JsonDeserialize(as = ImmutableRequiredStatusChecks.class) +public interface RequiredStatusChecks { + @JsonProperty("enforcement_level") + String enforcementLevel(); + + @Default + default List contexts() { + return Collections.emptyList(); + } +} diff --git a/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java b/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java index 6935fc86..7dac5700 100644 --- a/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java +++ b/src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java @@ -39,6 +39,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.contains; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -303,6 +304,11 @@ public void getBranch() throws Exception { assertThat( branch.commit().url().toString(), is("https://api.github.com/repos/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc")); + assertTrue(branch.protection().isPresent()); + assertTrue(branch.protection().get().enabled()); + assertThat(branch.protection().get().requiredStatusChecks().enforcementLevel(), is("non_admins")); + assertTrue(branch.protection().get().requiredStatusChecks().contexts().contains("Context 1")); + assertTrue(branch.protection().get().requiredStatusChecks().contexts().contains("Context 2")); } @Test diff --git a/src/test/resources/com/spotify/github/v3/repos/branch.json b/src/test/resources/com/spotify/github/v3/repos/branch.json index fdf8a19b..7725d38c 100644 --- a/src/test/resources/com/spotify/github/v3/repos/branch.json +++ b/src/test/resources/com/spotify/github/v3/repos/branch.json @@ -5,5 +5,15 @@ "url": "https://api.github.com/repos/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc" }, "protected": true, + "protection": { + "enabled": true, + "required_status_checks": { + "enforcement_level": "non_admins", + "contexts": [ + "Context 1", + "Context 2" + ] + } + }, "protection_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection" }