Skip to content

Commit 47314dd

Browse files
fix: some post-review changes and test additions
1 parent 33e1ccb commit 47314dd

File tree

4 files changed

+123
-8
lines changed

4 files changed

+123
-8
lines changed

src/main/java/org/kohsuke/github/GHBranchProtection.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,8 @@ public boolean isEnabled() {
225225
* The type Check.
226226
*/
227227
public static class Check {
228-
@JsonProperty
229228
private String context;
230-
231-
@JsonProperty
232-
private Integer app_id;
229+
private Integer appId;
233230

234231
/**
235232
* no-arg constructor for the serializer
@@ -247,7 +244,7 @@ public Check() {
247244
*/
248245
public Check(String context, Integer appId) {
249246
this.context = context;
250-
this.app_id = appId;
247+
this.appId = appId;
251248
}
252249

253250
/**
@@ -265,7 +262,7 @@ public String getContext() {
265262
* @return the integer
266263
*/
267264
public Integer getAppId() {
268-
return app_id;
265+
return appId;
269266
}
270267
}
271268

src/test/java/org/kohsuke/github/GHBranchProtectionTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.kohsuke.github.GHBranchProtection.RequiredReviews;
1414
import org.kohsuke.github.GHBranchProtection.RequiredStatusChecks;
1515

16+
import java.util.ArrayList;
17+
1618
import static org.hamcrest.Matchers.*;
1719

1820
// TODO: Auto-generated Javadoc
@@ -198,10 +200,18 @@ public void testSignedCommits() throws Exception {
198200
@Test
199201
public void testChecksWithAppIds() throws Exception {
200202
GHBranchProtection protection = branch.enableProtection()
201-
.addRequiredChecksWithAppIds(new GHBranchProtection.Check("context", -1))
203+
.addRequiredChecksWithAppIds(new GHBranchProtection.Check("context", -1),
204+
new GHBranchProtection.Check("context2", 123))
202205
.enable();
203206

204-
assertThat(protection.getRequiredStatusChecks().getChecks().isEmpty(), is(false));
207+
ArrayList<GHBranchProtection.Check> resultChecks = new ArrayList<>(
208+
protection.getRequiredStatusChecks().getChecks());
209+
210+
assertThat(resultChecks.size(), is(2));
211+
assertThat(resultChecks.get(0).getContext(), is("context"));
212+
assertThat(resultChecks.get(0).getAppId(), nullValue());
213+
assertThat(resultChecks.get(1).getContext(), is("context2"));
214+
assertThat(resultChecks.get(1).getAppId(), is(123));
205215
}
206216

207217
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testChecksWithAppIds/branches/main/protection",
3+
"required_status_checks": {
4+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testChecksWithAppIds/branches/main/protection/required_status_checks",
5+
"strict": false,
6+
"contexts": [
7+
"context",
8+
"context2"
9+
],
10+
"contexts_url": "https://api.github.com/repos/hub4j-test-org/temp-testChecksWithAppIds/branches/main/protection/required_status_checks/contexts",
11+
"checks": [
12+
{
13+
"context": "context",
14+
"app_id": null
15+
},
16+
{
17+
"context": "context2",
18+
"app_id": 123
19+
}
20+
]
21+
},
22+
"required_signatures": {
23+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testChecksWithAppIds/branches/main/protection/required_signatures",
24+
"enabled": false
25+
},
26+
"enforce_admins": {
27+
"url": "https://api.github.com/repos/hub4j-test-org/temp-testChecksWithAppIds/branches/main/protection/enforce_admins",
28+
"enabled": false
29+
},
30+
"required_linear_history": {
31+
"enabled": false
32+
},
33+
"allow_force_pushes": {
34+
"enabled": false
35+
},
36+
"allow_deletions": {
37+
"enabled": false
38+
},
39+
"block_creations": {
40+
"enabled": false
41+
},
42+
"required_conversation_resolution": {
43+
"enabled": false
44+
},
45+
"lock_branch": {
46+
"enabled": false
47+
},
48+
"allow_fork_syncing": {
49+
"enabled": false
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"id": "630402b5-486c-41df-83e7-f9f1a715ea08",
3+
"name": "repos_hub4j-test-org_temp-testcheckswithappids_branches_main_protection",
4+
"request": {
5+
"url": "/repos/hub4j-test-org/temp-testChecksWithAppIds/branches/main/protection",
6+
"method": "PUT",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github.luke-cage-preview+json"
10+
}
11+
},
12+
"bodyPatterns": [
13+
{
14+
"equalToJson": "{\"required_pull_request_reviews\":null,\"required_status_checks\":{\"strict\":false,\"checks\":[{\"context\":\"context\",\"app_id\":-1},{\"context\":\"context2\",\"app_id\":123}]},\"restrictions\":null,\"enforce_admins\":false}",
15+
"ignoreArrayOrder": true,
16+
"ignoreExtraElements": false
17+
}
18+
]
19+
},
20+
"response": {
21+
"status": 200,
22+
"bodyFileName": "5-r_h_t_branches_main_protection.json",
23+
"headers": {
24+
"Server": "GitHub.com",
25+
"Date": "Thu, 06 Jun 2024 08:33:48 GMT",
26+
"Content-Type": "application/json; charset=utf-8",
27+
"Cache-Control": "private, max-age=60, s-maxage=60",
28+
"Vary": [
29+
"Accept, Authorization, Cookie, X-GitHub-OTP",
30+
"Accept-Encoding, Accept, X-Requested-With"
31+
],
32+
"ETag": "W/\"eae3686ecc99456a89d4b1209c91dc3fefb1139da4cf8a9afbbd5c46ca4bb44c\"",
33+
"X-OAuth-Scopes": "admin:enterprise, admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, admin:ssh_signing_key, audit_log, codespace, copilot, delete:packages, delete_repo, gist, notifications, project, repo, user, workflow, write:discussion, write:packages",
34+
"X-Accepted-OAuth-Scopes": "",
35+
"github-authentication-token-expiration": "2024-06-16 12:56:36 UTC",
36+
"X-GitHub-Media-Type": "github.v3; param=luke-cage-preview; format=json",
37+
"x-github-api-version-selected": "2022-11-28",
38+
"X-RateLimit-Limit": "5000",
39+
"X-RateLimit-Remaining": "4995",
40+
"X-RateLimit-Reset": "1717666423",
41+
"X-RateLimit-Used": "5",
42+
"X-RateLimit-Resource": "core",
43+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
44+
"Access-Control-Allow-Origin": "*",
45+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
46+
"X-Frame-Options": "deny",
47+
"X-Content-Type-Options": "nosniff",
48+
"X-XSS-Protection": "0",
49+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
50+
"Content-Security-Policy": "default-src 'none'",
51+
"X-GitHub-Request-Id": "B950:2575A0:9D3C7A6:9E339B3:6661746C"
52+
}
53+
},
54+
"uuid": "630402b5-486c-41df-83e7-f9f1a715ea08",
55+
"persistent": true,
56+
"insertionIndex": 5
57+
}

0 commit comments

Comments
 (0)