Skip to content

Commit 78778a2

Browse files
1 parent 2e6dcc1 commit 78778a2

File tree

2 files changed

+101
-4
lines changed

2 files changed

+101
-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: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ public class GHBranchProtectionBuilder {
4343
includeAdmins(false);
4444
}
4545

46+
/**
47+
* Add required checks gh branch protection builder.
48+
*
49+
* @param checks
50+
* the checks
51+
* @return the gh branch protection builder
52+
*/
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+
4661
/**
4762
* Add required checks gh branch protection builder.
4863
*
@@ -51,7 +66,10 @@ public class GHBranchProtectionBuilder {
5166
* @return the gh branch protection builder
5267
*/
5368
public GHBranchProtectionBuilder addRequiredChecks(Collection<String> checks) {
54-
getStatusChecks().contexts.addAll(checks);
69+
if (!(getStatusChecks() instanceof StatusChecksDeprecated)) {
70+
statusChecks = new StatusChecksDeprecated();
71+
}
72+
((StatusChecksDeprecated) getStatusChecks()).contexts.addAll(checks);
5573
return this;
5674
}
5775

@@ -67,6 +85,18 @@ public GHBranchProtectionBuilder addRequiredChecks(String... checks) {
6785
return this;
6886
}
6987

88+
/**
89+
* Add required checks gh branch protection builder.
90+
*
91+
* @param checks
92+
* the checks
93+
* @return the gh branch protection builder
94+
*/
95+
public GHBranchProtectionBuilder addRequiredChecksWithAppIds(GHBranchProtection.Check... checks) {
96+
addRequiredChecksWithAppIds(Arrays.asList(checks));
97+
return this;
98+
}
99+
70100
/**
71101
* Allow deletion of the protected branch.
72102
*
@@ -532,7 +562,7 @@ private Restrictions getRestrictions() {
532562

533563
private StatusChecks getStatusChecks() {
534564
if (statusChecks == null) {
535-
statusChecks = new StatusChecks();
565+
statusChecks = new StatusChecksWithAppId();
536566
}
537567
return statusChecks;
538568
}
@@ -546,8 +576,15 @@ private static class Restrictions {
546576
private Set<String> users = new HashSet<String>();
547577
}
548578

549-
private static class StatusChecks {
550-
final List<String> contexts = new ArrayList<String>();
579+
private static abstract class StatusChecks {
551580
boolean strict;
552581
}
582+
583+
private static class StatusChecksWithAppId extends StatusChecks {
584+
final List<GHBranchProtection.Check> checks = new ArrayList<>();
585+
}
586+
587+
private static class StatusChecksDeprecated extends StatusChecks {
588+
final List<String> contexts = new ArrayList<>();
589+
}
553590
}

0 commit comments

Comments
 (0)