Skip to content

Commit 40b3783

Browse files
1 parent 2e6dcc1 commit 40b3783

File tree

2 files changed

+99
-4
lines changed

2 files changed

+99
-4
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,52 @@ 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+
* @param appId
245+
*/
246+
public Check(String context, Integer appId) {
247+
this.context = context;
248+
this.app_id = appId;
249+
}
250+
251+
/**
252+
* The context string of the check
253+
*
254+
* @return the string
255+
*/
256+
public String getContext() {
257+
return context;
258+
}
259+
260+
/**
261+
* The application ID the check is supposed to come from. The value "-1" indicates "any source".
262+
*
263+
* @return the integer
264+
*/
265+
public Integer getAppId() {
266+
return app_id;
267+
}
268+
}
269+
224270
/**
225271
* The type AllowForcePushes.
226272
*/
@@ -462,6 +508,9 @@ public static class RequiredStatusChecks {
462508
@JsonProperty
463509
private Collection<String> contexts;
464510

511+
@JsonProperty
512+
private Collection<Check> checks;
513+
465514
@JsonProperty
466515
private boolean strict;
467516

@@ -477,6 +526,15 @@ public Collection<String> getContexts() {
477526
return Collections.unmodifiableCollection(contexts);
478527
}
479528

529+
/**
530+
* Gets checks.
531+
*
532+
* @return the checks
533+
*/
534+
public Collection<Check> getChecks() {
535+
return Collections.unmodifiableCollection(checks);
536+
}
537+
480538
/**
481539
* Gets url.
482540
*

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)