Skip to content

Commit c8c7b30

Browse files
1 parent 2e6dcc1 commit c8c7b30

File tree

2 files changed

+103
-4
lines changed

2 files changed

+103
-4
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,54 @@ public boolean isEnabled() {
221221
}
222222
}
223223

224+
/**
225+
* The type Check.
226+
*/
227+
public static class Check {
228+
@JsonProperty
229+
private String context;
230+
231+
@JsonProperty
232+
private Integer app_id;
233+
234+
/**
235+
* no-arg constructor for the serializer
236+
*/
237+
public Check() {
238+
}
239+
240+
/**
241+
* Regular constructor for use in user business logic
242+
*
243+
* @param context
244+
* the context string of the check
245+
* @param appId
246+
* the application ID the check is supposed to come from
247+
*/
248+
public Check(String context, Integer appId) {
249+
this.context = context;
250+
this.app_id = appId;
251+
}
252+
253+
/**
254+
* The context string of the check
255+
*
256+
* @return the string
257+
*/
258+
public String getContext() {
259+
return context;
260+
}
261+
262+
/**
263+
* The application ID the check is supposed to come from. The value "-1" indicates "any source".
264+
*
265+
* @return the integer
266+
*/
267+
public Integer getAppId() {
268+
return app_id;
269+
}
270+
}
271+
224272
/**
225273
* The type AllowForcePushes.
226274
*/
@@ -462,6 +510,9 @@ public static class RequiredStatusChecks {
462510
@JsonProperty
463511
private Collection<String> contexts;
464512

513+
@JsonProperty
514+
private Collection<Check> checks;
515+
465516
@JsonProperty
466517
private boolean strict;
467518

@@ -477,6 +528,15 @@ public Collection<String> getContexts() {
477528
return Collections.unmodifiableCollection(contexts);
478529
}
479530

531+
/**
532+
* Gets checks.
533+
*
534+
* @return the checks
535+
*/
536+
public Collection<Check> getChecks() {
537+
return Collections.unmodifiableCollection(checks);
538+
}
539+
480540
/**
481541
* Gets url.
482542
*

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,27 @@ public class GHBranchProtectionBuilder {
5050
* the checks
5151
* @return the gh branch protection builder
5252
*/
53+
public GHBranchProtectionBuilder addRequiredChecksWithAppIds(Collection<GHBranchProtection.Check> checks) {
54+
if (!(getStatusChecks() instanceof StatusChecksWithAppId)) {
55+
statusChecks = new StatusChecksWithAppId();
56+
}
57+
((StatusChecksWithAppId) getStatusChecks()).checks.addAll(checks);
58+
return this;
59+
}
60+
61+
/**
62+
* Add required checks gh branch protection builder.
63+
*
64+
* @param checks
65+
* the checks
66+
* @return the gh branch protection builder
67+
*/
68+
@Deprecated
5369
public GHBranchProtectionBuilder addRequiredChecks(Collection<String> checks) {
54-
getStatusChecks().contexts.addAll(checks);
70+
if (!(getStatusChecks() instanceof StatusChecksDeprecated)) {
71+
statusChecks = new StatusChecksDeprecated();
72+
}
73+
((StatusChecksDeprecated) getStatusChecks()).contexts.addAll(checks);
5574
return this;
5675
}
5776

@@ -62,11 +81,24 @@ public GHBranchProtectionBuilder addRequiredChecks(Collection<String> checks) {
6281
* the checks
6382
* @return the gh branch protection builder
6483
*/
84+
@Deprecated
6585
public GHBranchProtectionBuilder addRequiredChecks(String... checks) {
6686
addRequiredChecks(Arrays.asList(checks));
6787
return this;
6888
}
6989

90+
/**
91+
* Add required checks gh branch protection builder.
92+
*
93+
* @param checks
94+
* the checks
95+
* @return the gh branch protection builder
96+
*/
97+
public GHBranchProtectionBuilder addRequiredChecksWithAppIds(GHBranchProtection.Check... checks) {
98+
addRequiredChecksWithAppIds(Arrays.asList(checks));
99+
return this;
100+
}
101+
70102
/**
71103
* Allow deletion of the protected branch.
72104
*
@@ -532,7 +564,7 @@ private Restrictions getRestrictions() {
532564

533565
private StatusChecks getStatusChecks() {
534566
if (statusChecks == null) {
535-
statusChecks = new StatusChecks();
567+
statusChecks = new StatusChecksWithAppId();
536568
}
537569
return statusChecks;
538570
}
@@ -546,8 +578,15 @@ private static class Restrictions {
546578
private Set<String> users = new HashSet<String>();
547579
}
548580

549-
private static class StatusChecks {
550-
final List<String> contexts = new ArrayList<String>();
581+
private static abstract class StatusChecks {
551582
boolean strict;
552583
}
584+
585+
private static class StatusChecksWithAppId extends StatusChecks {
586+
final List<GHBranchProtection.Check> checks = new ArrayList<>();
587+
}
588+
589+
private static class StatusChecksDeprecated extends StatusChecks {
590+
final List<String> contexts = new ArrayList<>();
591+
}
553592
}

0 commit comments

Comments
 (0)