The Unified and Autonomous Development Platform
Refactor gate keeper.
robin shine0499ef614fe8
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/extensionpoint/ConfigChangeListener.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/extensionpoint/ConfigChangeListener.javaindex 2004d6a2c7..4f6d801b2d 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/extensionpoint/ConfigChangeListener.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/extensionpoint/ConfigChangeListener.java@@ -1,6 +1,8 @@package com.pmease.gitplex.core.extensionpoint;+import com.pmease.commons.loader.ExtensionPoint;+@ExtensionPointpublic interface ConfigChangeListener {void systemSettingChanged();diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.javaindex 5ac9060b49..6930d999c7 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AbstractGateKeeper.java@@ -6,12 +6,12 @@ import javax.annotation.Nullable;import com.google.common.base.Preconditions;import com.pmease.commons.editable.annotation.Editable;-import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;+import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;import com.pmease.gitplex.core.gatekeeper.checkresult.Ignored;+import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;-import com.pmease.gitplex.core.gatekeeper.checkresult.PendingAndBlock;import com.pmease.gitplex.core.model.Branch;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;@@ -47,13 +47,6 @@ public abstract class AbstractGateKeeper implements GateKeeper {return ignored();}- public CheckResult checkBranch(User user, Branch branch) {- if (isEnabled())- return doCheckFile(user, branch, null);- else- return ignored();- }-@Overridepublic CheckResult checkCommit(User user, Branch branch, String commit) {if (isEnabled())@@ -89,11 +82,11 @@ public abstract class AbstractGateKeeper implements GateKeeper {* @param branch* branch to be checked* @param file- * file to be checked, pass <tt>null</tt> to check for any file+ * file to be checked* @return* result of the check*/- protected abstract CheckResult doCheckFile(User user, Branch branch, @Nullable String file);+ protected abstract CheckResult doCheckFile(User user, Branch branch, String file);/*** Check if specified user can push specified commit to specified branch, without considering enable flag.@@ -134,22 +127,6 @@ public abstract class AbstractGateKeeper implements GateKeeper {return this;}- protected CheckResult passed(String reason) {- return new Passed(reason);- }-- protected CheckResult failed(String reason) {- return new Failed(reason);- }-- protected CheckResult pending(String reason) {- return new Pending(reason);- }-- protected CheckResult pendingAndBlock(String reason) {- return new PendingAndBlock(reason);- }-protected CheckResult ignored() {return new Ignored();}@@ -166,8 +143,8 @@ public abstract class AbstractGateKeeper implements GateKeeper {return new Pending(reasons);}- protected CheckResult pendingAndBlock(List<String> reasons) {- return new PendingAndBlock(reasons);+ protected CheckResult blocking(List<String> reasons) {+ return new Blocking(reasons);}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndGateKeeper.javaindex 253488ca4f..6bd1b279b5 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/AndGateKeeper.java@@ -9,10 +9,11 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;-import com.pmease.gitplex.core.gatekeeper.checkresult.PendingAndBlock;+import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;@SuppressWarnings("serial")-@Editable(name="If All Contained Gate Keepers Are Passed", icon="pa-servers", order=100,+@Editable(name="And Composition", icon="pa-servers", order=100,+ category=GateKeeper.CATEGROY_COMPOSITION,description="This gate keeper will be passed if all contained gate keepers are passed.")@Horizontalpublic class AndGateKeeper extends AndOrGateKeeper {@@ -28,7 +29,7 @@ public class AndGateKeeper extends AndOrGateKeeper {acceptReasons.addAll(result.getReasons());} else if (result instanceof Failed) {return result;- } else if (result instanceof PendingAndBlock) {+ } else if (result instanceof Blocking) {result.getReasons().addAll(pendingReasons);return result;} else if (result instanceof Pending) {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/ApprovalGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/ApprovalGateKeeper.javadeleted file mode 100644index fa78f3edad..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/ApprovalGateKeeper.java+++ /dev/null@@ -1,9 +0,0 @@-package com.pmease.gitplex.core.gatekeeper;--import com.pmease.commons.editable.annotation.Editable;--@SuppressWarnings("serial")-@Editable(name="Approval Related Gate Keepers")-public abstract class ApprovalGateKeeper extends AbstractGateKeeper {--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchGateKeeper.javadeleted file mode 100644index 91bbeae530..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchGateKeeper.java+++ /dev/null@@ -1,9 +0,0 @@-package com.pmease.gitplex.core.gatekeeper;--import com.pmease.commons.editable.annotation.Editable;--@SuppressWarnings("serial")-@Editable(name="Branch Related Gate Keepers")-public abstract class BranchGateKeeper extends AbstractGateKeeper {--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.javaindex 3fb1f99c21..63cccbebd8 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BranchProtection.java@@ -21,10 +21,11 @@ import com.pmease.gitplex.core.model.Team;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=100, icon="pa-lock", description="By default, users with write permission of "- + "the repository can push code to all branches. Use this gate keeper to restrict write "- + "access of specified branches to specified teams.")-public class BranchProtection extends CommonGateKeeper {+@Editable(order=100, icon="pa-lock", category=GateKeeper.CATEGORY_COMMONLY_USED,+ description="By default, users with write permission of the repository can push "+ + "code to all branches. Use this gate keeper to restrict write access of "+ + "specified branches to specified teams.")+public class BranchProtection extends AbstractGateKeeper {private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByIds();diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.javaindex f7a4fb61e6..e05429d664 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/BuildVerificationOfBranch.java@@ -13,10 +13,11 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;-@Editable(icon="pa-lock", order=300, description="This gate keeper can be used to configure certain branches "- + "to only accept commits passing specified build criteria.")+@Editable(icon="pa-lock", order=300, category=GateKeeper.CATEGORY_COMMONLY_USED,+ description="This gate keeper can be used to configure certain branches to "+ + "only accept commits passing specified build criteria.")@SuppressWarnings("serial")-public class BuildVerificationOfBranch extends CommonGateKeeper {+public class BuildVerificationOfBranch extends AbstractGateKeeper {private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByIds();diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CommonGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CommonGateKeeper.javadeleted file mode 100644index 84269d0c65..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CommonGateKeeper.java+++ /dev/null@@ -1,9 +0,0 @@-package com.pmease.gitplex.core.gatekeeper;--import com.pmease.commons.editable.annotation.Editable;--@SuppressWarnings("serial")-@Editable(name="Commonly Used Gate Keepers")-public abstract class CommonGateKeeper extends AbstractGateKeeper {--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.javaindex 614f6c9c57..863c621cd2 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/CompositeGateKeeper.java@@ -1,14 +1,12 @@package com.pmease.gitplex.core.gatekeeper;-import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;-import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.PullRequest;+import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(name="Composite Gate Keepers")public abstract class CompositeGateKeeper extends AbstractGateKeeper {public static interface Checker {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.javaindex 0a901bef85..5ce34bcd04 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/DirectoryAndFileProtection.java@@ -23,11 +23,12 @@ import com.pmease.gitplex.core.model.Team;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=200, icon="pa-lock", description="By default, users with write permission of "- + "the repository can write to all directories/files. Use this gate keeper to restrict write "- + "access of certain directories/files of specified branches to certain teams. Note that if "- + "branch is not specified, the restriction will apply to all branches.")-public class DirectoryAndFileProtection extends CommonGateKeeper {+@Editable(order=200, icon="pa-lock", category=GateKeeper.CATEGORY_COMMONLY_USED,+ description="By default, users with write permission of the repository can write to "+ + "all directories/files. Use this gate keeper to restrict write access of "+ + "certain directories/files of specified branches to certain teams. Note "+ + "that if branch is not specified, the restriction will apply to all branches.")+public class DirectoryAndFileProtection extends AbstractGateKeeper {private TargetBranchSelection branchSelection;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/FileGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/FileGateKeeper.javadeleted file mode 100644index 7cc54a6d0c..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/FileGateKeeper.java+++ /dev/null@@ -1,9 +0,0 @@-package com.pmease.gitplex.core.gatekeeper;--import com.pmease.commons.editable.annotation.Editable;--@SuppressWarnings("serial")-@Editable(name="File Related Gate Keepers")-public abstract class FileGateKeeper extends AbstractGateKeeper {--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.javaindex 7565d65453..4998827406 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/GateKeeper.java@@ -13,6 +13,20 @@ import com.pmease.gitplex.core.model.Repository;@Editable(name="Misc")public interface GateKeeper extends Trimmable, Serializable {+ String CATEGORY_COMMONLY_USED = "Commonly Used";++ String CATEGROY_CHECK_BRANCH = "Check Destination Branch";++ String CATEGROY_CHECK_FILES = "Check Touched Files";++ String CATEGROY_CHECK_REVIEW = "Check Reviews";++ String CATEGROY_CHECK_SUBMITTER = "Check Submitter";++ String CATEGROY_COMPOSITION = "Gate Keeper Composition";++ String CATEGROY_OTHERS = "Misc Gate Keepers";+/*** Check the gate keeper against specified request. This is typically used to determine* whether or not to accept a pull request.@@ -32,24 +46,12 @@ public interface GateKeeper extends Trimmable, Serializable {* @param branch* branch to be checked* @param file- * file to be checked+ * file to be checked, pass <tt>null</tt> to check any file* @return* result of the check.*/CheckResult checkFile(User user, Branch branch, String file);- /**- * Check if specified user can modify/delete specified branch.- *- * @param user- * user to be checked- * @param branch- * branch to be checked- * @return- * result of the check.- */- CheckResult checkBranch(User user, Branch branch);-/*** Check if specified user can push specified commit to specified branch.*diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.javaindex fea5ed1bf5..9e7d949370 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/HistoryProtection.java@@ -13,9 +13,9 @@ import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=400, icon="pa-lock", description=+@Editable(order=400, icon="pa-lock", category=GateKeeper.CATEGORY_COMMONLY_USED, description="Use this gate keeper to prevent history of certain branches from being rewritten via forced push.")-public class HistoryProtection extends CommonGateKeeper {+public class HistoryProtection extends AbstractGateKeeper {private TargetBranchSelection branchSelection = new SpecifyTargetBranchesByIds();diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.javaindex 3dc0d63413..42a94ac6fc 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByMajoritiesOfSpecifiedTeam.java@@ -1,5 +1,6 @@package com.pmease.gitplex.core.gatekeeper;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@@ -10,7 +11,7 @@ import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=400, icon="pa-group-o", description=+@Editable(order=400, icon="pa-group-o", category=GateKeeper.CATEGROY_CHECK_REVIEW, description="This gate keeper will be passed if the commit is approved by majorities of specified team.")public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {@@ -19,9 +20,9 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {CheckResult result = getGateKeeper().checkRequest(request);if (result instanceof Passed)- result = passed("Approved by majorities of team '" + getTeam().getName() + "'.");+ result = passed(Lists.newArrayList("Approved by majorities of team '" + getTeam().getName() + "'."));else if (result instanceof Failed)- result = failed("Not approved by majorities of team '" + getTeam().getName() + "'.");+ result = failed(Lists.newArrayList("Not approved by majorities of team '" + getTeam().getName() + "'."));return result;}@@ -39,9 +40,9 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {CheckResult result = getGateKeeper().checkFile(user, branch, file);if (result instanceof Passed)- result = passed("Approved by majorities of team '" + getTeam().getName() + "'.");+ result = passed(Lists.newArrayList("Approved by majorities of team '" + getTeam().getName() + "'."));else if (result instanceof Failed)- result = failed("Not approved by majorities of team '" + getTeam().getName() + "'.");+ result = failed(Lists.newArrayList("Not approved by majorities of team '" + getTeam().getName() + "'."));return result;}@@ -51,9 +52,9 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {CheckResult result = getGateKeeper().checkCommit(user, branch, commit);if (result instanceof Passed)- result = passed("Approved by majorities of team '" + getTeam().getName() + "'.");+ result = passed(Lists.newArrayList("Approved by majorities of team '" + getTeam().getName() + "'."));else if (result instanceof Failed)- result = failed("Not approved by majorities of team '" + getTeam().getName() + "'.");+ result = failed(Lists.newArrayList("Not approved by majorities of team '" + getTeam().getName() + "'."));return result;}@@ -63,9 +64,9 @@ public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {CheckResult result = getGateKeeper().checkRef(user, repository, refName);if (result instanceof Passed)- result = passed("Approved by majorities of team '" + getTeam().getName() + "'.");+ result = passed(Lists.newArrayList("Approved by majorities of team '" + getTeam().getName() + "'."));else if (result instanceof Failed)- result = failed("Not approved by majorities of team '" + getTeam().getName() + "'.");+ result = failed(Lists.newArrayList("Not approved by majorities of team '" + getTeam().getName() + "'."));return result;}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.javaindex f6545756fc..5b16560f5f 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryOwner.java@@ -1,5 +1,6 @@package com.pmease.gitplex.core.gatekeeper;+import com.google.common.collect.Lists;import com.google.common.collect.Sets;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@@ -10,9 +11,9 @@ import com.pmease.gitplex.core.model.Review;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=300, icon="pa-user-o", description=+@Editable(order=300, icon="pa-user-o", category=GateKeeper.CATEGROY_CHECK_REVIEW, description="This gate keeper will be passed if the commit is approved by owner of the repository.")-public class IfApprovedByRepositoryOwner extends ApprovalGateKeeper {+public class IfApprovedByRepositoryOwner extends AbstractGateKeeper {@Overridepublic CheckResult doCheckRequest(PullRequest request) {@@ -22,19 +23,19 @@ public class IfApprovedByRepositoryOwner extends ApprovalGateKeeper {if (result == null) {request.pickReviewers(Sets.newHashSet(repoOwner), 1);- return pending("To be approved by " + repoOwner.getName() + ".");+ return pending(Lists.newArrayList("To be approved by " + repoOwner.getName() + "."));} else if (result == Review.Result.APPROVE) {- return passed("Approved by " + repoOwner.getName() + ".");+ return passed(Lists.newArrayList("Approved by " + repoOwner.getName() + "."));} else {- return failed("Rejected by " + repoOwner.getName() + ".");+ return failed(Lists.newArrayList("Rejected by " + repoOwner.getName() + "."));}}private CheckResult check(User user, Repository repository) {if (user.equals(repository.getOwner()))- return passed("Approved by repository owner.");+ return passed(Lists.newArrayList("Approved by repository owner."));else- return pending("Not approved by repository owner.");+ return pending(Lists.newArrayList("Not approved by repository owner."));}@Override@@ -50,9 +51,9 @@ public class IfApprovedByRepositoryOwner extends ApprovalGateKeeper {@Overrideprotected CheckResult doCheckRef(User user, Repository repository, String refName) {if (user.equals(repository.getOwner()))- return passed("Approved by repository owner.");+ return passed(Lists.newArrayList("Approved by repository owner."));else- return failed("Not approved by repository owner.");+ return failed(Lists.newArrayList("Not approved by repository owner."));}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.javaindex c1b246f9fc..53fc7ca6c3 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedByRepositoryWriters.java@@ -4,6 +4,7 @@ import java.util.Collection;import javax.validation.constraints.Min;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@@ -16,10 +17,10 @@ import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.permission.operation.GeneralOperation;@SuppressWarnings("serial")-@Editable(order=50, icon="pa-group-o", description=+@Editable(order=50, icon="pa-group-o", category=GateKeeper.CATEGROY_CHECK_REVIEW, description="This gate keeper will be passed if the commit is approved by specified number of users with "+ "writing permission.")-public class IfApprovedByRepositoryWriters extends ApprovalGateKeeper {+public class IfApprovedByRepositoryWriters extends AbstractGateKeeper {private int leastApprovals = 1;@@ -51,16 +52,16 @@ public class IfApprovedByRepositoryWriters extends ApprovalGateKeeper {}if (approvals >= getLeastApprovals()) {- return passed("Get at least " + getLeastApprovals() + " approvals from authorized users.");+ return passed(Lists.newArrayList("Get at least " + getLeastApprovals() + " approvals from authorized users."));} else if (getLeastApprovals() - approvals > pendings) {- return failed("Can not get at least " + getLeastApprovals()- + " approvals from authorized users.");+ return failed(Lists.newArrayList("Can not get at least " + getLeastApprovals()+ + " approvals from authorized users."));} else {int lackApprovals = getLeastApprovals() - approvals;request.pickReviewers(authorizedUsers, lackApprovals);- return pending("To be approved by " + lackApprovals + " authorized user(s).");+ return pending(Lists.newArrayList("To be approved by " + lackApprovals + " authorized user(s)."));}}@@ -79,12 +80,12 @@ public class IfApprovedByRepositoryWriters extends ApprovalGateKeeper {}if (approvals >= leastApprovals) {- return passed("Get at least " + leastApprovals + " approvals from authorized users.");+ return passed(Lists.newArrayList("Get at least " + leastApprovals + " approvals from authorized users."));} else if (leastApprovals - approvals > pendings) {- return failed("Can not get at least " + leastApprovals + " approvals from authorized users.");+ return failed(Lists.newArrayList("Can not get at least " + leastApprovals + " approvals from authorized users."));} else {int lackApprovals = getLeastApprovals() - approvals;- return pending("Lack " + lackApprovals + " approvals from authorized users.");+ return pending(Lists.newArrayList("Lack " + lackApprovals + " approvals from authorized users."));}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.javaindex 12691f9a24..eb6c0a05e3 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedTeam.java@@ -5,6 +5,7 @@ import java.util.HashSet;import javax.validation.constraints.Min;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;@@ -15,7 +16,7 @@ import com.pmease.gitplex.core.model.Review;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=100, icon="pa-group-o", description=+@Editable(order=100, icon="pa-group-o", category=GateKeeper.CATEGROY_CHECK_REVIEW, description="This gate keeper will be passed if the commit is approved by specified number of users "+ "from specified team.")public class IfApprovedBySpecifiedTeam extends TeamAwareGateKeeper {@@ -50,18 +51,18 @@ public class IfApprovedBySpecifiedTeam extends TeamAwareGateKeeper {}if (approvals >= getLeastApprovals()) {- return passed("Already get at least " + getLeastApprovals() + " approvals from team '"- + getTeam().getName() + "'.");+ return passed(Lists.newArrayList("Already get at least " + getLeastApprovals() + " approvals from team '"+ + getTeam().getName() + "'."));} else if (getLeastApprovals() - approvals > pendings) {- return failed("Unable to get at least " + getLeastApprovals()- + " approvals from team '" + getTeam().getName() + "'.");+ return failed(Lists.newArrayList("Unable to get at least " + getLeastApprovals()+ + " approvals from team '" + getTeam().getName() + "'."));} else {int lackApprovals = getLeastApprovals() - approvals;request.pickReviewers(members, lackApprovals);- return pending("To be approved by " + lackApprovals + " user(s) from team '"- + getTeam().getName() + "'.");+ return pending(Lists.newArrayList("To be approved by " + lackApprovals + " user(s) from team '"+ + getTeam().getName() + "'."));}}@@ -79,16 +80,16 @@ public class IfApprovedBySpecifiedTeam extends TeamAwareGateKeeper {}if (approvals >= getLeastApprovals()) {- return passed("Get at least " + leastApprovals + " approvals from team '"- + getTeam().getName() + "'.");+ return passed(Lists.newArrayList("Get at least " + leastApprovals + " approvals from team '"+ + getTeam().getName() + "'."));} else if (getLeastApprovals() - approvals > pendings) {- return failed("Can not get at least " + leastApprovals- + " approvals from team '" + getTeam().getName() + "'.");+ return failed(Lists.newArrayList("Can not get at least " + leastApprovals+ + " approvals from team '" + getTeam().getName() + "'."));} else {int lackApprovals = getLeastApprovals() - approvals;- return pending("Lack " + lackApprovals + " approvals from team '"- + getTeam().getName() + "'.");+ return pending(Lists.newArrayList("Lack " + lackApprovals + " approvals from team '"+ + getTeam().getName() + "'."));}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.javaindex 159cdfc50d..e86cf6b5af 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfApprovedBySpecifiedUser.java@@ -2,6 +2,7 @@ package com.pmease.gitplex.core.gatekeeper;import javax.validation.constraints.NotNull;+import com.google.common.collect.Lists;import com.google.common.collect.Sets;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.hibernate.dao.Dao;@@ -15,9 +16,9 @@ import com.pmease.gitplex.core.model.Review;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=200, icon="pa-user-o", description=+@Editable(order=200, icon="pa-user-o", category=GateKeeper.CATEGROY_CHECK_REVIEW, description="This gate keeper will be passed if the commit is approved by specified user.")-public class IfApprovedBySpecifiedUser extends ApprovalGateKeeper {+public class IfApprovedBySpecifiedUser extends AbstractGateKeeper {private Long userId;@@ -40,11 +41,11 @@ public class IfApprovedBySpecifiedUser extends ApprovalGateKeeper {if (result == null) {request.pickReviewers(Sets.newHashSet(user), 1);- return pending("To be approved by " + user.getDisplayName() + ".");+ return pending(Lists.newArrayList("To be approved by " + user.getDisplayName() + "."));} else if (result == Review.Result.APPROVE) {- return passed("Approved by " + user.getDisplayName() + ".");+ return passed(Lists.newArrayList("Approved by " + user.getDisplayName() + "."));} else {- return failed("Rejected by " + user.getDisplayName() + ".");+ return failed(Lists.newArrayList("Rejected by " + user.getDisplayName() + "."));}}@@ -59,9 +60,9 @@ public class IfApprovedBySpecifiedUser extends ApprovalGateKeeper {private CheckResult check(User user) {User approver = GitPlex.getInstance(Dao.class).load(User.class, userId);if (approver.getId().equals(user.getId())) {- return passed("Approved by " + approver.getName() + ".");+ return passed(Lists.newArrayList("Approved by " + approver.getName() + "."));} else {- return pending("Not approved by " + approver.getName() + ".");+ return pending(Lists.newArrayList("Not approved by " + approver.getName() + "."));}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfCreateSpecifiedBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfCreateSpecifiedBranches.javadeleted file mode 100644index a43cbcb07d..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfCreateSpecifiedBranches.java+++ /dev/null@@ -1,65 +0,0 @@-package com.pmease.gitplex.core.gatekeeper;--import org.hibernate.validator.constraints.NotEmpty;--import com.pmease.commons.editable.annotation.Editable;-import com.pmease.commons.git.Git;-import com.pmease.commons.util.pattern.WildcardUtils;-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;-import com.pmease.gitplex.core.model.Branch;-import com.pmease.gitplex.core.model.Repository;-import com.pmease.gitplex.core.model.PullRequest;-import com.pmease.gitplex.core.model.User;--@Editable(order=210, icon="pa-branch-pattern", description=- "This gate keeper will be passed if the branch to be created matches specified patterns.")-@SuppressWarnings("serial")-public class IfCreateSpecifiedBranches extends BranchGateKeeper {-- private String branchPatterns;-- @Editable(name="Specify Branch Patterns", description="Specify branch patterns to match. Below is some examples:"- + "<ul>"- + "<li><i>dev/*</i>: matches all branches directly under dev."- + "<li><i>dev/**</i>: matches all branches under dev recursively."- + "<li><i>**</i>: matches all branches."- + "<li><i>**/bugfix</i>: matches all branches whose last segment is bugfix."- + "<li><i>-dev/**, **</i>: matches all branches except those under dev."- + "</ul>")- @NotEmpty- public String getBranchPatterns() {- return branchPatterns;- }-- public void setBranchPatterns(String branchPatterns) {- this.branchPatterns = branchPatterns;- }-- @Override- protected CheckResult doCheckRequest(PullRequest request) {- return ignored();- }-- @Override- protected CheckResult doCheckFile(User user, Branch branch, String file) {- return ignored();- }-- @Override- protected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return ignored();- }-- @Override- protected CheckResult doCheckRef(User user, Repository repository, String refName) {- if (refName.startsWith(Git.REFS_HEADS)) {- if (WildcardUtils.matchPath(Git.REFS_HEADS + getBranchPatterns(), refName))- return passed("Branch to be created matches pattern '" + branchPatterns + "'.");- else- return failed("Branch to be created does not match pattern '" + branchPatterns + "'.");- } else {- return ignored();- }- }--}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.javaindex 25135ca842..722f371665 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfGetMinScoreFromSpecifiedTeam.java@@ -5,6 +5,7 @@ import java.util.HashSet;import javax.validation.constraints.Min;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;@@ -15,7 +16,7 @@ import com.pmease.gitplex.core.model.Review;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=500, icon="pa-group-o", description=+@Editable(order=500, icon="pa-group-o", category=GateKeeper.CATEGROY_CHECK_REVIEW, description="This gate keeper will be passed if specified score can be get from specified team, the score "+ "starts at zero, and will increase by one for each approval, and decrease by one for each "+ "rejection.")@@ -70,14 +71,14 @@ public class IfGetMinScoreFromSpecifiedTeam extends TeamAwareGateKeeper {int lackApprovals = calcLackApprovals(score, pendings);if (lackApprovals == 0) {- return passed("Get min score " + getMinScore() + " from team '" + getTeam().getName() + "'.");+ return passed(Lists.newArrayList("Get min score " + getMinScore() + " from team '" + getTeam().getName() + "'."));} else if (lackApprovals < 0) {- return failed("Can not get min score " + getMinScore() + " from team '" + getTeam().getName() + "'.");+ return failed(Lists.newArrayList("Can not get min score " + getMinScore() + " from team '" + getTeam().getName() + "'."));} else {request.pickReviewers(members, lackApprovals);- return pending("To be approved by " + lackApprovals + " users from team '"- + getTeam().getName() + ".");+ return pending(Lists.newArrayList("To be approved by " + lackApprovals + " users from team '"+ + getTeam().getName() + "."));}}@@ -119,12 +120,12 @@ public class IfGetMinScoreFromSpecifiedTeam extends TeamAwareGateKeeper {int lackApprovals = calcLackApprovals(score, pendings);if (lackApprovals == 0) {- return passed("Get min score " + getMinScore() + " from team '" + getTeam().getName() + "'.");+ return passed(Lists.newArrayList("Get min score " + getMinScore() + " from team '" + getTeam().getName() + "'."));} else if (lackApprovals < 0) {- return failed("Can not get min score " + getMinScore() + " from team '" + getTeam().getName() + "'.");+ return failed(Lists.newArrayList("Can not get min score " + getMinScore() + " from team '" + getTeam().getName() + "'."));} else {- return pending("Lack " + lackApprovals + " approvals from team '"- + getTeam().getName() + ".");+ return pending(Lists.newArrayList("Lack " + lackApprovals + " approvals from team '"+ + getTeam().getName() + "."));}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.javaindex ce2383aead..ee8123e7d9 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfNotDisapprovedBySpecifiedTeam.java@@ -1,5 +1,6 @@package com.pmease.gitplex.core.gatekeeper;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;@@ -10,7 +11,7 @@ import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.model.Review;@SuppressWarnings("serial")-@Editable(order=600, icon="pa-group-o", description=+@Editable(order=600, icon="pa-group-o", category=GateKeeper.CATEGROY_CHECK_REVIEW, description="This gate keeper will be passed if the commit is not disapproved by specified team.")public class IfNotDisapprovedBySpecifiedTeam extends TeamAwareGateKeeper {@@ -19,26 +20,26 @@ public class IfNotDisapprovedBySpecifiedTeam extends TeamAwareGateKeeper {for (Membership membership: getTeam().getMemberships()) {Review.Result result = membership.getUser().checkReviewSince(request.getReferentialUpdate());if (result == Review.Result.DISAPPROVE) {- return failed("Disapproved by user '" + membership.getUser().getName() + "'.");+ return failed(Lists.newArrayList("Disapproved by user '" + membership.getUser().getName() + "'."));}}- return passed("Not disapproved by anyone from team '" + getTeam().getName() + ".");+ return passed(Lists.newArrayList("Not disapproved by anyone from team '" + getTeam().getName() + "."));}@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {- return passed("Not disapproved by anyone from team '" + getTeam().getName() + "'.");+ return passed(Lists.newArrayList("Not disapproved by anyone from team '" + getTeam().getName() + "'."));}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return passed("Not disapproved by anyone from team '" + getTeam().getName() + "'.");+ return passed(Lists.newArrayList("Not disapproved by anyone from team '" + getTeam().getName() + "'."));}@Overrideprotected CheckResult doCheckRef(User user, Repository repository, String refName) {- return passed("Not disapproved by anyone from team '" + getTeam().getName() + "'.");+ return passed(Lists.newArrayList("Not disapproved by anyone from team '" + getTeam().getName() + "'."));}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedNonBranchRefs.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.javasimilarity index 60%rename from gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedNonBranchRefs.javarename to gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.javaindex c4beec23b1..b4944da8b7 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedNonBranchRefs.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushToSpecifiedRefs.java@@ -2,25 +2,22 @@ package com.pmease.gitplex.core.gatekeeper;import org.hibernate.validator.constraints.NotEmpty;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;-import com.pmease.commons.git.Git;import com.pmease.commons.util.pattern.WildcardUtils;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;-import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.PullRequest;+import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;-@Editable(order=200, icon="pa-branch-pattern", name="If Push To Specified Non-Branch Refs", description=- "This gate keeper will be passed if push to specified non-branch references. Note that "- + "touching various branch references under refs/heads will not trigger this gate "- + "keeper. Use branch related gate keepers if you would like to match desired branches.")+@Editable(order=200, icon="pa-branch-pattern", description="This gate keeper will be passed if push to specified references.")@SuppressWarnings("serial")-public class IfPushToSpecifiedNonBranchRefs extends AbstractGateKeeper {+public class IfPushToSpecifiedRefs extends AbstractGateKeeper {private String refPatterns;- @Editable(name="Specify Non-Branch Ref Patterns", description="Specify non-branch ref patterns to match. Below is some examples:"+ @Editable(name="Specify Ref Patterns", description="Specify ref patterns to match. Below is some examples:"+ "<ul>"+ "<li><i>refs/tags/*</i>: matches all refs directly under refs/tags."+ "<li><i>refs/tags/**</i>: matches all refs under refs/tags recursively."@@ -39,29 +36,25 @@ public class IfPushToSpecifiedNonBranchRefs extends AbstractGateKeeper {@Overrideprotected CheckResult doCheckRequest(PullRequest request) {- return ignored();+ return doCheckRef(request.getSubmitter(), request.getTarget().getRepository(), request.getTarget().getHeadRef());}@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {- return ignored();+ return doCheckRef(user, branch.getRepository(), branch.getHeadRef());}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return ignored();+ return doCheckRef(user, branch.getRepository(), branch.getHeadRef());}@Overrideprotected CheckResult doCheckRef(User user, Repository repository, String refName) {- if (refName.startsWith(Git.REFS_HEADS)) {- return ignored();- } else {- if (WildcardUtils.matchPath(getRefPatterns(), refName))- return passed("Target ref matches pattern '" + refPatterns + "'.");- else- return failed("Target ref does not match pattern '" + refPatterns + "'.");- }+ if (WildcardUtils.matchPath(getRefPatterns(), refName))+ return passed(Lists.newArrayList("Target ref matches pattern '" + refPatterns + "'."));+ else+ return failed(Lists.newArrayList("Target ref does not match pattern '" + refPatterns + "'."));}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.javaindex 51e4481b48..1359d1cf73 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfPushWithoutRewritingHistory.java@@ -1,5 +1,6 @@package com.pmease.gitplex.core.gatekeeper;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;@@ -7,9 +8,10 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;-@Editable(order=100, icon="pa-repo-locked", description="This gate keeper will be passed if the push operation does not rewrite history "- + "of target branch. Rewriting history of public branches is dangerous, and it happens when user forces "- + "a push without merging/rebasing with the branch head.")+@Editable(order=100, icon="pa-repo-locked", description="This gate keeper will be passed if the push "+ + "operation does not rewrite history of target branch. Rewriting history of public branches "+ + "is dangerous, and it happens when user forces a push without merging/rebasing with the "+ + "branch head.")@SuppressWarnings("serial")public class IfPushWithoutRewritingHistory extends AbstractGateKeeper {@@ -26,9 +28,9 @@ public class IfPushWithoutRewritingHistory extends AbstractGateKeeper {@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {if (branch.getRepository().git().isAncestor(branch.getHeadCommitHash(), commit))- return passed("Push operation does not rewrite history.");+ return passed(Lists.newArrayList("Push operation does not rewrite history."));else- return failed("Push operation rewrites history.");+ return failed(Lists.newArrayList("Push operation rewrites history."));}@Overridediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.javaindex 56845887bf..e79bea3923 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranchPatterns.java@@ -2,6 +2,7 @@ package com.pmease.gitplex.core.gatekeeper;import org.hibernate.validator.constraints.NotEmpty;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.util.pattern.WildcardUtils;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@@ -11,9 +12,9 @@ import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=200, icon="pa-branch-pattern", description=+@Editable(order=200, icon="pa-branch-pattern", category=GateKeeper.CATEGROY_CHECK_BRANCH, description="This gate keeper will be passed if the commit is submitted to specified branch pattern.")-public class IfSubmitToSpecifiedBranchPatterns extends BranchGateKeeper {+public class IfSubmitToSpecifiedBranchPatterns extends AbstractGateKeeper {private String branchPatterns;@@ -34,31 +35,35 @@ public class IfSubmitToSpecifiedBranchPatterns extends BranchGateKeeper {this.branchPatterns = branchPatterns;}- private CheckResult checkBranch(Branch branch) {- if (WildcardUtils.matchPath(getBranchPatterns(), branch.getName()))- return passed("Target branch matches pattern '" + branchPatterns + "'.");+ private CheckResult checkBranch(String branchName) {+ if (WildcardUtils.matchPath(getBranchPatterns(), branchName))+ return passed(Lists.newArrayList("Target branch matches pattern '" + branchPatterns + "'."));else- return failed("Target branch does not match pattern '" + branchPatterns + "'.");+ return failed(Lists.newArrayList("Target branch does not match pattern '" + branchPatterns + "'."));}@Overridepublic CheckResult doCheckRequest(PullRequest request) {- return checkBranch(request.getTarget());+ return checkBranch(request.getTarget().getName());}@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {- return checkBranch(branch);+ return checkBranch(branch.getName());}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return checkBranch(branch);+ return checkBranch(branch.getName());}@Overrideprotected CheckResult doCheckRef(User user, Repository repository, String refName) {- return ignored();+ String branchName = Branch.parseName(refName);+ if (branchName != null)+ return checkBranch(branchName);+ else+ return ignored();}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.javaindex 2e4ecc4dd4..c81e3e3f1a 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedBranches.java@@ -6,6 +6,7 @@ import java.util.List;import javax.validation.constraints.NotNull;import javax.validation.constraints.Size;+import com.google.common.collect.Lists;import com.pmease.gitplex.core.GitPlex;import org.apache.commons.lang3.StringUtils;@@ -21,9 +22,9 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=100, icon="pa-branch", description=+@Editable(order=100, icon="pa-branch", category=GateKeeper.CATEGROY_CHECK_BRANCH, description="This gate keeper will be passed if the commit is submitted to specified branches.")-public class IfSubmitToSpecifiedBranches extends BranchGateKeeper {+public class IfSubmitToSpecifiedBranches extends AbstractGateKeeper {private List<Long> branchIds = new ArrayList<>();@@ -41,7 +42,7 @@ public class IfSubmitToSpecifiedBranches extends BranchGateKeeper {@Overridepublic CheckResult doCheckRequest(PullRequest request) {- return checkBranch(request.getTarget());+ return checkBranch(request.getTarget().getName());}@Override@@ -53,38 +54,42 @@ public class IfSubmitToSpecifiedBranches extends BranchGateKeeper {return this;}- private CheckResult checkBranch(Branch branch) {+ private CheckResult checkBranch(String branchName) {List<String> branchNames = new ArrayList<>();Dao dao = GitPlex.getInstance(Dao.class);for (Long branchId: branchIds)branchNames.add(dao.load(Branch.class, branchId).getName());if (branchIds.size() > 1) {- if (branchIds.contains(branch.getId()))- return passed("Target branch is one of '" + StringUtils.join(branchNames, ", ") + "'.");+ if (branchNames.contains(branchName))+ return passed(Lists.newArrayList("Target branch is one of '" + StringUtils.join(branchNames, ", ") + "'."));else- return failed("Target branch is not any one of '" + StringUtils.join(branchNames, ", ") + "'.");+ return failed(Lists.newArrayList("Target branch is not any one of '" + StringUtils.join(branchNames, ", ") + "'."));} else {- if (branchIds.contains(branch.getId()))- return passed("Target branch is '" + branchNames.get(0) + "'.");+ if (branchNames.contains(branchName))+ return passed(Lists.newArrayList("Target branch is '" + branchNames.get(0) + "'."));else- return failed("Target branch is not '" + branchNames.get(0) + "'.");+ return failed(Lists.newArrayList("Target branch is not '" + branchNames.get(0) + "'."));}}@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {- return checkBranch(branch);+ return checkBranch(branch.getName());}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {- return checkBranch(branch);+ return checkBranch(branch.getName());}@Overrideprotected CheckResult doCheckRef(User user, Repository repository, String refName) {- return ignored();+ String branchName = Branch.parseName(refName);+ if (branchName != null)+ return checkBranch(branchName);+ else+ return ignored();}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.javaindex d863acea1e..3a9ae47949 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitWithGerritStylePatch.java@@ -1,5 +1,6 @@package com.pmease.gitplex.core.gatekeeper;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;@@ -7,9 +8,9 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;-@Editable(order=150, description="This gate keeper will be passed if the pull request is submitted with "- + "gerrit style patch, that is, only one commit is submitted for review at a time, and "- + "subsequent updates to the review should be done by amending previous commit.")+@Editable(order=150, icon="pa-diff", description="This gate keeper will be passed if the pull request "+ + "is submitted with gerrit style patch, that is, only one commit is submitted for review at "+ + "a time, and subsequent updates to the review should be done by amending previous commit.")@SuppressWarnings("serial")public class IfSubmitWithGerritStylePatch extends AbstractGateKeeper {@@ -18,9 +19,9 @@ public class IfSubmitWithGerritStylePatch extends AbstractGateKeeper {String branchHead = request.getBaseCommitHash();String requestHead = request.getLatestUpdate().getHeadCommitHash();if (request.git().log(branchHead, requestHead, null, 0, 0).size() > 1) {- return failed("Please squash/rebase your commits.");+ return failed(Lists.newArrayList("Please squash/rebase your commits."));} else {- return passed("No more than one commit.");+ return passed(Lists.newArrayList("No more than one commit."));}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.javaindex 620e745695..1bc916728c 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryOwner.java@@ -1,5 +1,6 @@package com.pmease.gitplex.core.gatekeeper;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;@@ -8,9 +9,9 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=300, icon="pa-user-o", description=+@Editable(order=300, icon="pa-user-o", category=GateKeeper.CATEGROY_CHECK_SUBMITTER, description="This gate keeper will be passed if the commit is submitted by owner of the repository.")-public class IfSubmittedByRepositoryOwner extends ApprovalGateKeeper {+public class IfSubmittedByRepositoryOwner extends AbstractGateKeeper {@Overridepublic CheckResult doCheckRequest(PullRequest request) {@@ -19,9 +20,9 @@ public class IfSubmittedByRepositoryOwner extends ApprovalGateKeeper {private CheckResult check(User user, Repository repository) {if (user.equals(repository.getOwner()))- return passed("Submitted by repository owner.");+ return passed(Lists.newArrayList("Submitted by repository owner."));else- return failed("Not submitted by repository owner.");+ return failed(Lists.newArrayList("Not submitted by repository owner."));}@Overridediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.javaindex 014362c822..ca0c853491 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedByRepositoryWriter.java@@ -1,5 +1,6 @@package com.pmease.gitplex.core.gatekeeper;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;@@ -9,10 +10,10 @@ import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.permission.ObjectPermission;@SuppressWarnings("serial")-@Editable(order=50, icon="pa-group-o", description=+@Editable(order=50, icon="pa-group-o", category=GateKeeper.CATEGROY_CHECK_SUBMITTER, description="This gate keeper will be passed if the commit is submitted by an user with "+ "write permission against the repository.")-public class IfSubmittedByRepositoryWriter extends ApprovalGateKeeper {+public class IfSubmittedByRepositoryWriter extends AbstractGateKeeper {@Overridepublic CheckResult doCheckRequest(PullRequest request) {@@ -21,9 +22,9 @@ public class IfSubmittedByRepositoryWriter extends ApprovalGateKeeper {private CheckResult check(User user, Repository repository) {if (user.asSubject().isPermitted(ObjectPermission.ofRepositoryWrite(repository)))- return passed("Submitted by repository writer");+ return passed(Lists.newArrayList("Submitted by repository writer"));else- return failed("Not submitted by repository writer");+ return failed(Lists.newArrayList("Not submitted by repository writer"));}@Overridediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.javaindex 6a9512ccf1..67099a18cb 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedTeam.java@@ -1,5 +1,6 @@package com.pmease.gitplex.core.gatekeeper;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.model.Branch;@@ -9,7 +10,7 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=100, icon="pa-group-o", description=+@Editable(order=100, icon="pa-group-o", category=GateKeeper.CATEGROY_CHECK_SUBMITTER, description="This gate keeper will be passed if the commit is submitted by a member of specified team.")public class IfSubmittedBySpecifiedTeam extends TeamAwareGateKeeper {@@ -21,9 +22,9 @@ public class IfSubmittedBySpecifiedTeam extends TeamAwareGateKeeper {private CheckResult check(User user) {for (Membership membership: user.getMemberships()) {if (membership.getTeam().equals(getTeam()))- return passed("Submitted by a member of team '" + getTeam().getName() + "'.");+ return passed(Lists.newArrayList("Submitted by a member of team '" + getTeam().getName() + "'."));}- return failed("Not submitted by a member of team '" + getTeam().getName() + "'.");+ return failed(Lists.newArrayList("Not submitted by a member of team '" + getTeam().getName() + "'."));}@Overridediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.javaindex 81b3e34137..161ddb61c6 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmittedBySpecifiedUser.java@@ -2,6 +2,7 @@ package com.pmease.gitplex.core.gatekeeper;import javax.validation.constraints.NotNull;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.gitplex.core.GitPlex;@@ -13,9 +14,9 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=200, icon="pa-user-o", description=+@Editable(order=200, icon="pa-user-o", category=GateKeeper.CATEGROY_CHECK_SUBMITTER, description="This gate keeper will be passed if the commit is submitted by specified user.")-public class IfSubmittedBySpecifiedUser extends ApprovalGateKeeper {+public class IfSubmittedBySpecifiedUser extends AbstractGateKeeper {private Long userId;@@ -46,9 +47,9 @@ public class IfSubmittedBySpecifiedUser extends ApprovalGateKeeper {private CheckResult check(User user) {User expectedUser = GitPlex.getInstance(Dao.class).load(User.class, userId);if (expectedUser.getId().equals(user.getId()))- return passed("Submitted by " + expectedUser.getDisplayName() + ".");+ return passed(Lists.newArrayList("Submitted by " + expectedUser.getDisplayName() + "."));else- return failed("Not submitted by " + expectedUser.getDisplayName() + ".");+ return failed(Lists.newArrayList("Not submitted by " + expectedUser.getDisplayName() + "."));}@Overridediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfThenGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfThenGateKeeper.javaindex 2a9eb88a62..d4144a0b1e 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfThenGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfThenGateKeeper.java@@ -9,12 +9,12 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;-import com.pmease.gitplex.core.gatekeeper.checkresult.PendingAndBlock;+import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;@SuppressWarnings("serial")-@Editable(name="Check Second Gate Keeper If First Gate Keeper Is Passed", order=300, icon="pa-servers",- description="If first gate keeper is passed, go ahead to check second gate keeper; otherwise, consider "- + "the whole gate keeper as passed.")+@Editable(name="If...Then... Composition", order=300, icon="pa-servers",+ category=GateKeeper.CATEGROY_COMPOSITION,+ description="If first gate keeper is passed, then go ahead to check second gate keeper;")@Horizontalpublic class IfThenGateKeeper extends CompositeGateKeeper {@@ -49,7 +49,7 @@ public class IfThenGateKeeper extends CompositeGateKeeper {return checker.check(getThenGate());} else if (ifResult instanceof Failed) {return passed(ifResult.getReasons());- } else if (ifResult instanceof PendingAndBlock) {+ } else if (ifResult instanceof Blocking) {return ifResult;} else if (ifResult instanceof Pending) {CheckResult thenResult = checker.check(getThenGate());diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.javaindex c75b0cee63..5cc1e33ba9 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedDirectories.java@@ -6,6 +6,7 @@ import java.util.List;import javax.validation.constraints.NotNull;import javax.validation.constraints.Size;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.util.pattern.WildcardUtils;import com.pmease.gitplex.core.editable.DirectoryChoice;@@ -17,9 +18,9 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=90, icon="pa-folder-o", description=+@Editable(order=90, icon="pa-folder-o", category=GateKeeper.CATEGROY_CHECK_FILES, description="This gate keeper will be passed if any commit files are under specified directories.")-public class IfTouchSpecifiedDirectories extends FileGateKeeper {+public class IfTouchSpecifiedDirectories extends AbstractGateKeeper {private List<String> directories = new ArrayList<>();@@ -42,22 +43,24 @@ public class IfTouchSpecifiedDirectories extends FileGateKeeper {for (String each: directories) {if (WildcardUtils.matchPath(each + "/**", file)) {request.setReferentialUpdate(update);- return passed("Touched directory '" + each + "'.");+ return passed(Lists.newArrayList("Touched directory '" + each + "'."));}}}}- return failed("Not touched directories '" + getDirectories() + "'.");+ return failed(Lists.newArrayList("Not touched directories '" + getDirectories() + "'."));}@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {+ if (file == null)+ return passed(new ArrayList<String>());for (String each: directories) {- if (file == null || WildcardUtils.matchPath(each + "/**", file))- return passed("Touched directory '" + each + "'.");+ if (WildcardUtils.matchPath(each + "/**", file))+ return passed(Lists.newArrayList("Touched directory '" + each + "'."));}- return failed("Not touched directories '" + getDirectories() + "'.");+ return failed(Lists.newArrayList("Not touched directories '" + getDirectories() + "'."));}@Override@@ -65,11 +68,11 @@ public class IfTouchSpecifiedDirectories extends FileGateKeeper {for (String file: branch.getRepository().git().listChangedFiles(branch.getHeadCommitHash(), commit, null)) {for (String each: directories) {if (WildcardUtils.matchPath(each + "/**", file))- return passed("Touched directory '" + each + "'.");+ return passed(Lists.newArrayList("Touched directory '" + each + "'."));}}- return failed("Not touched directories '" + getDirectories() + "'.");+ return failed(Lists.newArrayList("Not touched directories '" + getDirectories() + "'."));}@Overridediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.javaindex d566b1d04d..43bc56e358 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedFilePatterns.java@@ -1,7 +1,10 @@package com.pmease.gitplex.core.gatekeeper;+import java.util.ArrayList;+import org.hibernate.validator.constraints.NotEmpty;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.commons.util.pattern.WildcardUtils;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@@ -12,9 +15,9 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=100, icon="pa-file-txt", description=+@Editable(order=100, icon="pa-file-txt", category=GateKeeper.CATEGROY_CHECK_FILES, description="This gate keeper will be passed if any commit file maches specified file patterns.")-public class IfTouchSpecifiedFilePatterns extends FileGateKeeper {+public class IfTouchSpecifiedFilePatterns extends AbstractGateKeeper {private String filePatterns;@@ -34,30 +37,32 @@ public class IfTouchSpecifiedFilePatterns extends FileGateKeeper {for (String file: update.getChangedFiles()) {if (WildcardUtils.matchPath(getFilePatterns(), file)) {request.setReferentialUpdate(update);- return passed("Touched files match patterns '" + getFilePatterns() + "'.");+ return passed(Lists.newArrayList("Touched files match patterns '" + getFilePatterns() + "'."));}}}- return failed("No touched files match patterns '" + getFilePatterns() + "'.");+ return failed(Lists.newArrayList("No touched files match patterns '" + getFilePatterns() + "'."));}@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {- if (file == null || WildcardUtils.matchPath(filePatterns, file))- return passed("Touched files match patterns '" + filePatterns + "'.");+ if (file == null)+ return passed(new ArrayList<String>());+ else if (WildcardUtils.matchPath(filePatterns, file))+ return passed(Lists.newArrayList("Touched files match patterns '" + filePatterns + "'."));else- return failed("No touched files match patterns '" + filePatterns + "'.");+ return failed(Lists.newArrayList("No touched files match patterns '" + filePatterns + "'."));}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {for (String file: branch.getRepository().git().listChangedFiles(branch.getHeadCommitHash(), commit, null)) {if (WildcardUtils.matchPath(filePatterns, file))- return passed("Touched files match patterns '" + filePatterns + "'.");+ return passed(Lists.newArrayList("Touched files match patterns '" + filePatterns + "'."));}- return failed("No touched files match patterns '" + filePatterns + "'.");+ return failed(Lists.newArrayList("No touched files match patterns '" + filePatterns + "'."));}@Overridediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.javaindex 5528a6f9be..9f8faaa848 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfVerifiedByBuilds.java@@ -4,6 +4,7 @@ import java.util.Collection;import javax.validation.constraints.Min;+import com.google.common.collect.Lists;import com.pmease.commons.editable.annotation.Editable;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;@@ -15,7 +16,7 @@ import com.pmease.gitplex.core.model.PullRequestVerification;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.User;-@Editable(icon="pa-checkbox-checked", order=1000,+@Editable(icon="pa-checkbox-checked", order=1000, category=GateKeeper.CATEGORY_COMMONLY_USED,description="This gate keeper will be satisfied if commit is verified successfully "+ "by specified number of builds. To make this working, your CI system has to "+ "be configured to build against GitPlex pull requests.")@@ -64,9 +65,9 @@ public class IfVerifiedByBuilds extends AbstractGateKeeper {protected CheckResult doCheckRequest(PullRequest request) {if (request.isNew()) {if (blockMode)- return pendingAndBlock("To be verified by build");+ return blocking(Lists.newArrayList("To be verified by build"));else- return pending("To be verified by build");+ return pending(Lists.newArrayList("To be verified by build"));}String commit;@@ -74,13 +75,13 @@ public class IfVerifiedByBuilds extends AbstractGateKeeper {IntegrationPreview preview = request.getIntegrationPreview();if (preview == null) {if (blockMode)- return pendingAndBlock("To be verified by build");+ return blocking(Lists.newArrayList("To be verified by build"));else- return pending("To be verified by build");+ return pending(Lists.newArrayList("To be verified by build"));}commit = preview.getIntegrated();if (commit == null)- return failed("Can not build against integration result due to conflicts.");+ return failed(Lists.newArrayList("Can not build against integration result due to conflicts."));} else {commit = request.getLatestUpdate().getHeadCommitHash();}@@ -91,7 +92,7 @@ public class IfVerifiedByBuilds extends AbstractGateKeeper {Collection<PullRequestVerification> verifications = verificationManager.findBy(request, commit);for (PullRequestVerification each: verifications) {if (each.getStatus() == PullRequestVerification.Status.NOT_PASSED)- return failed("At least one build is not passed for the commit.");+ return failed(Lists.newArrayList("At least one build is not passed for the commit."));else if (each.getStatus() == PullRequestVerification.Status.PASSED)passedCount++;}@@ -100,34 +101,34 @@ public class IfVerifiedByBuilds extends AbstractGateKeeper {if (lacks > 0) {if (blockMode) {if (leastPassCount > 1)- return pendingAndBlock("To be verified by " + lacks + " more build(s)");+ return blocking(Lists.newArrayList("To be verified by " + lacks + " more build(s)"));else- return pendingAndBlock("To be verified by build");+ return blocking(Lists.newArrayList("To be verified by build"));} else {if (leastPassCount > 1)- return pending("To be verified by " + lacks + " more build(s)");+ return pending(Lists.newArrayList("To be verified by " + lacks + " more build(s)"));else- return pending("To be verified by build");+ return pending(Lists.newArrayList("To be verified by build"));}} else {- return passed("Builds passed");+ return passed(Lists.newArrayList("Builds passed"));}}@Overrideprotected CheckResult doCheckFile(User user, Branch branch, String file) {if (blockMode)- return pendingAndBlock("Not verified by build.");+ return blocking(Lists.newArrayList("Not verified by build."));else- return pending("Not verified by build.");+ return pending(Lists.newArrayList("Not verified by build."));}@Overrideprotected CheckResult doCheckCommit(User user, Branch branch, String commit) {if (blockMode) {- return pendingAndBlock("Has to be verified by builds.");+ return blocking(Lists.newArrayList("Has to be verified by builds."));} else {- return pendingAndBlock("Has to be verified by builds.");+ return blocking(Lists.newArrayList("Has to be verified by builds."));}}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/NotGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/NotGateKeeper.javaindex 61862fb840..264646bc79 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/NotGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/NotGateKeeper.java@@ -11,7 +11,8 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;import com.pmease.gitplex.core.model.Repository;@SuppressWarnings("serial")-@Editable(name="If Contained Gate Keeper Is Not Passed", order=400, icon="pa-servers",+@Editable(name="Not Composition", order=400, icon="pa-servers",+ category=GateKeeper.CATEGROY_COMPOSITION,description="This gate keeper will be passed if contained gate keeper is not passed.")@Horizontalpublic class NotGateKeeper extends CompositeGateKeeper {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/OrGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/OrGateKeeper.javaindex 9547510b08..c428c31987 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/OrGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/OrGateKeeper.java@@ -9,10 +9,11 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;-import com.pmease.gitplex.core.gatekeeper.checkresult.PendingAndBlock;+import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;@SuppressWarnings("serial")-@Editable(name="If Any Of Contained Gate Keepers Is Passed", order=200, icon="pa-servers",+@Editable(name="Or Composition", order=200, icon="pa-servers",+ category=GateKeeper.CATEGROY_COMPOSITION,description="This gate keeper will be passed if any of the contained gate keepers is passed.")@Horizontalpublic class OrGateKeeper extends AndOrGateKeeper {@@ -28,7 +29,7 @@ public class OrGateKeeper extends AndOrGateKeeper {rejectReasons.addAll(result.getReasons());} else if (result instanceof Passed) {return result;- } else if (result instanceof PendingAndBlock) {+ } else if (result instanceof Blocking) {result.getReasons().addAll(pendingReasons);return result;} else if (result instanceof Pending) {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/TeamAwareGateKeeper.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/TeamAwareGateKeeper.javaindex d2495523d1..896f87f687 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/TeamAwareGateKeeper.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/TeamAwareGateKeeper.java@@ -10,7 +10,7 @@ import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.Team;@SuppressWarnings("serial")-public abstract class TeamAwareGateKeeper extends ApprovalGateKeeper {+public abstract class TeamAwareGateKeeper extends AbstractGateKeeper {private Long teamId;diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/PendingAndBlock.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Blocking.javasimilarity index 68%rename from gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/PendingAndBlock.javarename to gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Blocking.javaindex 79aaa1f8a6..d966644e38 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/PendingAndBlock.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Blocking.java@@ -7,16 +7,12 @@ import java.util.List;* of this gate keeper has been determined.*/@SuppressWarnings("serial")-public class PendingAndBlock extends CheckResult {+public class Blocking extends CheckResult {- public PendingAndBlock(List<String> reasons) {+ public Blocking(List<String> reasons) {super(reasons);}- public PendingAndBlock(String reason) {- super(reason);- }-@Overridepublic String toString() {return "Blocked";diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/CheckResult.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/CheckResult.javaindex f269564064..7f54dab686 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/CheckResult.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/CheckResult.java@@ -3,8 +3,6 @@ package com.pmease.gitplex.core.gatekeeper.checkresult;import java.io.Serializable;import java.util.List;-import com.google.common.collect.Lists;-@SuppressWarnings("serial")public abstract class CheckResult implements Serializable {@@ -14,10 +12,6 @@ public abstract class CheckResult implements Serializable {this.reasons = reasons;}- public CheckResult(String reason) {- this.reasons = Lists.newArrayList(reason);- }-public List<String> getReasons() {return reasons;}@@ -34,8 +28,8 @@ public abstract class CheckResult implements Serializable {return this instanceof Pending;}- public boolean isPendingAndBlock() {- return this instanceof PendingAndBlock;+ public boolean isBlocking() {+ return this instanceof Blocking;}public boolean isIgnored() {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Failed.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Failed.javaindex a432803bf9..de86063ba0 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Failed.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Failed.java@@ -10,10 +10,6 @@ public class Failed extends CheckResult {super(reasons);}- public Failed(String reason) {- super(reason);- }-@Overridepublic String toString() {return "Failed";diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Ignored.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Ignored.javaindex 262a2c1bb6..b18b2a4f92 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Ignored.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Ignored.java@@ -1,5 +1,7 @@package com.pmease.gitplex.core.gatekeeper.checkresult;+import java.util.ArrayList;+/*** Represents an ignored result, for instance if some check is not applicable, or if@@ -12,7 +14,7 @@ package com.pmease.gitplex.core.gatekeeper.checkresult;public class Ignored extends CheckResult {public Ignored() {- super("Ignored");+ super(new ArrayList<String>());}@Overridediff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Passed.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Passed.javaindex 4117512ee9..962ff61484 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Passed.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Passed.java@@ -9,10 +9,6 @@ public class Passed extends CheckResult {super(reasons);}- public Passed(String reason) {- super(reason);- }-@Overridepublic String toString() {return "Passed";diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Pending.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Pending.javaindex 72c7059527..a103fb6b49 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Pending.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/checkresult/Pending.java@@ -10,10 +10,6 @@ public class Pending extends CheckResult {super(reasons);}- public Pending(String reason) {- super(reason);- }-@Overridepublic String toString() {return "Pending";diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.javaindex b3e19669a4..de77c9d670 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/hookcallback/GitUpdateCallback.java@@ -125,7 +125,7 @@ public class GitUpdateCallback extends HttpServlet {if (newCommitHash.equals(GitUtils.NULL_SHA1)) { // deleting a branch refGateKeeper gateKeeper = repository.getGateKeeper();- CheckResult checkResult = gateKeeper.checkBranch(user, branch);+ CheckResult checkResult = gateKeeper.checkFile(user, branch, null);if (!(checkResult instanceof Passed)) {List<String> messages = new ArrayList<>();diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.javaindex 378b497e63..f490330f37 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java@@ -42,7 +42,7 @@ import com.pmease.gitplex.core.comment.ChangeComments;import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;-import com.pmease.gitplex.core.gatekeeper.checkresult.PendingAndBlock;+import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;import com.pmease.gitplex.core.manager.PullRequestManager;import com.pmease.gitplex.core.manager.ReviewManager;import com.pmease.gitplex.core.permission.ObjectPermission;@@ -356,7 +356,7 @@ public class PullRequest extends AbstractEntity {return Status.INTEGRATED;else if (closeStatus == CloseStatus.DISCARDED)return Status.DISCARDED;- else if (getCheckResult() instanceof Pending || getCheckResult() instanceof PendingAndBlock)+ else if (getCheckResult() instanceof Pending || getCheckResult() instanceof Blocking)return Status.PENDING_APPROVAL;else if (getCheckResult() instanceof Failed)return Status.PENDING_UPDATE;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/gatekeeper/GateKeeperPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/gatekeeper/GateKeeperPanel.htmlindex da590852fc..1cc082bb7e 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/gatekeeper/GateKeeperPanel.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/gatekeeper/GateKeeperPanel.html@@ -36,14 +36,14 @@<tr><td class="ifthen if"><div wicket:id="if"></div>- <div wicket:id="ifTypeSelectorTrigger" class="well gate-keeper-add">Define First Condition<i class="pa pa-plus-round"></i></div>+ <div wicket:id="ifTypeSelectorTrigger" class="well gate-keeper-add">Define If Gate Keeper<i class="pa pa-plus-round"></i></div><div wicket:id="ifTypeSelector"></div><div wicket:id="ifEditor"></div></td><td class="ifthen connector"><div class="pa pa-arrow-right"></div></td><td class="ifthen then"><div wicket:id="then"></div>- <div wicket:id="thenTypeSelectorTrigger" class="well gate-keeper-add">Define Second Condition<i class="pa pa-plus-round"></i></div>+ <div wicket:id="thenTypeSelectorTrigger" class="well gate-keeper-add">Define Then Gate Keeper<i class="pa pa-plus-round"></i></div><div wicket:id="thenTypeSelector"></div><div wicket:id="thenEditor"></div></td>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/gatekeeper/GateKeeperSelector.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/gatekeeper/GateKeeperSelector.javaindex 3092f295ae..434bc1af1f 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/gatekeeper/GateKeeperSelector.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/admin/gatekeeper/GateKeeperSelector.java@@ -23,12 +23,7 @@ import com.pmease.commons.loader.ImplementationRegistry;import com.pmease.commons.wicket.behavior.CollapseBehavior;import com.pmease.commons.wicket.component.AccordionPanel;import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.gatekeeper.ApprovalGateKeeper;-import com.pmease.gitplex.core.gatekeeper.BranchGateKeeper;-import com.pmease.gitplex.core.gatekeeper.CommonGateKeeper;-import com.pmease.gitplex.core.gatekeeper.CompositeGateKeeper;import com.pmease.gitplex.core.gatekeeper.DefaultGateKeeper;-import com.pmease.gitplex.core.gatekeeper.FileGateKeeper;import com.pmease.gitplex.core.gatekeeper.GateKeeper;@SuppressWarnings("serial")@@ -42,18 +37,19 @@ public abstract class GateKeeperSelector extends Panel {protected void onInitialize() {super.onInitialize();- final Map<Class<?>, List<Class<?>>> gateKeeperClasses = new LinkedHashMap<>();- gateKeeperClasses.put(CommonGateKeeper.class, new ArrayList<Class<?>>());- gateKeeperClasses.put(CompositeGateKeeper.class, new ArrayList<Class<?>>());- gateKeeperClasses.put(BranchGateKeeper.class, new ArrayList<Class<?>>());- gateKeeperClasses.put(FileGateKeeper.class, new ArrayList<Class<?>>());- gateKeeperClasses.put(ApprovalGateKeeper.class, new ArrayList<Class<?>>());- gateKeeperClasses.put(GateKeeper.class, new ArrayList<Class<?>>());+ final Map<String, List<Class<?>>> gateKeeperClasses = new LinkedHashMap<>();+ gateKeeperClasses.put(GateKeeper.CATEGORY_COMMONLY_USED, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_BRANCH, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_FILES, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_REVIEW, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_SUBMITTER, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGROY_COMPOSITION, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGROY_OTHERS, new ArrayList<Class<?>>());List<Class<?>> implementations = new ArrayList<>();- for (Class<?> clazz: GitPlex.getInstance(ImplementationRegistry.class).getImplementations(GateKeeper.class)) {+ for (Class<?> clazz: GitPlex.getInstance(ImplementationRegistry.class).getImplementations(GateKeeper.class))implementations.add(clazz);- }+implementations.remove(DefaultGateKeeper.class);Collections.sort(implementations, new Comparator<Class<?>>() {@@ -65,26 +61,30 @@ public abstract class GateKeeperSelector extends Panel {});for (Class<?> implementation: implementations) {- for (Map.Entry<Class<?>, List<Class<?>>> entry: gateKeeperClasses.entrySet()) {- if (entry.getKey().isAssignableFrom(implementation)) {- entry.getValue().add(implementation);+ List<Class<?>> categoryClasses = null;+ for (Map.Entry<String, List<Class<?>>> entry: gateKeeperClasses.entrySet()) {+ if (entry.getKey().equals(EditableUtils.getCategory(implementation))) {+ categoryClasses = entry.getValue();break;}}+ if (categoryClasses == null)+ categoryClasses = gateKeeperClasses.get(GateKeeper.CATEGROY_OTHERS);+ categoryClasses.add(implementation);}- for (Iterator<Map.Entry<Class<?>, List<Class<?>>>> it = gateKeeperClasses.entrySet().iterator(); it.hasNext();) {+ for (Iterator<Map.Entry<String, List<Class<?>>>> it = gateKeeperClasses.entrySet().iterator(); it.hasNext();) {if (it.next().getValue().isEmpty())it.remove();}AccordionPanel accordion = new AccordionPanel("accordion");add(accordion);- accordion.add(new ListView<Class<?>>("categories", new ArrayList<Class<?>>(gateKeeperClasses.keySet())) {+ accordion.add(new ListView<String>("categories", new ArrayList<String>(gateKeeperClasses.keySet())) {@Override- protected void populateItem(ListItem<Class<?>> categoryItem) {- final Class<?> category = categoryItem.getModelObject();+ protected void populateItem(ListItem<String> categoryItem) {+ final String category = categoryItem.getModelObject();List<Class<?>> gateKeepersOfCategory = gateKeeperClasses.get(category);Preconditions.checkNotNull(gateKeepersOfCategory);@@ -118,7 +118,7 @@ public abstract class GateKeeperSelector extends Panel {WebMarkupContainer collapseTrigger = new WebMarkupContainer("collapseTrigger");categoryItem.add(collapseTrigger);- collapseTrigger.add(new Label("name", EditableUtils.getName(category))).add(new CollapseBehavior(collapsible));+ collapseTrigger.add(new Label("name", category)).add(new CollapseBehavior(collapsible));}});diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/RepoBranchesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/RepoBranchesPage.javaindex 11ca30ea1a..b7088d2cb7 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/RepoBranchesPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/RepoBranchesPage.java@@ -494,7 +494,7 @@ public class RepoBranchesPage extends RepositoryPage {User currentUser = getCurrentUser();if (currentUser != null) {GateKeeper gateKeeper = getRepository().getGateKeeper();- CheckResult checkResult = gateKeeper.checkBranch(currentUser, branch);+ CheckResult checkResult = gateKeeper.checkFile(currentUser, branch, null);if (checkResult instanceof Passed) {setVisible(true);PullRequest aheadOpen = aheadOpenRequestsModel.getObject().get(branch.getName());