Skip to content
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
3 changes: 2 additions & 1 deletion src/main/java/com/spotify/github/v3/repos/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ public interface Branch {
/** Branch protection API URL */
@JsonDeserialize(using = BranchProtectionUrlDeserializer.class)
Optional<URI> protectionUrl();
}

Optional<Protection> protection();
}
39 changes: 39 additions & 0 deletions src/main/java/com/spotify/github/v3/repos/Protection.java
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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<String> contexts() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/test/resources/com/spotify/github/v3/repos/branch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}