Skip to content

Commit b7d081e

Browse files
1 parent 2e6dcc1 commit b7d081e

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-4
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,33 @@ 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+
public Check() {
235+
}
236+
237+
public Check(String context, Integer appId) {
238+
this.context = context;
239+
this.app_id = appId;
240+
}
241+
242+
public String getContext() {
243+
return context;
244+
}
245+
246+
public Integer getAppId() {
247+
return app_id;
248+
}
249+
}
250+
224251
/**
225252
* The type AllowForcePushes.
226253
*/
@@ -462,6 +489,9 @@ public static class RequiredStatusChecks {
462489
@JsonProperty
463490
private Collection<String> contexts;
464491

492+
@JsonProperty
493+
private Collection<Check> checks;
494+
465495
@JsonProperty
466496
private boolean strict;
467497

@@ -477,6 +507,15 @@ public Collection<String> getContexts() {
477507
return Collections.unmodifiableCollection(contexts);
478508
}
479509

510+
/**
511+
* Gets checks.
512+
*
513+
* @return the checks
514+
*/
515+
public Collection<Check> getChecks() {
516+
return Collections.unmodifiableCollection(checks);
517+
}
518+
480519
/**
481520
* Gets url.
482521
*

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)