Skip to content

Commit

Permalink
Restored signature of the previous enableProtection() method
Browse files Browse the repository at this point in the history
  • Loading branch information
kohsuke committed Sep 8, 2017
1 parent 46b89a4 commit 2f8c399
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/kohsuke/github/EnforcementLevel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import java.util.Locale;

/**
* This was added during preview API period but it has changed since then.
*
* @author Kohsuke Kawaguchi
*/
@Deprecated
public enum EnforcementLevel {
OFF, NON_ADMINS, EVERYONE;

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/kohsuke/github/GHBranch.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.IOException;
import java.net.URL;
import java.util.Collection;

import com.fasterxml.jackson.annotation.JsonProperty;

Expand Down Expand Up @@ -95,6 +96,23 @@ public GHBranchProtectionBuilder enableProtection() {
return new GHBranchProtectionBuilder(this);
}

// backward compatibility with previous signature
@Deprecated
public void enableProtection(EnforcementLevel level, Collection<String> contexts) throws IOException {
switch (level) {
case OFF:
disableProtection();
break;
case NON_ADMINS:
case EVERYONE:
enableProtection()
.addRequiredChecks(contexts)
.includeAdmins(level==EnforcementLevel.EVERYONE)
.enable();
break;
}
}

String getApiRoute() {
return owner.getApiTailUrl("/branches/"+name);
}
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/org/kohsuke/github/GHBranchProtectionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
* Builder to configure the branch protection settings.
*
* @see GHBranch#enableProtection()
*/
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD",
"URF_UNREAD_FIELD" }, justification = "JSON API")
public class GHBranchProtectionBuilder {
Expand Down Expand Up @@ -53,17 +58,29 @@ public GHBranchProtection enable() throws IOException {
}

public GHBranchProtectionBuilder includeAdmins() {
enforceAdmins = true;
return includeAdmins(true);
}

public GHBranchProtectionBuilder includeAdmins(boolean v) {
enforceAdmins = v;
return this;
}

public GHBranchProtectionBuilder requireBranchIsUpToDate() {
getStatusChecks().strict = true;
return requireBranchIsUpToDate(true);
}

public GHBranchProtectionBuilder requireBranchIsUpToDate(boolean v) {
getStatusChecks().strict = v;
return this;
}

public GHBranchProtectionBuilder requireCodeOwnReviews() {
getPrReviews().put("require_code_owner_reviews", true);
return requireCodeOwnReviews(true);
}

public GHBranchProtectionBuilder requireCodeOwnReviews(boolean v) {
getPrReviews().put("require_code_owner_reviews", v);
return this;
}

Expand Down

0 comments on commit 2f8c399

Please sign in to comment.