Skip to content

Commit af2aa11

Browse files
authored
Add protection field to branch model. (#102)
Co-authored-by: Martin Kero <[email protected]>
1 parent 393d3d0 commit af2aa11

File tree

5 files changed

+102
-1
lines changed

5 files changed

+102
-1
lines changed

src/main/java/com/spotify/github/v3/repos/Branch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,6 @@ public interface Branch {
5252
/** Branch protection API URL */
5353
@JsonDeserialize(using = BranchProtectionUrlDeserializer.class)
5454
Optional<URI> protectionUrl();
55-
}
5655

56+
Optional<Protection> protection();
57+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.repos;
22+
23+
import com.fasterxml.jackson.annotation.JsonProperty;
24+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
25+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
26+
import com.spotify.github.GithubStyle;
27+
import org.immutables.value.Value;
28+
29+
/** Branch resource */
30+
@Value.Immutable
31+
@GithubStyle
32+
@JsonSerialize(as = ImmutableProtection.class)
33+
@JsonDeserialize(as = ImmutableProtection.class)
34+
public interface Protection {
35+
boolean enabled();
36+
37+
@JsonProperty("required_status_checks")
38+
RequiredStatusChecks requiredStatusChecks();
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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.repos;
22+
23+
import com.fasterxml.jackson.annotation.JsonProperty;
24+
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
25+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
26+
import com.spotify.github.GithubStyle;
27+
import java.util.Collections;
28+
import java.util.List;
29+
import org.immutables.value.Value;
30+
import org.immutables.value.Value.Default;
31+
32+
/** Branch resource */
33+
@Value.Immutable
34+
@GithubStyle
35+
@JsonSerialize(as = ImmutableRequiredStatusChecks.class)
36+
@JsonDeserialize(as = ImmutableRequiredStatusChecks.class)
37+
public interface RequiredStatusChecks {
38+
@JsonProperty("enforcement_level")
39+
String enforcementLevel();
40+
41+
@Default
42+
default List<String> contexts() {
43+
return Collections.emptyList();
44+
}
45+
}

src/test/java/com/spotify/github/v3/clients/RepositoryClientTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import static org.junit.Assert.assertFalse;
4040
import static org.junit.Assert.assertTrue;
4141
import static org.mockito.ArgumentMatchers.any;
42+
import static org.mockito.ArgumentMatchers.contains;
4243
import static org.mockito.ArgumentMatchers.eq;
4344
import static org.mockito.Mockito.mock;
4445
import static org.mockito.Mockito.when;
@@ -303,6 +304,11 @@ public void getBranch() throws Exception {
303304
assertThat(
304305
branch.commit().url().toString(),
305306
is("https://api.github.com/repos/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc"));
307+
assertTrue(branch.protection().isPresent());
308+
assertTrue(branch.protection().get().enabled());
309+
assertThat(branch.protection().get().requiredStatusChecks().enforcementLevel(), is("non_admins"));
310+
assertTrue(branch.protection().get().requiredStatusChecks().contexts().contains("Context 1"));
311+
assertTrue(branch.protection().get().requiredStatusChecks().contexts().contains("Context 2"));
306312
}
307313

308314
@Test

src/test/resources/com/spotify/github/v3/repos/branch.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,15 @@
55
"url": "https://api.github.com/repos/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc"
66
},
77
"protected": true,
8+
"protection": {
9+
"enabled": true,
10+
"required_status_checks": {
11+
"enforcement_level": "non_admins",
12+
"contexts": [
13+
"Context 1",
14+
"Context 2"
15+
]
16+
}
17+
},
818
"protection_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection"
919
}

0 commit comments

Comments
 (0)