The Unified and Autonomous Development Platform
midwork
robin shinefcba543a6f2f
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 7d895126f7..d5ff2c2f27 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@@ -1,46 +1,46 @@-package com.pmease.gitplex.core.gatekeeper;--import java.util.ArrayList;-import java.util.List;--import com.pmease.commons.wicket.editable.annotation.Editable;-import com.pmease.commons.wicket.editable.annotation.Horizontal;-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.Passed;-import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;--@SuppressWarnings("serial")-@Editable(name="And Composition", icon="fa-sitemap", order=100,- category=GateKeeper.CATEGROY_COMPOSITION,- description="This gate keeper will be passed if all contained gate keepers are passed.")-@Horizontal-public class AndGateKeeper extends AndOrGateKeeper {-- @Override- protected CheckResult aggregate(Checker checker) {- List<String> pendingReasons = new ArrayList<String>();- List<String> acceptReasons = new ArrayList<String>();-- for (GateKeeper each: getGateKeepers()) {- CheckResult result = checker.check(each);- if (result instanceof Passed) {- acceptReasons.addAll(result.getReasons());- } else if (result instanceof Failed) {- return result;- } else if (result instanceof Blocking) {- result.getReasons().addAll(pendingReasons);- return result;- } else if (result instanceof Pending) {- pendingReasons.addAll(result.getReasons());- }- }-- if (!pendingReasons.isEmpty())- return pending(pendingReasons);- else- return passed(acceptReasons);- }--}+package com.pmease.gitplex.core.gatekeeper;++import java.util.ArrayList;+import java.util.List;++import com.pmease.commons.wicket.editable.annotation.Editable;+import com.pmease.commons.wicket.editable.annotation.Horizontal;+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.Passed;+import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;++@SuppressWarnings("serial")+@Editable(name="And Composition", icon="fa-object-group", order=100,+ category=GateKeeper.CATEGORY_COMPOSITION,+ description="This gate keeper will be passed if all contained gate keepers are passed.")+@Horizontal+public class AndGateKeeper extends AndOrGateKeeper {++ @Override+ protected CheckResult aggregate(Checker checker) {+ List<String> pendingReasons = new ArrayList<String>();+ List<String> acceptReasons = new ArrayList<String>();++ for (GateKeeper each: getGateKeepers()) {+ CheckResult result = checker.check(each);+ if (result instanceof Passed) {+ acceptReasons.addAll(result.getReasons());+ } else if (result instanceof Failed) {+ return result;+ } else if (result instanceof Blocking) {+ result.getReasons().addAll(pendingReasons);+ return result;+ } else if (result instanceof Pending) {+ pendingReasons.addAll(result.getReasons());+ }+ }++ if (!pendingReasons.isEmpty())+ return pending(pendingReasons);+ else+ return passed(acceptReasons);+ }++}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 490526ea8f..771c959236 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@@ -14,17 +14,19 @@ import com.pmease.gitplex.core.model.User;@Editable(name="Misc")public interface GateKeeper extends Trimmable, Serializable {- String CATEGROY_CHECK_REFS = "Check Target Refs";+ String CATEGORY_CHECK_REFS = "Check Target Refs";- String CATEGROY_CHECK_FILES = "Check Touched Files";+ String CATEGORY_CHECK_FILES = "Check Touched Files";++ String CATEGORY_CHECK_OPERATIONS = "Check Operations";- String CATEGROY_CHECK_REVIEW = "Check Reviews";+ String CATEGORY_CHECK_APPROVALS = "Check Approvals";- String CATEGROY_CHECK_SUBMITTER = "Check Submitter";+ String CATEGORY_CHECK_SUBMITTER = "Check Submitter";- String CATEGROY_OTHERS = "Other Gate Keepers";+ String CATEGORY_OTHERS = "Other Gate Keepers";- String CATEGROY_COMPOSITION = "Gate Keeper Composition";+ String CATEGORY_COMPOSITION = "Gate Keeper Composition";/*** Check the gate keeper against specified request. This is typically used to determinediff --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 8af6acad8e..1c82792a22 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@@ -12,7 +12,7 @@ import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=400, icon="fa-group", category=GateKeeper.CATEGROY_CHECK_REVIEW, description=+@Editable(order=400, icon="fa-group", category=GateKeeper.CATEGORY_CHECK_APPROVALS, description="This gate keeper will be passed if the commit is approved by majorities of specified team.")public class IfApprovedByMajoritiesOfSpecifiedTeam extends TeamAwareGateKeeper {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 6a7c1bd37a..c290b3e964 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@@ -12,7 +12,7 @@ import com.pmease.gitplex.core.model.Review;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=300, icon="fa-user", category=GateKeeper.CATEGROY_CHECK_REVIEW, description=+@Editable(order=300, icon="fa-user", category=GateKeeper.CATEGORY_CHECK_APPROVALS, description="This gate keeper will be passed if the commit is approved by owner of the repository.")public class IfApprovedByRepositoryOwner extends AbstractGateKeeper {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 7d481a6b73..3ddb2689d2 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@@ -17,7 +17,7 @@ import com.pmease.gitplex.core.permission.operation.DepotOperation;import com.pmease.gitplex.core.security.SecurityUtils;@SuppressWarnings("serial")-@Editable(order=50, icon="fa-group", category=GateKeeper.CATEGROY_CHECK_REVIEW, description=+@Editable(order=50, icon="fa-group", category=GateKeeper.CATEGORY_CHECK_APPROVALS, description="This gate keeper will be passed if the commit is approved by specified number of users with "+ "writing permission.")public class IfApprovedByRepositoryWriters extends AbstractGateKeeper {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 7472a96efe..43c26f0a42 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@@ -17,7 +17,7 @@ import com.pmease.gitplex.core.model.Review;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=100, icon="fa-group", category=GateKeeper.CATEGROY_CHECK_REVIEW, description=+@Editable(order=100, icon="fa-group", category=GateKeeper.CATEGORY_CHECK_APPROVALS, 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 {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 d774b54f4c..44ed6f3575 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@@ -17,7 +17,7 @@ import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.util.editable.UserChoice;@SuppressWarnings("serial")-@Editable(order=200, icon="fa-user", category=GateKeeper.CATEGROY_CHECK_REVIEW, description=+@Editable(order=200, icon="fa-user", category=GateKeeper.CATEGORY_CHECK_APPROVALS, description="This gate keeper will be passed if the commit is approved by specified user.")public class IfApprovedBySpecifiedUser extends AbstractGateKeeper {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 590f223a81..ed90e1cd07 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@@ -17,7 +17,7 @@ import com.pmease.gitplex.core.model.Review;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=500, icon="fa-group", category=GateKeeper.CATEGROY_CHECK_REVIEW, description=+@Editable(order=500, icon="fa-group", category=GateKeeper.CATEGORY_CHECK_APPROVALS, 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.")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 b250c6b00a..d829be1f70 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@@ -12,7 +12,7 @@ import com.pmease.gitplex.core.model.Review;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=600, icon="fa-group", category=GateKeeper.CATEGROY_CHECK_REVIEW, description=+@Editable(order=600, icon="fa-group", category=GateKeeper.CATEGORY_CHECK_APPROVALS, description="This gate keeper will be passed if the commit is not disapproved by specified team.")public class IfNotDisapprovedBySpecifiedTeam extends TeamAwareGateKeeper {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedRefs.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedRefs.javadeleted file mode 100644index 3ac9736dfb..0000000000--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfSubmitToSpecifiedRefs.java+++ /dev/null@@ -1,56 +0,0 @@-package com.pmease.gitplex.core.gatekeeper;--import org.eclipse.jgit.lib.ObjectId;-import org.hibernate.validator.constraints.NotEmpty;--import com.google.common.collect.Lists;-import com.pmease.commons.git.GitUtils;-import com.pmease.commons.wicket.editable.annotation.Editable;-import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;-import com.pmease.gitplex.core.model.Depot;-import com.pmease.gitplex.core.model.PullRequest;-import com.pmease.gitplex.core.model.User;-import com.pmease.gitplex.core.util.editable.RefMatch;-import com.pmease.gitplex.core.util.refmatch.RefMatchUtils;--@SuppressWarnings("serial")-@Editable(order=100, icon="fa-ext fa-branch", category=GateKeeper.CATEGROY_CHECK_REFS, description=- "This gate keeper will be passed if the commit is submitted to specified refs.")-public class IfSubmitToSpecifiedRefs extends AbstractGateKeeper {-- private String refMatch;-- @Editable(name="Refs", description="Specify refs to match")- @RefMatch- @NotEmpty- public String getRefMatch() {- return refMatch;- }-- public void setRefMatch(String refMatch) {- this.refMatch = refMatch;- }-- @Override- public CheckResult doCheckRequest(PullRequest request) {- return checkRef(request.getTargetDepot(), request.getTargetRef());- }-- private CheckResult checkRef(Depot depot, String refName) {- if (RefMatchUtils.matches(refMatch, refName))- return passed(Lists.newArrayList("Target ref matches '" + refMatch + "'."));- else- return failed(Lists.newArrayList("Target ref does not match '" + refMatch + "'."));- }-- @Override- protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {- return checkRef(depot, GitUtils.branch2ref(branch));- }-- @Override- protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {- return checkRef(depot, refName);- }--}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 378c44d0a5..0b16f42cb4 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@@ -10,7 +10,7 @@ import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=300, icon="fa-user", category=GateKeeper.CATEGROY_CHECK_SUBMITTER, description=+@Editable(order=300, icon="fa-user", category=GateKeeper.CATEGORY_CHECK_SUBMITTER, description="This gate keeper will be passed if the commit is submitted by owner of the repository.")public class IfSubmittedByRepositoryOwner extends AbstractGateKeeper {diff --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 e19b9cdcbe..b8e11dc5a2 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@@ -11,7 +11,7 @@ import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.permission.ObjectPermission;@SuppressWarnings("serial")-@Editable(order=50, icon="fa-group", category=GateKeeper.CATEGROY_CHECK_SUBMITTER, description=+@Editable(order=50, icon="fa-group", category=GateKeeper.CATEGORY_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 AbstractGateKeeper {diff --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 02b640a291..6006d29c58 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@@ -11,7 +11,7 @@ import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=100, icon="fa-group", category=GateKeeper.CATEGROY_CHECK_SUBMITTER, description=+@Editable(order=100, icon="fa-group", category=GateKeeper.CATEGORY_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 {diff --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 78f0a07322..60545338f5 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@@ -15,7 +15,7 @@ import com.pmease.gitplex.core.model.User;import com.pmease.gitplex.core.util.editable.UserChoice;@SuppressWarnings("serial")-@Editable(order=200, icon="fa-user", category=GateKeeper.CATEGROY_CHECK_SUBMITTER, description=+@Editable(order=200, icon="fa-user", category=GateKeeper.CATEGORY_CHECK_SUBMITTER, description="This gate keeper will be passed if the commit is submitted by specified user.")public class IfSubmittedBySpecifiedUser extends AbstractGateKeeper {diff --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 63889f16e5..c2f8336a70 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@@ -1,65 +1,65 @@-package com.pmease.gitplex.core.gatekeeper;--import javax.validation.Valid;-import javax.validation.constraints.NotNull;--import com.pmease.commons.wicket.editable.annotation.Editable;-import com.pmease.commons.wicket.editable.annotation.Horizontal;-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.Passed;-import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;--@SuppressWarnings("serial")-@Editable(name="If...Then... Composition", order=300, icon="fa-sitemap",- category=GateKeeper.CATEGROY_COMPOSITION,- description="If first gate keeper is passed, then go ahead to check second gate keeper;")-@Horizontal-public class IfThenGateKeeper extends CompositeGateKeeper {-- private GateKeeper ifGate = new DefaultGateKeeper();-- private GateKeeper thenGate = new DefaultGateKeeper();-- @Valid- @NotNull- public GateKeeper getIfGate() {- return ifGate;- }-- public void setIfGate(GateKeeper ifGate) {- this.ifGate = ifGate;- }-- @Valid- @NotNull- public GateKeeper getThenGate() {- return thenGate;- }-- public void setThenGate(GateKeeper thenGate) {- this.thenGate = thenGate;- }-- @Override- protected CheckResult aggregate(Checker checker) {- CheckResult ifResult = checker.check(getIfGate());- if (ifResult instanceof Passed) {- return checker.check(getThenGate());- } else if (ifResult instanceof Failed) {- return passed(ifResult.getReasons());- } else if (ifResult instanceof Blocking) {- return ifResult;- } else if (ifResult instanceof Pending) {- CheckResult thenResult = checker.check(getThenGate());- if (thenResult instanceof Passed)- return thenResult;- else- return ifResult;- } else {- return ifResult;- }- }--}+package com.pmease.gitplex.core.gatekeeper;++import javax.validation.Valid;+import javax.validation.constraints.NotNull;++import com.pmease.commons.wicket.editable.annotation.Editable;+import com.pmease.commons.wicket.editable.annotation.Horizontal;+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.Passed;+import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;++@SuppressWarnings("serial")+@Editable(name="If...Then... Composition", order=300, icon="fa-sitemap",+ category=GateKeeper.CATEGORY_COMPOSITION,+ description="If first gate keeper is passed, then go ahead to check second gate keeper;")+@Horizontal+public class IfThenGateKeeper extends CompositeGateKeeper {++ private GateKeeper ifGate = new DefaultGateKeeper();++ private GateKeeper thenGate = new DefaultGateKeeper();++ @Valid+ @NotNull+ public GateKeeper getIfGate() {+ return ifGate;+ }++ public void setIfGate(GateKeeper ifGate) {+ this.ifGate = ifGate;+ }++ @Valid+ @NotNull+ public GateKeeper getThenGate() {+ return thenGate;+ }++ public void setThenGate(GateKeeper thenGate) {+ this.thenGate = thenGate;+ }++ @Override+ protected CheckResult aggregate(Checker checker) {+ CheckResult ifResult = checker.check(getIfGate());+ if (ifResult instanceof Passed) {+ return checker.check(getThenGate());+ } else if (ifResult instanceof Failed) {+ return passed(ifResult.getReasons());+ } else if (ifResult instanceof Blocking) {+ return ifResult;+ } else if (ifResult instanceof Pending) {+ CheckResult thenResult = checker.check(getThenGate());+ if (thenResult instanceof Passed)+ return thenResult;+ else+ return ifResult;+ } else {+ return ifResult;+ }+ }++}diff --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 afd7590d35..bb11259f0e 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@@ -13,7 +13,7 @@ import com.pmease.gitplex.core.model.PullRequestUpdate;import com.pmease.gitplex.core.model.User;@SuppressWarnings("serial")-@Editable(order=100, icon="fa-file-text", category=GateKeeper.CATEGROY_CHECK_FILES, description=+@Editable(order=100, icon="fa-file-text", category=GateKeeper.CATEGORY_CHECK_FILES, description="This gate keeper will be passed if any commit file maches specified file patterns.")public class IfTouchSpecifiedFilePatterns extends AbstractGateKeeper {diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedRefs.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedRefs.javanew file mode 100644index 0000000000..63d22a06d3--- /dev/null+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/gatekeeper/IfTouchSpecifiedRefs.java@@ -0,0 +1,134 @@+package com.pmease.gitplex.core.gatekeeper;++import javax.validation.ConstraintValidatorContext;++import org.eclipse.jgit.lib.ObjectId;+import org.hibernate.validator.constraints.NotEmpty;++import com.google.common.collect.Lists;+import com.pmease.commons.git.GitUtils;+import com.pmease.commons.validation.ClassValidating;+import com.pmease.commons.validation.Validatable;+import com.pmease.commons.wicket.editable.annotation.Editable;+import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;+import com.pmease.gitplex.core.model.Depot;+import com.pmease.gitplex.core.model.PullRequest;+import com.pmease.gitplex.core.model.User;+import com.pmease.gitplex.core.util.editable.RefMatch;+import com.pmease.gitplex.core.util.refmatch.RefMatchUtils;++@SuppressWarnings("serial")+@ClassValidating+@Editable(order=100, icon="fa-ext fa-branch", category=GateKeeper.CATEGORY_CHECK_REFS, description=+ "This gate keeper will be passed if specified refs is being changed with specified operations.")+public class IfTouchSpecifiedRefs extends AbstractGateKeeper implements Validatable {++ private String refMatch;++ private boolean onCreate;++ private boolean onUpdate;++ private boolean onDelete;++ @Editable(name="Refs", order=100, description="Specify refs to match")+ @RefMatch+ @NotEmpty+ public String getRefMatch() {+ return refMatch;+ }++ public void setRefMatch(String refMatch) {+ this.refMatch = refMatch;+ }++ @Editable(name="On Create", order=200, description="If checked, this gate keeper will "+ + "be passed if someone tries to create specified refs.")+ public boolean isOnCreate() {+ return onCreate;+ }++ public void setOnCreate(boolean onCreate) {+ this.onCreate = onCreate;+ }++ @Editable(name="On Update", order=300, description="If checked, this gate keeper will "+ + "be passed if someone tries to update specified refs.")+ public boolean isOnUpdate() {+ return onUpdate;+ }++ public void setOnUpdate(boolean onUpdate) {+ this.onUpdate = onUpdate;+ }++ @Editable(name="On Delete", order=400, description="If checked, this gate keeper will "+ + "be passed if someone tries to delete specified refs.")+ public boolean isOnDelete() {+ return onDelete;+ }++ public void setOnDelete(boolean onDelete) {+ this.onDelete = onDelete;+ }++ @Override+ public CheckResult doCheckRequest(PullRequest request) {+ if (RefMatchUtils.matches(refMatch, request.getTargetRef())) {+ if (onUpdate)+ return passed(Lists.newArrayList("Ref being updated matches '" + refMatch + "'."));+ else+ return failed(Lists.newArrayList("Ref being updated matches '" + refMatch + "', but operation is not 'update'."));+ } else {+ return failed(Lists.newArrayList("Ref does not match '" + refMatch + "'."));+ }+ }++ @Override+ protected CheckResult doCheckFile(User user, Depot depot, String branch, String file) {+ if (RefMatchUtils.matches(refMatch, GitUtils.branch2ref(branch))) {+ if (onUpdate)+ return passed(Lists.newArrayList("Ref being updated matches '" + refMatch + "'."));+ else+ return failed(Lists.newArrayList("Ref matches '" + refMatch + "', but operation is not 'update'."));+ } else {+ return failed(Lists.newArrayList("Target ref does not match '" + refMatch + "'."));+ }+ }++ @Override+ protected CheckResult doCheckPush(User user, Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {+ if (RefMatchUtils.matches(refMatch, refName)) {+ if (oldCommit.equals(ObjectId.zeroId())) {+ if (onCreate)+ return passed(Lists.newArrayList("Ref being created matches '" + refMatch + "'."));+ else+ return failed(Lists.newArrayList("Ref matches '" + refMatch + "', but operation is not 'create'."));+ } else if (newCommit.equals(ObjectId.zeroId())) {+ if (onDelete)+ return passed(Lists.newArrayList("Ref being deleted matches '" + refMatch + "'."));+ else+ return failed(Lists.newArrayList("Ref matches '" + refMatch + "', but operation is not 'delete'."));+ } else {+ if (onUpdate)+ return passed(Lists.newArrayList("Ref being updated matches '" + refMatch + "'."));+ else+ return failed(Lists.newArrayList("Ref matches '" + refMatch + "', but operation is not 'update'."));+ }+ } else {+ return failed(Lists.newArrayList("Ref does not match '" + refMatch + "'."));+ }+ }++ @Override+ public boolean isValid(ConstraintValidatorContext context) {+ if (!onCreate && !onUpdate && !onDelete) {+ context.disableDefaultConstraintViolation();+ context.buildConstraintViolationWithTemplate("Please select at least one operation to check").addConstraintViolation();+ return false;+ } else {+ return true;+ }+ }++}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 74ade12b4e..a952ee02e7 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,7 @@ import com.pmease.gitplex.core.gatekeeper.checkresult.Passed;import com.pmease.gitplex.core.model.Depot;@SuppressWarnings("serial")-@Editable(name="Not Composition", order=400, icon="fa-sitemap", category=GateKeeper.CATEGROY_COMPOSITION,+@Editable(name="Not Composition", order=400, icon="fa-sitemap", category=GateKeeper.CATEGORY_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 6a6f243d3f..336b83767a 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@@ -1,45 +1,45 @@-package com.pmease.gitplex.core.gatekeeper;--import java.util.ArrayList;-import java.util.List;--import com.pmease.commons.wicket.editable.annotation.Editable;-import com.pmease.commons.wicket.editable.annotation.Horizontal;-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.Passed;-import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;--@SuppressWarnings("serial")-@Editable(name="Or Composition", order=200, icon="fa-sitemap", category=GateKeeper.CATEGROY_COMPOSITION,- description="This gate keeper will be passed if any of the contained gate keepers is passed.")-@Horizontal-public class OrGateKeeper extends AndOrGateKeeper {-- @Override- protected CheckResult aggregate(Checker checker) {- List<String> pendingReasons = new ArrayList<String>();- List<String> rejectReasons = new ArrayList<String>();-- for (GateKeeper each: getGateKeepers()) {- CheckResult result = checker.check(each);- if (result instanceof Failed) {- rejectReasons.addAll(result.getReasons());- } else if (result instanceof Passed) {- return result;- } else if (result instanceof Blocking) {- result.getReasons().addAll(pendingReasons);- return result;- } else if (result instanceof Pending) {- pendingReasons.addAll(result.getReasons());- }- }-- if (!pendingReasons.isEmpty())- return pending(pendingReasons);- else- return failed(rejectReasons);- }--}+package com.pmease.gitplex.core.gatekeeper;++import java.util.ArrayList;+import java.util.List;++import com.pmease.commons.wicket.editable.annotation.Editable;+import com.pmease.commons.wicket.editable.annotation.Horizontal;+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.Passed;+import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;++@SuppressWarnings("serial")+@Editable(name="Or Composition", order=200, icon="fa-sitemap", category=GateKeeper.CATEGORY_COMPOSITION,+ description="This gate keeper will be passed if any of the contained gate keepers is passed.")+@Horizontal+public class OrGateKeeper extends AndOrGateKeeper {++ @Override+ protected CheckResult aggregate(Checker checker) {+ List<String> pendingReasons = new ArrayList<String>();+ List<String> rejectReasons = new ArrayList<String>();++ for (GateKeeper each: getGateKeepers()) {+ CheckResult result = checker.check(each);+ if (result instanceof Failed) {+ rejectReasons.addAll(result.getReasons());+ } else if (result instanceof Passed) {+ return result;+ } else if (result instanceof Blocking) {+ result.getReasons().addAll(pendingReasons);+ return result;+ } else if (result instanceof Pending) {+ pendingReasons.addAll(result.getReasons());+ }+ }++ if (!pendingReasons.isEmpty())+ return pending(pendingReasons);+ else+ return failed(rejectReasons);+ }++}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.htmlindex 137eae169b..b416dabc6a 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.html+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.html@@ -8,6 +8,7 @@<div wicket:id="description" class="gate-keeper-description"></div></div><form wicket:id="form">+ <div wicket:id="feedback" class="feedback"></div><div wicket:id="beanEditor" class="modal-body"></div><div class="modal-footer"><a wicket:id="cancel" class="btn btn-default">Cancel</a>diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.javaindex 24521d2b00..6f4b085435 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperEditor.java@@ -14,6 +14,8 @@ import com.pmease.commons.wicket.editable.BeanContext;import com.pmease.commons.wicket.editable.EditableUtils;import com.pmease.gitplex.core.gatekeeper.GateKeeper;+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;+@SuppressWarnings("serial")public abstract class GateKeeperEditor extends Panel {@@ -37,6 +39,7 @@ public abstract class GateKeeperEditor extends Panel {Form<?> form = new Form<Void>("form");add(form);+ form.add(new NotificationPanel("feedback", form));form.add(BeanContext.editBean("beanEditor", gateKeeper));form.add(new AjaxLink<Void>("cancel") {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperSelector.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperSelector.javaindex 71d0eef100..408a1ae580 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperSelector.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/GateKeeperSelector.java@@ -38,12 +38,13 @@ public abstract class GateKeeperSelector extends Panel {super.onInitialize();final Map<String, List<Class<?>>> gateKeeperClasses = new LinkedHashMap<>();- gateKeeperClasses.put(GateKeeper.CATEGROY_CHECK_REFS, 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_OTHERS, new ArrayList<Class<?>>());- gateKeeperClasses.put(GateKeeper.CATEGROY_COMPOSITION, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGORY_CHECK_REFS, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGORY_CHECK_FILES, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGORY_CHECK_OPERATIONS, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGORY_CHECK_APPROVALS, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGORY_CHECK_SUBMITTER, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGORY_OTHERS, new ArrayList<Class<?>>());+ gateKeeperClasses.put(GateKeeper.CATEGORY_COMPOSITION, new ArrayList<Class<?>>());List<Class<?>> implementations = new ArrayList<>();for (Class<?> clazz: GitPlex.getInstance(ImplementationRegistry.class).getImplementations(GateKeeper.class))@@ -68,7 +69,7 @@ public abstract class GateKeeperSelector extends Panel {}}if (categoryClasses == null)- categoryClasses = gateKeeperClasses.get(GateKeeper.CATEGROY_OTHERS);+ categoryClasses = gateKeeperClasses.get(GateKeeper.CATEGORY_OTHERS);categoryClasses.add(implementation);}diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/gate-keeper.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/gate-keeper.cssindex fb6710a58c..e613e4cbd0 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/gate-keeper.css+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/setting/gatekeeper/gate-keeper.css@@ -71,6 +71,12 @@margin-right: 8px;margin-top: 4px;}+.gate-keeper-editor form>.feedback {+ margin: 20px 16px -16px 16px;+}+.gate-keeper-editor form>.feedback .alert {+ margin-bottom: 0;+}.gate-keeper .panel-title {font-size: 14px;}