Skip to content

The Unified and Autonomous Development Platform

Gatekeeper removal, branch/tag protection, and more

robin shen448e63476005
diff --git a/core/src/main/java/com/gitplex/server/CoreModule.java b/core/src/main/java/com/gitplex/server/CoreModule.java
index ddc274d28b..cf092df268 100644
--- a/core/src/main/java/com/gitplex/server/CoreModule.java
+++ b/core/src/main/java/com/gitplex/server/CoreModule.java
@@ -70,12 +70,11 @@ import com.gitplex.server.manager.PullRequestCommentManager;
import com.gitplex.server.manager.PullRequestInfoManager;
import com.gitplex.server.manager.PullRequestManager;
import com.gitplex.server.manager.PullRequestReferenceManager;
-import com.gitplex.server.manager.PullRequestReviewInvitationManager;
-import com.gitplex.server.manager.PullRequestReviewManager;
+import com.gitplex.server.manager.ReviewInvitationManager;
+import com.gitplex.server.manager.ReviewManager;
import com.gitplex.server.manager.PullRequestStatusChangeManager;
import com.gitplex.server.manager.PullRequestTaskManager;
import com.gitplex.server.manager.PullRequestUpdateManager;
-import com.gitplex.server.manager.PullRequestVerificationManager;
import com.gitplex.server.manager.PullRequestWatchManager;
import com.gitplex.server.manager.StorageManager;
import com.gitplex.server.manager.TeamAuthorizationManager;
@@ -104,12 +103,11 @@ import com.gitplex.server.manager.impl.DefaultPullRequestCommentManager;
import com.gitplex.server.manager.impl.DefaultPullRequestInfoManager;
import com.gitplex.server.manager.impl.DefaultPullRequestManager;
import com.gitplex.server.manager.impl.DefaultPullRequestReferenceManager;
-import com.gitplex.server.manager.impl.DefaultPullRequestReviewInvitationManager;
-import com.gitplex.server.manager.impl.DefaultPullRequestReviewManager;
+import com.gitplex.server.manager.impl.DefaultReviewInvitationManager;
+import com.gitplex.server.manager.impl.DefaultReviewManager;
import com.gitplex.server.manager.impl.DefaultPullRequestStatusChangeManager;
import com.gitplex.server.manager.impl.DefaultPullRequestTaskManager;
import com.gitplex.server.manager.impl.DefaultPullRequestUpdateManager;
-import com.gitplex.server.manager.impl.DefaultPullRequestVerificationManager;
import com.gitplex.server.manager.impl.DefaultPullRequestWatchManager;
import com.gitplex.server.manager.impl.DefaultStorageManager;
import com.gitplex.server.manager.impl.DefaultTeamAuthorizationManager;
@@ -253,9 +251,8 @@ public class CoreModule extends AbstractPluginModule {
bind(PullRequestUpdateManager.class).to(DefaultPullRequestUpdateManager.class);
bind(DepotManager.class).to(DefaultDepotManager.class);
bind(AccountManager.class).to(DefaultAccountManager.class);
- bind(PullRequestVerificationManager.class).to(DefaultPullRequestVerificationManager.class);
- bind(PullRequestReviewInvitationManager.class).to(DefaultPullRequestReviewInvitationManager.class);
- bind(PullRequestReviewManager.class).to(DefaultPullRequestReviewManager.class);
+ bind(ReviewInvitationManager.class).to(DefaultReviewInvitationManager.class);
+ bind(ReviewManager.class).to(DefaultReviewManager.class);
bind(MailManager.class).to(DefaultMailManager.class);
bind(BranchWatchManager.class).to(DefaultBranchWatchManager.class);
bind(PullRequestTaskManager.class).to(DefaultPullRequestTaskManager.class);
diff --git a/core/src/main/java/com/gitplex/server/GitPlex.java b/core/src/main/java/com/gitplex/server/GitPlex.java
index 031d72067c..1a740d88b6 100644
--- a/core/src/main/java/com/gitplex/server/GitPlex.java
+++ b/core/src/main/java/com/gitplex/server/GitPlex.java
@@ -41,6 +41,8 @@ import com.gitplex.server.util.serverconfig.ServerConfig;
public class GitPlex extends AbstractPlugin implements Serializable {
+ public static final String NAME = "GitPlex";
+
private static final Logger logger = LoggerFactory.getLogger(GitPlex.class);
private static final Pattern DOCLINK_PATTERN = Pattern.compile("\\d+\\.\\d+");
diff --git a/core/src/main/java/com/gitplex/server/event/ReviewInvitationChanged.java b/core/src/main/java/com/gitplex/server/event/ReviewInvitationChanged.java
new file mode 100644
index 0000000000..42db8f6630
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/event/ReviewInvitationChanged.java
@@ -0,0 +1,17 @@
+package com.gitplex.server.event;
+
+import com.gitplex.server.model.ReviewInvitation;
+
+public class ReviewInvitationChanged {
+
+ private final ReviewInvitation invitation;
+
+ public ReviewInvitationChanged(ReviewInvitation invitation) {
+ this.invitation = invitation;
+ }
+
+ public ReviewInvitation getInvitation() {
+ return invitation;
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/event/TaskChangeEvent.java b/core/src/main/java/com/gitplex/server/event/TaskChanged.java
similarity index 71%
rename from core/src/main/java/com/gitplex/server/event/TaskChangeEvent.java
rename to core/src/main/java/com/gitplex/server/event/TaskChanged.java
index 0cf3ea466c..c183cc10bd 100644
--- a/core/src/main/java/com/gitplex/server/event/TaskChangeEvent.java
+++ b/core/src/main/java/com/gitplex/server/event/TaskChanged.java
@@ -2,11 +2,11 @@ package com.gitplex.server.event;
import com.gitplex.server.model.Account;
-public class TaskChangeEvent {
+public class TaskChanged {
private Long userId;
- public TaskChangeEvent(Account user) {
+ public TaskChanged(Account user) {
userId = user.getId();
}
diff --git a/core/src/main/java/com/gitplex/server/event/codecomment/CodeCommentEvent.java b/core/src/main/java/com/gitplex/server/event/codecomment/CodeCommentEvent.java
index d189113ef7..8184ee6bf3 100644
--- a/core/src/main/java/com/gitplex/server/event/codecomment/CodeCommentEvent.java
+++ b/core/src/main/java/com/gitplex/server/event/codecomment/CodeCommentEvent.java
@@ -2,6 +2,8 @@ package com.gitplex.server.event.codecomment;
import java.util.Date;
+import javax.annotation.Nullable;
+
import com.gitplex.server.event.MarkdownAware;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.CodeComment;
@@ -25,6 +27,7 @@ public abstract class CodeCommentEvent implements MarkdownAware {
return comment;
}
+ @Nullable
public abstract Account getUser();
public abstract Date getDate();
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/IntegrationPreviewCalculated.java b/core/src/main/java/com/gitplex/server/event/pullrequest/MergePreviewCalculated.java
similarity index 71%
rename from core/src/main/java/com/gitplex/server/event/pullrequest/IntegrationPreviewCalculated.java
rename to core/src/main/java/com/gitplex/server/event/pullrequest/MergePreviewCalculated.java
index 281c90416d..53ad0a1930 100644
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/IntegrationPreviewCalculated.java
+++ b/core/src/main/java/com/gitplex/server/event/pullrequest/MergePreviewCalculated.java
@@ -5,11 +5,11 @@ import java.util.Date;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.PullRequest;
-public class IntegrationPreviewCalculated extends PullRequestChangeEvent {
+public class MergePreviewCalculated extends PullRequestEvent {
private Date date;
- public IntegrationPreviewCalculated(PullRequest request) {
+ public MergePreviewCalculated(PullRequest request) {
super(request);
date = new Date();
}
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestChangeEvent.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestChangeEvent.java
deleted file mode 100644
index 3ca0ea7a07..0000000000
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestChangeEvent.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.gitplex.server.event.pullrequest;
-
-import java.util.Date;
-
-import javax.annotation.Nullable;
-
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.PullRequest;
-
-public abstract class PullRequestChangeEvent extends PullRequestEvent {
-
- public PullRequestChangeEvent(PullRequest request) {
- super(request);
- }
-
- @Nullable
- public abstract Account getUser();
-
- public abstract Date getDate();
-
-}
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestCodeCommentEvent.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestCodeCommentEvent.java
index 320f2a2545..551bc8b759 100644
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestCodeCommentEvent.java
+++ b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestCodeCommentEvent.java
@@ -4,7 +4,7 @@ import com.gitplex.server.event.MarkdownAware;
import com.gitplex.server.model.CodeComment;
import com.gitplex.server.model.PullRequest;
-public abstract class PullRequestCodeCommentEvent extends PullRequestChangeEvent implements MarkdownAware {
+public abstract class PullRequestCodeCommentEvent extends PullRequestEvent implements MarkdownAware {
private final CodeComment comment;
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestCommentCreated.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestCommentCreated.java
index e2838bc7cf..c72d9e365c 100644
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestCommentCreated.java
+++ b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestCommentCreated.java
@@ -8,7 +8,7 @@ import com.gitplex.server.model.PullRequestComment;
import com.gitplex.server.util.editable.annotation.Editable;
@Editable(name="commented")
-public class PullRequestCommentCreated extends PullRequestChangeEvent implements MarkdownAware {
+public class PullRequestCommentCreated extends PullRequestEvent implements MarkdownAware {
private final PullRequestComment comment;
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestEvent.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestEvent.java
index b6f96e5fb5..2e4cdc683b 100644
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestEvent.java
+++ b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestEvent.java
@@ -1,5 +1,10 @@
package com.gitplex.server.event.pullrequest;
+import java.util.Date;
+
+import javax.annotation.Nullable;
+
+import com.gitplex.server.model.Account;
import com.gitplex.server.model.PullRequest;
public abstract class PullRequestEvent {
@@ -14,4 +19,9 @@ public abstract class PullRequestEvent {
return request;
}
+ @Nullable
+ public abstract Account getUser();
+
+ public abstract Date getDate();
+
}
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestOpened.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestOpened.java
index b4d89e8229..fbfaf75262 100644
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestOpened.java
+++ b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestOpened.java
@@ -8,7 +8,7 @@ import com.gitplex.server.model.PullRequest;
import com.gitplex.server.util.editable.annotation.Editable;
@Editable(name="opened")
-public class PullRequestOpened extends PullRequestChangeEvent implements MarkdownAware {
+public class PullRequestOpened extends PullRequestEvent implements MarkdownAware {
public PullRequestOpened(PullRequest request) {
super(request);
@@ -21,7 +21,7 @@ public class PullRequestOpened extends PullRequestChangeEvent implements Markdow
@Override
public Account getUser() {
- return getRequest().getSubmitter();
+ return Account.getForDisplay(getRequest().getSubmitter(), getRequest().getSubmitterName());
}
@Override
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestPendingApproval.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestPendingApproval.java
deleted file mode 100644
index 12694b8bdd..0000000000
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestPendingApproval.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.gitplex.server.event.pullrequest;
-
-import com.gitplex.server.model.PullRequest;
-
-public class PullRequestPendingApproval extends PullRequestEvent {
-
- public PullRequestPendingApproval(PullRequest request) {
- super(request);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestPendingIntegration.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestPendingIntegration.java
deleted file mode 100644
index c81fefeeef..0000000000
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestPendingIntegration.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.gitplex.server.event.pullrequest;
-
-import com.gitplex.server.model.PullRequest;
-
-public class PullRequestPendingIntegration extends PullRequestEvent {
-
- public PullRequestPendingIntegration(PullRequest request) {
- super(request);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestPendingUpdate.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestPendingUpdate.java
deleted file mode 100644
index f774f49443..0000000000
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestPendingUpdate.java
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.gitplex.server.event.pullrequest;
-
-import com.gitplex.server.model.PullRequest;
-
-public class PullRequestPendingUpdate extends PullRequestEvent {
-
- public PullRequestPendingUpdate(PullRequest request) {
- super(request);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestReviewInvitationChanged.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestReviewInvitationChanged.java
deleted file mode 100644
index 970e2a9ecb..0000000000
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestReviewInvitationChanged.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.gitplex.server.event.pullrequest;
-
-import com.gitplex.server.model.PullRequestReviewInvitation;
-
-public class PullRequestReviewInvitationChanged extends PullRequestEvent {
-
- private final PullRequestReviewInvitation invitation;
-
- public PullRequestReviewInvitationChanged(PullRequestReviewInvitation invitation) {
- super(invitation.getRequest());
- this.invitation = invitation;
- }
-
- public PullRequestReviewInvitation getInvitation() {
- return invitation;
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestStatusChangeEvent.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestStatusChangeEvent.java
index b98b725976..3dbfaa93d9 100644
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestStatusChangeEvent.java
+++ b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestStatusChangeEvent.java
@@ -6,7 +6,7 @@ import com.gitplex.server.event.MarkdownAware;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.PullRequestStatusChange;
-public class PullRequestStatusChangeEvent extends PullRequestChangeEvent implements MarkdownAware {
+public class PullRequestStatusChangeEvent extends PullRequestEvent implements MarkdownAware {
private final PullRequestStatusChange statusChange;
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestUpdated.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestUpdated.java
index 1ac0196aac..ba171bbe1e 100644
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestUpdated.java
+++ b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestUpdated.java
@@ -7,7 +7,7 @@ import com.gitplex.server.model.PullRequestUpdate;
import com.gitplex.server.util.editable.annotation.Editable;
@Editable(name="has new commits")
-public class PullRequestUpdated extends PullRequestChangeEvent {
+public class PullRequestUpdated extends PullRequestEvent {
private final PullRequestUpdate update;
diff --git a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestVerificationRunning.java b/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestVerificationRunning.java
deleted file mode 100644
index 4c383f9ec0..0000000000
--- a/core/src/main/java/com/gitplex/server/event/pullrequest/PullRequestVerificationRunning.java
+++ /dev/null
@@ -1,33 +0,0 @@
-package com.gitplex.server.event.pullrequest;
-
-import java.util.Date;
-
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.PullRequestVerification;
-import com.gitplex.server.util.editable.annotation.Editable;
-
-@Editable(name="ran verification", icon="fa fa-cog")
-public class PullRequestVerificationRunning extends PullRequestChangeEvent {
-
- private final PullRequestVerification verification;
-
- public PullRequestVerificationRunning(PullRequestVerification verification) {
- super(verification.getRequest());
- this.verification = verification;
- }
-
- public PullRequestVerification getVerification() {
- return verification;
- }
-
- @Override
- public Account getUser() {
- return verification.getUser();
- }
-
- @Override
- public Date getDate() {
- return verification.getDate();
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/AbstractGateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/AbstractGateKeeper.java
deleted file mode 100644
index 114b7d842e..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/AbstractGateKeeper.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.List;
-
-import javax.annotation.Nullable;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.gitplex.server.gatekeeper.checkresult.Failed;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.gatekeeper.checkresult.Ignored;
-import com.gitplex.server.gatekeeper.checkresult.Passed;
-import com.gitplex.server.gatekeeper.checkresult.Pending;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.editable.annotation.Editable;
-
-@Editable
-public abstract class AbstractGateKeeper implements GateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private boolean enabled = true;
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- @Override
- public GateCheckResult checkRequest(PullRequest request) {
- if (enabled)
- return doCheckRequest(request);
- else
- return ignored();
- }
-
- @Override
- public GateCheckResult checkFile(Account user, Depot depot, String branch, String file) {
- if (isEnabled())
- return doCheckFile(user, depot, branch, file);
- else
- return ignored();
- }
-
- @Override
- public GateCheckResult checkPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- if (isEnabled())
- return doCheckPush(user, depot, refName, oldObjectId, newObjectId);
- else
- return ignored();
- }
-
- /**
- * Check gatekeeper against specified pull request without considering enable flag. This is
- * typically used to determine whether or not to accept a pull request.
- *
- * @param request
- * pull request to be checked
- * @return
- * result of the check
- */
- protected abstract GateCheckResult doCheckRequest(PullRequest request);
-
- /**
- * Check if specified user can modify specified file in specified branch, without considering enable flag.
- *
- * @param user
- * user to be checked
- * @param branch
- * branch to be checked
- * @param file
- * file to be checked
- * @return
- * result of the check
- */
- protected abstract GateCheckResult doCheckFile(Account user, Depot depot, String branch, @Nullable String file);
-
- /**
- * Check if specified user can push specified commit to specified branch, without considering enable flag.
- *
- * @param user
- * user to be checked
- * @param branch
- * branch to be checked
- * @param commit
- * commit to be checked
- * @return
- * result of the check
- */
- protected abstract GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId);
-
- protected GateCheckResult ignored() {
- return new Ignored();
- }
-
- protected GateCheckResult passed(List<String> reasons) {
- return new Passed(reasons);
- }
-
- protected GateCheckResult failed(List<String> reasons) {
- return new Failed(reasons);
- }
-
- protected GateCheckResult pending(List<String> reasons) {
- return new Pending(reasons);
- }
-
- @Override
- public void onDepotRename(Depot renamedDepot, String oldName) {
- }
-
- @Override
- public boolean onDepotTransfer(Depot depotDefiningGateKeeper, Depot transferredDepot,
- Account originalAccount) {
- return false;
- }
-
- @Override
- public void onAccountRename(String oldName, String newName) {
- }
-
- @Override
- public boolean onAccountDelete(String accountName) {
- return false;
- }
-
- @Override
- public boolean onDepotDelete(Depot depot) {
- return false;
- }
-
- @Override
- public void onTeamRename(String oldName, String newName) {
- }
-
- @Override
- public boolean onTeamDelete(String teamName) {
- return false;
- }
-
- @Override
- public boolean onRefDelete(String refName) {
- return false;
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/AndGateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/AndGateKeeper.java
deleted file mode 100644
index 1186be6172..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/AndGateKeeper.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.gitplex.server.gatekeeper.checkresult.Failed;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.gatekeeper.checkresult.Passed;
-import com.gitplex.server.gatekeeper.checkresult.Pending;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.gitplex.server.util.editable.annotation.Horizontal;
-
-@Editable(name="And Composition", icon="fa-object-group", order=100,
- category=GateKeeper.CATEGORY_COMPOSITION,
- description="This gatekeeper will be passed if all contained child gatekeepers are passed")
-@Horizontal
-public class AndGateKeeper extends AndOrGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected GateCheckResult aggregate(Checker checker) {
- List<String> pendingReasons = new ArrayList<String>();
- List<String> acceptReasons = new ArrayList<String>();
-
- for (GateKeeper each: getGateKeepers()) {
- GateCheckResult result = checker.check(each);
- if (result instanceof Passed) {
- acceptReasons.addAll(result.getReasons());
- } else if (result instanceof Failed) {
- return result;
- } else if (result instanceof Pending) {
- pendingReasons.addAll(result.getReasons());
- }
- }
-
- if (!pendingReasons.isEmpty())
- return pending(pendingReasons);
- else
- return passed(acceptReasons);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/AndOrGateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/AndOrGateKeeper.java
deleted file mode 100644
index 2a91d6842d..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/AndOrGateKeeper.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-
-public abstract class AndOrGateKeeper extends CompositeGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private List<GateKeeper> gateKeepers = new ArrayList<GateKeeper>();
-
- public void setGateKeepers(List<GateKeeper> gateKeepers) {
- this.gateKeepers = gateKeepers;
- }
-
- @Valid
- @NotNull
- public List<GateKeeper> getGateKeepers() {
- return gateKeepers;
- }
-
- @Override
- public void onAccountRename(String oldName, String newName) {
- for (GateKeeper gateKeeper: gateKeepers)
- gateKeeper.onAccountRename(oldName, newName);
- }
-
- @Override
- public boolean onAccountDelete(String accountName) {
- for (Iterator<GateKeeper> it = gateKeepers.iterator(); it.hasNext();) {
- if (it.next().onAccountDelete(accountName))
- it.remove();
- }
- return gateKeepers.isEmpty();
- }
-
- @Override
- public void onDepotRename(Depot renamedDepot, String oldName) {
- for (GateKeeper gateKeeper: gateKeepers)
- gateKeeper.onDepotRename(renamedDepot, oldName);
- }
-
- @Override
- public boolean onDepotTransfer(Depot depotDefiningGateKeeper, Depot transferredDepot,
- Account originalAccount) {
- for (Iterator<GateKeeper> it = gateKeepers.iterator(); it.hasNext();) {
- if (it.next().onDepotTransfer(depotDefiningGateKeeper, transferredDepot, originalAccount))
- it.remove();
- }
- return gateKeepers.isEmpty();
- }
-
- @Override
- public boolean onDepotDelete(Depot depot) {
- for (Iterator<GateKeeper> it = gateKeepers.iterator(); it.hasNext();) {
- if (it.next().onDepotDelete(depot))
- it.remove();
- }
- return gateKeepers.isEmpty();
- }
-
- @Override
- public void onTeamRename(String oldName, String newName) {
- for (GateKeeper gateKeeper: gateKeepers)
- gateKeeper.onTeamRename(oldName, newName);
- }
-
- @Override
- public boolean onTeamDelete(String teamName) {
- for (Iterator<GateKeeper> it = gateKeepers.iterator(); it.hasNext();) {
- if (it.next().onTeamDelete(teamName))
- it.remove();
- }
- return gateKeepers.isEmpty();
- }
-
- @Override
- public boolean onRefDelete(String refName) {
- for (Iterator<GateKeeper> it = gateKeepers.iterator(); it.hasNext();) {
- if (it.next().onRefDelete(refName))
- it.remove();
- }
- return gateKeepers.isEmpty();
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/ApprovedBySpecifiedTeam.java b/core/src/main/java/com/gitplex/server/gatekeeper/ApprovedBySpecifiedTeam.java
deleted file mode 100644
index 8832039ada..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/ApprovedBySpecifiedTeam.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.Collection;
-
-import javax.validation.constraints.Min;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.google.common.collect.Lists;
-
-@Editable(order=100, icon="fa-group", category=GateKeeper.CATEGORY_USER, description=
- "This gatekeeper will be passed if the commit is approved by specified number of users "
- + "from specified team")
-public class ApprovedBySpecifiedTeam extends TeamAwareGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private int leastApprovals = 1;
-
- @Editable(name="Least Approvals Required", order=200)
- @Min(value = 1, message = "Least approvals should not be less than 1")
- public int getLeastApprovals() {
- return leastApprovals;
- }
-
- public void setLeastApprovals(int leastApprovals) {
- this.leastApprovals = leastApprovals;
- }
-
- @Override
- public GateCheckResult doCheckRequest(PullRequest request) {
- int approvals = 0;
- int pendings = 0;
-
- Collection<Account> members = getTeamMembers(request.getTargetDepot().getAccount());
- for (Account member: members) {
- PullRequestReview.Result result = member.checkReviewSince(request.getReferentialUpdate());
- if (result == null) {
- pendings++;
- } else if (result == PullRequestReview.Result.APPROVE) {
- approvals++;
- }
- }
-
- if (approvals >= getLeastApprovals()) {
- return passed(Lists.newArrayList("Approved by at least " + getLeastApprovals()
- + " member(s) of team " + getTeamName()));
- } else if (getLeastApprovals() - approvals > pendings) {
- return failed(Lists.newArrayList("Unable to get at least " + getLeastApprovals()
- + " approvals from team " + getTeamName()));
- } else {
- int lackApprovals = getLeastApprovals() - approvals;
-
- request.pickReviewers(members, lackApprovals);
-
- return pending(Lists.newArrayList("To be approved by " + lackApprovals
- + " member(s) from team " + getTeamName()));
- }
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- return pending(Lists.newArrayList("Need to be approved by at least " + getLeastApprovals()
- + " member(s) of team " + getTeamName()));
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return pending(Lists.newArrayList("Need to be approved by at least " + getLeastApprovals()
- + " member(s) of team " + getTeamName()));
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/ApprovedBySpecifiedUser.java b/core/src/main/java/com/gitplex/server/gatekeeper/ApprovedBySpecifiedUser.java
deleted file mode 100644
index a608c6154f..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/ApprovedBySpecifiedUser.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.manager.AccountManager;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.util.editable.annotation.AccountChoice;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
-@Editable(order=200, icon="fa-user", category=GateKeeper.CATEGORY_USER, description=
- "This gatekeeper will be passed if the commit is approved by specified user")
-public class ApprovedBySpecifiedUser extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private String userName;
-
- @Editable(name="Select User")
- @AccountChoice
- @NotEmpty
- public String getUserName() {
- return userName;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- @Override
- public GateCheckResult doCheckRequest(PullRequest request) {
- Account user = Preconditions.checkNotNull(GitPlex.getInstance(AccountManager.class).findByName(userName));
-
- PullRequestReview.Result result = user.checkReviewSince(request.getReferentialUpdate());
- if (result == null) {
- request.pickReviewers(Sets.newHashSet(user), 1);
-
- return pending(Lists.newArrayList("To be approved by " + user.getDisplayName()));
- } else if (result == PullRequestReview.Result.APPROVE) {
- return passed(Lists.newArrayList("Approved by " + user.getDisplayName()));
- } else {
- return failed(Lists.newArrayList("Disapproved by " + user.getDisplayName()));
- }
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- Account approveUser = Preconditions.checkNotNull(GitPlex.getInstance(AccountManager.class).findByName(userName));
- return pending(Lists.newArrayList("Need approval from " + approveUser.getDisplayName()));
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- Account approveUser = Preconditions.checkNotNull(GitPlex.getInstance(AccountManager.class).findByName(userName));
- return pending(Lists.newArrayList("Need approval from " + approveUser.getDisplayName()));
- }
-
- @Override
- public void onAccountRename(String oldName, String newName) {
- if (userName.equals(oldName))
- userName = newName;
- }
-
- @Override
- public boolean onAccountDelete(String accountName) {
- return userName.equals(accountName);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/CompositeGateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/CompositeGateKeeper.java
deleted file mode 100644
index bf46ad7b24..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/CompositeGateKeeper.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-
-public abstract class CompositeGateKeeper extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- public static interface Checker {
- GateCheckResult check(GateKeeper gateKeeper);
- }
-
- protected abstract GateCheckResult aggregate(Checker checker);
-
- @Override
- public GateCheckResult doCheckRequest(final PullRequest request) {
- return aggregate(new Checker() {
-
- @Override
- public GateCheckResult check(GateKeeper gateKeeper) {
- return gateKeeper.checkRequest(request);
- }
-
- });
- }
-
- @Override
- protected GateCheckResult doCheckFile(final Account user, final Depot depot, final String branch, final String file) {
- return aggregate(new Checker() {
-
- @Override
- public GateCheckResult check(GateKeeper gateKeeper) {
- return gateKeeper.checkFile(user, depot, branch, file);
- }
-
- });
- }
-
- @Override
- protected GateCheckResult doCheckPush(final Account user, final Depot depot, final String refName,
- final ObjectId oldObjectId, final ObjectId newObjectId) {
- return aggregate(new Checker() {
-
- @Override
- public GateCheckResult check(GateKeeper gateKeeper) {
- return gateKeeper.checkPush(user, depot, refName, oldObjectId, newObjectId);
- }
-
- });
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/ConditionalGateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/ConditionalGateKeeper.java
deleted file mode 100644
index 2896fd0c56..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/ConditionalGateKeeper.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-
-import com.gitplex.server.gatekeeper.checkresult.Failed;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.gatekeeper.checkresult.Passed;
-import com.gitplex.server.gatekeeper.checkresult.Pending;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.gitplex.server.util.editable.annotation.Horizontal;
-
-@Editable(name="Conditional Composition", order=300, icon="fa-object-group",
- category=GateKeeper.CATEGORY_COMPOSITION,
- description="If first gatekeeper is passed, then continue to check second gatekeeper; "
- + "otherwise consider the conditional composition as passed")
-@Horizontal
-public class ConditionalGateKeeper extends CompositeGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- 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 GateCheckResult aggregate(Checker checker) {
- GateCheckResult 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 Pending) {
- GateCheckResult thenResult = checker.check(getThenGate());
- if (thenResult instanceof Passed)
- return thenResult;
- else
- return ifResult;
- } else {
- return ifResult;
- }
- }
-
- @Override
- public void onDepotRename(Depot renamedDepot, String oldName) {
- ifGate.onDepotRename(renamedDepot, oldName);
- thenGate.onDepotRename(renamedDepot, oldName);
- }
-
- @Override
- public void onAccountRename(String oldName, String newName) {
- ifGate.onAccountRename(oldName, newName);
- thenGate.onAccountRename(oldName, newName);
- }
-
- @Override
- public boolean onDepotTransfer(Depot depotDefiningGateKeeper, Depot transferredDepot,
- Account originalAccount) {
- return ifGate.onDepotTransfer(depotDefiningGateKeeper, transferredDepot, originalAccount)
- || thenGate.onDepotTransfer(depotDefiningGateKeeper, transferredDepot, originalAccount);
- }
-
- @Override
- public boolean onAccountDelete(String accountName) {
- return ifGate.onAccountDelete(accountName) || thenGate.onAccountDelete(accountName);
- }
-
- @Override
- public boolean onDepotDelete(Depot depot) {
- return ifGate.onDepotDelete(depot) || thenGate.onDepotDelete(depot);
- }
-
- @Override
- public void onTeamRename(String oldName, String newName) {
- ifGate.onTeamRename(oldName, newName);
- thenGate.onTeamRename(oldName, newName);
- }
-
- @Override
- public boolean onTeamDelete(String teamName) {
- return ifGate.onTeamDelete(teamName) || thenGate.onTeamDelete(teamName);
- }
-
- @Override
- public boolean onRefDelete(String refName) {
- return ifGate.onRefDelete(refName) || thenGate.onRefDelete(refName);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/DefaultGateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/DefaultGateKeeper.java
deleted file mode 100644
index c13e86e0b6..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/DefaultGateKeeper.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.editable.annotation.Editable;
-
-@Editable
-public class DefaultGateKeeper extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public GateCheckResult doCheckRequest(PullRequest request) {
- return ignored();
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return ignored();
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- return ignored();
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/DisapprovedBySpecifiedTeam.java b/core/src/main/java/com/gitplex/server/gatekeeper/DisapprovedBySpecifiedTeam.java
deleted file mode 100644
index 9b05309349..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/DisapprovedBySpecifiedTeam.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.Collection;
-
-import javax.validation.constraints.Min;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.google.common.collect.Lists;
-
-@Editable(order=300, icon="fa-group", category=GateKeeper.CATEGORY_USER, description=
- "This gatekeeper will be passed if the commit gets specified number "
- + "of disapprovals from specified team. It normally works together "
- + "with a NOT container to reject the pull request in case there are "
- + "disapprovals")
-public class DisapprovedBySpecifiedTeam extends TeamAwareGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private int leastDisapprovals = 1;
-
- @Editable(name="Least Disapprovals Required", order=200)
- @Min(value = 1, message = "Least disapprovals should not be less than 1")
- public int getLeastDisapprovals() {
- return leastDisapprovals;
- }
-
- public void setLeastDisapprovals(int leastDisapprovals) {
- this.leastDisapprovals = leastDisapprovals;
- }
-
- @Override
- protected GateCheckResult doCheckRequest(PullRequest request) {
- int disapprovals = 0;
-
- Collection<Account> members = getTeamMembers(request.getTargetDepot().getAccount());
- for (Account member : members) {
- PullRequestReview.Result result = member.checkReviewSince(request.getReferentialUpdate());
- if (result == PullRequestReview.Result.DISAPPROVE) {
- disapprovals++;
- }
- }
-
- if (disapprovals >= getLeastDisapprovals()) {
- return passed(Lists.newArrayList("Disapproved by at least " + getLeastDisapprovals()
- + " member(s) of team " + getTeamName()));
- } else {
- return failed(Lists.newArrayList("Not disapproved by at least " + getLeastDisapprovals()
- + " member(s) of team " + getTeamName()));
- }
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return failed(Lists.newArrayList("Not disapproved by anyone from team " + getTeamName()));
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName, ObjectId oldObjectId,
- ObjectId newObjectId) {
- return failed(Lists.newArrayList("Not disapproved by anyone from team " + getTeamName()));
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/DisapprovedBySpecifiedUser.java b/core/src/main/java/com/gitplex/server/gatekeeper/DisapprovedBySpecifiedUser.java
deleted file mode 100644
index 402f9b805d..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/DisapprovedBySpecifiedUser.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.manager.AccountManager;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.util.editable.annotation.AccountChoice;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-
-@Editable(order=300, icon="fa-user", category=GateKeeper.CATEGORY_USER, description=
- "This gatekeeper will be passed if the commit is disapproved by specified user. "
- + "It normally works together with a NOT container to reject the pull request "
- + "in case the user disapproved it")
-public class DisapprovedBySpecifiedUser extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private String userName;
-
- @Editable(name="Select User")
- @AccountChoice
- @NotEmpty
- public String getUserName() {
- return userName;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- @Override
- protected GateCheckResult doCheckRequest(PullRequest request) {
- Account user = Preconditions.checkNotNull(GitPlex.getInstance(AccountManager.class).findByName(userName));
- PullRequestReview.Result result = user.checkReviewSince(request.getReferentialUpdate());
- if (result == PullRequestReview.Result.DISAPPROVE) {
- return passed(Lists.newArrayList("Disapproved by " + userName));
- } else {
- return failed(Lists.newArrayList("Not disapproved by " + userName));
- }
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return failed(Lists.newArrayList("Not disapproved by " + userName));
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- return failed(Lists.newArrayList("Not disapproved by " + userName));
- }
-
- @Override
- public void onAccountRename(String oldName, String newName) {
- if (userName.equals(oldName))
- userName = newName;
- }
-
- @Override
- public boolean onAccountDelete(String accountName) {
- return userName.equals(accountName);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/GateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/GateKeeper.java
deleted file mode 100644
index 7999dbee72..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/GateKeeper.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.io.Serializable;
-
-import javax.annotation.Nullable;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.editable.annotation.Editable;
-
-@Editable(name="Misc")
-public interface GateKeeper extends Serializable {
-
- String CATEGORY_BASIC = "Basic Gatekeepers";
-
- String CATEGORY_USER = "Check Approver/Submitter";
-
- String CATEGORY_COMPOSITION = "Gatekeeper Compositions";
-
- /**
- * Check the gatekeeper against specified request. This is typically used to determine
- * whether or not to accept a pull request.
- *
- * @param request
- * pull request to be checked
- * @return
- * result of the check
- */
- GateCheckResult checkRequest(PullRequest request);
-
- /**
- * Check if specified user can modify specified file in specified branch.
- *
- * @param user
- * user to be checked
- * @param branch
- * branch to be checked
- * @param file
- * file to be checked, use <tt>null</tt> to ignore checking of file, that is,
- * only check the branch
- * @return
- * result of the check.
- */
- GateCheckResult checkFile(Account user, Depot depot, String branch, @Nullable String file);
-
- /**
- * Check if specified user can push specified commit to specified ref.
- *
- * @param user
- * user to be checked
- * @param refName
- * refName to be checked
- * @param oldObjectId
- * old object id of the ref
- * @param newObjectId
- * new object id of the ref
- * @return
- * result of the check
- */
- GateCheckResult checkPush(Account user, Depot depot, String refName, ObjectId oldObjectId, ObjectId newObjectId);
-
- void onDepotRename(Depot renamedDepot, String oldName);
-
- boolean onDepotDelete(Depot depot);
-
- boolean onDepotTransfer(Depot depotDefiningGateKeeper, Depot transferredDepot, Account originalAccount);
-
- void onTeamRename(String oldName, String newName);
-
- boolean onTeamDelete(String teamName);
-
- void onAccountRename(String oldName, String newName);
-
- boolean onAccountDelete(String accountName);
-
- boolean onRefDelete(String refName);
-
- boolean isEnabled();
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/NotGateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/NotGateKeeper.java
deleted file mode 100644
index b99f694e8e..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/NotGateKeeper.java
+++ /dev/null
@@ -1,86 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-
-import com.gitplex.server.gatekeeper.checkresult.Failed;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.gatekeeper.checkresult.Passed;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.gitplex.server.util.editable.annotation.Horizontal;
-
-@Editable(name="Not Composition", order=400, icon="fa-object-group", category=GateKeeper.CATEGORY_COMPOSITION,
- description="This gatekeeper will be passed if contained gatekeeper is not passed")
-@Horizontal
-public class NotGateKeeper extends CompositeGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private GateKeeper gateKeeper = new DefaultGateKeeper();
-
- @Valid
- @NotNull
- public GateKeeper getGateKeeper() {
- return gateKeeper;
- }
-
- public void setGateKeeper(GateKeeper gateKeeper) {
- this.gateKeeper = gateKeeper;
- }
-
- @Override
- protected GateCheckResult aggregate(Checker checker) {
- GateCheckResult result = checker.check(getGateKeeper());
-
- if (result instanceof Passed)
- return failed(result.getReasons());
- else if (result instanceof Failed)
- return passed(result.getReasons());
- else
- return result;
- }
-
- @Override
- public boolean onAccountDelete(String accountName) {
- return gateKeeper.onAccountDelete(accountName);
- }
-
- @Override
- public boolean onDepotDelete(Depot depot) {
- return gateKeeper.onDepotDelete(depot);
- }
-
- @Override
- public void onDepotRename(Depot renamedDepot, String oldName) {
- gateKeeper.onDepotRename(renamedDepot, oldName);
- }
-
- @Override
- public boolean onDepotTransfer(Depot depotDefiningGateKeeper, Depot transferredDepot,
- Account origninalAccount) {
- return gateKeeper.onDepotTransfer(depotDefiningGateKeeper, transferredDepot, origninalAccount);
- }
-
- @Override
- public void onAccountRename(String oldName, String newName) {
- gateKeeper.onAccountRename(oldName, newName);
- }
-
- @Override
- public void onTeamRename(String oldName, String newName) {
- gateKeeper.onTeamRename(oldName, newName);
- }
-
- @Override
- public boolean onTeamDelete(String teamName) {
- return gateKeeper.onTeamDelete(teamName);
- }
-
- @Override
- public boolean onRefDelete(String refName) {
- return gateKeeper.onRefDelete(refName);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/OrGateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/OrGateKeeper.java
deleted file mode 100644
index d13f6a1cf7..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/OrGateKeeper.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.gitplex.server.gatekeeper.checkresult.Failed;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.gatekeeper.checkresult.Passed;
-import com.gitplex.server.gatekeeper.checkresult.Pending;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.gitplex.server.util.editable.annotation.Horizontal;
-
-@Editable(name="Or Composition", order=200, icon="fa-object-group", category=GateKeeper.CATEGORY_COMPOSITION,
- description="This gatekeeper will be passed if any of the contained gatekeepers is passed")
-@Horizontal
-public class OrGateKeeper extends AndOrGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected GateCheckResult aggregate(Checker checker) {
- List<String> pendingReasons = new ArrayList<String>();
- List<String> rejectReasons = new ArrayList<String>();
-
- for (GateKeeper each: getGateKeepers()) {
- GateCheckResult result = checker.check(each);
- if (result instanceof Failed) {
- rejectReasons.addAll(result.getReasons());
- } else if (result instanceof Passed) {
- return result;
- } else if (result instanceof Pending) {
- pendingReasons.addAll(result.getReasons());
- }
- }
-
- if (!pendingReasons.isEmpty())
- return pending(pendingReasons);
- else
- return failed(rejectReasons);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/PerformSpecifiedOperations.java b/core/src/main/java/com/gitplex/server/gatekeeper/PerformSpecifiedOperations.java
deleted file mode 100644
index f78ca0bbba..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/PerformSpecifiedOperations.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.ConstraintValidatorContext;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.gitplex.server.util.validation.Validatable;
-import com.gitplex.server.util.validation.annotation.ClassValidating;
-import com.google.common.collect.Lists;
-
-@Editable(order=200, icon="fa-wrench", description=
- "This gatekeeper will be passed if one of specified operations is performed")
-@ClassValidating
-public class PerformSpecifiedOperations extends AbstractGateKeeper implements Validatable {
-
- private static final long serialVersionUID = 1L;
-
- private boolean createRef;
-
- private boolean updateRef;
-
- private boolean deleteRef;
-
- @Editable(order=100, description="Creates a ref such as branch, tag, etc.")
- public boolean isCreateRef() {
- return createRef;
- }
-
- public void setCreateRef(boolean createRef) {
- this.createRef = createRef;
- }
-
- @Editable(order=200, description="Updates a ref such as branch, tag, etc.")
- public boolean isUpdateRef() {
- return updateRef;
- }
-
- public void setUpdateRef(boolean updateRef) {
- this.updateRef = updateRef;
- }
-
- @Editable(order=300, description="Deletes a ref such as branch, tag, etc.")
- public boolean isDeleteRef() {
- return deleteRef;
- }
-
- public void setDeleteRef(boolean deleteRef) {
- this.deleteRef = deleteRef;
- }
-
- private GateCheckResult checkUpdate() {
- if (updateRef) {
- return passed(Lists.newArrayList("Trying to update a ref"));
- }
- List<String> reasons = new ArrayList<>();
- if (deleteRef) {
- reasons.add("Trying to delete a ref");
- }
- if (createRef) {
- reasons.add("Trying to create a ref");
- }
- return failed(reasons);
- }
-
- @Override
- public GateCheckResult doCheckRequest(PullRequest request) {
- return checkUpdate();
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return checkUpdate();
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- if (oldObjectId.equals(ObjectId.zeroId())) {
- if (createRef) {
- return passed(Lists.newArrayList("Trying to create a ref"));
- }
- List<String> reasons = new ArrayList<>();
- if (updateRef) {
- reasons.add("Trying to update a ref");
- }
- if (deleteRef) {
- reasons.add("Trying to delete a ref");
- }
- return failed(reasons);
- } else if (newObjectId.equals(ObjectId.zeroId())) {
- if (deleteRef) {
- return passed(Lists.newArrayList("Trying to delete a ref"));
- }
- List<String> reasons = new ArrayList<>();
- if (createRef) {
- reasons.add("Trying to create a ref");
- }
- if (updateRef) {
- reasons.add("Trying to update a ref");
- }
- return failed(reasons);
- } else {
- return checkUpdate();
- }
- }
-
- @Override
- public boolean isValid(ConstraintValidatorContext context) {
- if (!createRef && !updateRef && !deleteRef) {
- context.disableDefaultConstraintViolation();
- context.buildConstraintViolationWithTemplate("Please select at least one operation").addConstraintViolation();
- return false;
- } else {
- return true;
- }
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/PushWithoutRewritingHistory.java b/core/src/main/java/com/gitplex/server/gatekeeper/PushWithoutRewritingHistory.java
deleted file mode 100644
index e677bc738b..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/PushWithoutRewritingHistory.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import org.eclipse.jgit.errors.IncorrectObjectTypeException;
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.git.GitUtils;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.ExceptionUtils;
-import com.gitplex.server.util.editable.annotation.Editable;
-
-@Editable(order=2000, icon="fa-ext fa-repo-lock", description="This gatekeeper 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")
-public class PushWithoutRewritingHistory extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected GateCheckResult doCheckRequest(PullRequest request) {
- return ignored();
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return ignored();
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- if (!oldObjectId.equals(ObjectId.zeroId()) && !newObjectId.equals(ObjectId.zeroId())) {
- try {
- if (GitUtils.isMergedInto(depot.getRepository(), oldObjectId, newObjectId)) {
- return passed(Lists.newArrayList("Not trying to rewrite history"));
- } else {
- return failed(Lists.newArrayList("Trying to rewrite history"));
- }
- } catch (Exception e) {
- if (ExceptionUtils.find(e, IncorrectObjectTypeException.class) != null)
- return ignored();
- else
- throw Throwables.propagate(e);
- }
- } else {
- return ignored();
- }
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/SubmitWithGerritStylePatch.java b/core/src/main/java/com/gitplex/server/gatekeeper/SubmitWithGerritStylePatch.java
deleted file mode 100644
index be7e64f587..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/SubmitWithGerritStylePatch.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.io.IOException;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
-import org.eclipse.jgit.revwalk.RevWalkUtils;
-
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.google.common.collect.Lists;
-
-@Editable(order=3000, icon="fa-ext fa-file-diff", description="This gatekeeper 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")
-public class SubmitWithGerritStylePatch extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected GateCheckResult doCheckRequest(PullRequest request) {
- try (RevWalk revWalk = new RevWalk(request.getWorkDepot().getRepository())) {
- RevCommit requestHeadCommit = revWalk.parseCommit(ObjectId.fromString(request.getHeadCommitHash()));
- RevCommit branchHeadCommit = revWalk.parseCommit(ObjectId.fromString(request.getBaseCommitHash()));
- if (RevWalkUtils.count(revWalk, requestHeadCommit, branchHeadCommit) > 1) {
- return failed(Lists.newArrayList("Please squash/rebase your commits"));
- } else {
- return passed(Lists.newArrayList("No more than one commit"));
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return ignored();
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- return ignored();
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/SubmittedBySpecifiedTeam.java b/core/src/main/java/com/gitplex/server/gatekeeper/SubmittedBySpecifiedTeam.java
deleted file mode 100644
index 74dda30150..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/SubmittedBySpecifiedTeam.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.Collection;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.google.common.collect.Lists;
-
-@Editable(order=500, icon="fa-group", category=GateKeeper.CATEGORY_USER, description=
- "This gatekeeper will be passed if the commit is submitted by a member of specified team")
-public class SubmittedBySpecifiedTeam extends TeamAwareGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public GateCheckResult doCheckRequest(PullRequest request) {
- return checkSubmitter(request.getSubmitter(), request.getTargetDepot().getAccount());
- }
-
- private GateCheckResult checkSubmitter(Account user, Account organization) {
- Collection<Account> members = getTeamMembers(organization);
- if (members.contains(user)) {
- return passed(Lists.newArrayList("Submitted by a member of team " + getTeamName()));
- }
- return failed(Lists.newArrayList("Not submitted by a member of team " + getTeamName()));
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- return checkSubmitter(user, depot.getAccount());
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return checkSubmitter(user, depot.getAccount());
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/SubmittedBySpecifiedUser.java b/core/src/main/java/com/gitplex/server/gatekeeper/SubmittedBySpecifiedUser.java
deleted file mode 100644
index dba4a06b13..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/SubmittedBySpecifiedUser.java
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.manager.AccountManager;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.editable.annotation.AccountChoice;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-
-@Editable(order=600, icon="fa-user", category=GateKeeper.CATEGORY_USER, description=
- "This gatekeeper will be passed if the commit is submitted by specified user")
-public class SubmittedBySpecifiedUser extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private String userName;
-
- @Editable(name="Select User")
- @AccountChoice
- @NotEmpty
- public String getUserName() {
- return userName;
- }
-
- public void setUserName(String userName) {
- this.userName = userName;
- }
-
- @Override
- public GateCheckResult doCheckRequest(PullRequest request) {
- return checkSubmitter(request.getSubmitter());
- }
-
- private GateCheckResult checkSubmitter(Account user) {
- Account expectedUser = Preconditions.checkNotNull(GitPlex.getInstance(AccountManager.class).findByName(userName));
- if (expectedUser.equals(user))
- return passed(Lists.newArrayList("Submitted by " + expectedUser.getDisplayName()));
- else
- return failed(Lists.newArrayList("Not submitted by " + expectedUser.getDisplayName()));
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return checkSubmitter(user);
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- return checkSubmitter(user);
- }
-
- @Override
- public void onAccountRename(String oldName, String newName) {
- if (userName.equals(oldName))
- userName = newName;
- }
-
- @Override
- public boolean onAccountDelete(String accountName) {
- return userName.equals(accountName);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/TargetBranchIsMerged.java b/core/src/main/java/com/gitplex/server/gatekeeper/TargetBranchIsMerged.java
deleted file mode 100644
index 09f830d8a2..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/TargetBranchIsMerged.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.revwalk.RevCommit;
-
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.git.GitUtils;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.google.common.collect.Lists;
-
-@Editable(order=3100, icon="fa-ext fa-branch-merge", description="This gatekeeper will be passed if "
- + "head commit of target branch is merged into source branch of the pull request")
-public class TargetBranchIsMerged extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected GateCheckResult doCheckRequest(PullRequest request) {
- RevCommit requestHeadCommit = request.getHeadCommit();
- RevCommit branchHeadCommit = request.getTarget().getCommit();
- if (!GitUtils.isMergedInto(request.getTargetDepot().getRepository(), branchHeadCommit, requestHeadCommit)) {
- return failed(Lists.newArrayList("Please merge target branch into the source branch first"));
- } else {
- return passed(Lists.newArrayList("No more than one commit"));
- }
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return ignored();
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- return ignored();
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/TeamAwareGateKeeper.java b/core/src/main/java/com/gitplex/server/gatekeeper/TeamAwareGateKeeper.java
deleted file mode 100644
index 5e660e09de..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/TeamAwareGateKeeper.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.Collection;
-import java.util.HashSet;
-
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.manager.TeamManager;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.Team;
-import com.gitplex.server.model.TeamMembership;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.gitplex.server.util.editable.annotation.TeamChoice;
-import com.google.common.base.Preconditions;
-
-public abstract class TeamAwareGateKeeper extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private String teamName;
-
- @Editable(name="Team", order=100)
- @TeamChoice
- @NotEmpty
- public String getTeamName() {
- return teamName;
- }
-
- public void setTeamName(String teamName) {
- this.teamName = teamName;
- }
-
- @Override
- public void onTeamRename(String oldName, String newName) {
- if (teamName.equals(oldName))
- teamName = newName;
- }
-
- @Override
- public boolean onTeamDelete(String teamName) {
- return this.teamName.equals(teamName);
- }
-
- protected Team getTeam(Account organization) {
- return Preconditions.checkNotNull(GitPlex.getInstance(TeamManager.class).find(organization, teamName));
- }
-
- protected Collection<Account> getTeamMembers(Account organization) {
- Collection<Account> members = new HashSet<>();
- for (TeamMembership membership: getTeam(organization).getMemberships()) {
- members.add(membership.getUser());
- }
- return members;
- }
-
- @Override
- public boolean onDepotTransfer(Depot depotDefiningGateKeeper, Depot transferredDepot,
- Account originalAccount) {
- return depotDefiningGateKeeper.equals(transferredDepot);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/TouchSpecifiedFiles.java b/core/src/main/java/com/gitplex/server/gatekeeper/TouchSpecifiedFiles.java
deleted file mode 100644
index 878d69dc69..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/TouchSpecifiedFiles.java
+++ /dev/null
@@ -1,105 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.io.IOException;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.treewalk.TreeWalk;
-import org.eclipse.jgit.treewalk.filter.TreeFilter;
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.google.common.collect.Lists;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestUpdate;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.gitplex.server.util.editable.annotation.PathMatch;
-import com.gitplex.server.util.includeexclude.IncludeExcludeUtils;
-import com.gitplex.server.util.match.ChildAwareMatcher;
-import com.gitplex.server.util.match.ParentAwareMatcher;
-import com.gitplex.server.util.match.PatternMatcher;
-
-@Editable(order=300, icon="fa-file-text", description=
- "This gatekeeper will be passed if specified files are modified")
-public class TouchSpecifiedFiles extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private static final PatternMatcher INCLUDE_MATCHER = new ParentAwareMatcher();
-
- private static final PatternMatcher EXCLUDE_MATCHER = new ChildAwareMatcher();
-
- private String pathMatch;
-
- @Editable(name="Files to Match")
- @PathMatch
- @NotEmpty
- public String getPathMatch() {
- return pathMatch;
- }
-
- public void setPathMatch(String pathMatch) {
- this.pathMatch = pathMatch;
- }
-
- private boolean matches(String value) {
- return IncludeExcludeUtils.getIncludeExclude(pathMatch).matches(INCLUDE_MATCHER, EXCLUDE_MATCHER, value);
- }
-
- @Override
- public GateCheckResult doCheckRequest(PullRequest request) {
- for (PullRequestUpdate update: request.getEffectiveUpdates()) {
- for (String file: update.getChangedFiles()) {
- if (matches(file)) {
- request.setReferentialUpdate(update);
- return passed(Lists.newArrayList("Touched files matches '" + pathMatch + "'"));
- }
- }
- }
-
- return failed(Lists.newArrayList("No touched files match '" + pathMatch + "'"));
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- if (file != null) {
- if (matches(file))
- return passed(Lists.newArrayList("Touched files match '" + pathMatch + "'"));
- else
- return failed(Lists.newArrayList("No touched files match '" + pathMatch + "'"));
- } else {
- return ignored();
- }
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- if (!oldObjectId.equals(ObjectId.zeroId()) && !newObjectId.equals(ObjectId.zeroId())) {
- try (TreeWalk treeWalk = new TreeWalk(depot.getRepository())) {
- treeWalk.setFilter(TreeFilter.ANY_DIFF);
- treeWalk.setRecursive(true);
- RevCommit oldCommit = depot.getRevCommit(oldObjectId, false);
- if (oldCommit == null)
- return ignored();
- RevCommit newCommit = depot.getRevCommit(newObjectId, false);
- if (newCommit == null)
- return ignored();
- treeWalk.addTree(oldCommit.getTree());
- treeWalk.addTree(newCommit.getTree());
- while (treeWalk.next()) {
- if (matches(treeWalk.getPathString()))
- return passed(Lists.newArrayList("Touched files match '" + pathMatch + "'"));
- }
- return failed(Lists.newArrayList("No touched files match '" + pathMatch + "'"));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- } else {
- return ignored();
- }
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/TouchSpecifiedRefs.java b/core/src/main/java/com/gitplex/server/gatekeeper/TouchSpecifiedRefs.java
deleted file mode 100644
index 8914e8aaa8..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/TouchSpecifiedRefs.java
+++ /dev/null
@@ -1,85 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.google.common.collect.Lists;
-import com.gitplex.server.util.includeexclude.IncludeExcludeParser;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.git.GitUtils;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.gitplex.server.util.editable.annotation.RefMatch;
-import com.gitplex.server.util.includeexclude.IncludeExcludeUtils;
-import com.gitplex.server.util.match.ChildAwareMatcher;
-import com.gitplex.server.util.match.ParentAwareMatcher;
-import com.gitplex.server.util.match.PatternMatcher;
-
-@Editable(order=100, icon="fa-code-fork", description=
- "This gatekeeper will be passed if specified refs is being touched")
-public class TouchSpecifiedRefs extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private static final PatternMatcher INCLUDE_MATCHER = new ParentAwareMatcher();
-
- private static final PatternMatcher EXCLUDE_MATCHER = new ChildAwareMatcher();
-
- private String refMatch;
-
- @Editable(name="Refs to Match", order=100)
- @RefMatch
- @NotEmpty
- public String getRefMatch() {
- return refMatch;
- }
-
- public void setRefMatch(String refMatch) {
- this.refMatch = refMatch;
- }
-
- private GateCheckResult doCheck(String refName) {
- if (IncludeExcludeUtils.getIncludeExclude(refMatch).matches(INCLUDE_MATCHER, EXCLUDE_MATCHER, refName)) {
- return passed(Lists.newArrayList("Target ref matches '" + refMatch + "'"));
- } else {
- return failed(Lists.newArrayList("Target ref does not match '" + refMatch + "'"));
- }
- }
-
- @Override
- public GateCheckResult doCheckRequest(PullRequest request) {
- return doCheck(request.getTargetRef());
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return doCheck(GitUtils.branch2ref(branch));
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- return doCheck(refName);
- }
-
- @Override
- public boolean onRefDelete(String refName) {
- StringBuilder builder = new StringBuilder();
- for (IncludeExcludeParser.CriteriaContext criteriaContext: IncludeExcludeUtils.parse(refMatch).criteria()) {
- if (criteriaContext.includeMatch() != null) {
- String value = IncludeExcludeUtils.getValue(criteriaContext.includeMatch().Value());
- if (!value.equals(refName))
- builder.append(String.format("include(%s) ", value));
- } else {
- String value = IncludeExcludeUtils.getValue(criteriaContext.excludeMatch().Value());
- if (!value.equals(refName))
- builder.append(String.format("exclude(%s) ", value));
- }
- }
- refMatch = builder.toString().trim();
- return refMatch.length() == 0;
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/VerifiedByBuilds.java b/core/src/main/java/com/gitplex/server/gatekeeper/VerifiedByBuilds.java
deleted file mode 100644
index f481ccfc2b..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/VerifiedByBuilds.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.gitplex.server.gatekeeper;
-
-import java.util.Collection;
-
-import javax.validation.constraints.Min;
-
-import org.eclipse.jgit.lib.ObjectId;
-
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.manager.PullRequestVerificationManager;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestVerification;
-import com.gitplex.server.model.support.IntegrationPreview;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.google.common.collect.Lists;
-
-@Editable(icon="fa-check-circle", order=1000,
- description="This gatekeeper 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")
-public class VerifiedByBuilds extends AbstractGateKeeper {
-
- private static final long serialVersionUID = 1L;
-
- private int leastPassCount = 1;
-
- private boolean checkIntegrated = true;
-
- @Editable(order=100, description="This specifies number of builds has to be reported successful "
- + "for this gatekeeper to be passed. Normally this number represents number of build "
- + "configurations setting up to verify the code.")
- @Min(1)
- public int getLeastPassCount() {
- return leastPassCount;
- }
-
- public void setLeastPassCount(int leastPassCount) {
- this.leastPassCount = leastPassCount;
- }
-
- @Editable(order=200, description="Enable this to check the integrated commit instead of head commit.")
- public boolean isCheckIntegrated() {
- return checkIntegrated;
- }
-
- public void setCheckIntegrated(boolean checkIntegrated) {
- this.checkIntegrated = checkIntegrated;
- }
-
- @Override
- protected GateCheckResult doCheckRequest(PullRequest request) {
- if (request.isNew()) {
- return pending(Lists.newArrayList("To be verified by build"));
- }
-
- String commit;
- if (isCheckIntegrated()) {
- IntegrationPreview preview = request.getIntegrationPreview();
- if (preview == null) {
- return pending(Lists.newArrayList("To be verified by build"));
- }
- commit = preview.getIntegrated();
- if (commit == null)
- return failed(Lists.newArrayList("Can not build against integration result due to conflicts"));
- } else {
- commit = request.getHeadCommitHash();
- }
-
- PullRequestVerificationManager verificationManager = GitPlex.getInstance(PullRequestVerificationManager.class);
-
- int passedCount = 0;
- Collection<PullRequestVerification> verifications = verificationManager.findAll(request, commit);
- for (PullRequestVerification each: verifications) {
- if (each.getStatus() == PullRequestVerification.Status.FAILED)
- return failed(Lists.newArrayList("At least one build is failed for the commit"));
- else if (each.getStatus() == PullRequestVerification.Status.SUCCESSFUL)
- passedCount++;
- }
- int lacks = leastPassCount - passedCount;
-
- if (lacks > 0) {
- if (leastPassCount > 1)
- return pending(Lists.newArrayList("To be verified by " + lacks + " more build(s)"));
- else
- return pending(Lists.newArrayList("To be verified by build"));
- } else {
- return passed(Lists.newArrayList("Builds passed"));
- }
- }
-
- @Override
- protected GateCheckResult doCheckFile(Account user, Depot depot, String branch, String file) {
- return pending(Lists.newArrayList("Not verified by build"));
- }
-
- @Override
- protected GateCheckResult doCheckPush(Account user, Depot depot, String refName,
- ObjectId oldObjectId, ObjectId newObjectId) {
- if (!oldObjectId.equals(ObjectId.zeroId()) && !newObjectId.equals(ObjectId.zeroId())) {
- return pending(Lists.newArrayList("Has to be verified by builds"));
- } else {
- return ignored();
- }
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Failed.java b/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Failed.java
deleted file mode 100644
index 93755c571e..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Failed.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.gitplex.server.gatekeeper.checkresult;
-
-import java.util.List;
-
-/* Reject the merge request. */
-@SuppressWarnings("serial")
-public class Failed extends GateCheckResult {
-
- public Failed(List<String> reasons) {
- super(reasons);
- }
-
- @Override
- public String toString() {
- return "Failed";
- }
-
-}
\ No newline at end of file
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/GateCheckResult.java b/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/GateCheckResult.java
deleted file mode 100644
index ef6d075046..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/GateCheckResult.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.gitplex.server.gatekeeper.checkresult;
-
-import java.io.Serializable;
-import java.util.List;
-
-@SuppressWarnings("serial")
-public abstract class GateCheckResult implements Serializable {
-
- private final List<String> reasons;
-
- public GateCheckResult(List<String> reasons) {
- this.reasons = reasons;
- }
-
- public List<String> getReasons() {
- return reasons;
- }
-
- public boolean isFailed() {
- return this instanceof Failed;
- }
-
- public boolean isPassed() {
- return this instanceof Passed;
- }
-
- public boolean isPending() {
- return this instanceof Pending;
- }
-
- public boolean isIgnored() {
- return this instanceof Ignored;
- }
-
- public boolean isPassedOrIgnored() {
- return isPassed() || isIgnored();
- }
-
-}
\ No newline at end of file
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Ignored.java b/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Ignored.java
deleted file mode 100644
index dea20b1c0e..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Ignored.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.gitplex.server.gatekeeper.checkresult;
-
-import java.util.ArrayList;
-
-
-/**
- * Represents an ignored result, for instance if some check is not applicable, or if
- * some user selected to ignore the vote.
- *
- * @author robin
- *
- */
-@SuppressWarnings("serial")
-public class Ignored extends GateCheckResult {
-
- public Ignored() {
- super(new ArrayList<String>());
- }
-
- @Override
- public String toString() {
- return "Ignored";
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Passed.java b/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Passed.java
deleted file mode 100644
index c7209218e4..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Passed.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.gitplex.server.gatekeeper.checkresult;
-
-import java.util.List;
-
-@SuppressWarnings("serial")
-public class Passed extends GateCheckResult {
-
- public Passed(List<String> reasons) {
- super(reasons);
- }
-
- @Override
- public String toString() {
- return "Passed";
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Pending.java b/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Pending.java
deleted file mode 100644
index c584160738..0000000000
--- a/core/src/main/java/com/gitplex/server/gatekeeper/checkresult/Pending.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.gitplex.server.gatekeeper.checkresult;
-
-import java.util.List;
-
-/* merge request acceptance check is pending and result is unknown yet */
-@SuppressWarnings("serial")
-public class Pending extends GateCheckResult {
-
- public Pending(List<String> reasons) {
- super(reasons);
- }
-
- @Override
- public String toString() {
- return "Pending";
- }
-
-}
\ No newline at end of file
diff --git a/core/src/main/java/com/gitplex/server/git/GitPreReceiveCallback.java b/core/src/main/java/com/gitplex/server/git/GitPreReceiveCallback.java
index 451a09aab0..2218621fd2 100644
--- a/core/src/main/java/com/gitplex/server/git/GitPreReceiveCallback.java
+++ b/core/src/main/java/com/gitplex/server/git/GitPreReceiveCallback.java
@@ -3,7 +3,6 @@ package com.gitplex.server.git;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.InetAddress;
-import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
@@ -15,16 +14,19 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.shiro.SecurityUtils;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import com.gitplex.launcher.loader.LoaderUtils;
-import com.gitplex.server.gatekeeper.GateKeeper;
-import com.gitplex.server.gatekeeper.checkresult.Failed;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.manager.DepotManager;
+import com.gitplex.server.manager.ReviewManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.PullRequest;
+import com.gitplex.server.model.PullRequestUpdate;
+import com.gitplex.server.model.support.BranchProtection;
+import com.gitplex.server.model.support.TagProtection;
import com.gitplex.server.persistence.annotation.Transactional;
import com.gitplex.server.security.ObjectPermission;
import com.gitplex.server.util.StringUtils;
@@ -40,10 +42,13 @@ public class GitPreReceiveCallback extends HttpServlet {
private final AccountManager userManager;
+ private final ReviewManager reviewManager;
+
@Inject
- public GitPreReceiveCallback(DepotManager depotManager, AccountManager userManager) {
+ public GitPreReceiveCallback(DepotManager depotManager, AccountManager userManager, ReviewManager reviewManager) {
this.depotManager = depotManager;
this.userManager = userManager;
+ this.reviewManager = reviewManager;
}
private void error(Output output, String refName, String... messages) {
@@ -106,29 +111,48 @@ public class GitPreReceiveCallback extends HttpServlet {
Account user = userManager.getCurrent();
Preconditions.checkNotNull(user);
- if (refName.startsWith(Depot.REFS_GITPLEX)) {
+ if (refName.startsWith(PullRequest.REFS_PREFIX) || refName.startsWith(PullRequestUpdate.REFS_PREFIX)) {
if (!user.asSubject().isPermitted(ObjectPermission.ofDepotAdmin(depot))) {
error(output, refName, "Only repository administrators can update gitplex refs.");
break;
}
- } else {
- GateKeeper gateKeeper = depot.getGateKeeper();
- GateCheckResult checkResult = gateKeeper.checkPush(user, depot, refName, oldObjectId, newObjectId);
- if (!checkResult.isPassedOrIgnored()) {
- List<String> messages = new ArrayList<>();
- for (String each: checkResult.getReasons())
- messages.add(each);
- if (GitUtils.ref2branch(refName) != null
- && !oldObjectId.equals(ObjectId.zeroId())
- && !newObjectId.equals(ObjectId.zeroId())
- && !(checkResult instanceof Failed)) {
- messages.add("");
- messages.add("----------------------------------------------------");
- messages.add("You may submit a pull request instead.");
- }
- error(output, refName, messages.toArray(new String[messages.size()]));
- break;
+ } else if (refName.startsWith(Constants.R_HEADS)) {
+ String branchName = Preconditions.checkNotNull(GitUtils.branch2ref(refName));
+
+ if (!oldObjectId.equals(ObjectId.zeroId())) {
+ if (newObjectId.equals(ObjectId.zeroId())) {
+ BranchProtection protection = depot.getBranchProtection(branchName);
+ if (protection != null && protection.isNoDeletion())
+ error(output, refName, "Can not delete this branch according to branch protection setting");
+ } else if (!GitUtils.isMergedInto(depot.getRepository(), oldObjectId, newObjectId)) {
+ BranchProtection protection = depot.getBranchProtection(branchName);
+ if (protection != null && protection.isNoForcedPush())
+ error(output, refName, "Can not force-push to this branch according to branch protection setting");
+ } else {
+ if (!reviewManager.canPush(user, depot, refName, oldObjectId, newObjectId)) {
+ error(output, refName,
+ "Your changes need to be reviewed. Please submit pull request instead");
+ }
+ }
+ }
+ } else if (refName.startsWith(Constants.R_TAGS)) {
+ String tagName = Preconditions.checkNotNull(GitUtils.ref2tag(refName));
+ String errorMessage = null;
+ TagProtection protection = depot.getTagProtection(tagName);
+ if (protection != null) {
+ if (oldObjectId.equals(ObjectId.zeroId())) {
+ errorMessage = protection.getTagCreator().getNotMatchMessage(depot, user);
+ if (errorMessage != null)
+ errorMessage = "Unable to create protected tag: " + errorMessage;
+ } else if (newObjectId.equals(ObjectId.zeroId())) {
+ if (protection.isNoDeletion())
+ errorMessage = "Can not delete this tag according to tag protection setting";
+ } else if (protection.isNoUpdate()) {
+ errorMessage = "Can not update this tag according to tag protection setting";
+ }
}
+ if (errorMessage != null)
+ error(output, refName, errorMessage);
}
field = field.substring(40);
diff --git a/core/src/main/java/com/gitplex/server/manager/PullRequestManager.java b/core/src/main/java/com/gitplex/server/manager/PullRequestManager.java
index f3aaeed3cc..dc68141fbb 100644
--- a/core/src/main/java/com/gitplex/server/manager/PullRequestManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/PullRequestManager.java
@@ -1,27 +1,23 @@
package com.gitplex.server.manager;
import java.util.Collection;
-import java.util.List;
import javax.annotation.Nullable;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequest.IntegrationStrategy;
import com.gitplex.server.model.support.DepotAndBranch;
-import com.gitplex.server.model.support.IntegrationPreview;
+import com.gitplex.server.model.support.MergePreview;
import com.gitplex.server.persistence.dao.EntityManager;
public interface PullRequestManager extends EntityManager<PullRequest> {
@Nullable
- PullRequest findOpen(DepotAndBranch target, DepotAndBranch source);
+ PullRequest findEffective(DepotAndBranch target, DepotAndBranch source);
- Collection<PullRequest> findAllOpenTo(DepotAndBranch target, @Nullable Depot sourceDepot);
+ Collection<PullRequest> findAllOpenTo(DepotAndBranch target);
- Collection<PullRequest> findAllOpenFrom(DepotAndBranch source, @Nullable Depot targetDepot);
-
Collection<PullRequest> findAllOpen(DepotAndBranch sourceOrTarget);
@Nullable
@@ -33,33 +29,21 @@ public interface PullRequestManager extends EntityManager<PullRequest> {
@Nullable
PullRequest findLatest(Depot depot, Account submitter);
- /**
- * Integrate specified pull request.
- *
- * @param request
- * pull request to be integrated
- * @param note
- * comment for the integration
- */
- void integrate(PullRequest request, @Nullable String note);
-
void discard(PullRequest request, @Nullable String note);
void reopen(PullRequest request, @Nullable String note);
- void changeAssignee(PullRequest request);
-
- void check(PullRequest request);
+ void checkStatus(PullRequest request);
/**
- * Preview integration of this pull request.
+ * Preview merge of this pull request.
*
* @param request
- * pull request to preview integration of
+ * pull request to preview merge of
* @return
- * integration preview, or <tt>null</tt> if preview is being calculating
+ * merge preview, or <tt>null</tt> if preview is being calculating
*/
- IntegrationPreview previewIntegration(PullRequest request);
+ MergePreview previewMerge(PullRequest request);
/**
* Delete git refs of this pull request and all its updates.
@@ -73,12 +57,12 @@ public interface PullRequestManager extends EntityManager<PullRequest> {
void delete(PullRequest request);
- List<IntegrationStrategy> getApplicableIntegrationStrategies(PullRequest request);
-
void deleteSourceBranch(PullRequest request, @Nullable String note);
void restoreSourceBranch(PullRequest request, @Nullable String note);
+ void saveMergeStrategy(PullRequest request);
+
int countOpen(Depot depot);
}
diff --git a/core/src/main/java/com/gitplex/server/manager/PullRequestReviewInvitationManager.java b/core/src/main/java/com/gitplex/server/manager/PullRequestReviewInvitationManager.java
deleted file mode 100644
index a8c55a23de..0000000000
--- a/core/src/main/java/com/gitplex/server/manager/PullRequestReviewInvitationManager.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.gitplex.server.manager;
-
-import java.util.Collection;
-import java.util.Date;
-
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReviewInvitation;
-import com.gitplex.server.persistence.dao.EntityManager;
-
-public interface PullRequestReviewInvitationManager extends EntityManager<PullRequestReviewInvitation> {
-
- PullRequestReviewInvitation find(Account reviewer, PullRequest request);
-
- void update(Collection<PullRequestReviewInvitation> invitations, Date since);
-
-}
diff --git a/core/src/main/java/com/gitplex/server/manager/PullRequestReviewManager.java b/core/src/main/java/com/gitplex/server/manager/PullRequestReviewManager.java
deleted file mode 100644
index c1c4dbe14b..0000000000
--- a/core/src/main/java/com/gitplex/server/manager/PullRequestReviewManager.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.gitplex.server.manager;
-
-import java.util.List;
-
-import javax.annotation.Nullable;
-
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.model.PullRequestUpdate;
-import com.gitplex.server.persistence.dao.EntityManager;
-
-public interface PullRequestReviewManager extends EntityManager<PullRequestReview> {
-
- PullRequestReview find(Account user, PullRequestUpdate update);
-
- void review(PullRequest request, PullRequestReview.Result result, @Nullable String note);
-
- /**
- * Find list of reviews ordered by review date for specified pull request.
- *
- * @param request
- * pull request to find review for
- * @return
- * list of reviews ordered by review date
- */
- List<PullRequestReview> findAll(PullRequest request);
-
- void deleteAll(Account user, PullRequest request);
-
-}
diff --git a/core/src/main/java/com/gitplex/server/manager/PullRequestUpdateManager.java b/core/src/main/java/com/gitplex/server/manager/PullRequestUpdateManager.java
index ae9b827f1a..ef89b84c0b 100644
--- a/core/src/main/java/com/gitplex/server/manager/PullRequestUpdateManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/PullRequestUpdateManager.java
@@ -15,7 +15,7 @@ public interface PullRequestUpdateManager extends EntityManager<PullRequestUpdat
* update to be saved
* @param independent
* whether or not this update is an independent update. An independent update is
- * not created as result of other actions such as open and integrate
+ * not created as result of other actions such as open and merge
*/
void save(PullRequestUpdate update, boolean independent);
diff --git a/core/src/main/java/com/gitplex/server/manager/PullRequestVerificationManager.java b/core/src/main/java/com/gitplex/server/manager/PullRequestVerificationManager.java
deleted file mode 100644
index 0e8309c3ca..0000000000
--- a/core/src/main/java/com/gitplex/server/manager/PullRequestVerificationManager.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.gitplex.server.manager;
-
-import java.util.Collection;
-
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestVerification;
-import com.gitplex.server.persistence.dao.EntityManager;
-
-public interface PullRequestVerificationManager extends EntityManager<PullRequestVerification> {
-
- Collection<PullRequestVerification> findAll(PullRequest request, String commit);
-
- PullRequestVerification find(PullRequest request, String commit, String configuration);
-
- PullRequestVerification.Status getOverallStatus(Collection<PullRequestVerification> verifications);
-}
diff --git a/core/src/main/java/com/gitplex/server/manager/ReviewInvitationManager.java b/core/src/main/java/com/gitplex/server/manager/ReviewInvitationManager.java
new file mode 100644
index 0000000000..f7652e9038
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/manager/ReviewInvitationManager.java
@@ -0,0 +1,12 @@
+package com.gitplex.server.manager;
+
+import com.gitplex.server.model.ReviewInvitation;
+import com.gitplex.server.persistence.dao.EntityManager;
+
+public interface ReviewInvitationManager extends EntityManager<ReviewInvitation> {
+
+ boolean exclude(ReviewInvitation invitation);
+
+ void invite(ReviewInvitation invitation);
+
+}
diff --git a/core/src/main/java/com/gitplex/server/manager/ReviewManager.java b/core/src/main/java/com/gitplex/server/manager/ReviewManager.java
new file mode 100644
index 0000000000..465ea2aabb
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/manager/ReviewManager.java
@@ -0,0 +1,67 @@
+package com.gitplex.server.manager;
+
+import java.util.List;
+
+import javax.annotation.Nullable;
+
+import org.eclipse.jgit.lib.ObjectId;
+
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.PullRequest;
+import com.gitplex.server.model.PullRequestUpdate;
+import com.gitplex.server.model.Review;
+import com.gitplex.server.persistence.dao.EntityManager;
+import com.gitplex.server.util.ReviewCheckStatus;
+
+public interface ReviewManager extends EntityManager<Review> {
+
+ Review find(Account user, PullRequestUpdate update);
+
+ void review(PullRequest request, boolean approved, @Nullable String note);
+
+ /**
+ * Find list of reviews ordered by review date for specified pull request.
+ *
+ * @param request
+ * pull request to find review for
+ * @return
+ * list of reviews ordered by review date
+ */
+ List<Review> findAll(PullRequest request);
+
+ void delete(Account user, PullRequest request);
+
+ ReviewCheckStatus checkRequest(PullRequest request);
+
+ /**
+ * Check if specified user can modify specified file in specified branch.
+ *
+ * @param user
+ * user to be checked
+ * @param branch
+ * branch to be checked
+ * @param file
+ * file to be checked
+ * @return
+ * result of the check.
+ */
+ boolean canModify(Account user, Depot depot, String branch, String file);
+
+ /**
+ * Check if specified user can push specified commit to specified ref.
+ *
+ * @param user
+ * user to be checked
+ * @param branchName
+ * branchName to be checked
+ * @param oldObjectId
+ * old object id of the ref
+ * @param newObjectId
+ * new object id of the ref
+ * @return
+ * result of the check
+ */
+ boolean canPush(Account user, Depot depot, String branchName, ObjectId oldObjectId, ObjectId newObjectId);
+
+}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultAccountManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultAccountManager.java
index adf1de306e..e1889ed0f4 100644
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultAccountManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultAccountManager.java
@@ -1,6 +1,5 @@
package com.gitplex.server.manager.impl;
-import java.util.Iterator;
import java.util.List;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -17,14 +16,11 @@ import org.hibernate.criterion.Restrictions;
import com.gitplex.launcher.loader.Listen;
import com.gitplex.server.event.lifecycle.SystemStarted;
import com.gitplex.server.event.lifecycle.SystemStarting;
-import com.gitplex.server.event.pullrequest.PullRequestStatusChangeEvent;
import com.gitplex.server.manager.AccountManager;
-import com.gitplex.server.manager.PullRequestManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestStatusChange;
-import com.gitplex.server.model.support.IntegrationPolicy;
+import com.gitplex.server.model.support.BranchProtection;
+import com.gitplex.server.model.support.TagProtection;
import com.gitplex.server.persistence.annotation.Sessional;
import com.gitplex.server.persistence.annotation.Transactional;
import com.gitplex.server.persistence.dao.AbstractEntityManager;
@@ -36,8 +32,6 @@ import com.google.common.collect.HashBiMap;
@Singleton
public class DefaultAccountManager extends AbstractEntityManager<Account> implements AccountManager {
- private final PullRequestManager pullRequestManager;
-
private final PasswordService passwordService;
private final ReadWriteLock idLock = new ReentrantReadWriteLock();
@@ -47,10 +41,9 @@ public class DefaultAccountManager extends AbstractEntityManager<Account> implem
private final BiMap<String, Long> nameToId = HashBiMap.create();
@Inject
- public DefaultAccountManager(Dao dao, PullRequestManager pullRequestManager, PasswordService passwordService) {
+ public DefaultAccountManager(Dao dao, PasswordService passwordService) {
super(dao);
- this.pullRequestManager = pullRequestManager;
this.passwordService = passwordService;
}
@@ -65,10 +58,10 @@ public class DefaultAccountManager extends AbstractEntityManager<Account> implem
if (oldName != null && !oldName.equals(account.getName())) {
for (Depot depot: dao.findAll(Depot.class)) {
- for (IntegrationPolicy integrationPolicy: depot.getIntegrationPolicies()) {
- integrationPolicy.onAccountRename(oldName, account.getName());
- }
- depot.getGateKeeper().onAccountRename(oldName, account.getName());
+ for (BranchProtection protection: depot.getBranchProtections())
+ protection.onAccountRename(depot, oldName, account.getName());
+ for (TagProtection protection: depot.getTagProtections())
+ protection.onAccountRename(oldName, account.getName());
}
}
@@ -98,43 +91,67 @@ public class DefaultAccountManager extends AbstractEntityManager<Account> implem
@Transactional
@Override
public void delete(Account account) {
- Query query = getSession().createQuery("update PullRequest set lastEvent.user=null where lastEvent.user=:lastEventUser");
- query.setParameter("lastEventUser", account);
+ Query query = getSession().createQuery("update PullRequest set submitter=null, submitterName=:submitterName "
+ + "where submitter=:submitter");
+ query.setParameter("submitter", account);
+ query.setParameter("submitterName", account.getDisplayName());
query.executeUpdate();
-
- query = getSession().createQuery("from PullRequest where assignee=:assignee");
- query.setParameter("assignee", account);
-
- for (Object each: query.list()) {
- PullRequest request = (PullRequest) each;
- request.setAssignee(request.getTargetDepot().getAccount());
- pullRequestManager.save(request);
- }
- query = getSession().createQuery("update PullRequest set closeInfo.closedBy=null where closeInfo.closedBy=:closedBy");
+ query = getSession().createQuery("update PullRequest set closeInfo.closedBy=null, "
+ + "closeInfo.closedByName=:closedByName where closeInfo.closedBy=:closedBy");
query.setParameter("closedBy", account);
+ query.setParameter("closedByName", account.getDisplayName());
query.executeUpdate();
- query = getSession().createQuery("from PullRequest where submitter=:submitter");
- query.setParameter("submitter", account);
+ query = getSession().createQuery("update PullRequest set lastEvent.user=null, "
+ + "lastEvent.userName=:lastEventUserName where lastEvent.user=:lastEventUser");
+ query.setParameter("lastEventUser", account);
+ query.setParameter("lastEventUserName", account.getDisplayName());
+ query.executeUpdate();
- for (Object each: query.list()) {
- PullRequest request = (PullRequest) each;
- pullRequestManager.delete(request);
- }
+ query = getSession().createQuery("update PullRequestStatusChange set user=null, userName=:userName where user=:user");
+ query.setParameter("user", account);
+ query.setParameter("userName", account.getDisplayName());
+ query.executeUpdate();
+
+ query = getSession().createQuery("update PullRequestComment set user=null, userName=:userName where user=:user");
+ query.setParameter("user", account);
+ query.setParameter("userName", account.getDisplayName());
+ query.executeUpdate();
+
+ query = getSession().createQuery("update PullRequestReference set user=null, userName=:userName where user=:user");
+ query.setParameter("user", account);
+ query.setParameter("userName", account.getDisplayName());
+ query.executeUpdate();
+
+ query = getSession().createQuery("update CodeComment set user=null, userName=:userName where user=:user");
+ query.setParameter("user", account);
+ query.setParameter("userName", account.getDisplayName());
+ query.executeUpdate();
+
+ query = getSession().createQuery("update CodeComment set lastEvent.user=null, "
+ + "lastEvent.userName=:lastEventUserName where lastEvent.user=:lastEventUser");
+ query.setParameter("lastEventUser", account);
+ query.setParameter("lastEventUserName", account.getDisplayName());
+ query.executeUpdate();
- query = getSession().createQuery("update CodeComment set lastEvent.user=null where lastEvent.user=:user");
+ query = getSession().createQuery("update CodeCommentReply set user=null, userName=:userName where user=:user");
query.setParameter("user", account);
+ query.setParameter("userName", account.getDisplayName());
+ query.executeUpdate();
+
+ query = getSession().createQuery("update CodeCommentStatusChange set user=null, userName=:userName where user=:user");
+ query.setParameter("user", account);
+ query.setParameter("userName", account.getDisplayName());
query.executeUpdate();
dao.remove(account);
for (Depot depot: dao.findAll(Depot.class)) {
- for (Iterator<IntegrationPolicy> it = depot.getIntegrationPolicies().iterator(); it.hasNext();) {
- if (it.next().onAccountDelete(account.getName()))
- it.remove();
- }
- depot.getGateKeeper().onAccountDelete(account.getName());
+ for (BranchProtection protection: depot.getBranchProtections())
+ protection.onAccountDelete(depot, account.getName());
+ for (TagProtection protection: depot.getTagProtections())
+ protection.onAccountDelete(account.getName());
}
doAfterCommit(new Runnable() {
@@ -235,17 +252,6 @@ public class DefaultAccountManager extends AbstractEntityManager<Account> implem
return findRange(criteria, 0, 0);
}
- @Transactional
- @Listen
- public void on(PullRequestStatusChangeEvent event) {
- if (event.getStatusChange().getType() == PullRequestStatusChange.Type.APPROVED
- || event.getStatusChange().getType() == PullRequestStatusChange.Type.DISAPPROVED) {
- Account user = event.getStatusChange().getUser();
- user.setReviewEffort(user.getReviewEffort()+1);
- save(user);
- }
- }
-
@Listen
public void on(SystemStarted event) {
// Fix a critical issue that password of self-registered users are not hashed
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultDepotManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultDepotManager.java
index 1bf0fd26d0..b11edb6d7c 100644
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultDepotManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultDepotManager.java
@@ -35,7 +35,6 @@ import com.gitplex.server.event.depot.DepotTransferred;
import com.gitplex.server.event.lifecycle.SystemStarted;
import com.gitplex.server.event.lifecycle.SystemStarting;
import com.gitplex.server.event.lifecycle.SystemStopping;
-import com.gitplex.server.gatekeeper.GateKeeper;
import com.gitplex.server.git.GitUtils;
import com.gitplex.server.git.command.CloneCommand;
import com.gitplex.server.manager.AccountManager;
@@ -49,7 +48,8 @@ import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.Team;
import com.gitplex.server.model.TeamAuthorization;
-import com.gitplex.server.model.support.IntegrationPolicy;
+import com.gitplex.server.model.support.BranchProtection;
+import com.gitplex.server.model.support.TagProtection;
import com.gitplex.server.persistence.annotation.Sessional;
import com.gitplex.server.persistence.annotation.Transactional;
import com.gitplex.server.persistence.dao.AbstractEntityManager;
@@ -150,27 +150,15 @@ public class DefaultDepotManager extends AbstractEntityManager<Depot> implements
Account oldAccount = userManager.load(oldAccountId);
listenerRegistry.post(new DepotTransferred(depot, oldAccount));
- for (Depot each: findAll()) {
- for (IntegrationPolicy policy: each.getIntegrationPolicies()) {
- policy.onDepotTransfer(depot, oldAccount);
- }
- for (Iterator<GateKeeper> it = each.getGateKeepers().iterator(); it.hasNext();) {
- if (it.next().onDepotTransfer(each, depot, oldAccount))
- it.remove();
- }
- }
+ for (BranchProtection protection: depot.getBranchProtections()) {
+ protection.onDepotTransferred(depot);
+ }
+ for (TagProtection protection: depot.getTagProtections()) {
+ protection.onDepotTransferred(depot);
+ }
}
if (oldName != null && !depot.getName().equals(oldName)) {
listenerRegistry.post(new DepotRenamed(depot, oldName));
-
- for (Depot each: findAll()) {
- for (IntegrationPolicy integrationPolicy: each.getIntegrationPolicies()) {
- integrationPolicy.onDepotRename(depot.getAccount(), oldName, depot.getName());
- }
- for (GateKeeper gateKeeper: each.getGateKeepers()) {
- gateKeeper.onDepotRename(depot, oldName);
- }
- }
}
doAfterCommit(newAfterCommitRunnable(depot, isNew));
@@ -204,17 +192,6 @@ public class DefaultDepotManager extends AbstractEntityManager<Depot> implements
dao.remove(depot);
- for (Depot each: findAll()) {
- for (Iterator<IntegrationPolicy> it = each.getIntegrationPolicies().iterator(); it.hasNext();) {
- if (it.next().onDepotDelete(depot))
- it.remove();
- }
- for (Iterator<GateKeeper> it = each.getGateKeepers().iterator(); it.hasNext();) {
- if (it.next().onDepotDelete(depot))
- it.remove();
- }
- }
-
doAfterCommit(new Runnable() {
@Override
@@ -361,16 +338,18 @@ public class DefaultDepotManager extends AbstractEntityManager<Depot> implements
@Listen
public void on(RefUpdated event) {
if (event.getNewObjectId().equals(ObjectId.zeroId())) {
+ Depot depot = event.getDepot();
String branch = GitUtils.ref2branch(event.getRefName());
- for (Depot each: findAll()) {
- if (branch != null) {
- for (Iterator<IntegrationPolicy> it = each.getIntegrationPolicies().iterator(); it.hasNext();) {
- if (it.next().onBranchDelete(each, event.getDepot(), branch))
- it.remove();
- }
+ if (branch != null) {
+ for (Iterator<BranchProtection> it = depot.getBranchProtections().iterator(); it.hasNext();) {
+ if (it.next().onBranchDelete(branch))
+ it.remove();
}
- for (Iterator<GateKeeper> it = each.getGateKeepers().iterator(); it.hasNext();) {
- if (it.next().onRefDelete(event.getRefName()))
+ }
+ String tag = GitUtils.ref2tag(event.getRefName());
+ if (tag != null) {
+ for (Iterator<TagProtection> it = depot.getTagProtections().iterator(); it.hasNext();) {
+ if (it.next().onTagDelete(tag))
it.remove();
}
}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestManager.java
index b5d156c3c0..91de640aa6 100644
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestManager.java
@@ -6,28 +6,24 @@ import static com.gitplex.server.model.PullRequest.CriterionHelper.ofSourceDepot
import static com.gitplex.server.model.PullRequest.CriterionHelper.ofSubmitter;
import static com.gitplex.server.model.PullRequest.CriterionHelper.ofTarget;
import static com.gitplex.server.model.PullRequest.CriterionHelper.ofTargetDepot;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.MERGE_ALWAYS;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.MERGE_IF_NECESSARY;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
+import static com.gitplex.server.model.support.MergeStrategy.ALWAYS_MERGE;
+import static com.gitplex.server.model.support.MergeStrategy.MERGE_IF_NECESSARY;
+import static com.gitplex.server.model.support.MergeStrategy.SQUASH_MERGE;
+import static com.gitplex.server.model.support.MergeStrategy.REBASE_MERGE;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicLong;
-import javax.annotation.Nullable;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ThreadContext;
import org.apache.wicket.request.cycle.RequestCycle;
-import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
@@ -35,7 +31,6 @@ import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
-import org.eclipse.jgit.transport.RefSpec;
import org.hibernate.Query;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
@@ -44,42 +39,34 @@ import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Lists;
import com.gitplex.launcher.loader.Listen;
import com.gitplex.launcher.loader.ListenerRegistry;
+import com.gitplex.server.GitPlex;
import com.gitplex.server.event.RefUpdated;
import com.gitplex.server.event.depot.DepotDeleted;
-import com.gitplex.server.event.pullrequest.IntegrationPreviewCalculated;
+import com.gitplex.server.event.pullrequest.MergePreviewCalculated;
import com.gitplex.server.event.pullrequest.PullRequestOpened;
-import com.gitplex.server.event.pullrequest.PullRequestPendingApproval;
-import com.gitplex.server.event.pullrequest.PullRequestPendingIntegration;
-import com.gitplex.server.event.pullrequest.PullRequestPendingUpdate;
import com.gitplex.server.event.pullrequest.PullRequestStatusChangeEvent;
-import com.gitplex.server.gatekeeper.checkresult.Failed;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.gatekeeper.checkresult.Pending;
import com.gitplex.server.git.GitUtils;
import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.manager.BatchWorkManager;
import com.gitplex.server.manager.MarkdownManager;
import com.gitplex.server.manager.PullRequestManager;
-import com.gitplex.server.manager.PullRequestReviewInvitationManager;
import com.gitplex.server.manager.PullRequestStatusChangeManager;
import com.gitplex.server.manager.PullRequestUpdateManager;
+import com.gitplex.server.manager.ReviewInvitationManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReviewInvitation;
import com.gitplex.server.model.PullRequestStatusChange;
-import com.gitplex.server.model.PullRequestUpdate;
-import com.gitplex.server.model.PullRequest.IntegrationStrategy;
import com.gitplex.server.model.PullRequestStatusChange.Type;
+import com.gitplex.server.model.PullRequestUpdate;
+import com.gitplex.server.model.Review;
+import com.gitplex.server.model.ReviewInvitation;
import com.gitplex.server.model.support.CloseInfo;
import com.gitplex.server.model.support.DepotAndBranch;
-import com.gitplex.server.model.support.IntegrationPolicy;
-import com.gitplex.server.model.support.IntegrationPreview;
+import com.gitplex.server.model.support.MergePreview;
+import com.gitplex.server.model.support.MergeStrategy;
import com.gitplex.server.persistence.UnitOfWork;
import com.gitplex.server.persistence.annotation.Sessional;
import com.gitplex.server.persistence.annotation.Transactional;
@@ -88,11 +75,10 @@ import com.gitplex.server.persistence.dao.Dao;
import com.gitplex.server.persistence.dao.EntityCriteria;
import com.gitplex.server.security.SecurityUtils;
import com.gitplex.server.util.BatchWorker;
+import com.gitplex.server.util.ReviewCheckStatus;
import com.gitplex.server.util.concurrent.Prioritized;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchUtils;
-import com.gitplex.server.util.includeexclude.IncludeExcludeUtils;
-import com.gitplex.server.util.match.ChildAwareMatcher;
-import com.gitplex.server.util.match.PatternMatcher;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
@Singleton
public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest> implements PullRequestManager {
@@ -103,8 +89,6 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
private static final int BACKEND_PREVIEW_PRIORITY = 50;
- private static final PatternMatcher BRANCH_MATCHER = new ChildAwareMatcher();
-
private final PullRequestUpdateManager pullRequestUpdateManager;
private final AccountManager accountManager;
@@ -113,7 +97,7 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
private final ListenerRegistry listenerRegistry;
- private final PullRequestReviewInvitationManager reviewInvitationManager;
+ private final ReviewInvitationManager reviewInvitationManager;
private final BatchWorkManager batchWorkManager;
@@ -123,7 +107,7 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
@Inject
public DefaultPullRequestManager(Dao dao, PullRequestUpdateManager pullRequestUpdateManager,
- PullRequestReviewInvitationManager reviewInvitationManager, AccountManager accountManager,
+ ReviewInvitationManager reviewInvitationManager, AccountManager accountManager,
MarkdownManager markdownManager, BatchWorkManager batchWorkManager,
ListenerRegistry listenerRegistry, UnitOfWork unitOfWork,
PullRequestStatusChangeManager pullRequestStatusChangeManager) {
@@ -171,7 +155,7 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
statusChange.setDate(new Date());
statusChange.setNote(note);
statusChange.setRequest(request);
- statusChange.setType(Type.SOURCE_BRANCH_RESTORED);
+ statusChange.setType(Type.RESTORED_SOURCE_BRANCH);
statusChange.setUser(accountManager.getCurrent());
pullRequestStatusChangeManager.save(statusChange);
@@ -192,7 +176,7 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
statusChange.setDate(new Date());
statusChange.setNote(note);
statusChange.setRequest(request);
- statusChange.setType(Type.SOURCE_BRANCH_DELETED);
+ statusChange.setType(Type.DELETED_SOURCE_BRANCH);
statusChange.setUser(accountManager.getCurrent());
pullRequestStatusChangeManager.save(statusChange);
@@ -217,7 +201,7 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
request.setLastEvent(statusChange);
save(request);
- checkAsync(request);
+ checkStatusAsync(request);
}
@Transactional
@@ -244,105 +228,63 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
save(request);
}
- @Transactional
- @Override
- public void integrate(PullRequest request, String note) {
- IntegrationPreview preview = request.getIntegrationPreview();
+ private void merge(PullRequest request) {
+ MergePreview preview = request.getMergePreview();
if (preview == null)
- throw new IllegalStateException("Integration preview has not been calculated yet.");
+ throw new IllegalStateException("Merge preview has not been calculated yet.");
- String integrated = preview.getIntegrated();
- if (integrated == null)
- throw new IllegalStateException("There are integration conflicts.");
+ String merged = preview.getMerged();
+ if (merged == null)
+ throw new IllegalStateException("There are merge conflicts.");
- Account user = accountManager.getCurrent();
-
- ObjectId integratedId = ObjectId.fromString(integrated);
- RevCommit integratedCommit = request.getTargetDepot().getRevCommit(integratedId);
+ ObjectId mergedId = ObjectId.fromString(merged);
+ RevCommit mergedCommit = request.getTargetDepot().getRevCommit(mergedId);
+ PersonIdent committer = new PersonIdent(GitPlex.NAME, "");
+
Depot targetDepot = request.getTargetDepot();
- IntegrationStrategy strategy = request.getIntegrationStrategy();
- if ((strategy == MERGE_ALWAYS || strategy == MERGE_IF_NECESSARY || strategy == MERGE_WITH_SQUASH)
- && !preview.getIntegrated().equals(preview.getRequestHead())
- && !integratedCommit.getFullMessage().equals(request.getCommitMessage())) {
+ MergeStrategy strategy = request.getMergeStrategy();
+ if ((strategy == ALWAYS_MERGE || strategy == MERGE_IF_NECESSARY || strategy == SQUASH_MERGE)
+ && !preview.getMerged().equals(preview.getRequestHead())
+ && !mergedCommit.getFullMessage().equals(request.getCommitMessage())) {
try ( RevWalk revWalk = new RevWalk(targetDepot.getRepository());
ObjectInserter inserter = targetDepot.getRepository().newObjectInserter()) {
CommitBuilder newCommit = new CommitBuilder();
- newCommit.setAuthor(integratedCommit.getAuthorIdent());
- newCommit.setCommitter(user.asPerson());
+ newCommit.setAuthor(mergedCommit.getAuthorIdent());
+ newCommit.setCommitter(committer);
newCommit.setMessage(request.getCommitMessage());
- newCommit.setTreeId(integratedCommit.getTree());
- newCommit.setParentIds(integratedCommit.getParents());
- integratedId = inserter.insert(newCommit);
- integrated = integratedId.name();
+ newCommit.setTreeId(mergedCommit.getTree());
+ newCommit.setParentIds(mergedCommit.getParents());
+ mergedId = inserter.insert(newCommit);
+ merged = mergedId.name();
inserter.flush();
} catch (Exception e) {
Throwables.propagate(e);
}
- preview = new IntegrationPreview(preview.getTargetHead(), preview.getRequestHead(),
- preview.getIntegrationStrategy(), integrated);
- request.setLastIntegrationPreview(preview);
- RefUpdate refUpdate = targetDepot.updateRef(request.getIntegrateRef());
- refUpdate.setNewObjectId(integratedId);
+ preview = new MergePreview(preview.getTargetHead(), preview.getRequestHead(),
+ preview.getMergeStrategy(), merged);
+ request.setLastMergePreview(preview);
+ RefUpdate refUpdate = targetDepot.updateRef(request.getMergeRef());
+ refUpdate.setNewObjectId(mergedId);
GitUtils.updateRef(refUpdate);
}
- closeAsIntegrated(request, false, note);
-
- if (strategy == REBASE_SOURCE_ONTO_TARGET || strategy == MERGE_WITH_SQUASH) {
- Depot sourceDepot = request.getSourceDepot();
- if (!sourceDepot.equals(targetDepot)) {
- try {
- sourceDepot.git().fetch()
- .setRemote(targetDepot.getDirectory().getAbsolutePath())
- .setRefSpecs(new RefSpec(request.getIntegrateRef()))
- .call();
- } catch (GitAPIException e) {
- throw new RuntimeException(e);
- }
- }
- RefUpdate refUpdate = sourceDepot.updateRef(request.getSourceRef());
- refUpdate.setNewObjectId(integratedId);
- ObjectId requestHeadId = ObjectId.fromString(preview.getRequestHead());
- refUpdate.setExpectedOldObjectId(requestHeadId);
- refUpdate.setRefLogMessage("Pull request #" + request.getNumber(), true);
- GitUtils.updateRef(refUpdate);
-
- checkUpdate(request, false);
-
- Long requestId = request.getId();
- ObjectId newSourceHeadId = integratedId;
- Subject subject = SecurityUtils.getSubject();
- doUnitOfWorkAsyncAfterCommit(new Runnable() {
-
- @Override
- public void run() {
- ThreadContext.bind(subject);
- try {
- PullRequest request = load(requestId);
- request.getSourceDepot().cacheObjectId(request.getSourceRef(), newSourceHeadId);
- listenerRegistry.post(new RefUpdated(
- request.getSourceDepot(), request.getSourceRef(), requestHeadId, newSourceHeadId));
- } finally {
- ThreadContext.unbindSubject();
- }
- }
-
- });
- }
+ closeAsMerged(request, false, null);
String targetRef = request.getTargetRef();
ObjectId targetHeadId = ObjectId.fromString(preview.getTargetHead());
RefUpdate refUpdate = targetDepot.updateRef(targetRef);
- refUpdate.setRefLogIdent(user.asPerson());
+ refUpdate.setRefLogIdent(committer);
refUpdate.setRefLogMessage("Pull request #" + request.getNumber(), true);
refUpdate.setExpectedOldObjectId(targetHeadId);
- refUpdate.setNewObjectId(integratedId);
+ refUpdate.setNewObjectId(mergedId);
GitUtils.updateRef(refUpdate);
+ request.getTargetDepot().cacheObjectId(request.getTargetRef(), mergedId);
+
Long requestId = request.getId();
Subject subject = SecurityUtils.getSubject();
- ObjectId newTargetHeadId = integratedId;
+ ObjectId newTargetHeadId = mergedId;
doUnitOfWorkAsyncAfterCommit(new Runnable() {
@Override
@@ -402,63 +344,31 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
refUpdate.setNewObjectId(ObjectId.fromString(request.getBaseCommitHash()));
GitUtils.updateRef(refUpdate);
+ refUpdate = request.getTargetDepot().updateRef(request.getHeadRef());
+ refUpdate.setNewObjectId(ObjectId.fromString(request.getHeadCommitHash()));
+ GitUtils.updateRef(refUpdate);
+
for (PullRequestUpdate update: request.getUpdates()) {
pullRequestUpdateManager.save(update, false);
}
- for (PullRequestReviewInvitation invitation: request.getReviewInvitations())
+ for (ReviewInvitation invitation: request.getReviewInvitations())
reviewInvitationManager.save(invitation);
- checkAsync(request);
+ checkStatusAsync(request);
listenerRegistry.post(new PullRequestOpened(request));
}
- @Override
- public List<IntegrationStrategy> getApplicableIntegrationStrategies(PullRequest request) {
- List<IntegrationStrategy> strategies = null;
- for (IntegrationPolicy policy: request.getTargetDepot().getIntegrationPolicies()) {
- if (IncludeExcludeUtils.getIncludeExclude(policy.getTargetBranchMatch()).matches(BRANCH_MATCHER, request.getTargetBranch())
- && FullBranchMatchUtils.matches(policy.getSourceBranchMatch(), request.getTargetDepot(), request.getSource())) {
- strategies = policy.getIntegrationStrategies();
- break;
- }
- }
- if (strategies == null)
- strategies = Lists.newArrayList(IntegrationStrategy.MERGE_ALWAYS);
- return strategies;
- }
-
- @Transactional
- @Override
- public void changeAssignee(PullRequest request) {
- if (request.isOpen()) {
- String note = request.getAssignee().getDisplayName() + " is expected to integrate the pull request";
-
- PullRequestStatusChange statusChange = new PullRequestStatusChange();
- statusChange.setDate(new Date());
- statusChange.setNote(note);
- statusChange.setRequest(request);
- statusChange.setType(Type.ASSIGNED);
- statusChange.setUser(accountManager.getCurrent());
- pullRequestStatusChangeManager.save(statusChange);
-
- request.setLastEvent(statusChange);
- }
- save(request);
- }
-
- private void closeAsIntegrated(PullRequest request, boolean dueToMerged, String note) {
- Account user = accountManager.getCurrent();
+ private void closeAsMerged(PullRequest request, boolean dueToMerged, String note) {
Date date = new Date();
if (dueToMerged)
- request.setLastIntegrationPreview(null);
+ request.setLastMergePreview(null);
CloseInfo closeInfo = new CloseInfo();
closeInfo.setCloseDate(date);
- closeInfo.setClosedBy(user);
- closeInfo.setCloseStatus(CloseInfo.Status.INTEGRATED);
+ closeInfo.setCloseStatus(CloseInfo.Status.MERGED);
request.setCloseInfo(closeInfo);
if (dueToMerged)
@@ -468,15 +378,14 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
statusChange.setDate(date);
statusChange.setNote(note);
statusChange.setRequest(request);
- statusChange.setType(Type.INTEGRATED);
- statusChange.setUser(user);
+ statusChange.setType(Type.MERGED);
pullRequestStatusChangeManager.save(statusChange);
request.setLastEvent(statusChange);
save(request);
}
- private void checkUpdate(PullRequest request, boolean independent) {
+ private void checkUpdate(PullRequest request) {
if (!request.getHeadCommitHash().equals(request.getSource().getObjectName())) {
ObjectId mergeBase = GitUtils.getMergeBase(
request.getTargetDepot().getRepository(), request.getTarget().getObjectId(),
@@ -486,16 +395,20 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
PullRequestUpdate update = new PullRequestUpdate();
update.setRequest(request);
update.setHeadCommitHash(request.getSource().getObjectName());
- update.setMergeCommitHash(mergeBase.name());
+ update.setMergeBaseCommitHash(mergeBase.name());
request.addUpdate(update);
- pullRequestUpdateManager.save(update, independent);
+ pullRequestUpdateManager.save(update, true);
+
+ RefUpdate refUpdate = request.getTargetDepot().updateRef(request.getHeadRef());
+ refUpdate.setNewObjectId(ObjectId.fromString(request.getHeadCommitHash()));
+ GitUtils.updateRef(refUpdate);
}
}
}
@Transactional
@Override
- public void check(PullRequest request) {
+ public void checkStatus(PullRequest request) {
if (request.isOpen()) {
if (request.getSourceDepot() == null) {
discard(request, "Source repository no longer exists");
@@ -504,27 +417,28 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
} else if (request.getTarget().getObjectId(false) == null) {
discard(request, "Target branch no longer exists");
} else {
- checkUpdate(request, true);
- if (request.isMerged()) {
- closeAsIntegrated(request, true, null);
+ checkUpdate(request);
+ if (request.isMergeIntoTarget()) {
+ closeAsMerged(request, true, null);
} else {
- IntegrationPreview integrationPreview = request.getIntegrationPreview();
- Date timeBeforeCheck = new Date();
- GateCheckResult result = request.checkGates(false);
- if (result instanceof Pending) {
- for (PullRequestReviewInvitation invitation: request.getReviewInvitations()) {
- if (invitation.getDate().getTime()>=timeBeforeCheck.getTime())
- reviewInvitationManager.save(invitation);
+ MergePreview mergePreview = request.getMergePreview();
+ ReviewCheckStatus checkStatus = request.getReviewCheckStatus();
+
+ for (ReviewInvitation invitation: request.getReviewInvitations()) {
+ if (checkStatus.getAwaitingReviewers().contains(invitation.getUser()))
+ reviewInvitationManager.save(invitation);
+ }
+
+ boolean hasDisapprovals = false;
+ for (Review review: checkStatus.getEffectiveReviews().values()) {
+ if (!review.isApproved()) {
+ hasDisapprovals = true;
+ break;
}
- listenerRegistry.post(new PullRequestPendingApproval(request));
- } else if (result instanceof Failed) {
- listenerRegistry.post(new PullRequestPendingUpdate(request));
- } else if (integrationPreview != null
- && integrationPreview.getIntegrated() != null
- && request.getAssignee() == null) {
- integrate(request, "Integrated automatically by GitPlex");
- } else {
- listenerRegistry.post(new PullRequestPendingIntegration(request));
+ }
+ if (!hasDisapprovals && checkStatus.getAwaitingReviewers().isEmpty()
+ && mergePreview != null && mergePreview.getMerged() != null) {
+ merge(request);
}
}
}
@@ -532,31 +446,35 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
}
@Override
- public IntegrationPreview previewIntegration(PullRequest request) {
- IntegrationPreview preview = request.getLastIntegrationPreview();
- if (request.isOpen() && !request.isMerged() && (preview == null || preview.isObsolete(request))) {
- int priority = RequestCycle.get() != null?UI_PREVIEW_PRIORITY:BACKEND_PREVIEW_PRIORITY;
- if (dao.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE) {
- doAfterCommit(new Runnable() {
-
- @Override
- public void run() {
- batchWorkManager.submit(getIntegrationPreviewer(request), new Prioritized(priority));
- }
-
- });
+ public MergePreview previewMerge(PullRequest request) {
+ if (request.getMergeStrategy() != MergeStrategy.DO_NOT_MERGE) {
+ MergePreview lastPreview = request.getLastMergePreview();
+ if (request.isOpen() && !request.isMergeIntoTarget() && (lastPreview == null || lastPreview.isObsolete(request))) {
+ int priority = RequestCycle.get() != null?UI_PREVIEW_PRIORITY:BACKEND_PREVIEW_PRIORITY;
+ if (dao.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE) {
+ doAfterCommit(new Runnable() {
+
+ @Override
+ public void run() {
+ batchWorkManager.submit(getMergePreviewer(request), new Prioritized(priority));
+ }
+
+ });
+ } else {
+ batchWorkManager.submit(getMergePreviewer(request), new Prioritized(priority));
+ }
+ return null;
} else {
- batchWorkManager.submit(getIntegrationPreviewer(request), new Prioritized(priority));
+ return lastPreview;
}
- return null;
} else {
- return preview;
+ return null;
}
}
- private BatchWorker getIntegrationPreviewer(PullRequest request) {
+ private BatchWorker getMergePreviewer(PullRequest request) {
Long requestId = request.getId();
- return new BatchWorker("request-" + requestId + "-previewIntegration", 1) {
+ return new BatchWorker("request-" + requestId + "-previewMerge", 1) {
@Override
public void doWork(Collection<Prioritized> works) {
@@ -567,57 +485,56 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
public Void call() throws Exception {
PullRequest request = load(requestId);
try {
- IntegrationPreview preview = request.getLastIntegrationPreview();
- if (request.isOpen() && !request.isMerged() && (preview == null || preview.isObsolete(request))) {
- logger.info("Calculating integration preview of pull request #{} in repository '{}'...",
+ MergePreview preview = request.getLastMergePreview();
+ if (request.isOpen() && !request.isMergeIntoTarget() && (preview == null || preview.isObsolete(request))) {
+ logger.info("Calculating merge preview of pull request #{} in repository '{}'...",
request.getNumber(), request.getTargetDepot());
String requestHead = request.getHeadCommitHash();
String targetHead = request.getTarget().getObjectName();
Depot targetDepot = request.getTargetDepot();
- preview = new IntegrationPreview(targetHead, requestHead, request.getIntegrationStrategy(), null);
- request.setLastIntegrationPreview(preview);
- String integrateRef = request.getIntegrateRef();
+ preview = new MergePreview(targetHead, requestHead, request.getMergeStrategy(), null);
+ request.setLastMergePreview(preview);
+ String mergeRef = request.getMergeRef();
ObjectId requestHeadId = ObjectId.fromString(requestHead);
ObjectId targetHeadId = ObjectId.fromString(targetHead);
- if (preview.getIntegrationStrategy() == MERGE_IF_NECESSARY
+ if ((preview.getMergeStrategy() == MERGE_IF_NECESSARY)
&& GitUtils.isMergedInto(targetDepot.getRepository(), targetHeadId, requestHeadId)) {
- preview.setIntegrated(requestHead);
- RefUpdate refUpdate = targetDepot.updateRef(integrateRef);
+ preview.setMerged(requestHead);
+ RefUpdate refUpdate = targetDepot.updateRef(mergeRef);
refUpdate.setNewObjectId(ObjectId.fromString(requestHead));
GitUtils.updateRef(refUpdate);
} else {
- PersonIdent user = accountManager.getRoot().asPerson();
- ObjectId integrated;
- if (preview.getIntegrationStrategy() == REBASE_TARGET_ONTO_SOURCE) {
- integrated = GitUtils.rebase(targetDepot.getRepository(), targetHeadId, requestHeadId, user);
- } else if (preview.getIntegrationStrategy() == REBASE_SOURCE_ONTO_TARGET) {
- integrated = GitUtils.rebase(targetDepot.getRepository(), requestHeadId, targetHeadId, user);
- } else if (preview.getIntegrationStrategy() == MERGE_WITH_SQUASH) {
- integrated = GitUtils.merge(targetDepot.getRepository(),
+ PersonIdent user = new PersonIdent(GitPlex.NAME, "");
+ ObjectId merged;
+ if (preview.getMergeStrategy() == REBASE_MERGE) {
+ merged = GitUtils.rebase(targetDepot.getRepository(), requestHeadId, targetHeadId, user);
+ } else if (preview.getMergeStrategy() == SQUASH_MERGE) {
+ merged = GitUtils.merge(targetDepot.getRepository(),
requestHeadId, targetHeadId, true, user, request.getCommitMessage());
} else {
- integrated = GitUtils.merge(targetDepot.getRepository(),
+ merged = GitUtils.merge(targetDepot.getRepository(),
requestHeadId, targetHeadId, false, user, request.getCommitMessage());
}
- if (integrated != null) {
- preview.setIntegrated(integrated.name());
- RefUpdate refUpdate = targetDepot.updateRef(integrateRef);
- refUpdate.setNewObjectId(integrated);
+ if (merged != null) {
+ preview.setMerged(merged.name());
+ RefUpdate refUpdate = targetDepot.updateRef(mergeRef);
+ refUpdate.setNewObjectId(merged);
GitUtils.updateRef(refUpdate);
} else {
- RefUpdate refUpdate = targetDepot.updateRef(integrateRef);
+ RefUpdate refUpdate = targetDepot.updateRef(mergeRef);
GitUtils.deleteRef(refUpdate);
}
}
+ preview.setDate(new Date());
dao.persist(request);
- listenerRegistry.post(new IntegrationPreviewCalculated(request));
- logger.info("Integration preview of pull request #{} in repository '{}' is calculated.",
+ listenerRegistry.post(new MergePreviewCalculated(request));
+ logger.info("Merge preview of pull request #{} in repository '{}' is calculated.",
request.getNumber(), request.getTargetDepot());
}
} catch (Exception e) {
- logger.error("Error calculating pull request integration preview", e);
+ logger.error("Error calculating pull request merge preview", e);
}
return null;
}
@@ -652,16 +569,22 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
ofOpen(),
Restrictions.or(ofSource(depotAndBranch), ofTarget(depotAndBranch)));
for (PullRequest request: findAll(EntityCriteria.of(PullRequest.class).add(criterion))) {
- check(request);
+ checkStatus(request);
}
}
}
@Sessional
@Override
- public PullRequest findOpen(DepotAndBranch target, DepotAndBranch source) {
- return find(EntityCriteria.of(PullRequest.class)
- .add(ofTarget(target)).add(ofSource(source)).add(ofOpen()));
+ public PullRequest findEffective(DepotAndBranch target, DepotAndBranch source) {
+ EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
+ Criterion merged = Restrictions.and(
+ Restrictions.eq("closeInfo.closeStatus", CloseInfo.Status.MERGED),
+ Restrictions.eq("lastMergePreview.requestHead", source.getObjectName()));
+
+ criteria.add(ofTarget(target)).add(ofSource(source)).add(Restrictions.or(ofOpen(), merged));
+
+ return find(criteria);
}
@Sessional
@@ -677,24 +600,9 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
@Sessional
@Override
- public Collection<PullRequest> findAllOpenTo(DepotAndBranch target, @Nullable Depot sourceDepot) {
+ public Collection<PullRequest> findAllOpenTo(DepotAndBranch target) {
EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
criteria.add(ofTarget(target));
-
- if (sourceDepot != null)
- criteria.add(Restrictions.eq("sourceDepot", sourceDepot));
- criteria.add(ofOpen());
- return findAll(criteria);
- }
-
- @Sessional
- @Override
- public Collection<PullRequest> findAllOpenFrom(DepotAndBranch source, @Nullable Depot targetDepot) {
- EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
- criteria.add(ofSource(source));
-
- if (targetDepot != null)
- criteria.add(Restrictions.eq("targetDepot", targetDepot));
criteria.add(ofOpen());
return findAll(criteria);
}
@@ -737,28 +645,27 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
@Listen
public void on(PullRequestStatusChangeEvent event) {
Type type = event.getStatusChange().getType();
- if (type == Type.APPROVED || type == Type.DISAPPROVED || type == Type.REVIEW_DELETED
- || type == Type.VERIFICATION_DELETED || type == Type.VERIFICATION_SUCCEEDED
- || type == Type.VERIFICATION_FAILED) {
- checkAsync(event.getRequest());
+ if (type == Type.APPROVED || type == Type.DISAPPROVED || type == Type.WITHDRAWED_REVIEW
+ || type == Type.REMOVED_REVIEWER || type == Type.ADDED_REVIEWER) {
+ checkStatusAsync(event.getRequest());
}
}
@Listen
- public void on(IntegrationPreviewCalculated event) {
- checkAsync(event.getRequest());
+ public void on(MergePreviewCalculated event) {
+ checkStatusAsync(event.getRequest());
}
- private Runnable newCheckRunnable(Long requestId, Subject subject) {
+ private Runnable newCheckStatusRunnable(Long requestId, Subject subject) {
return new Runnable() {
@Override
public void run() {
try {
ThreadContext.bind(subject);
- check(load(requestId));
+ checkStatus(load(requestId));
} catch (Exception e) {
- logger.error("Error checking pull request", e);
+ logger.error("Error checking pull request status", e);
} finally {
ThreadContext.unbindSubject();
}
@@ -768,14 +675,30 @@ public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest
}
@Sessional
- protected void checkAsync(PullRequest request) {
+ protected void checkStatusAsync(PullRequest request) {
Long requestId = request.getId();
Subject subject = SecurityUtils.getSubject();
if (dao.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE) {
- doUnitOfWorkAsyncAfterCommit(newCheckRunnable(requestId, subject));
+ doUnitOfWorkAsyncAfterCommit(newCheckStatusRunnable(requestId, subject));
} else {
- unitOfWork.doAsync(newCheckRunnable(requestId, subject));
+ unitOfWork.doAsync(newCheckStatusRunnable(requestId, subject));
}
}
+ @Transactional
+ @Override
+ public void saveMergeStrategy(PullRequest request) {
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(new Date());
+ statusChange.setRequest(request);
+ statusChange.setType(Type.CHANGED_MERGE_STRATEGY);
+ statusChange.setUser(accountManager.getCurrent());
+
+ pullRequestStatusChangeManager.save(statusChange);
+
+ request.setLastEvent(statusChange);
+
+ save(request);
+ }
+
}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReferenceManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReferenceManager.java
index 86c1d4bedc..c07123263f 100644
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReferenceManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReferenceManager.java
@@ -9,7 +9,7 @@ import org.hibernate.criterion.Restrictions;
import com.gitplex.launcher.loader.Listen;
import com.gitplex.server.event.MarkdownAware;
-import com.gitplex.server.event.pullrequest.PullRequestChangeEvent;
+import com.gitplex.server.event.pullrequest.PullRequestEvent;
import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.manager.MarkdownManager;
import com.gitplex.server.manager.PullRequestReferenceManager;
@@ -39,7 +39,7 @@ public class DefaultPullRequestReferenceManager extends AbstractEntityManager<Pu
@Transactional
@Listen
- public void on(PullRequestChangeEvent event) {
+ public void on(PullRequestEvent event) {
if (event instanceof MarkdownAware) {
String markdown = ((MarkdownAware)event).getMarkdown();
if (markdown != null) {
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReviewInvitationManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReviewInvitationManager.java
deleted file mode 100644
index 2bbec0b200..0000000000
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReviewInvitationManager.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.gitplex.server.manager.impl;
-
-import java.util.Collection;
-import java.util.Date;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.hibernate.criterion.Restrictions;
-
-import com.gitplex.launcher.loader.ListenerRegistry;
-import com.gitplex.server.event.pullrequest.PullRequestReviewInvitationChanged;
-import com.gitplex.server.manager.PullRequestReviewInvitationManager;
-import com.gitplex.server.manager.PullRequestReviewManager;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReviewInvitation;
-import com.gitplex.server.persistence.annotation.Sessional;
-import com.gitplex.server.persistence.annotation.Transactional;
-import com.gitplex.server.persistence.dao.AbstractEntityManager;
-import com.gitplex.server.persistence.dao.Dao;
-import com.gitplex.server.persistence.dao.EntityCriteria;
-
-@Singleton
-public class DefaultPullRequestReviewInvitationManager extends AbstractEntityManager<PullRequestReviewInvitation>
- implements PullRequestReviewInvitationManager {
-
- private final PullRequestReviewManager reviewManager;
-
- private final ListenerRegistry listenerRegistry;
-
- @Inject
- public DefaultPullRequestReviewInvitationManager(Dao dao, PullRequestReviewManager reviewManager,
- ListenerRegistry listenerRegistry) {
- super(dao);
-
- this.reviewManager = reviewManager;
- this.listenerRegistry = listenerRegistry;
- }
-
- @Sessional
- @Override
- public PullRequestReviewInvitation find(Account reviewer, PullRequest request) {
- return find(EntityCriteria.of(PullRequestReviewInvitation.class)
- .add(Restrictions.eq("reviewer", reviewer))
- .add(Restrictions.eq("request", request)));
- }
-
- @Transactional
- @Override
- public void save(PullRequestReviewInvitation invitation) {
- dao.persist(invitation);
-
- listenerRegistry.post(new PullRequestReviewInvitationChanged(invitation));
- }
-
- @Transactional
- @Override
- public void update(Collection<PullRequestReviewInvitation> invitations, Date since) {
- for (PullRequestReviewInvitation invitation: invitations) {
- if (invitation.getDate().getTime()>=since.getTime()) {
- save(invitation);
- if (invitation.getStatus() == PullRequestReviewInvitation.Status.EXCLUDED)
- reviewManager.deleteAll(invitation.getUser(), invitation.getRequest());
- }
- }
- }
-}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReviewManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReviewManager.java
deleted file mode 100644
index 3fa60d1391..0000000000
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestReviewManager.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package com.gitplex.server.manager.impl;
-
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Restrictions;
-
-import com.gitplex.server.manager.AccountManager;
-import com.gitplex.server.manager.PullRequestManager;
-import com.gitplex.server.manager.PullRequestReviewManager;
-import com.gitplex.server.manager.PullRequestStatusChangeManager;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.model.PullRequestStatusChange;
-import com.gitplex.server.model.PullRequestUpdate;
-import com.gitplex.server.model.PullRequestStatusChange.Type;
-import com.gitplex.server.persistence.annotation.Sessional;
-import com.gitplex.server.persistence.annotation.Transactional;
-import com.gitplex.server.persistence.dao.AbstractEntityManager;
-import com.gitplex.server.persistence.dao.Dao;
-import com.gitplex.server.persistence.dao.EntityCriteria;
-
-@Singleton
-public class DefaultPullRequestReviewManager extends AbstractEntityManager<PullRequestReview> implements PullRequestReviewManager {
-
- private final AccountManager accountManager;
-
- private final PullRequestManager pullRequestManager;
-
- private final PullRequestStatusChangeManager pullRequestStatusChangeManager;
-
- @Inject
- public DefaultPullRequestReviewManager(Dao dao, AccountManager accountManager, PullRequestManager pullRequestManager,
- PullRequestStatusChangeManager pullRequestStatusChangeManager) {
- super(dao);
-
- this.accountManager = accountManager;
- this.pullRequestManager = pullRequestManager;
- this.pullRequestStatusChangeManager = pullRequestStatusChangeManager;
- }
-
- @Sessional
- @Override
- public PullRequestReview find(Account user, PullRequestUpdate update) {
- return find(EntityCriteria.of(PullRequestReview.class)
- .add(Restrictions.eq("user", user))
- .add(Restrictions.eq("update", update)));
- }
-
- @Transactional
- @Override
- public void review(PullRequest request, PullRequestReview.Result result, String note) {
- Account user = accountManager.getCurrent();
- Date date = new Date();
-
- PullRequestReview review = new PullRequestReview();
- review.setUpdate(request.getLatestUpdate());
- review.setResult(result);
- review.setUser(user);
- review.setDate(date);
- save(review);
-
- PullRequestStatusChange statusChange = new PullRequestStatusChange();
- statusChange.setDate(date);
- statusChange.setNote(note);
- statusChange.setRequest(request);
- if (result == PullRequestReview.Result.APPROVE) {
- statusChange.setType(Type.APPROVED);
- } else {
- statusChange.setType(Type.DISAPPROVED);
- }
- statusChange.setUser(user);
- pullRequestStatusChangeManager.save(statusChange);
-
- request.setLastEvent(statusChange);
- pullRequestManager.save(request);
- }
-
- @Transactional
- @Override
- public void delete(PullRequestReview entity) {
- super.delete(entity);
-
- PullRequest request = entity.getUpdate().getRequest();
-
- PullRequestStatusChange statusChange = new PullRequestStatusChange();
- statusChange.setDate(new Date());
- statusChange.setRequest(request);
- statusChange.setType(Type.REVIEW_DELETED);
- statusChange.setUser(accountManager.getCurrent());
- pullRequestStatusChangeManager.save(statusChange);
-
- request.setLastEvent(statusChange);
- pullRequestManager.save(request);
- }
-
- @Sessional
- @Override
- public List<PullRequestReview> findAll(PullRequest request) {
- EntityCriteria<PullRequestReview> criteria = EntityCriteria.of(PullRequestReview.class);
- criteria.createCriteria("update").add(Restrictions.eq("request", request));
- criteria.addOrder(Order.asc("date"));
- return findAll(criteria);
- }
-
- @Transactional
- @Override
- public void deleteAll(Account user, PullRequest request) {
- for (Iterator<PullRequestReview> it = request.getReviews().iterator(); it.hasNext();) {
- PullRequestReview review = it.next();
- if (review.getUser().equals(user)) {
- delete(review);
- it.remove();
- }
- }
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestTaskManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestTaskManager.java
index 01a990292f..ec123500f5 100644
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestTaskManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestTaskManager.java
@@ -1,25 +1,19 @@
package com.gitplex.server.manager.impl;
-import static com.gitplex.server.model.PullRequest.Status.PENDING_INTEGRATE;
-import static com.gitplex.server.model.PullRequestTask.Type.INTEGRATE;
+import static com.gitplex.server.model.PullRequestTask.Type.RESOLVE_CONFLICT;
import static com.gitplex.server.model.PullRequestTask.Type.REVIEW;
import static com.gitplex.server.model.PullRequestTask.Type.UPDATE;
import javax.inject.Inject;
import javax.inject.Singleton;
-import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
import com.gitplex.launcher.loader.Listen;
import com.gitplex.launcher.loader.ListenerRegistry;
-import com.gitplex.server.event.TaskChangeEvent;
-import com.gitplex.server.event.pullrequest.PullRequestPendingApproval;
-import com.gitplex.server.event.pullrequest.PullRequestPendingIntegration;
-import com.gitplex.server.event.pullrequest.PullRequestPendingUpdate;
-import com.gitplex.server.event.pullrequest.PullRequestReviewInvitationChanged;
+import com.gitplex.server.event.ReviewInvitationChanged;
+import com.gitplex.server.event.TaskChanged;
+import com.gitplex.server.event.pullrequest.MergePreviewCalculated;
import com.gitplex.server.event.pullrequest.PullRequestStatusChangeEvent;
import com.gitplex.server.event.pullrequest.PullRequestUpdated;
import com.gitplex.server.manager.MailManager;
@@ -27,13 +21,14 @@ import com.gitplex.server.manager.PullRequestTaskManager;
import com.gitplex.server.manager.UrlManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReviewInvitation;
import com.gitplex.server.model.PullRequestStatusChange;
import com.gitplex.server.model.PullRequestTask;
+import com.gitplex.server.model.ReviewInvitation;
import com.gitplex.server.persistence.annotation.Transactional;
import com.gitplex.server.persistence.dao.AbstractEntityManager;
import com.gitplex.server.persistence.dao.Dao;
import com.gitplex.server.persistence.dao.EntityCriteria;
+import com.google.common.collect.Sets;
/**
* This class manages pull request tasks and send task notifications if necessary.
@@ -66,25 +61,25 @@ public class DefaultPullRequestTaskManager extends AbstractEntityManager<PullReq
EntityCriteria<PullRequestTask> criteria = newCriteria();
criteria.add(Restrictions.eq("request", event.getRequest())).add(Restrictions.eq("type", UPDATE));
for (PullRequestTask task: findAll(criteria)) {
- listenerRegistry.post(new TaskChangeEvent(task.getUser()));
+ listenerRegistry.post(new TaskChanged(task.getUser()));
delete(task);
}
}
@Transactional
@Listen
- public void on(PullRequestReviewInvitationChanged event) {
- PullRequestReviewInvitation invitation = event.getInvitation();
+ public void on(ReviewInvitationChanged event) {
+ ReviewInvitation invitation = event.getInvitation();
PullRequest request = invitation.getRequest();
Account user = invitation.getUser();
- if (invitation.getStatus() == PullRequestReviewInvitation.Status.EXCLUDED) {
+ if (invitation.getType() == ReviewInvitation.Type.EXCLUDE) {
EntityCriteria<PullRequestTask> criteria = newCriteria();
criteria.add(Restrictions.eq("request", request)).add(Restrictions.eq("user", user)).add(Restrictions.eq("type", REVIEW));
for (PullRequestTask task: findAll(criteria)) {
- listenerRegistry.post(new TaskChangeEvent(task.getUser()));
+ listenerRegistry.post(new TaskChanged(task.getUser()));
delete(task);
}
- } else if (invitation.getStatus() == PullRequestReviewInvitation.Status.ADDED_BY_RULE) {
+ } else {
PullRequestTask task = new PullRequestTask();
task.setRequest(request);
task.setUser(user);
@@ -99,22 +94,14 @@ public class DefaultPullRequestTaskManager extends AbstractEntityManager<PullReq
String subject = String.format("Please review pull request #%d (%s)",
request.getNumber(), request.getTitle());
String url = urlManager.urlFor(request);
- String body = String.format("You are designated to review pull request #%d (%s).<br>"
+ String body = String.format("You are selected to review pull request #%d (%s).<br>"
+ "Please visit <a href='%s'>%s</a> to do the review.",
request.getNumber(), request.getTitle(), url, url);
mailManager.sendMailAsync(Sets.newHashSet(task.getUser().getEmail()), subject, decorate(user, body));
- listenerRegistry.post(new TaskChangeEvent(user));
+ listenerRegistry.post(new TaskChanged(user));
}
- } else {
- String subject = String.format("You are invited to review pull request #%d (%s)",
- request.getNumber(), request.getTitle());
- String url = urlManager.urlFor(request);
- String body = String.format("You are invited to review pull request #%d (%s).<br>"
- + "Please visit <a href='%s'>%s</a> to do the review.",
- request.getNumber(), request.getTitle(), url, url);
- mailManager.sendMailAsync(Sets.newHashSet(invitation.getUser().getEmail()), subject, decorate(user, body));
- }
+ }
}
private String decorate(Account user, String body) {
@@ -128,102 +115,81 @@ public class DefaultPullRequestTaskManager extends AbstractEntityManager<PullReq
@Transactional
@Listen
- public void on(PullRequestPendingApproval event) {
- EntityCriteria<PullRequestTask> criteria = newCriteria();
- Criterion typeCriterion = Restrictions.or(Restrictions.eq("type", UPDATE), Restrictions.eq("type", INTEGRATE));
- criteria.add(Restrictions.eq("request", event.getRequest())).add(typeCriterion);
- for (PullRequestTask task: findAll(criteria)) {
- listenerRegistry.post(new TaskChangeEvent(task.getUser()));
- delete(task);
- }
- }
-
- private void requestIntegration(PullRequest request) {
- Account user = request.getAssignee();
- PullRequestTask task = new PullRequestTask();
- task.setRequest(request);
- task.setUser(user);
- task.setType(INTEGRATE);
- EntityCriteria<PullRequestTask> criteria = EntityCriteria.of(PullRequestTask.class);
- criteria.add(Restrictions.eq("request", task.getRequest()))
- .add(Restrictions.eq("user", user))
- .add(Restrictions.eq("type", task.getType()));
- if (find(criteria) == null) {
- save(task);
- String subject = String.format("Please integrate pull request #%d (%s)",
- request.getNumber(), request.getTitle());
- String url = urlManager.urlFor(request);
- String body = String.format("Pull request #%d (%s) is pending integration.<br>"
- + "Please visit <a href='%s'>%s</a> to check and integrate.",
- request.getNumber(), request.getTitle(), url, url);
-
- mailManager.sendMailAsync(Sets.newHashSet(task.getUser().getEmail()), subject, decorate(user, body));
- listenerRegistry.post(new TaskChangeEvent(user));
- }
- }
-
- @Transactional
- @Listen
- public void on(PullRequestPendingIntegration event) {
+ public void on(MergePreviewCalculated event) {
PullRequest request = event.getRequest();
- if (request.getAssignee() != null)
- requestIntegration(request);
- }
-
- @Transactional
- @Listen
- public void on(PullRequestPendingUpdate event) {
- PullRequest request = event.getRequest();
- PullRequestTask task = new PullRequestTask();
- task.setRequest(request);
- task.setUser(request.getSubmitter());
- task.setType(UPDATE);
- EntityCriteria<PullRequestTask> criteria = EntityCriteria.of(PullRequestTask.class);
- criteria.add(Restrictions.eq("request", task.getRequest()))
- .add(Restrictions.eq("user", task.getUser()))
- .add(Restrictions.eq("type", task.getType()));
- if (find(criteria) == null) {
- save(task);
- String subject = String.format("New commits are expected in pull request #%d (%s)",
- request.getNumber(), request.getTitle());
- String url = urlManager.urlFor(request);
- String body = String.format("Next commits are expected for next round of review in pull request #%d (%s).<br>"
- + "Please visit <a href='%s'>%s</a> for details",
- request.getNumber(), request.getTitle(), url, url);
- mailManager.sendMailAsync(Sets.newHashSet(request.getSubmitter().getEmail()), subject,
- decorate(request.getSubmitter(), body));
- listenerRegistry.post(new TaskChangeEvent(request.getSubmitter()));
+ Account user = request.getSubmitter();
+ if (user != null && request.getMergePreview() != null) {
+ if (request.getMergePreview().getMerged() != null) {
+ EntityCriteria<PullRequestTask> criteria = newCriteria();
+ criteria.add(Restrictions.eq("user", user)).add(Restrictions.eq("type", RESOLVE_CONFLICT));
+ for (PullRequestTask task: findAll(criteria)) {
+ listenerRegistry.post(new TaskChanged(task.getUser()));
+ delete(task);
+ }
+ } else {
+ PullRequestTask task = new PullRequestTask();
+ task.setRequest(request);
+ task.setUser(user);
+ task.setType(RESOLVE_CONFLICT);
+ EntityCriteria<PullRequestTask> criteria = EntityCriteria.of(PullRequestTask.class);
+ criteria.add(Restrictions.eq("request", task.getRequest()))
+ .add(Restrictions.eq("user", user))
+ .add(Restrictions.eq("type", task.getType()));
+ if (find(criteria) == null) {
+ save(task);
+ String subject = String.format("Please resolve conflicts in pull request #%d (%s)",
+ request.getNumber(), request.getTitle());
+ String url = urlManager.urlFor(request);
+ String body = String.format("Pull request #%d (%s) has merge conflicts<br>"
+ + "Please visit <a href='%s'>%s</a> for details.",
+ request.getNumber(), request.getTitle(), url, url);
+
+ mailManager.sendMailAsync(Sets.newHashSet(task.getUser().getEmail()), subject, decorate(user, body));
+ listenerRegistry.post(new TaskChanged(user));
+ }
+ }
}
}
@Transactional
@Listen
public void on(PullRequestStatusChangeEvent event) {
+ PullRequest request = event.getRequest();
PullRequestStatusChange statusChange = event.getStatusChange();
PullRequestStatusChange.Type type = statusChange.getType();
EntityCriteria<PullRequestTask> criteria = newCriteria();
- criteria.add(Restrictions.eq("request", event.getRequest()));
- if (type == PullRequestStatusChange.Type.APPROVED || type == PullRequestStatusChange.Type.DISAPPROVED) {
+ criteria.add(Restrictions.eq("request", request));
+ if (type == PullRequestStatusChange.Type.APPROVED || type == PullRequestStatusChange.Type.DISAPPROVED) {
criteria.add(Restrictions.eq("user", statusChange.getUser())).add(Restrictions.eq("type", REVIEW));
for (PullRequestTask task: findAll(criteria)) {
- listenerRegistry.post(new TaskChangeEvent(task.getUser()));
+ listenerRegistry.post(new TaskChanged(task.getUser()));
delete(task);
}
- } else if (type == PullRequestStatusChange.Type.ASSIGNED) {
- PullRequest request = event.getRequest();
- Preconditions.checkNotNull(request.getAssignee());
-
- if (request.getStatus() == PENDING_INTEGRATE) {
- criteria.add(Restrictions.ne("user", request.getAssignee())).add(Restrictions.eq("type", INTEGRATE));
- for (PullRequestTask task: findAll(criteria)) {
- listenerRegistry.post(new TaskChangeEvent(task.getUser()));
- delete(task);
+ if (type == PullRequestStatusChange.Type.DISAPPROVED && request.getSubmitter() != null) {
+ PullRequestTask task = new PullRequestTask();
+ task.setRequest(request);
+ task.setUser(request.getSubmitter());
+ task.setType(UPDATE);
+ criteria = EntityCriteria.of(PullRequestTask.class);
+ criteria.add(Restrictions.eq("request", task.getRequest()))
+ .add(Restrictions.eq("user", task.getUser()))
+ .add(Restrictions.eq("type", task.getType()));
+ if (find(criteria) == null) {
+ save(task);
+ String subject = String.format("Someone raised concerns in pull request #%d (%s)",
+ request.getNumber(), request.getTitle());
+ String url = urlManager.urlFor(request);
+ String body = String.format("Someone raised concerns in pull request #%d (%s).<br>"
+ + "Please visit <a href='%s'>%s</a> for details",
+ request.getNumber(), request.getTitle(), url, url);
+ mailManager.sendMailAsync(Sets.newHashSet(request.getSubmitter().getEmail()), subject,
+ decorate(request.getSubmitter(), body));
+ listenerRegistry.post(new TaskChanged(request.getSubmitter()));
}
- requestIntegration(request);
}
- } else if (type == PullRequestStatusChange.Type.INTEGRATED || type == PullRequestStatusChange.Type.DISCARDED) {
+ } else if (type == PullRequestStatusChange.Type.MERGED || type == PullRequestStatusChange.Type.DISCARDED) {
for (PullRequestTask task: findAll(criteria)) {
- listenerRegistry.post(new TaskChangeEvent(task.getUser()));
+ listenerRegistry.post(new TaskChanged(task.getUser()));
delete(task);
}
}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestVerificationManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestVerificationManager.java
deleted file mode 100644
index aa9dfb3b43..0000000000
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestVerificationManager.java
+++ /dev/null
@@ -1,131 +0,0 @@
-package com.gitplex.server.manager.impl;
-
-import java.util.Collection;
-import java.util.Date;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.hibernate.criterion.Restrictions;
-
-import com.gitplex.launcher.loader.ListenerRegistry;
-import com.gitplex.server.event.pullrequest.PullRequestVerificationRunning;
-import com.gitplex.server.manager.AccountManager;
-import com.gitplex.server.manager.PullRequestManager;
-import com.gitplex.server.manager.PullRequestStatusChangeManager;
-import com.gitplex.server.manager.PullRequestVerificationManager;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestStatusChange;
-import com.gitplex.server.model.PullRequestVerification;
-import com.gitplex.server.model.PullRequestStatusChange.Type;
-import com.gitplex.server.model.PullRequestVerification.Status;
-import com.gitplex.server.persistence.annotation.Sessional;
-import com.gitplex.server.persistence.annotation.Transactional;
-import com.gitplex.server.persistence.dao.AbstractEntityManager;
-import com.gitplex.server.persistence.dao.Dao;
-import com.gitplex.server.persistence.dao.EntityCriteria;
-
-@Singleton
-public class DefaultPullRequestVerificationManager extends AbstractEntityManager<PullRequestVerification>
- implements PullRequestVerificationManager {
-
- private final AccountManager accountManager;
-
- private final PullRequestStatusChangeManager pullRequestStatusChangeManager;
-
- private final PullRequestManager pullRequestManager;
-
- private final ListenerRegistry listenerRegistry;
-
- @Inject
- public DefaultPullRequestVerificationManager(Dao dao, AccountManager accountManager,
- PullRequestStatusChangeManager pullRequestStatusChangeManager,
- PullRequestManager pullRequestManager, ListenerRegistry listenerRegistry) {
- super(dao);
- this.accountManager = accountManager;
- this.pullRequestStatusChangeManager = pullRequestStatusChangeManager;
- this.pullRequestManager = pullRequestManager;
- this.listenerRegistry = listenerRegistry;
- }
-
- @Transactional
- @Override
- public void save(PullRequestVerification entity) {
- super.save(entity);
-
- PullRequest request = entity.getRequest();
-
- if (entity.getStatus() == PullRequestVerification.Status.RUNNING) {
- listenerRegistry.post(new PullRequestVerificationRunning(entity));
- } else {
- PullRequestStatusChange statusChange = new PullRequestStatusChange();
- statusChange.setDate(new Date());
- statusChange.setNote("configuration: " + entity.getConfiguration() + "\n"
- + "message: " + entity.getMessage());
- statusChange.setRequest(request);
- if (entity.getStatus() == PullRequestVerification.Status.FAILED)
- statusChange.setType(Type.VERIFICATION_FAILED);
- else
- statusChange.setType(Type.VERIFICATION_SUCCEEDED);
- statusChange.setRequest(request);
- statusChange.setUser(entity.getUser());
- pullRequestStatusChangeManager.save(statusChange);
-
- request.setLastEvent(statusChange);
- pullRequestManager.save(request);
- }
- }
-
- @Transactional
- @Override
- public void delete(PullRequestVerification entity) {
- super.delete(entity);
-
- PullRequest request = entity.getRequest();
-
- PullRequestStatusChange statusChange = new PullRequestStatusChange();
- statusChange.setDate(new Date());
- statusChange.setNote("configuration: " + entity.getConfiguration());
- statusChange.setRequest(request);
- statusChange.setType(Type.VERIFICATION_DELETED);
- statusChange.setUser(accountManager.getCurrent());
- pullRequestStatusChangeManager.save(statusChange);
-
- request.setLastEvent(statusChange);
- pullRequestManager.save(request);
- }
-
- @Sessional
- @Override
- public Collection<PullRequestVerification> findAll(PullRequest request, String commit) {
- return findRange(EntityCriteria.of(PullRequestVerification.class)
- .add(Restrictions.eq("request", request))
- .add(Restrictions.eq("commit", commit)), 0, 0);
- }
-
- @Sessional
- @Override
- public PullRequestVerification find(PullRequest request, String commit, String configuration) {
- return find(EntityCriteria.of(PullRequestVerification.class)
- .add(Restrictions.eq("request", request))
- .add(Restrictions.eq("commit", commit))
- .add(Restrictions.eq("configuration", configuration)));
- }
-
- @Override
- public Status getOverallStatus(Collection<PullRequestVerification> verifications) {
- PullRequestVerification.Status overallStatus = null;
- for (PullRequestVerification verification: verifications) {
- if (verification.getStatus() == PullRequestVerification.Status.FAILED) {
- overallStatus = PullRequestVerification.Status.FAILED;
- break;
- } else if (verification.getStatus() == PullRequestVerification.Status.RUNNING) {
- overallStatus = PullRequestVerification.Status.RUNNING;
- } else if (overallStatus == null) {
- overallStatus = PullRequestVerification.Status.SUCCESSFUL;
- }
- }
- return overallStatus;
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestWatchManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestWatchManager.java
index b5de4573ea..d174202b92 100644
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestWatchManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultPullRequestWatchManager.java
@@ -12,19 +12,17 @@ import javax.inject.Singleton;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.revwalk.RevCommit;
-import com.google.common.collect.Sets;
import com.gitplex.launcher.loader.Listen;
import com.gitplex.server.event.MarkdownAware;
-import com.gitplex.server.event.pullrequest.IntegrationPreviewCalculated;
-import com.gitplex.server.event.pullrequest.PullRequestChangeEvent;
+import com.gitplex.server.event.ReviewInvitationChanged;
+import com.gitplex.server.event.pullrequest.MergePreviewCalculated;
import com.gitplex.server.event.pullrequest.PullRequestCodeCommentActivityEvent;
import com.gitplex.server.event.pullrequest.PullRequestCodeCommentCreated;
import com.gitplex.server.event.pullrequest.PullRequestCommentCreated;
+import com.gitplex.server.event.pullrequest.PullRequestEvent;
import com.gitplex.server.event.pullrequest.PullRequestOpened;
-import com.gitplex.server.event.pullrequest.PullRequestReviewInvitationChanged;
import com.gitplex.server.event.pullrequest.PullRequestStatusChangeEvent;
import com.gitplex.server.event.pullrequest.PullRequestUpdated;
-import com.gitplex.server.event.pullrequest.PullRequestVerificationRunning;
import com.gitplex.server.git.NameAndEmail;
import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.manager.BranchWatchManager;
@@ -36,10 +34,10 @@ import com.gitplex.server.manager.VisitInfoManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.BranchWatch;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReviewInvitation;
+import com.gitplex.server.model.PullRequestStatusChange.Type;
import com.gitplex.server.model.PullRequestUpdate;
import com.gitplex.server.model.PullRequestWatch;
-import com.gitplex.server.model.PullRequestStatusChange.Type;
+import com.gitplex.server.model.ReviewInvitation;
import com.gitplex.server.persistence.annotation.Transactional;
import com.gitplex.server.persistence.dao.AbstractEntityManager;
import com.gitplex.server.persistence.dao.Dao;
@@ -77,8 +75,8 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
@Transactional
@Listen
- public void on(PullRequestChangeEvent event) {
- if (event instanceof IntegrationPreviewCalculated || event instanceof PullRequestVerificationRunning) {
+ public void on(PullRequestEvent event) {
+ if (event instanceof MergePreviewCalculated) {
return;
}
String eventType;
@@ -86,7 +84,7 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
if (event instanceof PullRequestStatusChangeEvent) {
statusChangeType = ((PullRequestStatusChangeEvent) event).getStatusChange().getType();
eventType = statusChangeType.getName();
- if (statusChangeType == Type.SOURCE_BRANCH_DELETED || statusChangeType == Type.SOURCE_BRANCH_RESTORED) {
+ if (statusChangeType == Type.DELETED_SOURCE_BRANCH || statusChangeType == Type.RESTORED_SOURCE_BRANCH) {
return;
}
} else {
@@ -96,24 +94,16 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
PullRequest request = event.getRequest();
Account user = event.getUser();
- /*
- * verification is often performed automatically by robots (such as CI system), and it does not make
- * sense to make them watching the pull request
- */
- if (user != null && statusChangeType != Type.VERIFICATION_SUCCEEDED && statusChangeType != Type.VERIFICATION_FAILED) {
+ if (user != null && user.getEmail() != null) {
watch(request, user,
"You've set to watch this pull request as you've " + eventType);
}
if (event instanceof PullRequestOpened) {
- if (request.getAssignee() != null)
- watch(request, request.getAssignee(), "You are set to watch this pull request as you are assigned to integrate it.");
for (BranchWatch branchWatch: branchWatchManager.find(request.getTargetDepot(), request.getTargetBranch())) {
watch(request, branchWatch.getUser(),
"You are set to watch this pull request as you are watching the target branch.");
}
makeContributorsWatching(request.getLatestUpdate());
- } else if (statusChangeType == Type.ASSIGNED) {
- watch(request, request.getAssignee(), "You are set to watch this pull request as you are assigned to integrate it.");
} else if (event instanceof PullRequestUpdated) {
PullRequestUpdated updated = (PullRequestUpdated) event;
makeContributorsWatching(updated.getUpdate());
@@ -175,19 +165,6 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
}
watchUsers.removeAll(mentionUsers);
-
- if ((event instanceof PullRequestOpened || statusChangeType == Type.ASSIGNED)
- && request.getAssignee() != null
- && !request.getAssignee().equals(event.getUser())) {
- watchUsers.remove(request.getAssignee());
- String subject = String.format("You are assigned with pull request #%d (%s)",
- request.getNumber(), request.getTitle());
- String url = urlManager.urlFor(request);
- String body = String.format("You are assigned with pull request #%d (%s).<br>"
- + "Please visit <a href='%s'>%s</a> for details.",
- request.getNumber(), request.getTitle(), url, url);
- mailManager.sendMailAsync(Sets.newHashSet(request.getAssignee().getEmail()), subject, decorateBody(body));
- }
if (!watchUsers.isEmpty()) {
String subject, body;
@@ -244,9 +221,9 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
@Transactional
@Listen
- public void on(PullRequestReviewInvitationChanged event) {
- PullRequestReviewInvitation invitation = event.getInvitation();
- if (invitation.getStatus() != PullRequestReviewInvitation.Status.EXCLUDED) {
+ public void on(ReviewInvitationChanged event) {
+ ReviewInvitation invitation = event.getInvitation();
+ if (invitation.getType() != ReviewInvitation.Type.EXCLUDE) {
watch(invitation.getRequest(), invitation.getUser(),
"You are set to watch this pull request as you are invited to review it.");
}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultReviewInvitationManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultReviewInvitationManager.java
new file mode 100644
index 0000000000..44e6c1dce3
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultReviewInvitationManager.java
@@ -0,0 +1,96 @@
+package com.gitplex.server.manager.impl;
+
+import java.util.Date;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import com.gitplex.launcher.loader.ListenerRegistry;
+import com.gitplex.server.event.ReviewInvitationChanged;
+import com.gitplex.server.manager.PullRequestManager;
+import com.gitplex.server.manager.PullRequestStatusChangeManager;
+import com.gitplex.server.manager.ReviewInvitationManager;
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.PullRequest;
+import com.gitplex.server.model.PullRequestStatusChange;
+import com.gitplex.server.model.ReviewInvitation;
+import com.gitplex.server.persistence.annotation.Transactional;
+import com.gitplex.server.persistence.dao.AbstractEntityManager;
+import com.gitplex.server.persistence.dao.Dao;
+import com.gitplex.server.security.SecurityUtils;
+
+@Singleton
+public class DefaultReviewInvitationManager extends AbstractEntityManager<ReviewInvitation>
+ implements ReviewInvitationManager {
+
+ private final ListenerRegistry listenerRegistry;
+
+ private final PullRequestManager pullRequestManager;
+
+ private final PullRequestStatusChangeManager pullRequestStatusChangeManager;
+
+ @Inject
+ public DefaultReviewInvitationManager(Dao dao, ListenerRegistry listenerRegistry,
+ PullRequestManager pullRequestManager, PullRequestStatusChangeManager pullRequestStatusChangeManger) {
+ super(dao);
+
+ this.listenerRegistry = listenerRegistry;
+ this.pullRequestManager = pullRequestManager;
+ this.pullRequestStatusChangeManager = pullRequestStatusChangeManger;
+ }
+
+ @Transactional
+ @Override
+ public void save(ReviewInvitation invitation) {
+ dao.persist(invitation);
+
+ listenerRegistry.post(new ReviewInvitationChanged(invitation));
+ }
+
+ @Transactional
+ @Override
+ public boolean exclude(ReviewInvitation invitation) {
+ invitation.setType(ReviewInvitation.Type.EXCLUDE);
+ PullRequest request = invitation.getRequest();
+
+ save(invitation);
+
+ Account reviewer = invitation.getUser();
+ if (request.getReviewCheckStatus().getAwaitingReviewers().contains(reviewer)
+ || request.getReviewCheckStatus().getEffectiveReviews().containsKey(reviewer)) {
+ return false;
+ } else {
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(new Date());
+ statusChange.setRequest(request);
+ statusChange.setType(PullRequestStatusChange.Type.REMOVED_REVIEWER);
+ statusChange.setUser(SecurityUtils.getAccount());
+ statusChange.setNote("User '" + reviewer.getDisplayName() + "' is removed from reviewer list");
+ pullRequestStatusChangeManager.save(statusChange);
+
+ request.setLastEvent(statusChange);
+ pullRequestManager.save(request);
+ return true;
+ }
+ }
+
+ @Transactional
+ @Override
+ public void invite(ReviewInvitation invitation) {
+ save(invitation);
+
+ PullRequest request = invitation.getRequest();
+
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(new Date());
+ statusChange.setRequest(request);
+ statusChange.setType(PullRequestStatusChange.Type.ADDED_REVIEWER);
+ statusChange.setNote("User '" + invitation.getUser().getDisplayName() + "' is added as a reviewer");
+ statusChange.setUser(SecurityUtils.getAccount());
+ pullRequestStatusChangeManager.save(statusChange);
+
+ request.setLastEvent(statusChange);
+ pullRequestManager.save(request);
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultReviewManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultReviewManager.java
new file mode 100644
index 0000000000..730b8736ac
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultReviewManager.java
@@ -0,0 +1,385 @@
+package com.gitplex.server.manager.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Nullable;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.TreeFilter;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
+
+import com.gitplex.server.manager.AccountManager;
+import com.gitplex.server.manager.PullRequestManager;
+import com.gitplex.server.manager.PullRequestStatusChangeManager;
+import com.gitplex.server.manager.ReviewManager;
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.PullRequest;
+import com.gitplex.server.model.PullRequestStatusChange;
+import com.gitplex.server.model.PullRequestStatusChange.Type;
+import com.gitplex.server.model.PullRequestUpdate;
+import com.gitplex.server.model.Review;
+import com.gitplex.server.model.ReviewInvitation;
+import com.gitplex.server.model.Team;
+import com.gitplex.server.model.support.BranchProtection;
+import com.gitplex.server.model.support.FileProtection;
+import com.gitplex.server.persistence.annotation.Sessional;
+import com.gitplex.server.persistence.annotation.Transactional;
+import com.gitplex.server.persistence.dao.AbstractEntityManager;
+import com.gitplex.server.persistence.dao.Dao;
+import com.gitplex.server.persistence.dao.EntityCriteria;
+import com.gitplex.server.security.ObjectPermission;
+import com.gitplex.server.security.SecurityUtils;
+import com.gitplex.server.security.privilege.DepotPrivilege;
+import com.gitplex.server.util.ReviewCheckStatus;
+import com.gitplex.server.util.reviewappointment.ReviewAppointment;
+import com.google.common.base.Preconditions;
+
+@Singleton
+public class DefaultReviewManager extends AbstractEntityManager<Review> implements ReviewManager {
+
+ private final AccountManager accountManager;
+
+ private final PullRequestManager pullRequestManager;
+
+ private final PullRequestStatusChangeManager pullRequestStatusChangeManager;
+
+ @Inject
+ public DefaultReviewManager(Dao dao, AccountManager accountManager, PullRequestManager pullRequestManager,
+ PullRequestStatusChangeManager pullRequestStatusChangeManager) {
+ super(dao);
+
+ this.accountManager = accountManager;
+ this.pullRequestManager = pullRequestManager;
+ this.pullRequestStatusChangeManager = pullRequestStatusChangeManager;
+ }
+
+ @Transactional
+ @Override
+ public ReviewCheckStatus checkRequest(PullRequest request) {
+ return new ReviewCheckStatusImpl(request);
+ }
+
+ @Sessional
+ @Override
+ public Review find(Account user, PullRequestUpdate update) {
+ return find(EntityCriteria.of(Review.class)
+ .add(Restrictions.eq("user", user))
+ .add(Restrictions.eq("update", update)));
+ }
+
+ @Transactional
+ @Override
+ public void review(PullRequest request, boolean approved, String note) {
+ Account user = accountManager.getCurrent();
+ Date date = new Date();
+
+ Review review = new Review();
+ review.setRequest(request);
+ review.setApproved(approved);
+ review.setNote(note);
+ review.setUser(user);
+ review.setDate(date);
+ save(review);
+
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(date);
+ statusChange.setNote(note);
+ statusChange.setRequest(request);
+ if (approved) {
+ statusChange.setType(Type.APPROVED);
+ } else {
+ statusChange.setType(Type.DISAPPROVED);
+ }
+ statusChange.setUser(user);
+ pullRequestStatusChangeManager.save(statusChange);
+
+ request.setLastEvent(statusChange);
+ pullRequestManager.save(request);
+ }
+
+ @Sessional
+ @Override
+ public List<Review> findAll(PullRequest request) {
+ EntityCriteria<Review> criteria = EntityCriteria.of(Review.class);
+ criteria.createCriteria("update").add(Restrictions.eq("request", request));
+ criteria.addOrder(Order.asc("date"));
+ return findAll(criteria);
+ }
+
+ @Transactional
+ @Override
+ public void delete(Account user, PullRequest request) {
+ for (Iterator<Review> it = request.getReviews().iterator(); it.hasNext();) {
+ Review review = it.next();
+ if (review.getUser().equals(user)) {
+ delete(review);
+ it.remove();
+ }
+ }
+
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(new Date());
+ statusChange.setRequest(request);
+ statusChange.setType(Type.WITHDRAWED_REVIEW);
+ statusChange.setNote("Review of user '" + user.getDisplayName() + "' is withdrawed");
+ statusChange.setUser(accountManager.getCurrent());
+ pullRequestStatusChangeManager.save(statusChange);
+
+ request.setLastEvent(statusChange);
+ pullRequestManager.save(request);
+ }
+
+ @Override
+ public boolean canModify(Account user, Depot depot, String branch, String file) {
+ BranchProtection branchProtection = depot.getBranchProtection(branch);
+ if (branchProtection != null) {
+ if (branchProtection.getReviewAppointment(depot) != null
+ && !branchProtection.getReviewAppointment(depot).matches(user)) {
+ return false;
+ }
+ FileProtection fileProtection = branchProtection.getFileProtection(file);
+ if (fileProtection != null && !fileProtection.getReviewAppointment(depot).matches(user))
+ return false;
+ }
+ return true;
+ }
+
+ private Set<String> getChangedFiles(Depot depot, ObjectId oldObjectId, ObjectId newObjectId) {
+ Set<String> changedFiles = new HashSet<>();
+ try (TreeWalk treeWalk = new TreeWalk(depot.getRepository())) {
+ treeWalk.setFilter(TreeFilter.ANY_DIFF);
+ treeWalk.setRecursive(true);
+ RevCommit oldCommit = depot.getRevCommit(oldObjectId);
+ RevCommit newCommit = depot.getRevCommit(newObjectId);
+ treeWalk.addTree(oldCommit.getTree());
+ treeWalk.addTree(newCommit.getTree());
+ while (treeWalk.next()) {
+ changedFiles.add(treeWalk.getPathString());
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return changedFiles;
+ }
+
+ @Override
+ public boolean canPush(Account user, Depot depot, String branch, ObjectId oldObjectId, ObjectId newObjectId) {
+ BranchProtection branchProtection = depot.getBranchProtection(branch);
+ if (branchProtection != null) {
+ if (branchProtection.getReviewAppointment(depot) != null
+ && !branchProtection.getReviewAppointment(depot).matches(user)) {
+ return false;
+ }
+
+ for (String changedFile: getChangedFiles(depot, oldObjectId, newObjectId)) {
+ FileProtection fileProtection = branchProtection.getFileProtection(changedFile);
+ if (fileProtection != null && !fileProtection.getReviewAppointment(depot).matches(user))
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static class ReviewCheckStatusImpl implements ReviewCheckStatus {
+
+ private final PullRequest request;
+
+ private final List<Account> awaitingReviewers = new ArrayList<>();
+
+ private final Map<Account, Review> effectiveReviews = new HashMap<>();
+
+ @Override
+ public List<Account> getAwaitingReviewers() {
+ return awaitingReviewers;
+ }
+
+ @Override
+ public Map<Account, Review> getEffectiveReviews() {
+ return effectiveReviews;
+ }
+
+ @Nullable
+ private ReviewInvitation getInvitation(Account user) {
+ for (ReviewInvitation invitation: request.getReviewInvitations()) {
+ if (invitation.getUser().equals(user))
+ return invitation;
+ }
+ return null;
+ }
+
+ public ReviewCheckStatusImpl(PullRequest request) {
+ this.request = request;
+
+ for (ReviewInvitation invitation: request.getReviewInvitations()) {
+ if (!invitation.getUser().equals(request.getSubmitter())
+ && invitation.getType() == ReviewInvitation.Type.MANUAL) {
+ Review effectiveReview = invitation.getUser().getReviewAfter(request.getLatestUpdate());
+ if (effectiveReview == null)
+ awaitingReviewers.add(invitation.getUser());
+ else
+ effectiveReviews.put(effectiveReview.getUser(), effectiveReview);
+ }
+ }
+
+ BranchProtection branchProtection = request.getTargetDepot().getBranchProtection(request.getTargetBranch());
+ if (branchProtection != null) {
+ ReviewAppointment appointment = branchProtection.getReviewAppointment(request.getTargetDepot());
+ if (appointment != null)
+ checkReviews(appointment, request.getLatestUpdate());
+
+ Set<FileProtection> checkedFileProtections = new HashSet<>();
+ for (int i=request.getSortedUpdates().size()-1; i>=0; i--) {
+ if (checkedFileProtections.containsAll(branchProtection.getFileProtections()))
+ break;
+ PullRequestUpdate update = request.getSortedUpdates().get(i);
+ for (String file: update.getChangedFiles()) {
+ FileProtection fileProtection = branchProtection.getFileProtection(file);
+ if (fileProtection != null && !checkedFileProtections.contains(fileProtection)) {
+ checkedFileProtections.add(fileProtection);
+ checkReviews(fileProtection.getReviewAppointment(request.getTargetDepot()), update);
+ }
+ }
+ }
+ }
+
+ ObjectPermission writePermission = ObjectPermission.ofDepotWrite(request.getTargetDepot());
+ if (request.getSubmitter() == null || !request.getSubmitter().asSubject().isPermitted(writePermission)) {
+ checkReviews(SecurityUtils.findUsersCan(request.getTargetDepot(), DepotPrivilege.WRITE), 1,
+ request.getLatestUpdate());
+ }
+
+ for (Iterator<Map.Entry<Account, Review>> it = effectiveReviews.entrySet().iterator(); it.hasNext();) {
+ Review review = it.next().getValue();
+ if (review.isCheckMerged()) {
+ if (request.getMergePreview() == null
+ || request.getMergePreview().getDate().after(review.getDate())) {
+ if (!awaitingReviewers.contains(review.getUser()))
+ awaitingReviewers.add(review.getUser());
+ it.remove();
+ }
+ }
+ }
+
+ }
+
+ private void checkReviews(ReviewAppointment appointment, PullRequestUpdate update) {
+ for (Account user: appointment.getUsers()) {
+ if (!user.equals(request.getSubmitter()) && !awaitingReviewers.contains(user)) {
+ Review effectiveReview = user.getReviewAfter(update);
+ if (effectiveReview == null) {
+ awaitingReviewers.add(user);
+ recordReviewer(user);
+ } else {
+ effectiveReviews.put(effectiveReview.getUser(), effectiveReview);
+ }
+ }
+ }
+
+ for (Map.Entry<Team, Integer> entry: appointment.getTeams().entrySet()) {
+ Team team = entry.getKey();
+ int requiredCount = entry.getValue();
+ checkReviews(team.getMembers(), requiredCount, update);
+ }
+ }
+
+ private void checkReviews(Collection<Account> users, int requiredCount, PullRequestUpdate update) {
+ if (requiredCount == 0 || requiredCount > users.size())
+ requiredCount = users.size();
+
+ int effectiveCount = 0;
+ Set<Account> potentialReviewers = new HashSet<>();
+ for (Account user: users) {
+ if (user.equals(request.getSubmitter())) {
+ effectiveCount++;
+ } else if (awaitingReviewers.contains(user)) {
+ requiredCount--;
+ } else {
+ Review effectiveReview = user.getReviewAfter(update);
+ if (effectiveReview != null) {
+ effectiveCount++;
+ } else {
+ potentialReviewers.add(user);
+ }
+ }
+ if (effectiveCount >= requiredCount)
+ break;
+ }
+
+ int missingCount = requiredCount - effectiveCount;
+
+ Set<Account> candidateReviewers = new HashSet<>();
+ for (Account user: potentialReviewers) {
+ ReviewInvitation invitation = getInvitation(user);
+ if (invitation != null && invitation.getType() != ReviewInvitation.Type.EXCLUDE)
+ candidateReviewers.add(user);
+ }
+ if (candidateReviewers.size() < missingCount) {
+ for (Account user: potentialReviewers) {
+ ReviewInvitation invitation = getInvitation(user);
+ if (invitation == null) {
+ candidateReviewers.add(user);
+ if (candidateReviewers.size() == missingCount)
+ break;
+ }
+ }
+ }
+ if (candidateReviewers.size() < missingCount) {
+ for (Account user: potentialReviewers) {
+ if (!candidateReviewers.contains(user)) {
+ candidateReviewers.add(user);
+ if (candidateReviewers.size() == missingCount)
+ break;
+ }
+ }
+ }
+
+ Set<Account> selectedReviewers = selectReviewers(candidateReviewers, missingCount);
+ for (Account user: selectedReviewers) {
+ awaitingReviewers.add(user);
+ recordReviewer(user);
+ }
+ }
+
+ private Set<Account> selectReviewers(Set<Account> candidateReviewers, int count) {
+ Preconditions.checkArgument(candidateReviewers.size() >= count);
+ Set<Account> selectedReviewers = new HashSet<>();
+ if (count > 0) {
+ for (Account user: candidateReviewers) {
+ selectedReviewers.add(user);
+ if (selectedReviewers.size() == count)
+ break;
+ }
+ }
+ return selectedReviewers;
+ }
+
+ private void recordReviewer(Account user) {
+ ReviewInvitation invitation = getInvitation(user);
+ if (invitation != null) {
+ invitation.setType(ReviewInvitation.Type.RULE);
+ } else {
+ invitation = new ReviewInvitation();
+ invitation.setRequest(request);
+ invitation.setUser(user);
+ invitation.setType(ReviewInvitation.Type.RULE);
+ request.getReviewInvitations().add(invitation);
+ }
+ }
+
+ }
+}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultTeamManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultTeamManager.java
index 8ac84d1beb..553dc451a7 100644
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultTeamManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultTeamManager.java
@@ -1,17 +1,16 @@
package com.gitplex.server.manager.impl;
-import java.util.Iterator;
-
import javax.inject.Inject;
import javax.inject.Singleton;
import org.hibernate.criterion.Restrictions;
-import com.gitplex.server.gatekeeper.GateKeeper;
import com.gitplex.server.manager.TeamManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.Team;
+import com.gitplex.server.model.support.BranchProtection;
+import com.gitplex.server.model.support.TagProtection;
import com.gitplex.server.persistence.annotation.Sessional;
import com.gitplex.server.persistence.annotation.Transactional;
import com.gitplex.server.persistence.dao.AbstractEntityManager;
@@ -31,9 +30,10 @@ public class DefaultTeamManager extends AbstractEntityManager<Team> implements T
public void save(Team team, String oldName) {
if (oldName != null && !oldName.equals(team.getName())) {
for (Depot depot: team.getOrganization().getDepots()) {
- for (GateKeeper gateKeeper: depot.getGateKeepers()) {
- gateKeeper.onTeamRename(oldName, team.getName());
- }
+ for (BranchProtection protection: depot.getBranchProtections())
+ protection.onTeamRename(depot, oldName, team.getName());
+ for (TagProtection protection: depot.getTagProtections())
+ protection.onTeamRename(oldName, team.getName());
}
}
dao.persist(team);
@@ -43,10 +43,10 @@ public class DefaultTeamManager extends AbstractEntityManager<Team> implements T
@Override
public void delete(Team team) {
for (Depot depot: team.getOrganization().getDepots()) {
- for (Iterator<GateKeeper> it = depot.getGateKeepers().iterator(); it.hasNext();) {
- if (it.next().onTeamDelete(team.getName()))
- it.remove();
- }
+ for (BranchProtection protection: depot.getBranchProtections())
+ protection.onTeamDelete(depot, team.getName());
+ for (TagProtection protection: depot.getTagProtections())
+ protection.onTeamDelete(team.getName());
}
dao.remove(team);
}
diff --git a/core/src/main/java/com/gitplex/server/manager/impl/DefaultVisitInfoManager.java b/core/src/main/java/com/gitplex/server/manager/impl/DefaultVisitInfoManager.java
index e10d803e16..17601c0417 100644
--- a/core/src/main/java/com/gitplex/server/manager/impl/DefaultVisitInfoManager.java
+++ b/core/src/main/java/com/gitplex/server/manager/impl/DefaultVisitInfoManager.java
@@ -202,15 +202,18 @@ public class DefaultVisitInfoManager implements VisitInfoManager {
@Listen
public void on(CodeCommentActivityEvent event) {
CodeCommentActivity activity = event.getActivity();
- visit(activity.getUser(), activity.getComment());
- for (CodeCommentRelation relation: activity.getComment().getRelations()) {
- visit(activity.getUser(), relation.getRequest());
+ if (activity.getUser() != null) {
+ visit(activity.getUser(), activity.getComment());
+ for (CodeCommentRelation relation: activity.getComment().getRelations()) {
+ visit(activity.getUser(), relation.getRequest());
+ }
}
}
@Listen
public void on(CodeCommentCreated event) {
- visit(event.getComment().getUser(), event.getComment());
+ if (event.getComment().getUser() != null)
+ visit(event.getComment().getUser(), event.getComment());
}
private byte[] longToBytes(long value) {
@@ -233,12 +236,14 @@ public class DefaultVisitInfoManager implements VisitInfoManager {
@Listen
public void on(PullRequestOpened event) {
- visit(event.getRequest().getSubmitter(), event.getRequest());
+ if (event.getRequest().getSubmitter() != null)
+ visit(event.getRequest().getSubmitter(), event.getRequest());
}
@Listen
public void on(PullRequestStatusChangeEvent event) {
- visit(event.getUser(), event.getRequest());
+ if (event.getUser() != null)
+ visit(event.getUser(), event.getRequest());
}
@Transactional
diff --git a/core/src/main/java/com/gitplex/server/model/Account.java b/core/src/main/java/com/gitplex/server/model/Account.java
index 0984da74ae..3736847557 100644
--- a/core/src/main/java/com/gitplex/server/model/Account.java
+++ b/core/src/main/java/com/gitplex/server/model/Account.java
@@ -57,7 +57,7 @@ public class Account extends AbstractEntity implements AuthenticationInfo, Prote
private static final long serialVersionUID = 1L;
public static final Long ADMINISTRATOR_ID = 1L;
-
+
@Column(unique=true, nullable=false)
private String name;
@@ -72,9 +72,6 @@ public class Account extends AbstractEntity implements AuthenticationInfo, Prote
@Column(unique=true)
private String email;
- /* used by user account */
- private int reviewEffort;
-
/* used by organization account */
@Column(nullable=false)
private DepotPrivilege defaultPrivilege = DepotPrivilege.NONE;
@@ -89,7 +86,7 @@ public class Account extends AbstractEntity implements AuthenticationInfo, Prote
/*
* Optimistic lock is necessary to ensure database integrity when update
- * gatekeepers and integration policies upon account renaming/deletion
+ * branch and tag protection settings upon account renaming/deletion
*/
@Version
private long version;
@@ -114,16 +111,10 @@ public class Account extends AbstractEntity implements AuthenticationInfo, Prote
private Collection<Team> definedTeams = new ArrayList<>();
@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<PullRequestReference> requestReferences = new ArrayList<>();
-
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<PullRequestReview> reviews = new ArrayList<PullRequestReview>();
-
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<PullRequestVerification> verifications = new ArrayList<PullRequestVerification>();
+ private Collection<Review> reviews = new ArrayList<>();
@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<PullRequestReviewInvitation> reviewInvitations = new ArrayList<>();
+ private Collection<ReviewInvitation> reviewInvitations = new ArrayList<>();
@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
private Collection<BranchWatch> branchWatches = new ArrayList<>();
@@ -134,21 +125,6 @@ public class Account extends AbstractEntity implements AuthenticationInfo, Prote
@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
private Collection<PullRequestTask> requestTasks = new ArrayList<>();
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<PullRequestStatusChange> requestStatusChanges = new ArrayList<>();
-
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<PullRequestComment> requestComments = new ArrayList<>();
-
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<CodeComment> codeComments = new ArrayList<>();
-
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<CodeCommentStatusChange> codeCommentStatusChanges = new ArrayList<>();
-
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<CodeCommentReply> codeCommentReplies = new ArrayList<>();
-
private transient Collection<TeamAuthorization> allTeamAuthorizationsInOrganization;
private transient Collection<TeamMembership> allTeamMembershipsInOrganiation;
@@ -290,14 +266,6 @@ public class Account extends AbstractEntity implements AuthenticationInfo, Prote
this.joinedTeams = joinedTeams;
}
- public int getReviewEffort() {
- return reviewEffort;
- }
-
- public void setReviewEffort(int reviewEffort) {
- this.reviewEffort = reviewEffort;
- }
-
public Collection<Depot> getDepots() {
return depots;
}
@@ -334,13 +302,13 @@ public class Account extends AbstractEntity implements AuthenticationInfo, Prote
return false;
}
}
-
- public PullRequestReview.Result checkReviewSince(PullRequestUpdate update) {
- for (PullRequestReview vote: update.listReviewsOnwards()) {
- if (vote.getUser().equals(this))
- return vote.getResult();
+
+ @Nullable
+ public Review getReviewAfter(PullRequestUpdate update) {
+ for (Review review: update.getRequest().getReviews()) {
+ if (review.getUser().equals(this) && review.getDate().after(update.getDate()))
+ return review;
}
-
return null;
}
@@ -453,4 +421,12 @@ public class Account extends AbstractEntity implements AuthenticationInfo, Prote
return Sets.newHashSet("defaultPrivilege", "description");
}
+ public static Account getForDisplay(@Nullable Account account, @Nullable String accountName) {
+ if (account == null && accountName != null) {
+ account = new Account();
+ account.setName(accountName);
+ }
+ return account;
+ }
+
}
diff --git a/core/src/main/java/com/gitplex/server/model/CodeComment.java b/core/src/main/java/com/gitplex/server/model/CodeComment.java
index e37794d836..5bc5c74246 100644
--- a/core/src/main/java/com/gitplex/server/model/CodeComment.java
+++ b/core/src/main/java/com/gitplex/server/model/CodeComment.java
@@ -56,8 +56,10 @@ public class CodeComment extends AbstractEntity {
private Depot depot;
@ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
+ @JoinColumn
private Account user;
+
+ private String userName;
@Lob
@Column(nullable=false, length=65535)
@@ -108,6 +110,15 @@ public class CodeComment extends AbstractEntity {
this.user = user;
}
+ @Nullable
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
public long getVersion() {
return version;
}
diff --git a/core/src/main/java/com/gitplex/server/model/Depot.java b/core/src/main/java/com/gitplex/server/model/Depot.java
index f6925627a6..c836d1d99e 100644
--- a/core/src/main/java/com/gitplex/server/model/Depot.java
+++ b/core/src/main/java/com/gitplex/server/model/Depot.java
@@ -31,7 +31,6 @@ import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;
import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.shiro.subject.Subject;
@@ -69,8 +68,6 @@ import com.gitplex.launcher.loader.ListenerRegistry;
import com.gitplex.launcher.loader.LoaderUtils;
import com.gitplex.server.GitPlex;
import com.gitplex.server.event.RefUpdated;
-import com.gitplex.server.gatekeeper.AndGateKeeper;
-import com.gitplex.server.gatekeeper.GateKeeper;
import com.gitplex.server.git.Blob;
import com.gitplex.server.git.BlobIdent;
import com.gitplex.server.git.BlobIdentFilter;
@@ -83,14 +80,16 @@ import com.gitplex.server.manager.ConfigManager;
import com.gitplex.server.manager.DepotManager;
import com.gitplex.server.manager.StorageManager;
import com.gitplex.server.manager.VisitInfoManager;
+import com.gitplex.server.model.support.BranchProtection;
import com.gitplex.server.model.support.CommitMessageTransformSetting;
-import com.gitplex.server.model.support.IntegrationPolicy;
+import com.gitplex.server.model.support.TagProtection;
import com.gitplex.server.persistence.UnitOfWork;
import com.gitplex.server.security.SecurityUtils;
import com.gitplex.server.security.protectedobject.AccountBelonging;
import com.gitplex.server.security.protectedobject.ProtectedObject;
import com.gitplex.server.util.FileUtils;
import com.gitplex.server.util.LockUtils;
+import com.gitplex.server.util.PathUtils;
import com.gitplex.server.util.StringUtils;
import com.gitplex.server.util.editable.annotation.Editable;
import com.gitplex.server.util.editable.annotation.Markdown;
@@ -115,8 +114,6 @@ public class Depot extends AbstractEntity implements AccountBelonging {
public static final String REF_FQN_SEPARATOR = ":";
- public static final String REFS_GITPLEX = "refs/gitplex/";
-
private static final int LAST_COMMITS_CACHE_THRESHOLD = 1000;
private static final int MAX_READ_BLOB_SIZE = 5*1024*1024;
@@ -147,18 +144,18 @@ public class Depot extends AbstractEntity implements AccountBelonging {
/*
* Optimistic lock is necessary to ensure database integrity when update
- * gatekeepers and integration policies upon depot renaming/deletion
+ * branch and tag protection settings upon depot renaming/deletion
*/
@Version
private long version;
@Lob
@Column(nullable=false, length=65535)
- private ArrayList<GateKeeper> gateKeepers = new ArrayList<>();
+ private ArrayList<BranchProtection> branchProtections = new ArrayList<>();
@Lob
@Column(nullable=false, length=65535)
- private ArrayList<IntegrationPolicy> integrationPolicies = new ArrayList<>();
+ private ArrayList<TagProtection> tagProtections = new ArrayList<>();
@Column(nullable=false)
private Date createdAt = new Date();
@@ -250,23 +247,20 @@ public class Depot extends AbstractEntity implements AccountBelonging {
this.uuid = uuid;
}
- @NotNull
- @Valid
- public List<GateKeeper> getGateKeepers() {
- return gateKeepers;
+ public ArrayList<BranchProtection> getBranchProtections() {
+ return branchProtections;
}
- public void setGateKeepers(ArrayList<GateKeeper> gateKeepers) {
- this.gateKeepers = gateKeepers;
+ public void setBranchProtections(ArrayList<BranchProtection> branchProtections) {
+ this.branchProtections = branchProtections;
}
- @Valid
- public List<IntegrationPolicy> getIntegrationPolicies() {
- return integrationPolicies;
+ public ArrayList<TagProtection> getTagProtections() {
+ return tagProtections;
}
- public void setIntegrationPolicies(ArrayList<IntegrationPolicy> integrationPolicies) {
- this.integrationPolicies = integrationPolicies;
+ public void setTagProtections(ArrayList<TagProtection> tagProtections) {
+ this.tagProtections = tagProtections;
}
public Date getCreatedAt() {
@@ -397,13 +391,6 @@ public class Depot extends AbstractEntity implements AccountBelonging {
return true;
}
- public GateKeeper getGateKeeper() {
- AndGateKeeper andGateKeeper = new AndGateKeeper();
- for (GateKeeper each: getGateKeepers())
- andGateKeeper.getGateKeepers().add(each);
- return andGateKeeper;
- }
-
/**
* Find fork root of this repository.
*
@@ -1034,4 +1021,23 @@ public class Depot extends AbstractEntity implements AccountBelonging {
return FileMode.TREE.getBits();
}
}
+
+ @Nullable
+ public TagProtection getTagProtection(String tagName) {
+ for (TagProtection protection: tagProtections) {
+ if (PathUtils.matchChildAware(protection.getTag(), tagName))
+ return protection;
+ }
+ return null;
+ }
+
+ @Nullable
+ public BranchProtection getBranchProtection(String branchName) {
+ for (BranchProtection protection: branchProtections) {
+ if (PathUtils.matchChildAware(protection.getBranch(), branchName))
+ return protection;
+ }
+ return null;
+ }
+
}
diff --git a/core/src/main/java/com/gitplex/server/model/PullRequest.java b/core/src/main/java/com/gitplex/server/model/PullRequest.java
index 1e4184b204..4b5e653d72 100644
--- a/core/src/main/java/com/gitplex/server/model/PullRequest.java
+++ b/core/src/main/java/com/gitplex/server/model/PullRequest.java
@@ -9,7 +9,7 @@ import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
+import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
@@ -40,24 +40,20 @@ import org.hibernate.criterion.Restrictions;
import com.fasterxml.jackson.annotation.JsonView;
import com.gitplex.server.GitPlex;
import com.gitplex.server.event.pullrequest.PullRequestCodeCommentEvent;
-import com.gitplex.server.gatekeeper.checkresult.Failed;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
-import com.gitplex.server.gatekeeper.checkresult.Pending;
import com.gitplex.server.git.GitUtils;
-import com.gitplex.server.git.exception.ObjectNotFoundException;
import com.gitplex.server.manager.CodeCommentRelationManager;
import com.gitplex.server.manager.PullRequestManager;
-import com.gitplex.server.manager.PullRequestReviewManager;
+import com.gitplex.server.manager.ReviewManager;
import com.gitplex.server.manager.VisitInfoManager;
import com.gitplex.server.model.support.CloseInfo;
import com.gitplex.server.model.support.CompareContext;
import com.gitplex.server.model.support.DepotAndBranch;
-import com.gitplex.server.model.support.IntegrationPreview;
import com.gitplex.server.model.support.LastEvent;
-import com.gitplex.server.persistence.UnitOfWork;
-import com.gitplex.server.persistence.dao.Dao;
-import com.gitplex.server.security.ObjectPermission;
+import com.gitplex.server.model.support.MergePreview;
+import com.gitplex.server.model.support.MergeStrategy;
import com.gitplex.server.security.SecurityUtils;
+import com.gitplex.server.security.privilege.DepotPrivilege;
+import com.gitplex.server.util.ReviewCheckStatus;
import com.gitplex.server.util.diff.WhitespaceOption;
import com.gitplex.server.util.editable.EditableUtils;
import com.gitplex.server.util.jackson.ExternalView;
@@ -75,69 +71,16 @@ import com.google.common.base.Preconditions;
@Index(columnList="title"), @Index(columnList="uuid"),
@Index(columnList="numberStr"), @Index(columnList="noSpaceTitle"),
@Index(columnList="number"), @Index(columnList="g_targetDepot_id"),
- @Index(columnList="g_sourceDepot_id"), @Index(columnList="g_submitter_id"),
- @Index(columnList="g_assignee_id")},
+ @Index(columnList="g_sourceDepot_id"), @Index(columnList="g_submitter_id")},
uniqueConstraints={@UniqueConstraint(columnNames={"g_targetDepot_id", "number"})})
public class PullRequest extends AbstractEntity {
private static final long serialVersionUID = 1L;
+ public static final String REFS_PREFIX = "refs/pulls/";
+
public static final int MAX_CODE_COMMENTS = 1000;
- public enum Status {
- PENDING_APPROVAL("Pending Approval"),
- PENDING_UPDATE("Pending Update"), PENDING_INTEGRATE("Pending Integration"),
- INTEGRATED("Integrated"), DISCARDED("Discarded");
-
- private final String displayName;
-
- Status(String displayName) {
- this.displayName = displayName;
- }
-
- @Override
- public String toString() {
- return displayName;
- }
-
- }
-
- public enum IntegrationStrategy {
- MERGE_ALWAYS("Merge always",
- "Always create merge commit when integrate into target branch"),
- MERGE_IF_NECESSARY("Merge if necessary",
- "Create merge commit only if target branch can not be fast-forwarded to the pull request"),
- MERGE_WITH_SQUASH("Merge with squash",
- "Squash all commits in the pull request and then merge with target branch"),
- REBASE_SOURCE_ONTO_TARGET("Rebase source onto target",
- "Rebase source branch onto target branch and then fast-forward target branch to source branch"),
- REBASE_TARGET_ONTO_SOURCE("Rebase target onto source",
- "Rebase target branch onto source branch");
-
- private final String displayName;
-
- private final String description;
-
- IntegrationStrategy(String displayName, String description) {
- this.displayName = displayName;
- this.description = description;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public String getDescription() {
- return description;
- }
-
- @Override
- public String toString() {
- return displayName;
- }
-
- }
-
@Embedded
private CloseInfo closeInfo;
@@ -149,9 +92,11 @@ public class PullRequest extends AbstractEntity {
private String description;
@ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
+ @JoinColumn
private Account submitter;
+ private String submitterName;
+
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false)
private Depot targetDepot;
@@ -168,9 +113,6 @@ public class PullRequest extends AbstractEntity {
@Column(nullable=false)
private String baseCommitHash;
- @ManyToOne(fetch=FetchType.LAZY)
- private Account assignee;
-
@Embedded
private LastEvent lastEvent;
@@ -190,13 +132,13 @@ public class PullRequest extends AbstractEntity {
@OptimisticLock(excluded=true)
@Embedded
- private IntegrationPreview lastIntegrationPreview;
+ private MergePreview lastMergePreview;
@Column(nullable=false)
private Date submitDate = new Date();
@Column(nullable=false)
- private IntegrationStrategy integrationStrategy;
+ private MergeStrategy mergeStrategy;
@Column(nullable=false)
private String uuid = UUID.randomUUID().toString();
@@ -210,7 +152,10 @@ public class PullRequest extends AbstractEntity {
private Collection<CodeCommentRelation> codeCommentRelations = new ArrayList<>();
@OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
- private Collection<PullRequestReviewInvitation> reviewInvitations = new ArrayList<>();
+ private Collection<ReviewInvitation> reviewInvitations = new ArrayList<>();
+
+ @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
+ private Collection<Review> reviews = new ArrayList<>();
@OneToMany(mappedBy="referenced", cascade=CascadeType.REMOVE)
private Collection<PullRequestReference> referencedBy = new ArrayList<>();
@@ -218,9 +163,6 @@ public class PullRequest extends AbstractEntity {
@OneToMany(mappedBy="referencedBy",cascade=CascadeType.REMOVE)
private Collection<PullRequestReference> referenced = new ArrayList<>();
- @OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
- private Collection<PullRequestVerification> verifications = new ArrayList<>();
-
@OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
private Collection<PullRequestComment> comments = new ArrayList<>();
@@ -233,23 +175,17 @@ public class PullRequest extends AbstractEntity {
@OneToMany(mappedBy="request", cascade=CascadeType.REMOVE)
private Collection<PullRequestWatch> watches = new ArrayList<>();
- private transient GateCheckResult gateResult;
+ private transient ReviewCheckStatus reviewCheckStatus;
- private transient Boolean merged;
+ private transient Boolean mergedIntoTarget;
private transient List<PullRequestUpdate> sortedUpdates;
- private transient List<PullRequestUpdate> effectiveUpdates;
-
- private transient PullRequestUpdate referentialUpdate;
-
private transient Collection<RevCommit> pendingCommits;
private transient Collection<RevCommit> mergedCommits;
- private transient List<PullRequestReview> reviews;
-
- private transient IntegrationPreview integrationPreview;
+ private transient Optional<MergePreview> mergePreviewOpt;
private transient List<CodeComment> codeComments;
@@ -282,6 +218,7 @@ public class PullRequest extends AbstractEntity {
* @return
* the user submitting the pull request
*/
+ @Nullable
public Account getSubmitter() {
return submitter;
}
@@ -290,20 +227,13 @@ public class PullRequest extends AbstractEntity {
this.submitter = submitter;
}
- /**
- * Get the user responsible for integration of the pull request.
- *
- * @return
- * the user responsible for integration of this pull request, or <tt>null</tt> to have the
- * system integrate the pull request automatically
- */
@Nullable
- public Account getAssignee() {
- return assignee;
+ public String getSubmitterName() {
+ return submitterName;
}
- public void setAssignee(Account assignee) {
- this.assignee = assignee;
+ public void setSubmitterName(String submitterName) {
+ this.submitterName = submitterName;
}
public Depot getTargetDepot() {
@@ -411,13 +341,11 @@ public class PullRequest extends AbstractEntity {
public void setUpdates(Collection<PullRequestUpdate> updates) {
this.updates = updates;
sortedUpdates = null;
- effectiveUpdates = null;
}
public void addUpdate(PullRequestUpdate update) {
updates.add(update);
sortedUpdates = null;
- effectiveUpdates = null;
}
public Collection<CodeCommentRelation> getCodeCommentRelations() {
@@ -428,22 +356,14 @@ public class PullRequest extends AbstractEntity {
this.codeCommentRelations = codeCommentRelations;
}
- public Collection<PullRequestReviewInvitation> getReviewInvitations() {
+ public Collection<ReviewInvitation> getReviewInvitations() {
return reviewInvitations;
}
- public void setReviewInvitations(Collection<PullRequestReviewInvitation> reviewInvitations) {
+ public void setReviewInvitations(Collection<ReviewInvitation> reviewInvitations) {
this.reviewInvitations = reviewInvitations;
}
- public Collection<PullRequestVerification> getVerifications() {
- return verifications;
- }
-
- public void setVerifications(Collection<PullRequestVerification> verifications) {
- this.verifications = verifications;
- }
-
public Collection<PullRequestReference> getReferencedBy() {
return referencedBy;
}
@@ -492,46 +412,14 @@ public class PullRequest extends AbstractEntity {
this.watches = watches;
}
- public Status getStatus() {
- if (closeInfo != null) {
- if (closeInfo.getCloseStatus() == CloseInfo.Status.INTEGRATED) {
- return Status.INTEGRATED;
- } else {
- return Status.DISCARDED;
- }
- } else {
- GateCheckResult result = checkGates(false);
- if (result instanceof Pending) {
- return Status.PENDING_APPROVAL;
- } else if (result instanceof Failed) {
- return Status.PENDING_UPDATE;
- } else {
- return Status.PENDING_INTEGRATE;
- }
- }
+ public ReviewCheckStatus getReviewCheckStatus() {
+ if (reviewCheckStatus == null)
+ reviewCheckStatus = GitPlex.getInstance(ReviewManager.class).checkRequest(this);
+ return reviewCheckStatus;
}
- public GateCheckResult checkGates(boolean recheck) {
- if (recheck || gateResult == null) {
- Long requestId = getId();
- try {
- gateResult = getTargetDepot().getGateKeeper().checkRequest(this);
- } catch (ObjectNotFoundException e) {
- // in case target/source branch is deleted but the pull request is not closed
- // for some reason, we call check again to make sure they will be closed
- GitPlex.getInstance(UnitOfWork.class).doAsync(new Runnable() {
-
- @Override
- public void run() {
- PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
- pullRequestManager.check(pullRequestManager.load(requestId));
- }
-
- });
- throw e;
- }
- }
- return gateResult;
+ public void clearReviewCheckStatus() {
+ reviewCheckStatus = null;
}
@Nullable
@@ -547,50 +435,39 @@ public class PullRequest extends AbstractEntity {
return closeInfo == null;
}
- public PullRequestUpdate getReferentialUpdate() {
- if (referentialUpdate != null)
- return referentialUpdate;
- else
- return getEffectiveUpdates().get(0);
- }
-
- public void setReferentialUpdate(PullRequestUpdate referentiralUpdate) {
- this.referentialUpdate = referentiralUpdate;
- }
-
/**
- * Get last integration preview of this pull request. Note that this method may return an
- * out dated integration preview. Refer to {@link this#getIntegrationPreview()}
- * if you'd like to get an update-to-date integration preview
+ * Get last merge preview of this pull request. Note that this method may return an
+ * out dated merge preview. Refer to {@link this#getIntegrationPreview()}
+ * if you'd like to get an update-to-date merge preview
*
* @return
- * integration preview of this pull request, or <tt>null</tt> if integration
+ * merge preview of this pull request, or <tt>null</tt> if merge
* preview has not been calculated yet.
*/
@Nullable
- public IntegrationPreview getLastIntegrationPreview() {
- return lastIntegrationPreview;
+ public MergePreview getLastMergePreview() {
+ return lastMergePreview;
}
- public void setLastIntegrationPreview(IntegrationPreview lastIntegrationPreview) {
- this.lastIntegrationPreview = lastIntegrationPreview;
+ public void setLastMergePreview(MergePreview lastIntegrationPreview) {
+ this.lastMergePreview = lastIntegrationPreview;
}
/**
- * Get effective integration preview of this pull request.
+ * Get effective merge preview of this pull request.
*
* @return
- * update to date integration preview of this pull request, or <tt>null</tt> if
- * the integration preview has not been calculated or out dated. In both cases,
+ * update to date merge preview of this pull request, or <tt>null</tt> if
+ * the merge preview has not been calculated or out dated. In both cases,
* it will trigger a re-calculation, and client should call this method later
* to get the calculated result
*/
@JsonView(ExternalView.class)
@Nullable
- public IntegrationPreview getIntegrationPreview() {
- if (integrationPreview == null)
- integrationPreview = GitPlex.getInstance(PullRequestManager.class).previewIntegration(this);
- return integrationPreview;
+ public MergePreview getMergePreview() {
+ if (mergePreviewOpt == null)
+ mergePreviewOpt = Optional.ofNullable(GitPlex.getInstance(PullRequestManager.class).previewMerge(this));
+ return mergePreviewOpt.orElse(null);
}
/**
@@ -608,38 +485,12 @@ public class PullRequest extends AbstractEntity {
return sortedUpdates;
}
- /**
- * Get list of effective updates reversely sorted by id. Update is considered effective if it is
- * not ancestor of target branch head.
- *
- * @return
- * list of effective updates reversely sorted by id
- */
- public List<PullRequestUpdate> getEffectiveUpdates() {
- Preconditions.checkState(isOpen(), "Can only be called while request is open");
- if (effectiveUpdates == null) {
- effectiveUpdates = new ArrayList<PullRequestUpdate>();
-
- for (int i=getSortedUpdates().size()-1; i>=0; i--) {
- PullRequestUpdate update = getSortedUpdates().get(i);
- ObjectId headCommitId = ObjectId.fromString(update.getHeadCommitHash());
- if (!GitUtils.isMergedInto(getTargetDepot().getRepository(), headCommitId, getTarget().getObjectId()))
- effectiveUpdates.add(update);
- else
- break;
- }
-
- Preconditions.checkState(!effectiveUpdates.isEmpty());
- }
- return effectiveUpdates;
- }
-
- public IntegrationStrategy getIntegrationStrategy() {
- return integrationStrategy;
+ public MergeStrategy getMergeStrategy() {
+ return mergeStrategy;
}
- public void setIntegrationStrategy(IntegrationStrategy integrationStrategy) {
- this.integrationStrategy = integrationStrategy;
+ public void setMergeStrategy(MergeStrategy mergeStrategy) {
+ this.mergeStrategy = mergeStrategy;
}
@JsonView(ExternalView.class)
@@ -650,99 +501,28 @@ public class PullRequest extends AbstractEntity {
@JsonView(ExternalView.class)
public String getBaseRef() {
Preconditions.checkNotNull(getId());
- return Depot.REFS_GITPLEX + "pulls/" + getNumber() + "/base";
+ return REFS_PREFIX + getNumber() + "/base";
}
@JsonView(ExternalView.class)
- public String getIntegrateRef() {
+ public String getMergeRef() {
Preconditions.checkNotNull(getId());
- return Depot.REFS_GITPLEX + "pulls/" + getNumber() + "/integrate";
+ return REFS_PREFIX + getNumber() + "/merge";
}
+ @JsonView(ExternalView.class)
+ public String getHeadRef() {
+ Preconditions.checkNotNull(getId());
+ return REFS_PREFIX + getNumber() + "/head";
+ }
+
/**
* Delete refs of this pull request, without touching refs of its updates.
*/
public void deleteRefs() {
GitUtils.deleteRef(getTargetDepot().updateRef(getBaseRef()));
- GitUtils.deleteRef(getTargetDepot().updateRef(getIntegrateRef()));
- }
-
- /**
- * Invite specified number of users in candidates to review this request.
- * <p>
- *
- * @param candidates
- * a collection of users to invite users from
- * @param count
- * number of users to invite
- */
- public void pickReviewers(Collection<Account> candidates, int count) {
- List<Account> pickList = new ArrayList<Account>(candidates);
-
- /*
- * users already reviewed since base update should be excluded from
- * invitation list as their reviews are still valid
- */
- for (PullRequestReview review: getReferentialUpdate().listReviewsOnwards()) {
- pickList.remove(review.getUser());
- }
-
- Set<Account> firstChoices = new HashSet<>();
- Set<Account> lastChoices = new HashSet<>();
-
- for (PullRequestReviewInvitation invitation: getReviewInvitations()) {
- if (invitation.getStatus() != PullRequestReviewInvitation.Status.EXCLUDED)
- firstChoices.add(invitation.getUser());
- else
- lastChoices.add(invitation.getUser());
- }
-
- lastChoices.add(getSubmitter());
-
- List<Account> firstPickList = new ArrayList<>();
- List<Account> lastPickList = new ArrayList<>();
- List<Account> otherPickList = new ArrayList<>();
- for (Account user: pickList) {
- if (firstChoices.contains(user))
- firstPickList.add(user);
- else if (lastChoices.contains(user))
- lastPickList.add(user);
- else
- otherPickList.add(user);
- }
- firstPickList.sort(Comparator.comparing(Account::getReviewEffort));
- lastPickList.sort(Comparator.comparing(Account::getReviewEffort));
- otherPickList.sort(Comparator.comparing(Account::getReviewEffort));
- pickList.clear();
- pickList.addAll(firstPickList);
- pickList.addAll(lastPickList);
- pickList.addAll(otherPickList);
-
- List<Account> picked;
- if (count <= pickList.size())
- picked = pickList.subList(0, count);
- else
- picked = pickList;
-
- for (Account user: picked) {
- boolean found = false;
- for (PullRequestReviewInvitation invitation: getReviewInvitations()) {
- if (invitation.getUser().equals(user)) {
- invitation.setDate(new Date());
- invitation.setStatus(PullRequestReviewInvitation.Status.ADDED_BY_RULE);
- found = true;
- }
- }
- if (!found) {
- PullRequestReviewInvitation invitation = new PullRequestReviewInvitation();
- invitation.setDate(new Date());
- invitation.setStatus(PullRequestReviewInvitation.Status.ADDED_BY_RULE);
- invitation.setRequest(this);
- invitation.setUser(user);
- getReviewInvitations().add(invitation);
- }
- }
-
+ GitUtils.deleteRef(getTargetDepot().updateRef(getMergeRef()));
+ GitUtils.deleteRef(getTargetDepot().updateRef(getHeadRef()));
}
public static class CriterionHelper {
@@ -789,10 +569,10 @@ public class PullRequest extends AbstractEntity {
}
/**
- * Get commits pending integration.
+ * Get commits pending merge.
*
* @return
- * commits pending integration
+ * commits pending merge
*/
public Collection<RevCommit> getPendingCommits() {
if (pendingCommits == null) {
@@ -830,60 +610,12 @@ public class PullRequest extends AbstractEntity {
return mergedCommits;
}
- public List<PullRequestReview> getReviews() {
- if (reviews == null) {
- if (!isNew())
- reviews = GitPlex.getInstance(PullRequestReviewManager.class).findAll(this);
- else
- reviews = new ArrayList<>();
- }
+ public Collection<Review> getReviews() {
return reviews;
}
- /**
- * This method is here for performance consideration. Often we need to load reviews of
- * different updates in a pull request. And we optimize it to load all reviews at once
- * for all updates in a pull request to reduce SQL queries.
- *
- * @param update
- * @return
- */
- public List<PullRequestReview> getReviews(PullRequestUpdate update) {
- List<PullRequestReview> reviews = new ArrayList<>();
- for (PullRequestReview review: getReviews()) {
- if (review.getUpdate().equals(update))
- reviews.add(review);
- }
- return reviews;
- }
-
- public boolean isReviewEffective(Account user) {
- for (PullRequestReview review: getReviews()) {
- if (review.getUpdate().equals(getLatestUpdate()) && review.getUser().equals(user))
- return true;
- }
- return false;
- }
-
- /**
- * Calculate list of users can be added as reviewers of this pull request.
- *
- * @return
- * list of potential reviewers
- */
- public List<Account> getPotentialReviewers() {
- List<Account> reviewers = new ArrayList<>();
- Set<Account> alreadyInvited = new HashSet<>();
- for (PullRequestReviewInvitation invitation: getReviewInvitations()) {
- if (invitation.getStatus() != PullRequestReviewInvitation.Status.EXCLUDED)
- alreadyInvited.add(invitation.getUser());
- }
- ObjectPermission readPerm = ObjectPermission.ofDepotRead(getTargetDepot());
- for (Account user: GitPlex.getInstance(Dao.class).findAll(Account.class)) {
- if (user.asSubject().isPermitted(readPerm) && !alreadyInvited.contains(user))
- reviewers.add(user);
- }
- return reviewers;
+ public void setReviews(Collection<Review> reviews) {
+ this.reviews = reviews;
}
@Nullable
@@ -981,7 +713,7 @@ public class PullRequest extends AbstractEntity {
String commitMessage = getTitle() + "\n\n";
if (getDescription() != null)
commitMessage += getDescription() + "\n\n";
- commitMessage += "This commit is created as result of integrating pull request #" + getNumber();
+ commitMessage += "This commit is created as result of accepting pull request #" + getNumber();
return commitMessage;
}
@@ -1012,9 +744,19 @@ public class PullRequest extends AbstractEntity {
}
public boolean isMerged() {
- if (merged == null)
- merged = GitUtils.isMergedInto(getTargetDepot().getRepository(), ObjectId.fromString(getHeadCommitHash()), getTarget().getObjectId());
- return merged;
+ return closeInfo != null && closeInfo.getCloseStatus() == CloseInfo.Status.MERGED;
+ }
+
+ public boolean isDiscarded() {
+ return closeInfo != null && closeInfo.getCloseStatus() == CloseInfo.Status.DISCARDED;
+ }
+
+ public boolean isMergeIntoTarget() {
+ if (mergedIntoTarget == null) {
+ mergedIntoTarget = GitUtils.isMergedInto(getTargetDepot().getRepository(), ObjectId.fromString(getHeadCommitHash()),
+ getTarget().getObjectId());
+ }
+ return mergedIntoTarget;
}
public void setLastEvent(PullRequestStatusChange statusChange) {
@@ -1043,6 +785,18 @@ public class PullRequest extends AbstractEntity {
return null;
}
+ public List<Account> getRemainingReviewers() {
+ ReviewCheckStatus checkStatus = getReviewCheckStatus();
+ Collection<Account> users = SecurityUtils.findUsersCan(getTargetDepot(), DepotPrivilege.READ);
+ users.removeAll(checkStatus.getAwaitingReviewers());
+ for (Review review: checkStatus.getEffectiveReviews().values())
+ users.remove(review.getUser());
+ users.remove(SecurityUtils.getAccount());
+ List<Account> userList = new ArrayList<>(users);
+ userList.sort(Comparator.comparing(Account::getName));
+ return userList;
+ }
+
public static class ComparingInfo implements Serializable {
private static final long serialVersionUID = 1L;
diff --git a/core/src/main/java/com/gitplex/server/model/PullRequestComment.java b/core/src/main/java/com/gitplex/server/model/PullRequestComment.java
index 2bfc249317..82153042b6 100644
--- a/core/src/main/java/com/gitplex/server/model/PullRequestComment.java
+++ b/core/src/main/java/com/gitplex/server/model/PullRequestComment.java
@@ -36,9 +36,11 @@ public class PullRequestComment extends AbstractEntity {
private PullRequest request;
@ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
+ @JoinColumn
private Account user;
+ private String userName;
+
@Lob
@Column(nullable=false, length=65535)
private String content;
@@ -63,6 +65,15 @@ public class PullRequestComment extends AbstractEntity {
this.user = user;
}
+ @Nullable
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
public long getVersion() {
return version;
}
diff --git a/core/src/main/java/com/gitplex/server/model/PullRequestReference.java b/core/src/main/java/com/gitplex/server/model/PullRequestReference.java
index bf94cd96aa..825d60d07c 100644
--- a/core/src/main/java/com/gitplex/server/model/PullRequestReference.java
+++ b/core/src/main/java/com/gitplex/server/model/PullRequestReference.java
@@ -2,6 +2,7 @@ package com.gitplex.server.model;
import java.util.Date;
+import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
@@ -37,8 +38,10 @@ public class PullRequestReference extends AbstractEntity {
private Date date;
@ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
+ @JoinColumn
private Account user;
+
+ private String userName;
public PullRequest getReferenced() {
return referenced;
@@ -64,6 +67,7 @@ public class PullRequestReference extends AbstractEntity {
this.date = date;
}
+ @Nullable
public Account getUser() {
return user;
}
@@ -71,5 +75,14 @@ public class PullRequestReference extends AbstractEntity {
public void setUser(Account user) {
this.user = user;
}
+
+ @Nullable
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
}
diff --git a/core/src/main/java/com/gitplex/server/model/PullRequestStatusChange.java b/core/src/main/java/com/gitplex/server/model/PullRequestStatusChange.java
index f686b9b14e..7c20fc3055 100644
--- a/core/src/main/java/com/gitplex/server/model/PullRequestStatusChange.java
+++ b/core/src/main/java/com/gitplex/server/model/PullRequestStatusChange.java
@@ -24,16 +24,15 @@ public class PullRequestStatusChange extends AbstractEntity {
public enum Type {
APPROVED("approved", "fa fa-thumbs-o-up"),
DISAPPROVED("disapproved", "fa fa-thumbs-o-down"),
- ASSIGNED("assigned", "fa fa-user"),
DISCARDED("discarded", "fa fa-ban"),
- INTEGRATED("integrated", "fa fa-check"),
+ MERGED("merged", "fa fa-check"),
REOPENED("reopened", "fa fa-repeat"),
- REVIEW_DELETED("deleted review", "fa fa-times"),
- VERIFICATION_DELETED("deleted verification", "fa fa-times"),
- VERIFICATION_FAILED("completed verification (failed)", "fa fa-thumbs-o-down"),
- VERIFICATION_SUCCEEDED("completed verification (successful)", "fa fa-thumbs-o-up"),
- SOURCE_BRANCH_DELETED("deleted source branch", "fa fa-times"),
- SOURCE_BRANCH_RESTORED("restored source branch", "fa fa-repeat"),
+ WITHDRAWED_REVIEW("withdrawed review", "fa fa-undo"),
+ ADDED_REVIEWER("added reviewer", "fa fa-plus"),
+ REMOVED_REVIEWER("removed reviewer", "fa fa-trash"),
+ CHANGED_MERGE_STRATEGY("changed merge strategy", "fa fa-pencil"),
+ DELETED_SOURCE_BRANCH("deleted source branch", "fa fa-trash"),
+ RESTORED_SOURCE_BRANCH("restored source branch", "fa fa-repeat"),
;
private final String name;
@@ -66,9 +65,11 @@ public class PullRequestStatusChange extends AbstractEntity {
private Type type;
@ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
+ @JoinColumn
private Account user;
+ private String userName;
+
@Column(nullable=false)
private Date date;
@@ -107,6 +108,15 @@ public class PullRequestStatusChange extends AbstractEntity {
this.user = user;
}
+ @Nullable
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
public Date getDate() {
return date;
}
diff --git a/core/src/main/java/com/gitplex/server/model/PullRequestTask.java b/core/src/main/java/com/gitplex/server/model/PullRequestTask.java
index 9e49ee58a4..e1dc953e2d 100644
--- a/core/src/main/java/com/gitplex/server/model/PullRequestTask.java
+++ b/core/src/main/java/com/gitplex/server/model/PullRequestTask.java
@@ -21,9 +21,9 @@ public class PullRequestTask extends AbstractEntity {
private static final long serialVersionUID = 1L;
public enum Type {
- REVIEW("Please review this pull request."),
- UPDATE("Please update this pull request."),
- INTEGRATE("Please integrate this pull request.");
+ REVIEW("There are new changes to review"),
+ UPDATE("Someone disapproved current changes"),
+ RESOLVE_CONFLICT("There are merge conflicts");
private final String displayName;
diff --git a/core/src/main/java/com/gitplex/server/model/PullRequestUpdate.java b/core/src/main/java/com/gitplex/server/model/PullRequestUpdate.java
index 7d6f6cab26..fb50481676 100644
--- a/core/src/main/java/com/gitplex/server/model/PullRequestUpdate.java
+++ b/core/src/main/java/com/gitplex/server/model/PullRequestUpdate.java
@@ -7,17 +7,14 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import java.util.UUID;
-import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
-import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
@@ -41,6 +38,8 @@ public class PullRequestUpdate extends AbstractEntity {
private static final long serialVersionUID = 1L;
+ public static final String REFS_PREFIX = "refs/updates/";
+
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false)
private PullRequest request;
@@ -49,14 +48,11 @@ public class PullRequestUpdate extends AbstractEntity {
private String headCommitHash;
@Column(nullable=false)
- private String mergeCommitHash;
+ private String mergeBaseCommitHash;
@Column(nullable=false)
private Date date = new Date();
- @OneToMany(mappedBy="update", cascade=CascadeType.REMOVE)
- private Collection<PullRequestReview> reviews = new ArrayList<PullRequestReview>();
-
@Column(nullable=false)
private String uuid = UUID.randomUUID().toString();
@@ -80,12 +76,12 @@ public class PullRequestUpdate extends AbstractEntity {
this.headCommitHash = headCommitHash;
}
- public String getMergeCommitHash() {
- return mergeCommitHash;
+ public String getMergeBaseCommitHash() {
+ return mergeBaseCommitHash;
}
- public void setMergeCommitHash(String mergeCommitHash) {
- this.mergeCommitHash = mergeCommitHash;
+ public void setMergeBaseCommitHash(String mergeBaseCommitHash) {
+ this.mergeBaseCommitHash = mergeBaseCommitHash;
}
public Date getDate() {
@@ -96,41 +92,12 @@ public class PullRequestUpdate extends AbstractEntity {
this.date = date;
}
- public Collection<PullRequestReview> getReviews() {
- return getRequest().getReviews(this);
- }
-
@JsonProperty
public String getHeadRef() {
Preconditions.checkNotNull(getId());
- return Depot.REFS_GITPLEX + "updates/" + getId();
+ return REFS_PREFIX + getId();
}
- /**
- * List reviews against this update and all subsequent updates.
- * <p>
- * @return
- * list of found reviews, ordered by associated updates reversely
- */
- public List<PullRequestReview> listReviewsOnwards() {
- List<PullRequestReview> reviews = new ArrayList<PullRequestReview>();
- Set<Account> excludedReviewers = new HashSet<>();
- for (PullRequestReviewInvitation invitation: getRequest().getReviewInvitations()) {
- if (invitation.getStatus() == PullRequestReviewInvitation.Status.EXCLUDED)
- excludedReviewers.add(invitation.getUser());
- }
- for (PullRequestUpdate update: getRequest().getEffectiveUpdates()) {
- for (PullRequestReview review: update.getReviews()) {
- if (!excludedReviewers.contains(review.getUser()))
- reviews.add(review);
- }
- if (update.equals(this))
- break;
- }
-
- return reviews;
- }
-
public void deleteRefs() {
GitUtils.deleteRef(getRequest().getTargetDepot().updateRef(getHeadRef()));
}
@@ -147,7 +114,7 @@ public class PullRequestUpdate extends AbstractEntity {
Repository repository = getRequest().getWorkDepot().getRepository();
try ( RevWalk revWalk = new RevWalk(repository);
TreeWalk treeWalk = new TreeWalk(repository)) {
- RevCommit mergeCommit = revWalk.parseCommit(ObjectId.fromString(getMergeCommitHash()));
+ RevCommit mergeCommit = revWalk.parseCommit(ObjectId.fromString(getMergeBaseCommitHash()));
RevCommit baseCommit = revWalk.parseCommit(ObjectId.fromString(getBaseCommitHash()));
RevCommit headCommit = revWalk.parseCommit(ObjectId.fromString(getHeadCommitHash()));
revWalk.markStart(mergeCommit);
@@ -267,7 +234,7 @@ public class PullRequestUpdate extends AbstractEntity {
* update
* 2. commits of this update will remain unchanged even if tip of the target branch changes
*/
- revWalk.markUninteresting(revWalk.parseCommit(ObjectId.fromString(getMergeCommitHash())));
+ revWalk.markUninteresting(revWalk.parseCommit(ObjectId.fromString(getMergeBaseCommitHash())));
revWalk.forEach(c->commits.add(c));
} catch (IOException e) {
diff --git a/core/src/main/java/com/gitplex/server/model/PullRequestVerification.java b/core/src/main/java/com/gitplex/server/model/PullRequestVerification.java
deleted file mode 100644
index cada95b412..0000000000
--- a/core/src/main/java/com/gitplex/server/model/PullRequestVerification.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package com.gitplex.server.model;
-
-import java.util.Date;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.Index;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-import javax.persistence.UniqueConstraint;
-
-@Entity
-@Table(
- indexes={@Index(columnList="g_request_id"), @Index(columnList="g_user_id"),
- @Index(columnList="commit"), @Index(columnList="configuration")},
- uniqueConstraints={@UniqueConstraint(columnNames={"g_request_id", "commit", "configuration"})
-})
-public class PullRequestVerification extends AbstractEntity {
-
- private static final long serialVersionUID = 1L;
-
- public enum Status {RUNNING, SUCCESSFUL, FAILED}
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private PullRequest request;
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private Account user;
-
- @Column(nullable=false)
- private String commit;
-
- @Column(nullable=false)
- private String configuration;
-
- @Column(nullable=false)
- private String message;
-
- @Column(nullable=false)
- private Status status;
-
- private Date date;
-
- public String getCommit() {
- return commit;
- }
-
- public void setCommit(String commit) {
- this.commit = commit;
- }
-
- public Status getStatus() {
- return status;
- }
-
- public void setStatus(Status status) {
- this.status = status;
- }
-
- public PullRequest getRequest() {
- return request;
- }
-
- public void setRequest(PullRequest request) {
- this.request = request;
- }
-
- public Account getUser() {
- return user;
- }
-
- public void setUser(Account user) {
- this.user = user;
- }
-
- public String getConfiguration() {
- return configuration;
- }
-
- public void setConfiguration(String configuration) {
- this.configuration = configuration;
- }
-
- public String getMessage() {
- return message;
- }
-
- public void setMessage(String message) {
- this.message = message;
- }
-
- public Date getDate() {
- return date;
- }
-
- public void setDate(Date date) {
- this.date = date;
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/model/PullRequestReview.java b/core/src/main/java/com/gitplex/server/model/Review.java
similarity index 56%
rename from core/src/main/java/com/gitplex/server/model/PullRequestReview.java
rename to core/src/main/java/com/gitplex/server/model/Review.java
index cf212faef9..08c046d389 100644
--- a/core/src/main/java/com/gitplex/server/model/PullRequestReview.java
+++ b/core/src/main/java/com/gitplex/server/model/Review.java
@@ -9,18 +9,14 @@ import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
-import javax.persistence.UniqueConstraint;
@Entity
@Table(
- indexes={@Index(columnList="g_user_id"), @Index(columnList="g_update_id")},
- uniqueConstraints={@UniqueConstraint(columnNames={"g_user_id", "g_update_id"})
+ indexes={@Index(columnList="g_user_id"), @Index(columnList="g_request_id")
})
-public class PullRequestReview extends AbstractEntity {
+public class Review extends AbstractEntity {
private static final long serialVersionUID = 1L;
-
- public static enum Result {APPROVE, DISAPPROVE};
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false)
@@ -31,10 +27,13 @@ public class PullRequestReview extends AbstractEntity {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false)
- private PullRequestUpdate update;
+ private PullRequest request;
- @Column(nullable=false)
- private Result result;
+ private boolean checkMerged;
+
+ private boolean approved;
+
+ private String note;
public Date getDate() {
return date;
@@ -52,20 +51,36 @@ public class PullRequestReview extends AbstractEntity {
this.user = user;
}
- public PullRequestUpdate getUpdate() {
- return update;
+ public PullRequest getRequest() {
+ return request;
+ }
+
+ public void setRequest(PullRequest request) {
+ this.request = request;
}
- public void setUpdate(PullRequestUpdate update) {
- this.update = update;
+ public boolean isApproved() {
+ return approved;
}
- public Result getResult() {
- return result;
+ public void setApproved(boolean approved) {
+ this.approved = approved;
}
- public void setResult(Result result) {
- this.result = result;
+ public boolean isCheckMerged() {
+ return checkMerged;
}
+ public void setCheckMerged(boolean checkMerged) {
+ this.checkMerged = checkMerged;
+ }
+
+ public String getNote() {
+ return note;
+ }
+
+ public void setNote(String note) {
+ this.note = note;
+ }
+
}
diff --git a/core/src/main/java/com/gitplex/server/model/PullRequestReviewInvitation.java b/core/src/main/java/com/gitplex/server/model/ReviewInvitation.java
similarity index 67%
rename from core/src/main/java/com/gitplex/server/model/PullRequestReviewInvitation.java
rename to core/src/main/java/com/gitplex/server/model/ReviewInvitation.java
index 6d6abe25a0..d5080538da 100644
--- a/core/src/main/java/com/gitplex/server/model/PullRequestReviewInvitation.java
+++ b/core/src/main/java/com/gitplex/server/model/ReviewInvitation.java
@@ -1,8 +1,5 @@
package com.gitplex.server.model;
-import java.util.Date;
-
-import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
@@ -16,12 +13,12 @@ import javax.persistence.UniqueConstraint;
indexes={@Index(columnList="g_user_id"), @Index(columnList="g_request_id")},
uniqueConstraints={@UniqueConstraint(columnNames={"g_user_id", "g_request_id"})
})
-public class PullRequestReviewInvitation extends AbstractEntity {
+public class ReviewInvitation extends AbstractEntity {
private static final long serialVersionUID = 1L;
- public enum Status {ADDED_BY_RULE, ADDED_MANUALLY, EXCLUDED}
-
+ public enum Type {MANUAL, RULE, EXCLUDE};
+
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false)
private Account user;
@@ -30,10 +27,7 @@ public class PullRequestReviewInvitation extends AbstractEntity {
@JoinColumn(nullable=false)
private PullRequest request;
- private Status status;
-
- @Column(nullable=false)
- private Date date;
+ private Type type;
public Account getUser() {
return user;
@@ -51,20 +45,12 @@ public class PullRequestReviewInvitation extends AbstractEntity {
this.request = request;
}
- public Status getStatus() {
- return status;
- }
-
- public void setStatus(Status status) {
- this.status = status;
- }
-
- public Date getDate() {
- return date;
+ public Type getType() {
+ return type;
}
- public void setDate(Date date) {
- this.date = date;
+ public void setType(Type type) {
+ this.type = type;
}
}
diff --git a/core/src/main/java/com/gitplex/server/model/support/BranchProtection.java b/core/src/main/java/com/gitplex/server/model/support/BranchProtection.java
new file mode 100644
index 0000000000..a146d6f990
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/model/support/BranchProtection.java
@@ -0,0 +1,254 @@
+package com.gitplex.server.model.support;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+import javax.annotation.Nullable;
+import javax.validation.constraints.NotNull;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.Team;
+import com.gitplex.server.util.PathUtils;
+import com.gitplex.server.util.editable.annotation.BranchPattern;
+import com.gitplex.server.util.editable.annotation.Editable;
+import com.gitplex.server.util.reviewappointment.ReviewAppointment;
+
+@Editable
+public class BranchProtection implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String branch;
+
+ private boolean noForcedPush = true;
+
+ private boolean noDeletion = true;
+
+ private String reviewAppointmentExpr;
+
+ private transient Optional<ReviewAppointment> reviewAppointmentOpt;
+
+ private List<FileProtection> fileProtections = new ArrayList<>();
+
+ @Editable(order=100, description="Specify branch to be protected. Wildcard may be used to "
+ + "specify multiple branches")
+ @BranchPattern
+ @NotEmpty
+ public String getBranch() {
+ return branch;
+ }
+
+ public void setBranch(String branch) {
+ this.branch = branch;
+ }
+
+ @Editable(order=200, description="Check this to not allow forced push")
+ public boolean isNoForcedPush() {
+ return noForcedPush;
+ }
+
+ public void setNoForcedPush(boolean noForcedPush) {
+ this.noForcedPush = noForcedPush;
+ }
+
+ @Editable(order=300, description="Check this to not allow branch deletion")
+ public boolean isNoDeletion() {
+ return noDeletion;
+ }
+
+ public void setNoDeletion(boolean noDeletion) {
+ this.noDeletion = noDeletion;
+ }
+
+ @Editable(order=400, name="Reviewers", description="Optionally specify required reviewers for changes of "
+ + "specified branch. Note that the user submitting the change is considered to reviewed the change "
+ + "automatically")
+ @com.gitplex.server.util.editable.annotation.ReviewAppointment
+ public String getReviewAppointmentExpr() {
+ return reviewAppointmentExpr;
+ }
+
+ public void setReviewAppointmentExpr(String reviewAppointmentExpr) {
+ this.reviewAppointmentExpr = reviewAppointmentExpr;
+ }
+
+ @Editable(order=500, description="Optionally specify additional users to review particular paths. For each changed file, "
+ + "the first matched file protection setting will be used")
+ @NotNull
+ public List<FileProtection> getFileProtections() {
+ return fileProtections;
+ }
+
+ public void setFileProtections(List<FileProtection> fileProtections) {
+ this.fileProtections = fileProtections;
+ }
+
+ @Nullable
+ public FileProtection getFileProtection(String file) {
+ for (FileProtection protection: fileProtections) {
+ if (PathUtils.matchChildAware(protection.getPath(), file))
+ return protection;
+ }
+ return null;
+ }
+
+ @Nullable
+ public ReviewAppointment getReviewAppointment(Depot depot) {
+ if (reviewAppointmentOpt == null) {
+ if (reviewAppointmentExpr != null)
+ reviewAppointmentOpt = Optional.of(new ReviewAppointment(depot, reviewAppointmentExpr));
+ else
+ reviewAppointmentOpt = Optional.empty();
+ }
+ return reviewAppointmentOpt.orElse(null);
+ }
+
+ public void onDepotTransferred(Depot depot) {
+ ReviewAppointment reviewAppointment = getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ reviewAppointment.getTeams().clear();
+ setReviewAppointmentExpr(reviewAppointment.toExpr());
+ }
+
+ for (Iterator<FileProtection> it = getFileProtections().iterator(); it.hasNext();) {
+ FileProtection fileProtection = it.next();
+ reviewAppointment = fileProtection.getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ reviewAppointment.getTeams().clear();
+ String reviewAppointmentExpr = reviewAppointment.toExpr();
+ if (reviewAppointmentExpr != null)
+ fileProtection.setReviewAppointmentExpr(reviewAppointmentExpr);
+ else
+ it.remove();
+ } else {
+ it.remove();
+ }
+ }
+ }
+
+ public void onTeamRename(Depot depot, String oldName, String newName) {
+ ReviewAppointment reviewAppointment = getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Team team: reviewAppointment.getTeams().keySet()) {
+ if (team.getName().equals(oldName))
+ team.setName(newName);
+ }
+ setReviewAppointmentExpr(reviewAppointment.toExpr());
+ }
+
+ for (Iterator<FileProtection> it = getFileProtections().iterator(); it.hasNext();) {
+ FileProtection fileProtection = it.next();
+ reviewAppointment = fileProtection.getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Team team: reviewAppointment.getTeams().keySet()) {
+ if (team.getName().equals(oldName))
+ team.setName(newName);
+ }
+ fileProtection.setReviewAppointmentExpr(reviewAppointment.toExpr());
+ } else {
+ it.remove();
+ }
+ }
+ }
+
+ public void onTeamDelete(Depot depot, String teamName) {
+ ReviewAppointment reviewAppointment = getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Iterator<Map.Entry<Team, Integer>> it = reviewAppointment.getTeams().entrySet().iterator();
+ it.hasNext();) {
+ Team team = it.next().getKey();
+ if (team.getName().equals(teamName))
+ it.remove();
+ }
+ setReviewAppointmentExpr(reviewAppointment.toExpr());
+ }
+
+ for (Iterator<FileProtection> it = getFileProtections().iterator(); it.hasNext();) {
+ FileProtection fileProtection = it.next();
+ reviewAppointment = fileProtection.getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Iterator<Map.Entry<Team, Integer>> itTeam = reviewAppointment.getTeams().entrySet().iterator();
+ itTeam.hasNext();) {
+ Team team = itTeam.next().getKey();
+ if (team.getName().equals(teamName))
+ itTeam.remove();
+ }
+ String reviewAppointmentExpr = reviewAppointment.toExpr();
+ if (reviewAppointmentExpr != null)
+ fileProtection.setReviewAppointmentExpr(reviewAppointmentExpr);
+ else
+ it.remove();
+ } else {
+ it.remove();
+ }
+ }
+ }
+
+ public void onAccountRename(Depot depot, String oldName, String newName) {
+ ReviewAppointment reviewAppointment = getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Account user: reviewAppointment.getUsers()) {
+ if (user.getName().equals(oldName))
+ user.setName(newName);
+ }
+ setReviewAppointmentExpr(reviewAppointment.toExpr());
+ }
+
+ for (Iterator<FileProtection> it = getFileProtections().iterator(); it.hasNext();) {
+ FileProtection fileProtection = it.next();
+ reviewAppointment = fileProtection.getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Account user: reviewAppointment.getUsers()) {
+ if (user.getName().equals(oldName))
+ user.setName(newName);
+ }
+ fileProtection.setReviewAppointmentExpr(reviewAppointment.toExpr());
+ } else {
+ it.remove();
+ }
+ }
+ }
+
+ public void onAccountDelete(Depot depot, String accountName) {
+ ReviewAppointment reviewAppointment = getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Iterator<Account> it = reviewAppointment.getUsers().iterator(); it.hasNext();) {
+ Account user = it.next();
+ if (user.getName().equals(accountName))
+ it.remove();
+ }
+ setReviewAppointmentExpr(reviewAppointment.toExpr());
+ }
+
+ for (Iterator<FileProtection> it = getFileProtections().iterator(); it.hasNext();) {
+ FileProtection fileProtection = it.next();
+ reviewAppointment = fileProtection.getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Iterator<Account> itUser = reviewAppointment.getUsers().iterator(); itUser.hasNext();) {
+ Account user = itUser.next();
+ if (user.getName().equals(accountName))
+ itUser.remove();
+ }
+ String reviewAppointmentExpr = reviewAppointment.toExpr();
+ if (reviewAppointmentExpr != null)
+ fileProtection.setReviewAppointmentExpr(reviewAppointmentExpr);
+ else
+ it.remove();
+ } else {
+ it.remove();
+ }
+ }
+ }
+
+ public boolean onBranchDelete(String branchName) {
+ return branchName.equals(getBranch());
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/model/support/CloseInfo.java b/core/src/main/java/com/gitplex/server/model/support/CloseInfo.java
index 71f2add5bd..42d8de7ae5 100644
--- a/core/src/main/java/com/gitplex/server/model/support/CloseInfo.java
+++ b/core/src/main/java/com/gitplex/server/model/support/CloseInfo.java
@@ -16,11 +16,14 @@ public class CloseInfo implements Serializable {
private static final long serialVersionUID = 1L;
- public enum Status {INTEGRATED, DISCARDED};
+ public enum Status {MERGED, DISCARDED};
@OptimisticLock(excluded=true)
@ManyToOne(fetch=FetchType.LAZY)
private Account closedBy;
+
+ @OptimisticLock(excluded=true)
+ private String closedByName;
@OptimisticLock(excluded=true)
private Date closeDate;
@@ -36,6 +39,14 @@ public class CloseInfo implements Serializable {
this.closedBy = closedBy;
}
+ public String getClosedByName() {
+ return closedByName;
+ }
+
+ public void setClosedByName(String closedByName) {
+ this.closedByName = closedByName;
+ }
+
public Date getCloseDate() {
return closeDate;
}
diff --git a/core/src/main/java/com/gitplex/server/model/support/CodeCommentActivity.java b/core/src/main/java/com/gitplex/server/model/support/CodeCommentActivity.java
index 60909c6bce..9fefa7241f 100644
--- a/core/src/main/java/com/gitplex/server/model/support/CodeCommentActivity.java
+++ b/core/src/main/java/com/gitplex/server/model/support/CodeCommentActivity.java
@@ -2,6 +2,7 @@ package com.gitplex.server.model.support;
import java.util.Date;
+import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.FetchType;
@@ -25,8 +26,10 @@ public abstract class CodeCommentActivity extends AbstractEntity {
private CodeComment comment;
@ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
+ @JoinColumn
private Account user;
+
+ private String userName;
@Column(nullable=false)
private Date date;
@@ -45,6 +48,7 @@ public abstract class CodeCommentActivity extends AbstractEntity {
this.comment = comment;
}
+ @Nullable
public Account getUser() {
return user;
}
@@ -53,6 +57,15 @@ public abstract class CodeCommentActivity extends AbstractEntity {
this.user = user;
}
+ @Nullable
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
public Date getDate() {
return date;
}
diff --git a/core/src/main/java/com/gitplex/server/model/support/FileProtection.java b/core/src/main/java/com/gitplex/server/model/support/FileProtection.java
new file mode 100644
index 0000000000..11268321c2
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/model/support/FileProtection.java
@@ -0,0 +1,53 @@
+package com.gitplex.server.model.support;
+
+import java.io.Serializable;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.util.editable.annotation.Editable;
+import com.gitplex.server.util.editable.annotation.PathPattern;
+import com.gitplex.server.util.reviewappointment.ReviewAppointment;
+
+@Editable
+public class FileProtection implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String path;
+
+ private String reviewAppointmentExpr;
+
+ private transient ReviewAppointment reviewAppointment;
+
+ @Editable(order=100, description="Specify path to be protected. Wildcard can be used in the path "
+ + "to match multiple files")
+ @PathPattern
+ @NotEmpty
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ @Editable(order=200, name="Reviewers", description="Optionally specify required reviewers if specified path is "
+ + "changed. Note that the user submitting the change is considered to reviewed the change automatically")
+ @com.gitplex.server.util.editable.annotation.ReviewAppointment
+ @NotEmpty
+ public String getReviewAppointmentExpr() {
+ return reviewAppointmentExpr;
+ }
+
+ public void setReviewAppointmentExpr(String reviewAppointmentExpr) {
+ this.reviewAppointmentExpr = reviewAppointmentExpr;
+ }
+
+ public ReviewAppointment getReviewAppointment(Depot depot) {
+ if (reviewAppointment == null)
+ reviewAppointment = new ReviewAppointment(depot, reviewAppointmentExpr);
+ return reviewAppointment;
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/model/support/IntegrationPolicy.java b/core/src/main/java/com/gitplex/server/model/support/IntegrationPolicy.java
deleted file mode 100644
index 24ee5d5bf6..0000000000
--- a/core/src/main/java/com/gitplex/server/model/support/IntegrationPolicy.java
+++ /dev/null
@@ -1,292 +0,0 @@
-package com.gitplex.server.model.support;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.constraints.Size;
-
-import org.apache.commons.lang3.StringUtils;
-import org.hibernate.validator.constraints.NotEmpty;
-
-import com.gitplex.server.util.includeexclude.IncludeExcludeParser;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest.IntegrationStrategy;
-import com.gitplex.server.util.editable.annotation.BranchMatch;
-import com.gitplex.server.util.editable.annotation.Editable;
-import com.gitplex.server.util.editable.annotation.FullBranchMatch;
-import com.gitplex.server.util.editable.annotation.Horizontal;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchUtils;
-import com.gitplex.server.util.includeexclude.IncludeExcludeUtils;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchParser.CriteriaContext;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchParser.FullBranchMatchContext;
-
-@Editable
-@Horizontal
-public class IntegrationPolicy implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private String targetBranchMatch;
-
- private String sourceBranchMatch;
-
- private List<IntegrationStrategy> integrationStrategies = new ArrayList<>();
-
- @Editable(name="Target Branches", order=100, description="Specify target branches of pull requests to which "
- + "this policy applies to.")
- @BranchMatch
- @NotEmpty
- public String getTargetBranchMatch() {
- return targetBranchMatch;
- }
-
- public void setTargetBranchMatch(String targetBranchMatch) {
- this.targetBranchMatch = targetBranchMatch;
- }
-
- @Editable(name="Source Branches", order=200, description="Specify source branches of pull requests to which "
- + "this policy applies to.")
- @FullBranchMatch
- @NotEmpty
- public String getSourceBranchMatch() {
- return sourceBranchMatch;
- }
-
- public void setSourceBranchMatch(String sourceBranchMatch) {
- this.sourceBranchMatch = sourceBranchMatch;
- }
-
- @Editable(order=300, descriptionProvider="getIntegrationStrategyHelp")
- @Size(min=1, message="At least one integration strategy should be specified")
- public List<IntegrationStrategy> getIntegrationStrategies() {
- return integrationStrategies;
- }
-
- public void setIntegrationStrategies(List<IntegrationStrategy> integrationStrategies) {
- this.integrationStrategies = integrationStrategies;
- }
-
- @SuppressWarnings("unused")
- private static String getIntegrationStrategyHelp() {
- StringBuilder help = new StringBuilder("<p>Choose one or more integration strategies applicable for pull requests "
- + "matching branch criterias specified above. User can decide to use one of the applicable "
- + "strategy to integrate pull request into target branch. Note that the first selected strategy "
- + "here will appear as default strategy of the pull request. GitPlex for now provides below "
- + "integration strategies:</p>");
-
- help.append("<dl>");
-
- for (IntegrationStrategy strategy: IntegrationStrategy.values()) {
- help.append("<dt>").append(strategy.toString()).append("</dt>");
- help.append("<dd>").append(strategy.getDescription()).append("</dd>");
- }
-
- help.append("</dl>");
-
- return help.toString();
- }
-
- public boolean onAccountDelete(String accountName) {
- StringBuilder builder = new StringBuilder();
- for (CriteriaContext criteriaContext: FullBranchMatchUtils.parse(sourceBranchMatch).criteria()) {
- if (criteriaContext.includeMatch() != null) {
- String deleted = deleteAccount(accountName, criteriaContext.includeMatch().fullBranchMatch());
- if (deleted != null)
- builder.append(String.format("include(%s) ", deleted));
- } else {
- String deleted = deleteAccount(accountName, criteriaContext.excludeMatch().fullBranchMatch());
- if (deleted != null)
- builder.append(String.format("exclude(%s) ", deleted));
- }
- }
- sourceBranchMatch = builder.toString().trim();
- return sourceBranchMatch.length() == 0;
- }
-
- private String deleteAccount(String accountName, FullBranchMatchContext fullBranchMatchContext) {
- if (fullBranchMatchContext.fullDepotMatch() != null) {
- String fullDepotMatch = StringUtils.deleteWhitespace(fullBranchMatchContext.fullDepotMatch().getText());
- String accountMatch = StringUtils.substringBeforeLast(fullDepotMatch, Depot.FQN_SEPARATOR);
- if (accountMatch.equals(accountName)) {
- return null;
- }
- }
- return fullBranchMatchContext.getText();
- }
-
- public boolean onBranchDelete(Depot depotDefiningPolicy, Depot depotContainingBranch, String branch) {
- StringBuilder builder = new StringBuilder();
- if (depotDefiningPolicy.equals(depotContainingBranch)) {
- for (IncludeExcludeParser.CriteriaContext criteriaContext: IncludeExcludeUtils.parse(targetBranchMatch).criteria()) {
- if (criteriaContext.includeMatch() != null) {
- String value = IncludeExcludeUtils.getValue(criteriaContext.includeMatch().Value());
- if (!value.equals(branch))
- builder.append(String.format("include(%s) ", value));
- } else {
- String value = IncludeExcludeUtils.getValue(criteriaContext.excludeMatch().Value());
- if (!value.equals(branch))
- builder.append(String.format("exclude(%s) ", value));
- }
- }
- targetBranchMatch = builder.toString().trim();
- if (targetBranchMatch.length() == 0)
- return true;
- }
-
- builder = new StringBuilder();
- for (CriteriaContext criteriaContext: FullBranchMatchUtils.parse(sourceBranchMatch).criteria()) {
- if (criteriaContext.includeMatch() != null) {
- String deleted = deleteSourceBranch(depotDefiningPolicy, depotContainingBranch,
- branch, criteriaContext.includeMatch().fullBranchMatch());
- if (deleted != null)
- builder.append(String.format("include(%s) ", deleted));
- } else {
- String deleted = deleteSourceBranch(depotDefiningPolicy, depotContainingBranch,
- branch, criteriaContext.excludeMatch().fullBranchMatch());
- if (deleted != null)
- builder.append(String.format("exclude(%s) ", deleted));
- }
- }
- sourceBranchMatch = builder.toString().trim();
-
- return sourceBranchMatch.length() == 0;
- }
-
- private String deleteSourceBranch(Depot depotDefiningPolicy, Depot depotContainingBranch,
- String branch, FullBranchMatchContext fullBranchMatchContext) {
- DepotAndRevision depotAndRevision = new DepotAndRevision(depotContainingBranch, branch);
- String fullBranchMatch = StringUtils.deleteWhitespace(fullBranchMatchContext.getText());
- if (fullBranchMatch.equals(depotAndRevision.getFQN())
- || depotContainingBranch.equals(depotDefiningPolicy) && branch.equals(fullBranchMatch)) {
- return null;
- } else {
- return fullBranchMatchContext.getText();
- }
- }
-
- public boolean onDepotDelete(Depot depot) {
- StringBuilder builder = new StringBuilder();
- for (CriteriaContext criteriaContext: FullBranchMatchUtils.parse(sourceBranchMatch).criteria()) {
- if (criteriaContext.includeMatch() != null) {
- String deleted = deleteDepot(depot, criteriaContext.includeMatch().fullBranchMatch());
- if (deleted != null)
- builder.append(String.format("include(%s) ", deleted));
- } else {
- String deleted = deleteDepot(depot, criteriaContext.excludeMatch().fullBranchMatch());
- if (deleted != null)
- builder.append(String.format("exclude(%s) ", deleted));
- }
- }
- sourceBranchMatch = builder.toString().trim();
- return sourceBranchMatch.length() == 0;
- }
-
- private String deleteDepot(Depot depot, FullBranchMatchContext fullBranchMatchContext) {
- if (fullBranchMatchContext.fullDepotMatch() != null) {
- String fullDepotMatch = StringUtils.deleteWhitespace(fullBranchMatchContext.fullDepotMatch().getText());
- if (fullDepotMatch.equals(depot.getFQN())) {
- return null;
- }
- }
- return fullBranchMatchContext.getText();
- }
-
- public void onDepotTransfer(Depot transferredDepot, Account originalAccount) {
- StringBuilder builder = new StringBuilder();
- for (CriteriaContext criteriaContext: FullBranchMatchUtils.parse(sourceBranchMatch).criteria()) {
- if (criteriaContext.includeMatch() != null) {
- String updated = updateDepotAccount(transferredDepot.getName(),
- originalAccount.getName(), transferredDepot.getAccount().getName(),
- criteriaContext.includeMatch().fullBranchMatch());
- builder.append(String.format("include(%s) ", updated));
- } else {
- String updated = updateDepotAccount(transferredDepot.getName(),
- originalAccount.getName(), transferredDepot.getAccount().getName(),
- criteriaContext.excludeMatch().fullBranchMatch());
- builder.append(String.format("exclude(%s) ", updated));
- }
- }
- sourceBranchMatch = builder.toString().trim();
- }
-
- private static String updateDepotAccount(String depotName, String oldAccountName, String newAccountName,
- FullBranchMatchContext fullBranchMatchContext) {
- if (fullBranchMatchContext.fullDepotMatch() != null) {
- String fullDepotMatch = StringUtils.deleteWhitespace(fullBranchMatchContext.fullDepotMatch().getText());
- if (fullDepotMatch.equals(oldAccountName + Depot.FQN_SEPARATOR + depotName)) {
- return newAccountName
- + Depot.FQN_SEPARATOR
- + depotName
- + DepotAndBranch.SEPARATOR
- + fullBranchMatchContext.branchMatch().getText().trim();
- }
- }
- return fullBranchMatchContext.getText();
- }
-
- public void onDepotRename(Account depotAccount, String oldName, String newName) {
- StringBuilder builder = new StringBuilder();
- for (CriteriaContext criteriaContext: FullBranchMatchUtils.parse(sourceBranchMatch).criteria()) {
- if (criteriaContext.includeMatch() != null) {
- String updated = updateDepotName(depotAccount, oldName, newName,
- criteriaContext.includeMatch().fullBranchMatch());
- builder.append(String.format("include(%s) ", updated));
- } else {
- String updated = updateDepotName(depotAccount, oldName, newName,
- criteriaContext.excludeMatch().fullBranchMatch());
- builder.append(String.format("exclude(%s) ", updated));
- }
- }
- sourceBranchMatch = builder.toString().trim();
- }
-
- private String updateDepotName(Account depotAccount, String oldName, String newName,
- FullBranchMatchContext fullBranchMatchContext) {
- if (fullBranchMatchContext.fullDepotMatch() != null) {
- String fullDepot = StringUtils.deleteWhitespace(fullBranchMatchContext.fullDepotMatch().getText());
- if (fullDepot.equals(depotAccount.getName() + Depot.FQN_SEPARATOR + oldName)) {
- return depotAccount.getName()
- + Depot.FQN_SEPARATOR
- + newName
- + DepotAndBranch.SEPARATOR
- + fullBranchMatchContext.branchMatch().getText().trim();
- }
- }
- return fullBranchMatchContext.getText();
- }
-
- public void onAccountRename(String oldName, String newName) {
- StringBuilder builder = new StringBuilder();
- for (CriteriaContext criteriaContext: FullBranchMatchUtils.parse(sourceBranchMatch).criteria()) {
- if (criteriaContext.includeMatch() != null) {
- String updated = updateAccountName(oldName, newName,
- criteriaContext.includeMatch().fullBranchMatch());
- builder.append(String.format("include(%s) ", updated));
- } else {
- String updated = updateAccountName(oldName, newName,
- criteriaContext.excludeMatch().fullBranchMatch());
- builder.append(String.format("exclude(%s) ", updated));
- }
- }
- sourceBranchMatch = builder.toString().trim();
- }
-
- private static String updateAccountName(String oldName, String newName,
- FullBranchMatchContext fullBranchMatchContext) {
- if (fullBranchMatchContext.fullDepotMatch() != null) {
- String fullDepotMatch = StringUtils.deleteWhitespace(fullBranchMatchContext.fullDepotMatch().getText());
- String accountMatch = StringUtils.substringBeforeLast(fullDepotMatch, Depot.FQN_SEPARATOR);
- if (accountMatch.equals(oldName)) {
- return newName
- + Depot.FQN_SEPARATOR
- + StringUtils.substringAfterLast(fullDepotMatch, Depot.FQN_SEPARATOR)
- + DepotAndBranch.SEPARATOR
- + fullBranchMatchContext.branchMatch().getText().trim();
- }
- }
- return fullBranchMatchContext.getText();
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/model/support/LastEvent.java b/core/src/main/java/com/gitplex/server/model/support/LastEvent.java
index 8264576364..f438f94df2 100644
--- a/core/src/main/java/com/gitplex/server/model/support/LastEvent.java
+++ b/core/src/main/java/com/gitplex/server/model/support/LastEvent.java
@@ -3,6 +3,7 @@ package com.gitplex.server.model.support;
import java.io.Serializable;
import java.util.Date;
+import javax.annotation.Nullable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.FetchType;
@@ -19,6 +20,9 @@ public class LastEvent implements Serializable {
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="LAST_EVENT_USER")
private Account user;
+
+ @Column(name="LAST_EVENT_USER_NAME")
+ private String userName;
@Column(name="LAST_EVENT_TYPE")
private String type;
@@ -42,6 +46,7 @@ public class LastEvent implements Serializable {
this.date = date;
}
+ @Nullable
public Account getUser() {
return user;
}
@@ -49,5 +54,14 @@ public class LastEvent implements Serializable {
public void setUser(Account user) {
this.user = user;
}
+
+ @Nullable
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
}
diff --git a/core/src/main/java/com/gitplex/server/model/support/IntegrationPreview.java b/core/src/main/java/com/gitplex/server/model/support/MergePreview.java
similarity index 51%
rename from core/src/main/java/com/gitplex/server/model/support/IntegrationPreview.java
rename to core/src/main/java/com/gitplex/server/model/support/MergePreview.java
index d366cabeb5..ceeb770177 100644
--- a/core/src/main/java/com/gitplex/server/model/support/IntegrationPreview.java
+++ b/core/src/main/java/com/gitplex/server/model/support/MergePreview.java
@@ -1,6 +1,7 @@
package com.gitplex.server.model.support;
import java.io.Serializable;
+import java.util.Date;
import javax.annotation.Nullable;
import javax.persistence.Column;
@@ -9,11 +10,10 @@ import javax.persistence.Embeddable;
import org.eclipse.jgit.lib.ObjectId;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequest.IntegrationStrategy;
@SuppressWarnings("serial")
@Embeddable
-public class IntegrationPreview implements Serializable {
+public class MergePreview implements Serializable {
@Column(name="PREVIEW_TARGET_HEAD")
private String targetHead;
@@ -21,22 +21,23 @@ public class IntegrationPreview implements Serializable {
@Column(name="PREVIEW_REQUEST_HEAD")
private String requestHead;
- @Column(name="PREVIEW_INTEGRATION_STRATEGY")
- private IntegrationStrategy integrationStrategy;
+ @Column(name="PREVIEW_MERGE_STRATEGY")
+ private MergeStrategy mergeStrategy;
- @Column(name="PREVIEW_INTEGRATED")
- private String integrated;
+ @Column(name="PREVIEW_MERGED")
+ private String merged;
+
+ private Date date = new Date();
@SuppressWarnings("unused")
- private IntegrationPreview() {
+ private MergePreview() {
}
- public IntegrationPreview(String targetHead, String requestHead,
- IntegrationStrategy integrationStrategy, @Nullable String integrated) {
+ public MergePreview(String targetHead, String requestHead, MergeStrategy mergeStrategy, @Nullable String merged) {
this.targetHead = targetHead;
this.requestHead = requestHead;
- this.integrationStrategy = integrationStrategy;
- this.integrated = integrated;
+ this.mergeStrategy = mergeStrategy;
+ this.merged = merged;
}
public String getTargetHead() {
@@ -47,8 +48,8 @@ public class IntegrationPreview implements Serializable {
return requestHead;
}
- public IntegrationStrategy getIntegrationStrategy() {
- return integrationStrategy;
+ public MergeStrategy getMergeStrategy() {
+ return mergeStrategy;
}
public void setTargetHead(String targetHead) {
@@ -59,8 +60,16 @@ public class IntegrationPreview implements Serializable {
this.requestHead = requestHead;
}
- public void setIntegrationStrategy(IntegrationStrategy integrationStrategy) {
- this.integrationStrategy = integrationStrategy;
+ public void setIntegrationStrategy(MergeStrategy mergeStrategy) {
+ this.mergeStrategy = mergeStrategy;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
}
/**
@@ -70,19 +79,19 @@ public class IntegrationPreview implements Serializable {
* null if there are conflicts
*/
@Nullable
- public String getIntegrated() {
- return integrated;
+ public String getMerged() {
+ return merged;
}
- public void setIntegrated(String integrated) {
- this.integrated = integrated;
+ public void setMerged(String merged) {
+ this.merged = merged;
}
public boolean isObsolete(PullRequest request) {
if (getRequestHead().equals(request.getHeadCommitHash())
&& getTargetHead().equals(request.getTarget().getObjectName())
- && getIntegrationStrategy() == request.getIntegrationStrategy()
- && (getIntegrated() == null || ObjectId.fromString(getIntegrated()).equals((request.getTargetDepot().getObjectId(request.getIntegrateRef(), false))))) {
+ && getMergeStrategy() == request.getMergeStrategy()
+ && (getMerged() == null || ObjectId.fromString(getMerged()).equals((request.getTargetDepot().getObjectId(request.getMergeRef(), false))))) {
return false;
} else {
return true;
diff --git a/core/src/main/java/com/gitplex/server/model/support/MergeStrategy.java b/core/src/main/java/com/gitplex/server/model/support/MergeStrategy.java
new file mode 100644
index 0000000000..650e55f0ba
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/model/support/MergeStrategy.java
@@ -0,0 +1,37 @@
+package com.gitplex.server.model.support;
+
+public enum MergeStrategy {
+ ALWAYS_MERGE("Always Merge",
+ "Add all commits from source branch to target branch with a merge commit."),
+ MERGE_IF_NECESSARY("Merge If Necessary",
+ "Only create merge commit if target branch can not be fast-forwarded to source branch"),
+ SQUASH_MERGE("Squash Merge",
+ "Squash all commits from source branch into a single commit in target branch"),
+ REBASE_MERGE("Rebase Merge",
+ "Rebase all commits from source branch onto target branch"),
+ DO_NOT_MERGE("Do Not Merge",
+ "Do not merge now, only for review");
+
+ private final String displayName;
+
+ private final String description;
+
+ MergeStrategy(String displayName, String description) {
+ this.displayName = displayName;
+ this.description = description;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public String toString() {
+ return displayName;
+ }
+
+}
\ No newline at end of file
diff --git a/core/src/main/java/com/gitplex/server/model/support/TagProtection.java b/core/src/main/java/com/gitplex/server/model/support/TagProtection.java
new file mode 100644
index 0000000000..25813c43bf
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/model/support/TagProtection.java
@@ -0,0 +1,110 @@
+package com.gitplex.server.model.support;
+
+import java.io.Serializable;
+
+import javax.validation.constraints.NotNull;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.support.tagcreator.DepotWriters;
+import com.gitplex.server.model.support.tagcreator.SpecifiedTeam;
+import com.gitplex.server.model.support.tagcreator.SpecifiedUser;
+import com.gitplex.server.model.support.tagcreator.TagCreator;
+import com.gitplex.server.util.editable.annotation.Editable;
+import com.gitplex.server.util.editable.annotation.TagPattern;
+
+@Editable
+public class TagProtection implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String tag;
+
+ private boolean noUpdate = true;
+
+ private boolean noDeletion = true;
+
+ private TagCreator tagCreator = new DepotWriters();
+
+ @Editable(order=100, description="Specify tag to be protected. Wildcard can be used to match multiple tags")
+ @TagPattern
+ @NotEmpty
+ public String getTag() {
+ return tag;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ @Editable(order=200, description="Check this to not allow tag update")
+ public boolean isNoUpdate() {
+ return noUpdate;
+ }
+
+ public void setNoUpdate(boolean noUpdate) {
+ this.noUpdate = noUpdate;
+ }
+
+ @Editable(order=300, description="Check this to not allow tag deletion")
+ public boolean isNoDeletion() {
+ return noDeletion;
+ }
+
+ public void setNoDeletion(boolean noDeletion) {
+ this.noDeletion = noDeletion;
+ }
+
+ @Editable(order=400, name="Allowed Creator", description="Specify users allowed to create specified tag")
+ @NotNull
+ public TagCreator getTagCreator() {
+ return tagCreator;
+ }
+
+ public void setTagCreator(TagCreator tagCreator) {
+ this.tagCreator = tagCreator;
+ }
+
+ public void onDepotTransferred(Depot depot) {
+ if (getTagCreator() instanceof SpecifiedTeam)
+ setTagCreator(new DepotWriters());
+ }
+
+ public void onTeamRename(String oldName, String newName) {
+ if (getTagCreator() instanceof SpecifiedTeam) {
+ SpecifiedTeam specifiedTeam = (SpecifiedTeam) getTagCreator();
+ if (specifiedTeam.getTeamName().equals(oldName))
+ specifiedTeam.setTeamName(newName);
+ }
+ }
+
+ public void onTeamDelete(String teamName) {
+ if (getTagCreator() instanceof SpecifiedTeam) {
+ SpecifiedTeam specifiedTeam = (SpecifiedTeam) getTagCreator();
+ if (specifiedTeam.getTeamName().equals(teamName))
+ setTagCreator(new DepotWriters());
+ }
+ }
+
+ public void onAccountRename(String oldName, String newName) {
+ if (getTagCreator() instanceof SpecifiedUser) {
+ SpecifiedUser specifiedUser = (SpecifiedUser) getTagCreator();
+ if (specifiedUser.getUserName().equals(oldName))
+ specifiedUser.setUserName(newName);
+ }
+ }
+
+ public void onAccountDelete(String accountName) {
+ if (getTagCreator() instanceof SpecifiedUser) {
+ SpecifiedUser specifiedUser = (SpecifiedUser) getTagCreator();
+ if (specifiedUser.getUserName().equals(accountName))
+ setTagCreator(new DepotWriters());
+ }
+ }
+
+ public boolean onTagDelete(String tagName) {
+ return tagName.equals(getTag());
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/model/support/tagcreator/DepotAdministrators.java b/core/src/main/java/com/gitplex/server/model/support/tagcreator/DepotAdministrators.java
new file mode 100644
index 0000000000..a29321795d
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/model/support/tagcreator/DepotAdministrators.java
@@ -0,0 +1,22 @@
+package com.gitplex.server.model.support.tagcreator;
+
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.security.ObjectPermission;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable(order=200, name="Repository Administrators")
+public class DepotAdministrators implements TagCreator {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getNotMatchMessage(Depot depot, Account user) {
+ if (!user.asSubject().isPermitted(ObjectPermission.ofDepotAdmin(depot))) {
+ return "This operation can only be performed by repository administrators";
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/model/support/tagcreator/DepotWriters.java b/core/src/main/java/com/gitplex/server/model/support/tagcreator/DepotWriters.java
new file mode 100644
index 0000000000..0513acfac1
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/model/support/tagcreator/DepotWriters.java
@@ -0,0 +1,22 @@
+package com.gitplex.server.model.support.tagcreator;
+
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.security.ObjectPermission;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable(order=100, name="All Users Able to Write to the Repository")
+public class DepotWriters implements TagCreator {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getNotMatchMessage(Depot depot, Account user) {
+ if (!user.asSubject().isPermitted(ObjectPermission.ofDepotWrite(depot))) {
+ return "This operation can only be performed by repository writers";
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/model/support/tagcreator/SpecifiedTeam.java b/core/src/main/java/com/gitplex/server/model/support/tagcreator/SpecifiedTeam.java
new file mode 100644
index 0000000000..c0a0f573e1
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/model/support/tagcreator/SpecifiedTeam.java
@@ -0,0 +1,42 @@
+package com.gitplex.server.model.support.tagcreator;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import com.gitplex.server.GitPlex;
+import com.gitplex.server.manager.TeamManager;
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.Team;
+import com.gitplex.server.util.editable.annotation.Editable;
+import com.gitplex.server.util.editable.annotation.TeamChoice;
+import com.google.common.base.Preconditions;
+
+@Editable(order=300, name="Specified Team")
+public class SpecifiedTeam implements TagCreator {
+
+ private static final long serialVersionUID = 1L;
+
+ private String teamName;
+
+ @Editable(name="Team")
+ @TeamChoice
+ @NotEmpty
+ public String getTeamName() {
+ return teamName;
+ }
+
+ public void setTeamName(String teamName) {
+ this.teamName = teamName;
+ }
+
+ @Override
+ public String getNotMatchMessage(Depot depot, Account user) {
+ TeamManager teamManager = GitPlex.getInstance(TeamManager.class);
+ Team team = Preconditions.checkNotNull(teamManager.find(depot.getAccount(), teamName));
+ if (!team.getMembers().contains(user))
+ return "This operation can only be performed by team: " + teamName;
+ else
+ return null;
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/model/support/tagcreator/SpecifiedUser.java b/core/src/main/java/com/gitplex/server/model/support/tagcreator/SpecifiedUser.java
new file mode 100644
index 0000000000..2c72ecb5db
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/model/support/tagcreator/SpecifiedUser.java
@@ -0,0 +1,41 @@
+package com.gitplex.server.model.support.tagcreator;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import com.gitplex.server.GitPlex;
+import com.gitplex.server.manager.AccountManager;
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.util.editable.annotation.AccountChoice;
+import com.gitplex.server.util.editable.annotation.Editable;
+import com.google.common.base.Preconditions;
+
+@Editable(order=400, name="Specified User")
+public class SpecifiedUser implements TagCreator {
+
+ private static final long serialVersionUID = 1L;
+
+ private String userName;
+
+ @Editable(name="User")
+ @AccountChoice(type=AccountChoice.Type.DEPOT_WRITER)
+ @NotEmpty
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ @Override
+ public String getNotMatchMessage(Depot depot, Account user) {
+ AccountManager accountManager = GitPlex.getInstance(AccountManager.class);
+ Account specifiedUser = Preconditions.checkNotNull(accountManager.findByName(userName));
+ if (!specifiedUser.equals(user))
+ return "This operation can only be performed by user: " + userName;
+ else
+ return null;
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/model/support/tagcreator/TagCreator.java b/core/src/main/java/com/gitplex/server/model/support/tagcreator/TagCreator.java
new file mode 100644
index 0000000000..afeee8e917
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/model/support/tagcreator/TagCreator.java
@@ -0,0 +1,17 @@
+package com.gitplex.server.model.support.tagcreator;
+
+import java.io.Serializable;
+
+import javax.annotation.Nullable;
+
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable
+public interface TagCreator extends Serializable {
+
+ @Nullable
+ String getNotMatchMessage(Depot depot, Account user);
+
+}
diff --git a/core/src/main/java/com/gitplex/server/security/SecurityUtils.java b/core/src/main/java/com/gitplex/server/security/SecurityUtils.java
index 62b8cf6319..1415e7a14c 100644
--- a/core/src/main/java/com/gitplex/server/security/SecurityUtils.java
+++ b/core/src/main/java/com/gitplex/server/security/SecurityUtils.java
@@ -10,14 +10,17 @@ import org.eclipse.jgit.lib.ObjectId;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.AccountManager;
+import com.gitplex.server.manager.ReviewManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.CodeComment;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
import com.gitplex.server.model.PullRequestComment;
-import com.gitplex.server.model.PullRequestReview;
import com.gitplex.server.model.PullRequestStatusChange;
+import com.gitplex.server.model.Review;
+import com.gitplex.server.model.support.BranchProtection;
import com.gitplex.server.model.support.CodeCommentActivity;
+import com.gitplex.server.model.support.TagProtection;
import com.gitplex.server.security.privilege.DepotPrivilege;
import com.gitplex.server.security.privilege.Privilege;
@@ -26,8 +29,9 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
public static Collection<Account> findUsersCan(Depot depot, DepotPrivilege operation) {
Set<Account> authorizedUsers = new HashSet<Account>();
for (Account account: GitPlex.getInstance(AccountManager.class).findAll()) {
- if (!account.isOrganization() && account.asSubject().isPermitted(new ObjectPermission(depot, operation)))
+ if (!account.isOrganization() && account.asSubject().isPermitted(new ObjectPermission(depot, operation))) {
authorizedUsers.add(account);
+ }
}
return authorizedUsers;
}
@@ -38,8 +42,7 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
return true;
} else {
Account currentUser = getAccount();
- return currentUser != null &&
- (currentUser.equals(request.getSubmitter()) || currentUser.equals(request.getAssignee()));
+ return currentUser != null && currentUser.equals(request.getSubmitter());
}
}
@@ -47,8 +50,8 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
return GitPlex.getInstance(AccountManager.class).getCurrent();
}
- public static boolean canModify(PullRequestReview review) {
- Depot depot = review.getUpdate().getRequest().getTargetDepot();
+ public static boolean canModify(Review review) {
+ Depot depot = review.getRequest().getTargetDepot();
if (canManage(depot)) {
return true;
} else {
@@ -92,15 +95,51 @@ public class SecurityUtils extends org.apache.shiro.SecurityUtils {
}
}
- public static boolean canPushRef(Depot depot, String refName, ObjectId oldCommit, ObjectId newCommit) {
- Account currentUser = getAccount();
- return currentUser != null
- && currentUser.asSubject().isPermitted(ObjectPermission.ofDepotWrite(depot))
- && depot.getGateKeeper().checkPush(currentUser, depot, refName, oldCommit, newCommit).isPassedOrIgnored();
+ public static boolean canDeleteBranch(Depot depot, String branchName) {
+ if (canWrite(depot)) {
+ BranchProtection protection = depot.getBranchProtection(branchName);
+ return protection == null || !protection.isNoDeletion();
+ } else {
+ return false;
+ }
}
-
- public static boolean canModify(Depot depot, String branch, @Nullable String file) {
- return canWrite(depot) && depot.getGateKeeper().checkFile(getAccount(), depot, branch, file).isPassedOrIgnored();
+
+ public static boolean canUpdateTag(Depot depot, String tagName) {
+ if (canWrite(depot)) {
+ TagProtection protection = depot.getTagProtection(tagName);
+ return protection == null || !protection.isNoUpdate();
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean canDeleteTag(Depot depot, String tagName) {
+ if (canWrite(depot)) {
+ TagProtection protection = depot.getTagProtection(tagName);
+ return protection == null || !protection.isNoDeletion();
+ } else {
+ return false;
+ }
+ }
+
+ @Nullable
+ public static boolean canCreateTag(Depot depot, String tagName) {
+ if (canWrite(depot)) {
+ TagProtection protection = depot.getTagProtection(tagName);
+ return protection == null ||
+ protection.getTagCreator().getNotMatchMessage(depot, SecurityUtils.getAccount()) == null;
+ } else {
+ return false;
+ }
+ }
+
+ public static boolean canModify(Depot depot, String branch, String file) {
+ return canWrite(depot) && GitPlex.getInstance(ReviewManager.class).canModify(getAccount(), depot, branch, file);
+ }
+
+ public static boolean canPush(Depot depot, String branchName, ObjectId oldObjectId, ObjectId newObjectId) {
+ return canWrite(depot) && GitPlex.getInstance(ReviewManager.class).canPush(getAccount(), depot, branchName,
+ oldObjectId, newObjectId);
}
public static boolean canManage(Account account) {
diff --git a/core/src/main/java/com/gitplex/server/util/PathUtils.java b/core/src/main/java/com/gitplex/server/util/PathUtils.java
index 3306f6a507..13783671a1 100644
--- a/core/src/main/java/com/gitplex/server/util/PathUtils.java
+++ b/core/src/main/java/com/gitplex/server/util/PathUtils.java
@@ -4,11 +4,15 @@ import java.util.Collection;
import javax.annotation.Nullable;
-import com.gitplex.launcher.loader.LoaderUtils;
import com.gitplex.jsymbol.Range;
+import com.gitplex.launcher.loader.LoaderUtils;
+import com.gitplex.server.util.stringmatch.ChildAwareMatcher;
+import com.gitplex.server.util.stringmatch.Matcher;
public class PathUtils {
+ private static final Matcher CHILDAWARE_MATCHER = new ChildAwareMatcher();
+
/**
* Match specified path against a collection of base paths to find out the longest match.
* For instance, if collection contains /path1/path2/path3 and /path1/path2, the eager
@@ -52,4 +56,8 @@ public class PathUtils {
return null;
}
+ public static boolean matchChildAware(String pattern, String value) {
+ return CHILDAWARE_MATCHER.matches(pattern, value);
+ }
+
}
diff --git a/core/src/main/java/com/gitplex/server/util/ReviewCheckStatus.java b/core/src/main/java/com/gitplex/server/util/ReviewCheckStatus.java
new file mode 100644
index 0000000000..6b7499f6b7
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/util/ReviewCheckStatus.java
@@ -0,0 +1,15 @@
+package com.gitplex.server.util;
+
+import java.util.List;
+import java.util.Map;
+
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Review;
+
+public interface ReviewCheckStatus {
+
+ List<Account> getAwaitingReviewers();
+
+ Map<Account, Review> getEffectiveReviews();
+
+}
diff --git a/core/src/main/java/com/gitplex/server/util/editable/annotation/AccountChoice.java b/core/src/main/java/com/gitplex/server/util/editable/annotation/AccountChoice.java
index 36dc19f159..73b0cbcb95 100644
--- a/core/src/main/java/com/gitplex/server/util/editable/annotation/AccountChoice.java
+++ b/core/src/main/java/com/gitplex/server/util/editable/annotation/AccountChoice.java
@@ -8,5 +8,8 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface AccountChoice {
- boolean organization() default false;
+
+ public enum Type{ORGANIZATION, USER, DEPOT_READER, DEPOT_WRITER, DEPOT_ADMINISTRATOR}
+
+ Type type() default Type.USER;
}
diff --git a/core/src/main/java/com/gitplex/server/util/editable/annotation/RefMatch.java b/core/src/main/java/com/gitplex/server/util/editable/annotation/BranchPattern.java
similarity index 89%
rename from core/src/main/java/com/gitplex/server/util/editable/annotation/RefMatch.java
rename to core/src/main/java/com/gitplex/server/util/editable/annotation/BranchPattern.java
index 9fd9d2830d..9bfab41562 100644
--- a/core/src/main/java/com/gitplex/server/util/editable/annotation/RefMatch.java
+++ b/core/src/main/java/com/gitplex/server/util/editable/annotation/BranchPattern.java
@@ -7,5 +7,5 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
-public @interface RefMatch {
+public @interface BranchPattern {
}
diff --git a/core/src/main/java/com/gitplex/server/util/editable/annotation/BranchMatch.java b/core/src/main/java/com/gitplex/server/util/editable/annotation/PathPattern.java
similarity index 89%
rename from core/src/main/java/com/gitplex/server/util/editable/annotation/BranchMatch.java
rename to core/src/main/java/com/gitplex/server/util/editable/annotation/PathPattern.java
index f5cbd46782..4e61517d9b 100644
--- a/core/src/main/java/com/gitplex/server/util/editable/annotation/BranchMatch.java
+++ b/core/src/main/java/com/gitplex/server/util/editable/annotation/PathPattern.java
@@ -7,5 +7,5 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
-public @interface BranchMatch {
+public @interface PathPattern {
}
diff --git a/core/src/main/java/com/gitplex/server/util/editable/annotation/FullBranchMatch.java b/core/src/main/java/com/gitplex/server/util/editable/annotation/ReviewAppointment.java
similarity index 88%
rename from core/src/main/java/com/gitplex/server/util/editable/annotation/FullBranchMatch.java
rename to core/src/main/java/com/gitplex/server/util/editable/annotation/ReviewAppointment.java
index 27fca2e5b0..f5b64bb66b 100644
--- a/core/src/main/java/com/gitplex/server/util/editable/annotation/FullBranchMatch.java
+++ b/core/src/main/java/com/gitplex/server/util/editable/annotation/ReviewAppointment.java
@@ -7,6 +7,5 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
-public @interface FullBranchMatch {
-
+public @interface ReviewAppointment {
}
diff --git a/core/src/main/java/com/gitplex/server/util/editable/annotation/PathMatch.java b/core/src/main/java/com/gitplex/server/util/editable/annotation/TagPattern.java
similarity index 90%
rename from core/src/main/java/com/gitplex/server/util/editable/annotation/PathMatch.java
rename to core/src/main/java/com/gitplex/server/util/editable/annotation/TagPattern.java
index d019c8a615..71503c4eb5 100644
--- a/core/src/main/java/com/gitplex/server/util/editable/annotation/PathMatch.java
+++ b/core/src/main/java/com/gitplex/server/util/editable/annotation/TagPattern.java
@@ -7,5 +7,5 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
-public @interface PathMatch {
+public @interface TagPattern {
}
diff --git a/core/src/main/java/com/gitplex/server/util/editable/annotation/TeamChoice.java b/core/src/main/java/com/gitplex/server/util/editable/annotation/TeamChoice.java
index 93577ed828..c0e37bf536 100644
--- a/core/src/main/java/com/gitplex/server/util/editable/annotation/TeamChoice.java
+++ b/core/src/main/java/com/gitplex/server/util/editable/annotation/TeamChoice.java
@@ -8,5 +8,4 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface TeamChoice {
- String[] excludes() default {};
}
diff --git a/core/src/main/java/com/gitplex/server/util/fullbranchmatch/FullBranchMatch.g4 b/core/src/main/java/com/gitplex/server/util/fullbranchmatch/FullBranchMatch.g4
deleted file mode 100644
index f053ac72b8..0000000000
--- a/core/src/main/java/com/gitplex/server/util/fullbranchmatch/FullBranchMatch.g4
+++ /dev/null
@@ -1,21 +0,0 @@
-grammar FullBranchMatch;
-
-match: ' '* criteria (' '+ criteria)* ' '* EOF;
-
-criteria: includeMatch | excludeMatch;
-
-includeMatch: INCLUDE '(' fullBranchMatch ')';
-excludeMatch: EXCLUDE '(' fullBranchMatch ')';
-
-fullBranchMatch: branchMatch | fullDepotMatch ':' branchMatch;
-
-fullDepotMatch: Value;
-branchMatch: Value;
-
-INCLUDE: 'include';
-EXCLUDE: 'exclude';
-
-Value: (ESCAPE|~[:() \\])+;
-
-fragment
-ESCAPE: '\\'[:()\\];
\ No newline at end of file
diff --git a/core/src/main/java/com/gitplex/server/util/fullbranchmatch/FullBranchMatchUtils.java b/core/src/main/java/com/gitplex/server/util/fullbranchmatch/FullBranchMatchUtils.java
deleted file mode 100644
index d6df933b6e..0000000000
--- a/core/src/main/java/com/gitplex/server/util/fullbranchmatch/FullBranchMatchUtils.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package com.gitplex.server.util.fullbranchmatch;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.ValidationException;
-
-import org.antlr.v4.runtime.ANTLRInputStream;
-import org.antlr.v4.runtime.BailErrorStrategy;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.apache.commons.lang3.StringUtils;
-
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchLexer;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchParser;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchParser.CriteriaContext;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchParser.FullBranchMatchContext;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchParser.MatchContext;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.support.DepotAndBranch;
-import com.gitplex.server.util.match.IncludeExclude;
-import com.gitplex.server.util.match.Matcher;
-import com.gitplex.server.util.match.WildcardUtils;
-
-public class FullBranchMatchUtils {
-
- public static MatchContext parse(String match) {
- ANTLRInputStream is = new ANTLRInputStream(match);
- FullBranchMatchLexer lexer = new FullBranchMatchLexer(is);
- lexer.removeErrorListeners();
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- FullBranchMatchParser parser = new FullBranchMatchParser(tokens);
- parser.removeErrorListeners();
- parser.setErrorHandler(new BailErrorStrategy());
- return parser.match();
- }
-
- public static boolean matches(String match, final Depot currentDepot, DepotAndBranch depotAndBranch) {
- MatchContext matchContext = parse(match);
- List<FullBranchMatchContext> includes = new ArrayList<>();
- List<FullBranchMatchContext> excludes = new ArrayList<>();
- for (CriteriaContext criteriaContext: matchContext.criteria()) {
- if (criteriaContext.includeMatch() != null) {
- includes.add(criteriaContext.includeMatch().fullBranchMatch());
- } else if (criteriaContext.excludeMatch() != null) {
- excludes.add(criteriaContext.excludeMatch().fullBranchMatch());
- }
- }
-
- Matcher<FullBranchMatchContext, DepotAndBranch> matcher = new Matcher<FullBranchMatchContext, DepotAndBranch>() {
-
- @Override
- public boolean matches(FullBranchMatchContext rule, DepotAndBranch value) {
- if (rule.fullDepotMatch() != null) {
- String fullDepotMatch = rule.fullDepotMatch().getText().trim();
- String branchMatch = rule.branchMatch().getText().trim();
- String accountMatch = StringUtils.substringBeforeLast(fullDepotMatch, Depot.FQN_SEPARATOR).trim();
- String depotMatch = StringUtils.substringAfterLast(fullDepotMatch, Depot.FQN_SEPARATOR).trim();
- return WildcardUtils.matchString(accountMatch, value.getDepot().getAccount().getName())
- && WildcardUtils.matchString(depotMatch, value.getDepot().getName())
- && WildcardUtils.matchString(branchMatch, value.getBranch());
- } else {
- String branchPattern = rule.branchMatch().Value().getText().trim();
- return value.getDepot().equals(currentDepot)
- && WildcardUtils.matchString(branchPattern, value.getBranch());
- }
- }
-
- };
- return new IncludeExclude<FullBranchMatchContext, DepotAndBranch>(includes, excludes).matches(matcher, depotAndBranch);
- }
-
- public static void validate(String match) {
- for (CriteriaContext criteriaContext: parse(match).criteria()) {
- if (criteriaContext.includeMatch() != null) {
- if (criteriaContext.includeMatch().fullBranchMatch().fullDepotMatch() != null) {
- String fullDepotMatch = criteriaContext.includeMatch().fullBranchMatch().fullDepotMatch().getText();
- if (fullDepotMatch.indexOf("/") == -1)
- throw new ValidationException("Depot match '" + fullDepotMatch + "' should contain '/'");
- }
- } else if (criteriaContext.excludeMatch() != null) {
- if (criteriaContext.excludeMatch().fullBranchMatch().fullDepotMatch() != null) {
- String fullDepotMatch = criteriaContext.excludeMatch().fullBranchMatch().fullDepotMatch().getText();
- if (fullDepotMatch.indexOf("/") == -1)
- throw new ValidationException("Depot match '" + fullDepotMatch + "' should contain '/'");
- }
- }
- }
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/util/includeexclude/IncludeExclude.g4 b/core/src/main/java/com/gitplex/server/util/includeexclude/IncludeExclude.g4
deleted file mode 100644
index bfdd87f055..0000000000
--- a/core/src/main/java/com/gitplex/server/util/includeexclude/IncludeExclude.g4
+++ /dev/null
@@ -1,16 +0,0 @@
-grammar IncludeExclude;
-
-match: ' '* criteria (' '+ criteria)* ' '* EOF;
-
-criteria: includeMatch | excludeMatch;
-
-includeMatch: INCLUDE Value;
-excludeMatch: EXCLUDE Value;
-
-INCLUDE: 'include';
-EXCLUDE: 'exclude';
-
-Value: '(' (ESCAPE|~[()\\])+? ')';
-
-fragment
-ESCAPE: '\\'[()\\];
diff --git a/core/src/main/java/com/gitplex/server/util/includeexclude/IncludeExcludeUtils.java b/core/src/main/java/com/gitplex/server/util/includeexclude/IncludeExcludeUtils.java
deleted file mode 100644
index 0ecc391799..0000000000
--- a/core/src/main/java/com/gitplex/server/util/includeexclude/IncludeExcludeUtils.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.gitplex.server.util.includeexclude;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.antlr.v4.runtime.ANTLRInputStream;
-import org.antlr.v4.runtime.BailErrorStrategy;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.tree.TerminalNode;
-
-import com.gitplex.server.util.includeexclude.IncludeExcludeLexer;
-import com.gitplex.server.util.includeexclude.IncludeExcludeParser;
-import com.gitplex.server.util.includeexclude.IncludeExcludeParser.CriteriaContext;
-import com.gitplex.server.util.includeexclude.IncludeExcludeParser.MatchContext;
-import com.gitplex.server.util.match.IncludeExclude;
-
-public class IncludeExcludeUtils {
-
- public static MatchContext parse(String match) {
- ANTLRInputStream is = new ANTLRInputStream(match);
- IncludeExcludeLexer lexer = new IncludeExcludeLexer(is);
- lexer.removeErrorListeners();
- CommonTokenStream tokens = new CommonTokenStream(lexer);
- IncludeExcludeParser parser = new IncludeExcludeParser(tokens);
- parser.removeErrorListeners();
- parser.setErrorHandler(new BailErrorStrategy());
- return parser.match();
- }
-
- public static String getValue(TerminalNode terminal) {
- String value = terminal.getText().substring(1);
- return value.substring(0, value.length()-1).trim();
- }
-
- public static IncludeExclude<String, String> getIncludeExclude(String match) {
- MatchContext matchContext = parse(match);
- List<String> includes = new ArrayList<>();
- List<String> excludes = new ArrayList<>();
- for (CriteriaContext criteriaContext: matchContext.criteria()) {
- if (criteriaContext.includeMatch() != null) {
- includes.add(getValue(criteriaContext.includeMatch().Value()));
- } else if (criteriaContext.excludeMatch() != null) {
- excludes.add(getValue(criteriaContext.excludeMatch().Value()));
- }
- }
-
- return new IncludeExclude<String, String>(includes, excludes);
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/util/match/IncludeExclude.java b/core/src/main/java/com/gitplex/server/util/match/IncludeExclude.java
deleted file mode 100644
index 4f02b382f3..0000000000
--- a/core/src/main/java/com/gitplex/server/util/match/IncludeExclude.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.gitplex.server.util.match;
-
-import java.util.List;
-
-public class IncludeExclude<T, V> {
-
- private final List<T> includes;
-
- private final List<T> excludes;
-
- public IncludeExclude(List<T> includes, List<T> excludes) {
- this.includes = includes;
- this.excludes = excludes;
- }
-
- public boolean matches(Matcher<T, V> matcher, V value) {
- return matches(matcher, matcher, value);
- }
-
- public boolean matches(Matcher<T, V> includeMatcher, Matcher<T, V> excludeMatcher, V value) {
- for (T exclude: excludes) {
- if (excludeMatcher.matches(exclude, value))
- return false;
- }
- if (includes.isEmpty()) {
- return true;
- } else {
- for (T include: includes) {
- if (includeMatcher.matches(include, value))
- return true;
- }
- return false;
- }
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/util/match/Matcher.java b/core/src/main/java/com/gitplex/server/util/match/Matcher.java
deleted file mode 100644
index 0f435f694e..0000000000
--- a/core/src/main/java/com/gitplex/server/util/match/Matcher.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.gitplex.server.util.match;
-
-public interface Matcher<R, V> {
- boolean matches(R rule, V value);
-}
diff --git a/core/src/main/java/com/gitplex/server/util/match/ParentAwareMatcher.java b/core/src/main/java/com/gitplex/server/util/match/ParentAwareMatcher.java
deleted file mode 100644
index 37e3dfc25b..0000000000
--- a/core/src/main/java/com/gitplex/server/util/match/ParentAwareMatcher.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.gitplex.server.util.match;
-
-/**
- * Besides the normal child aware match, this matcher also matches
- * parent path ending with slash. For instance, if pattern is defined
- * as &quot;parent/child&quot;, it will match value &quot;parent/&quot;.
- * A scenario using this matcher:
- * <ol>
- * <li> A gatekeeper is defined to require that all created tags should match
- * the format &quot;refs/tags/v*&quot;
- * <li> The tag creation link checks the gatekeeper using ref value &quot;refs/tags/&quot;
- * to see if tag creation is allowed, and it matches meaning one can create tag
- * <li> User then input tag name, and this name will be matched again with the gatekeeper
- * and if it does not starts with letter &quot;v&quot;, the tag creation will not be allowed
- *
- * @author robin
- *
- */
-public class ParentAwareMatcher extends ChildAwareMatcher {
-
- @Override
- public boolean matches(String rule, String value) {
- if (rule.startsWith(value) && value.endsWith("/")) {
- return true;
- } else {
- return super.matches(rule, value);
- }
- }
-
-}
diff --git a/core/src/main/java/com/gitplex/server/util/match/PatternMatcher.java b/core/src/main/java/com/gitplex/server/util/match/PatternMatcher.java
deleted file mode 100644
index 9ddb8b946d..0000000000
--- a/core/src/main/java/com/gitplex/server/util/match/PatternMatcher.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.gitplex.server.util.match;
-
-public interface PatternMatcher extends Matcher<String, String> {
-}
diff --git a/core/src/main/java/com/gitplex/server/util/reviewappointment/ReviewAppointment.g4 b/core/src/main/java/com/gitplex/server/util/reviewappointment/ReviewAppointment.g4
new file mode 100644
index 0000000000..b5177b4f84
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/util/reviewappointment/ReviewAppointment.g4
@@ -0,0 +1,20 @@
+grammar ReviewAppointment;
+
+expr: ' '* criteria (' '+ criteria)* ' '* EOF;
+
+criteria: userCriteria | teamCriteria;
+
+userCriteria: USER Value;
+teamCriteria: TEAM Value (':' count)?;
+
+count: 'all' | DIGIT;
+
+DIGIT: [1-9][0-9]*;
+
+USER: 'user';
+TEAM: 'team';
+
+Value: '(' (ESCAPE|~[()\\])+? ')';
+
+fragment
+ESCAPE: '\\'[()\\];
diff --git a/core/src/main/java/com/gitplex/server/util/reviewappointment/ReviewAppointment.java b/core/src/main/java/com/gitplex/server/util/reviewappointment/ReviewAppointment.java
new file mode 100644
index 0000000000..a05fd074b6
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/util/reviewappointment/ReviewAppointment.java
@@ -0,0 +1,119 @@
+package com.gitplex.server.util.reviewappointment;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Nullable;
+
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.BailErrorStrategy;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.tree.TerminalNode;
+
+import com.gitplex.server.GitPlex;
+import com.gitplex.server.manager.AccountManager;
+import com.gitplex.server.manager.TeamManager;
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.Team;
+import com.gitplex.server.util.reviewappointment.ReviewAppointmentParser.CountContext;
+import com.gitplex.server.util.reviewappointment.ReviewAppointmentParser.CriteriaContext;
+import com.gitplex.server.util.reviewappointment.ReviewAppointmentParser.ExprContext;
+
+public class ReviewAppointment {
+
+ private final List<Account> users = new ArrayList<>();
+
+ private final Map<Team, Integer> teams = new LinkedHashMap<>();
+
+ public ReviewAppointment(Depot depot, String expr) {
+ ExprContext exprContext = parse(expr);
+
+ for (CriteriaContext criteriaContext: exprContext.criteria()) {
+ if (criteriaContext.userCriteria() != null) {
+ String userName = getBracedValue(criteriaContext.userCriteria().Value());
+ Account user = GitPlex.getInstance(AccountManager.class).findByName(userName);
+ if (user != null) {
+ users.add(user);
+ }
+ } else if (criteriaContext.teamCriteria() != null) {
+ String teamName = getBracedValue(criteriaContext.teamCriteria().Value());
+ Team team = GitPlex.getInstance(TeamManager.class).find(depot.getAccount(), teamName);
+ if (team != null) {
+ CountContext countContext = criteriaContext.teamCriteria().count();
+ if (countContext != null) {
+ if (countContext.DIGIT() != null)
+ teams.put(team, Integer.parseInt(countContext.DIGIT().getText()));
+ else
+ teams.put(team, 0);
+ } else {
+ teams.put(team, 1);
+ }
+ }
+ }
+ }
+ }
+
+ public static ExprContext parse(String expr) {
+ ANTLRInputStream is = new ANTLRInputStream(expr);
+ ReviewAppointmentLexer lexer = new ReviewAppointmentLexer(is);
+ lexer.removeErrorListeners();
+ CommonTokenStream tokens = new CommonTokenStream(lexer);
+ ReviewAppointmentParser parser = new ReviewAppointmentParser(tokens);
+ parser.removeErrorListeners();
+ parser.setErrorHandler(new BailErrorStrategy());
+ return parser.expr();
+ }
+
+ private String getBracedValue(TerminalNode terminal) {
+ String value = terminal.getText().substring(1);
+ return value.substring(0, value.length()-1).trim();
+ }
+
+ public List<Account> getUsers() {
+ return users;
+ }
+
+ public Map<Team, Integer> getTeams() {
+ return teams;
+ }
+
+ public boolean matches(Account user) {
+ for (Account eachUser: users) {
+ if (!eachUser.equals(user))
+ return false;
+ }
+ for (Map.Entry<Team, Integer> entry: teams.entrySet()) {
+ Team team = entry.getKey();
+ int requiredCount = entry.getValue();
+ if (requiredCount == 0 || requiredCount > team.getMembers().size())
+ requiredCount = team.getMembers().size();
+
+ if (requiredCount > 1 || requiredCount == 1 && !team.getMembers().contains(user))
+ return false;
+ }
+ return true;
+ }
+
+ @Nullable
+ public String toExpr() {
+ StringBuilder builder = new StringBuilder();
+ for (Account user: users)
+ builder.append("user(").append(user.getName()).append(") ");
+ for (Map.Entry<Team, Integer> entry: teams.entrySet()) {
+ builder.append("team(").append(entry.getKey().getName()).append(")");
+ if (entry.getValue() == 0)
+ builder.append(":all");
+ else if (entry.getValue() != 1)
+ builder.append(":").append(entry.getValue());
+ builder.append(" ");
+ }
+ if (builder.length() != 0)
+ return builder.toString().trim();
+ else
+ return null;
+ }
+
+}
diff --git a/core/src/main/java/com/gitplex/server/util/match/ChildAwareMatcher.java b/core/src/main/java/com/gitplex/server/util/stringmatch/ChildAwareMatcher.java
similarity index 92%
rename from core/src/main/java/com/gitplex/server/util/match/ChildAwareMatcher.java
rename to core/src/main/java/com/gitplex/server/util/stringmatch/ChildAwareMatcher.java
index 053a837a64..ff76df7ef2 100644
--- a/core/src/main/java/com/gitplex/server/util/match/ChildAwareMatcher.java
+++ b/core/src/main/java/com/gitplex/server/util/stringmatch/ChildAwareMatcher.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.util.match;
+package com.gitplex.server.util.stringmatch;
/**
* Besides the normal wildcard string match, this matcher also matches
diff --git a/core/src/main/java/com/gitplex/server/util/stringmatch/Matcher.java b/core/src/main/java/com/gitplex/server/util/stringmatch/Matcher.java
new file mode 100644
index 0000000000..ab823dae16
--- /dev/null
+++ b/core/src/main/java/com/gitplex/server/util/stringmatch/Matcher.java
@@ -0,0 +1,5 @@
+package com.gitplex.server.util.stringmatch;
+
+public interface Matcher {
+ boolean matches(String pattern, String value);
+}
diff --git a/core/src/main/java/com/gitplex/server/util/match/PatternApplied.java b/core/src/main/java/com/gitplex/server/util/stringmatch/PatternApplied.java
similarity index 92%
rename from core/src/main/java/com/gitplex/server/util/match/PatternApplied.java
rename to core/src/main/java/com/gitplex/server/util/stringmatch/PatternApplied.java
index 4e1a6aa602..bfd486db35 100644
--- a/core/src/main/java/com/gitplex/server/util/match/PatternApplied.java
+++ b/core/src/main/java/com/gitplex/server/util/stringmatch/PatternApplied.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.util.match;
+package com.gitplex.server.util.stringmatch;
import java.io.Serializable;
diff --git a/core/src/main/java/com/gitplex/server/util/match/WildcardPathMatcher.java b/core/src/main/java/com/gitplex/server/util/stringmatch/WildcardPathMatcher.java
similarity index 98%
rename from core/src/main/java/com/gitplex/server/util/match/WildcardPathMatcher.java
rename to core/src/main/java/com/gitplex/server/util/stringmatch/WildcardPathMatcher.java
index 374ff56df2..d90dba01b9 100644
--- a/core/src/main/java/com/gitplex/server/util/match/WildcardPathMatcher.java
+++ b/core/src/main/java/com/gitplex/server/util/stringmatch/WildcardPathMatcher.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package com.gitplex.server.util.match;
+package com.gitplex.server.util.stringmatch;
import com.gitplex.server.util.StringUtils;
@@ -59,9 +59,9 @@ import com.gitplex.server.util.StringUtils;
*
* @since 16.07.2003
*/
-public class WildcardPathMatcher implements PatternMatcher {
+public class WildcardPathMatcher implements Matcher {
- private static final PatternMatcher STRING_MATCHER = new WildcardStringMatcher();
+ private static final Matcher STRING_MATCHER = new WildcardStringMatcher();
//TODO - complete JavaDoc
diff --git a/core/src/main/java/com/gitplex/server/util/match/WildcardStringMatcher.java b/core/src/main/java/com/gitplex/server/util/stringmatch/WildcardStringMatcher.java
similarity index 97%
rename from core/src/main/java/com/gitplex/server/util/match/WildcardStringMatcher.java
rename to core/src/main/java/com/gitplex/server/util/stringmatch/WildcardStringMatcher.java
index d018c0ad9e..2d010b3c07 100644
--- a/core/src/main/java/com/gitplex/server/util/match/WildcardStringMatcher.java
+++ b/core/src/main/java/com/gitplex/server/util/stringmatch/WildcardStringMatcher.java
@@ -1,6 +1,6 @@
-package com.gitplex.server.util.match;
+package com.gitplex.server.util.stringmatch;
-public class WildcardStringMatcher implements PatternMatcher {
+public class WildcardStringMatcher implements Matcher {
@Override
public boolean matches(String pattern, String str) {
diff --git a/core/src/main/java/com/gitplex/server/util/match/WildcardUtils.java b/core/src/main/java/com/gitplex/server/util/stringmatch/WildcardUtils.java
similarity index 96%
rename from core/src/main/java/com/gitplex/server/util/match/WildcardUtils.java
rename to core/src/main/java/com/gitplex/server/util/stringmatch/WildcardUtils.java
index 67ce041c96..6c9e5dbd2a 100644
--- a/core/src/main/java/com/gitplex/server/util/match/WildcardUtils.java
+++ b/core/src/main/java/com/gitplex/server/util/stringmatch/WildcardUtils.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.util.match;
+package com.gitplex.server.util.stringmatch;
import java.util.ArrayList;
import java.util.List;
@@ -9,9 +9,9 @@ import com.gitplex.jsymbol.Range;
public class WildcardUtils {
- private static final PatternMatcher PATH_MATCHER = new WildcardPathMatcher();
+ private static final Matcher PATH_MATCHER = new WildcardPathMatcher();
- private static final PatternMatcher STRING_MATCHER = new WildcardStringMatcher();
+ private static final Matcher STRING_MATCHER = new WildcardStringMatcher();
/**
* Tests whether or not a given path matches a given pattern using of
diff --git a/core/src/test/java/com/gitplex/server/entity/PullRequestTest.java b/core/src/test/java/com/gitplex/server/entity/PullRequestTest.java
deleted file mode 100644
index 4d8e760b68..0000000000
--- a/core/src/test/java/com/gitplex/server/entity/PullRequestTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.gitplex.server.entity;
-
-import java.io.File;
-
-import org.eclipse.jgit.lib.Repository;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-
-import com.gitplex.launcher.loader.AppLoader;
-import com.gitplex.server.git.AbstractGitTest;
-import com.gitplex.server.manager.DepotManager;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestUpdate;
-
-public class PullRequestTest extends AbstractGitTest {
-
- private Depot depot;
-
- @Override
- public void before() {
- super.before();
-
- depot = new Depot() {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public File getDirectory() {
- return git.getRepository().getDirectory();
- }
-
- @Override
- public Repository getRepository() {
- return git.getRepository();
- }
-
- };
- DepotManager depotManager = Mockito.mock(DepotManager.class);
- Mockito.when(depotManager.load(Matchers.any())).thenReturn(depot);
- Mockito.when(AppLoader.getInstance(DepotManager.class)).thenReturn(depotManager);
- }
-
- @Test
- public void shouldReturnAllUpdatesAsEffectiveIfTheyAreFastForward() throws Exception {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("a", "", "commit");
-
- git.checkout().setName("dev").setCreateBranch(true).call();
-
- addFileAndCommit("b", "", "commit");
-
- depot.cacheObjectId("master", git.getRepository().resolve("master"));
-
- request.setBaseCommitHash(git.getRepository().resolve("master").name());
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- updateRef(update1.getHeadRef(), "HEAD", null);
- update1.setHeadCommitHash(git.getRepository().resolve(update1.getHeadRef()).name());
- request.addUpdate(update1);
-
- addFileAndCommit("c", "", "commit");
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- updateRef(update2.getHeadRef(), "HEAD", null);
- update2.setHeadCommitHash(git.getRepository().resolve(update2.getHeadRef()).name());
- request.addUpdate(update2);
-
- Assert.assertEquals(request.getEffectiveUpdates().size(), 2);
- }
-
- @Test
- public void shouldReturnLatestUpdateAsEffectiveIfAllOthersHaveBeenMerged() throws Exception {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("a", "", "master:1");
-
- git.checkout().setName("dev").setCreateBranch(true).call();
-
- addFileAndCommit("b", "", "dev:2");
-
- request.setBaseCommitHash(git.getRepository().resolve("master").name());
-
- addFileAndCommit("c", "", "dev:3");
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- updateRef(update1.getHeadRef(), "HEAD", null);
- update1.setHeadCommitHash(git.getRepository().resolve(update1.getHeadRef()).name());
- String secondRef = update1.getHeadRef();
- request.addUpdate(update1);
-
- addFileAndCommit("d", "", "dev:4");
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- updateRef(update2.getHeadRef(), "HEAD", null);
- update2.setHeadCommitHash(git.getRepository().resolve(update2.getHeadRef()).name());
- request.addUpdate(update2);
-
- git.checkout().setName("master").call();
-
- addFileAndCommit("e", "", "master:5");
-
- git.merge().include(git.getRepository().resolve(secondRef)).setCommit(true).call();
-
- depot.cacheObjectId("master", git.getRepository().resolve("master"));
-
- Assert.assertEquals(1, request.getEffectiveUpdates().size());
- Assert.assertEquals(2L, request.getEffectiveUpdates().get(0).getId().longValue());
- }
-
-}
\ No newline at end of file
diff --git a/core/src/test/java/com/gitplex/server/entity/PullRequestUpdateTest.java b/core/src/test/java/com/gitplex/server/entity/PullRequestUpdateTest.java
deleted file mode 100644
index 8f4e70c3e2..0000000000
--- a/core/src/test/java/com/gitplex/server/entity/PullRequestUpdateTest.java
+++ /dev/null
@@ -1,224 +0,0 @@
-package com.gitplex.server.entity;
-
-import java.io.File;
-
-import org.eclipse.jgit.lib.Repository;
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.gitplex.server.git.AbstractGitTest;
-import com.gitplex.server.git.GitUtils;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestUpdate;
-import com.google.common.collect.Sets;
-
-public class PullRequestUpdateTest extends AbstractGitTest {
-
- private Depot depot;
-
- @Override
- public void before() {
- super.before();
-
- depot = new Depot() {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public File getDirectory() {
- return git.getRepository().getDirectory();
- }
-
- @Override
- public Repository getRepository() {
- return git.getRepository();
- }
-
- };
-
- }
-
- @Test
- public void testResolveChangedFilesWhenThereIsNoMerge() throws Exception {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setSourceDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("a", "", "master:1");
-
- git.checkout().setCreateBranch(true).setName("dev").call();
-
- addFileAndCommit("b", "", "dev:2");
-
- addFileAndCommit("c", "", "dev:3");
-
- git.checkout().setName("master").call();
-
- addFileAndCommit("d", "", "master:4");
-
- request.setBaseCommitHash(git.getRepository().resolve("master~1").name());
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- update1.setHeadCommitHash(git.getRepository().resolve("dev~1").name());
- update1.setMergeCommitHash(request.getBaseCommitHash());
- updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null);
- request.addUpdate(update1);
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- update2.setHeadCommitHash(git.getRepository().resolve("dev").name());
- update2.setMergeCommitHash(request.getBaseCommitHash());
- updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null);
- request.addUpdate(update2);
-
- Assert.assertEquals(Sets.newHashSet("c"), update2.getChangedFiles());
- Assert.assertEquals(Sets.newHashSet("b"), update1.getChangedFiles());
- }
-
- @Test
- public void testResolveChangedFilesWhenThereIsMerge() throws Exception {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setSourceDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("1", "", "master:1");
-
- addFileAndCommit("2", "", "master:2");
-
- git.checkout().setStartPoint("master~1").setName("dev").setCreateBranch(true).call();
-
- addFileAndCommit("3", "", "dev:3");
-
- git.merge().include(git.getRepository().resolve("master")).setCommit(true).call();
-
- addFileAndCommit("4", "", "dev:4");
-
- Repository repository = depot.getRepository();
- request.setBaseCommitHash(GitUtils.getMergeBase(repository, repository.resolve("dev~2"), repository.resolve("master")).name());
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- update1.setHeadCommitHash(git.getRepository().resolve("dev~2").name());
- update1.setMergeCommitHash(request.getBaseCommitHash());
- updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null);
- request.addUpdate(update1);
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- update2.setHeadCommitHash(git.getRepository().resolve("dev").name());
- update2.setMergeCommitHash(git.getRepository().resolve("master").name());
- updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null);
- request.addUpdate(update2);
-
- Assert.assertEquals(Sets.newHashSet("4"), update2.getChangedFiles());
- }
-
- @Test
- public void testGetCommitsWhenTargetBranchIsMergedToSourceBranch() throws Exception {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setSourceDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("0", "", "0");
-
- git.checkout().setName("dev").setCreateBranch(true).call();
- git.checkout().setName("master").call();
-
- addFileAndCommit("m1", "", "m1");
-
- git.checkout().setName("dev").call();
-
- addFileAndCommit("d1", "", "d1");
-
- addFileAndCommit("d2", "", "d2");
-
- Repository repository = depot.getRepository();
- request.setBaseCommitHash(GitUtils.getMergeBase(repository, repository.resolve("master"), repository.resolve("dev")).name());
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- update1.setHeadCommitHash(git.getRepository().resolve("dev").name());
- update1.setMergeCommitHash(request.getBaseCommitHash());
- updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null);
- request.addUpdate(update1);
-
- git.merge().include(git.getRepository().resolve("master")).setCommit(true).setMessage("merge master to dev").call();
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- update2.setHeadCommitHash(git.getRepository().resolve("dev").name());
- update2.setMergeCommitHash(git.getRepository().resolve("master").name());
- updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null);
- request.addUpdate(update2);
-
- Assert.assertEquals(2, update1.getCommits().size());
- Assert.assertEquals("d1", update1.getCommits().get(0).getFullMessage().trim());
- Assert.assertEquals("d2", update1.getCommits().get(1).getFullMessage().trim());
-
- Assert.assertEquals(1, update2.getCommits().size());
- Assert.assertTrue(update2.getCommits().get(0).getFullMessage().startsWith("merge master to dev"));
- }
-
- @Test
- public void testGetCommitsWhenSourceBranchIsMergedToTargetBranch() throws Exception {
- PullRequest request = new PullRequest();
- request.setTargetDepot(depot);
- request.setSourceDepot(depot);
- request.setTargetBranch("master");
-
- addFileAndCommit("0", "", "0");
-
- git.checkout().setName("dev").setCreateBranch(true).call();
- git.checkout().setName("master").call();
-
- addFileAndCommit("m1", "", "m1");
-
- git.checkout().setName("dev").call();
-
- addFileAndCommit("d1", "", "d1");
-
- request.setBaseCommitHash(git.getRepository().resolve("master~1").name());
-
- PullRequestUpdate update1 = new PullRequestUpdate();
- update1.setId(1L);
- update1.setRequest(request);
- update1.setHeadCommitHash(git.getRepository().resolve("dev").name());
- update1.setMergeCommitHash(request.getBaseCommitHash());
- request.addUpdate(update1);
-
- addFileAndCommit("d2", "", "d2");
-
- git.checkout().setName("master").call();
- git.merge().include(git.getRepository().resolve("dev")).setCommit(true).call();
-
- git.checkout().setName("dev").call();
-
- addFileAndCommit("d3", "", "d3");
-
- updateRef(update1.getHeadRef(), update1.getHeadCommitHash(), null);
-
- PullRequestUpdate update2 = new PullRequestUpdate();
- update2.setId(2L);
- update2.setRequest(request);
- update2.setHeadCommitHash(git.getRepository().resolve("dev").name());
- update2.setMergeCommitHash(git.getRepository().resolve("dev~1").name());
- updateRef(update2.getHeadRef(), update2.getHeadCommitHash(), null);
-
- request.addUpdate(update2);
-
- Assert.assertEquals(1, update2.getCommits().size());
- Assert.assertEquals("d3", update2.getCommits().get(0).getFullMessage().trim());
- }
-
-}
\ No newline at end of file
diff --git a/core/src/test/java/com/gitplex/server/util/pattern/WildcardUtilsTest.java b/core/src/test/java/com/gitplex/server/util/pattern/WildcardUtilsTest.java
index cd9ed462c6..dccb6c7d4c 100644
--- a/core/src/test/java/com/gitplex/server/util/pattern/WildcardUtilsTest.java
+++ b/core/src/test/java/com/gitplex/server/util/pattern/WildcardUtilsTest.java
@@ -1,6 +1,6 @@
package com.gitplex.server.util.pattern;
-import static com.gitplex.server.util.match.WildcardUtils.*;
+import static com.gitplex.server.util.stringmatch.WildcardUtils.*;
import static org.junit.Assert.*;
import org.junit.Test;
diff --git a/product/system/site/avatars/gitplex.png b/product/system/site/avatars/gitplex.png
new file mode 100644
index 0000000000..2876c5b4c2
Binary files /dev/null and b/product/system/site/avatars/gitplex.png differ
diff --git a/rest/src/main/java/com/gitplex/server/rest/PullRequestResource.java b/rest/src/main/java/com/gitplex/server/rest/PullRequestResource.java
index 604a5605b0..304e26fdf1 100644
--- a/rest/src/main/java/com/gitplex/server/rest/PullRequestResource.java
+++ b/rest/src/main/java/com/gitplex/server/rest/PullRequestResource.java
@@ -57,8 +57,7 @@ public class PullRequestResource {
@QueryParam("targetDepotId") Long targetDepotId, @QueryParam("targetBranch") String targetBranch,
@QueryParam("sourceDepotId") Long sourceDepotId, @QueryParam("sourceBranch") String sourceBranch,
@QueryParam("submitterId") Long submitterId, @QueryParam("status") String status,
- @QueryParam("assigneeId") Long assigneeId, @QueryParam("beginDate") Date beginDate,
- @QueryParam("endDate") Date endDate) {
+ @QueryParam("beginDate") Date beginDate, @QueryParam("endDate") Date endDate) {
EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
@@ -79,8 +78,6 @@ public class PullRequestResource {
if (submitterId != null)
criteria.add(Restrictions.eq("submitter.id", submitterId));
- if (assigneeId != null)
- criteria.add(Restrictions.eq("assignee.id", assigneeId));
if (beginDate != null)
criteria.add(Restrictions.ge("submitDate", beginDate));
if (endDate != null)
diff --git a/rest/src/main/java/com/gitplex/server/rest/PullRequestVerificationResource.java b/rest/src/main/java/com/gitplex/server/rest/PullRequestVerificationResource.java
deleted file mode 100644
index 674215c213..0000000000
--- a/rest/src/main/java/com/gitplex/server/rest/PullRequestVerificationResource.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package com.gitplex.server.rest;
-
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import javax.validation.Valid;
-import javax.validation.constraints.NotNull;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.shiro.authz.UnauthorizedException;
-import org.hibernate.criterion.Restrictions;
-
-import com.gitplex.server.manager.AccountManager;
-import com.gitplex.server.manager.PullRequestVerificationManager;
-import com.gitplex.server.model.PullRequestVerification;
-import com.gitplex.server.persistence.dao.Dao;
-import com.gitplex.server.persistence.dao.EntityCriteria;
-import com.gitplex.server.rest.jersey.ValidQueryParams;
-import com.gitplex.server.security.SecurityUtils;
-
-@Path("/pull_request_verifications")
-@Consumes(MediaType.WILDCARD)
-@Produces(MediaType.APPLICATION_JSON)
-@Singleton
-public class PullRequestVerificationResource {
-
- private final Dao dao;
-
- private final PullRequestVerificationManager verificationManager;
-
- private final AccountManager accountManager;
-
- @Inject
- public PullRequestVerificationResource(Dao dao, PullRequestVerificationManager verificationManager,
- AccountManager accountManager) {
- this.dao = dao;
- this.verificationManager = verificationManager;
- this.accountManager = accountManager;
- }
-
- @GET
- @Path("/{id}")
- public PullRequestVerification get(@PathParam("id") Long id) {
- PullRequestVerification verification = dao.load(PullRequestVerification.class, id);
- if (!SecurityUtils.canRead(verification.getRequest().getTargetDepot()))
- throw new UnauthorizedException();
- return verification;
- }
-
- @ValidQueryParams
- @GET
- public Collection<PullRequestVerification> query(
- @QueryParam("requestId") Long requestId,
- @QueryParam("configuration") String configuration,
- @QueryParam("commit") String commit) {
- EntityCriteria<PullRequestVerification> criteria = EntityCriteria.of(PullRequestVerification.class);
- if (requestId != null)
- criteria.add(Restrictions.eq("request.id", requestId));
- if (configuration != null)
- criteria.add(Restrictions.eq("configuration", configuration));
- if (commit != null)
- criteria.add(Restrictions.eq("commit", commit));
-
- List<PullRequestVerification> verifications = dao.findAll(criteria);
-
- for (PullRequestVerification verification: verifications) {
- if (!SecurityUtils.canRead(verification.getRequest().getTargetDepot())) {
- throw new UnauthorizedException("Unauthorized access to verification "
- + verification.getRequest() + "/" + verification.getId());
- }
- }
-
- return verifications;
- }
-
- @DELETE
- @Path("/{id}")
- public void delete(@PathParam("id") Long id) {
- PullRequestVerification verification = dao.load(PullRequestVerification.class, id);
- if (!SecurityUtils.canWrite(verification.getRequest().getTargetDepot()))
- throw new UnauthorizedException();
-
- verificationManager.delete(verification);
- }
-
- @POST
- public Long save(@NotNull @Valid PullRequestVerification verification) {
- if (!SecurityUtils.canWrite(verification.getRequest().getTargetDepot()))
- throw new UnauthorizedException();
-
- verification.setDate(new Date());
- verification.setUser(accountManager.getCurrent());
- verificationManager.save(verification);
-
- return verification.getId();
- }
-
-}
diff --git a/search/src/main/java/com/gitplex/server/search/query/FileQuery.java b/search/src/main/java/com/gitplex/server/search/query/FileQuery.java
index bed482c91a..a2b7205c9d 100644
--- a/search/src/main/java/com/gitplex/server/search/query/FileQuery.java
+++ b/search/src/main/java/com/gitplex/server/search/query/FileQuery.java
@@ -16,7 +16,7 @@ import org.eclipse.jgit.treewalk.TreeWalk;
import com.gitplex.jsymbol.Range;
import com.gitplex.server.search.hit.FileHit;
import com.gitplex.server.search.hit.QueryHit;
-import com.gitplex.server.util.match.WildcardUtils;
+import com.gitplex.server.util.stringmatch.WildcardUtils;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
diff --git a/search/src/main/java/com/gitplex/server/search/query/SymbolQuery.java b/search/src/main/java/com/gitplex/server/search/query/SymbolQuery.java
index 036c0153ce..5a413c89e7 100644
--- a/search/src/main/java/com/gitplex/server/search/query/SymbolQuery.java
+++ b/search/src/main/java/com/gitplex/server/search/query/SymbolQuery.java
@@ -22,7 +22,7 @@ import com.gitplex.server.GitPlex;
import com.gitplex.server.search.SearchManager;
import com.gitplex.server.search.hit.QueryHit;
import com.gitplex.server.search.hit.SymbolHit;
-import com.gitplex.server.util.match.WildcardUtils;
+import com.gitplex.server.util.stringmatch.WildcardUtils;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
diff --git a/web/src/main/java/com/gitplex/server/web/UrlMapper.java b/web/src/main/java/com/gitplex/server/web/UrlMapper.java
index e7d20cfc0a..78b5704dbb 100644
--- a/web/src/main/java/com/gitplex/server/web/UrlMapper.java
+++ b/web/src/main/java/com/gitplex/server/web/UrlMapper.java
@@ -47,16 +47,16 @@ import com.gitplex.server.web.page.depot.compare.RevisionComparePage;
import com.gitplex.server.web.page.depot.pullrequest.newrequest.NewRequestPage;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.codecomments.RequestCodeCommentsPage;
-import com.gitplex.server.web.page.depot.pullrequest.requestdetail.integrationpreview.IntegrationPreviewPage;
+import com.gitplex.server.web.page.depot.pullrequest.requestdetail.mergepreview.MergePreviewPage;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
import com.gitplex.server.web.page.depot.pullrequest.requestlist.RequestListPage;
import com.gitplex.server.web.page.depot.setting.authorization.DepotCollaboratorListPage;
import com.gitplex.server.web.page.depot.setting.authorization.DepotEffectivePrivilegePage;
-import com.gitplex.server.web.page.depot.setting.authorization.DepotTeamListPage;
+import com.gitplex.server.web.page.depot.setting.authorization.DepotTeamAuthorizationPage;
+import com.gitplex.server.web.page.depot.setting.branchprotection.BranchProtectionPage;
import com.gitplex.server.web.page.depot.setting.commitmessagetransform.CommitMessageTransformPage;
-import com.gitplex.server.web.page.depot.setting.gatekeeper.GateKeeperPage;
import com.gitplex.server.web.page.depot.setting.general.GeneralSettingPage;
-import com.gitplex.server.web.page.depot.setting.integrationpolicy.IntegrationPolicyPage;
+import com.gitplex.server.web.page.depot.setting.tagprotection.TagProtectionPage;
import com.gitplex.server.web.page.depot.tags.DepotTagsPage;
import com.gitplex.server.web.page.init.ServerInitPage;
import com.gitplex.server.web.page.init.WelcomePage;
@@ -206,16 +206,16 @@ public class UrlMapper extends CompoundRequestMapper {
add(new DepotMapper(
"${account}/${depot}/pulls/${request}/changes", RequestChangesPage.class));
add(new DepotMapper(
- "${account}/${depot}/pulls/${request}/integration-preview", IntegrationPreviewPage.class));
+ "${account}/${depot}/pulls/${request}/merge-preview", MergePreviewPage.class));
add(new DepotMapper("${account}/${depot}/comments", DepotCommentsPage.class));
add(new DepotMapper("${account}/${depot}/comments/${comment}", CodeCommentPage.class));
add(new DepotMapper("${account}/${depot}/settings/general", GeneralSettingPage.class));
- add(new DepotMapper("${account}/${depot}/settings/teams", DepotTeamListPage.class));
+ add(new DepotMapper("${account}/${depot}/settings/team-authorization", DepotTeamAuthorizationPage.class));
add(new DepotMapper("${account}/${depot}/settings/collaborators", DepotCollaboratorListPage.class));
add(new DepotMapper("${account}/${depot}/settings/effective-privilege", DepotEffectivePrivilegePage.class));
- add(new DepotMapper("${account}/${depot}/settings/gate-keeper", GateKeeperPage.class));
- add(new DepotMapper("${account}/${depot}/settings/integration-policy", IntegrationPolicyPage.class));
+ add(new DepotMapper("${account}/${depot}/settings/branch-protection", BranchProtectionPage.class));
+ add(new DepotMapper("${account}/${depot}/settings/tag-protection", TagProtectionPage.class));
add(new DepotMapper("${account}/${depot}/settings/commit-message-transform", CommitMessageTransformPage.class));
add(new DepotMapper("${account}/${depot}/no-branches", NoBranchesPage.class));
diff --git a/web/src/main/java/com/gitplex/server/web/assets/image/add.png b/web/src/main/java/com/gitplex/server/web/assets/image/add.png
deleted file mode 100644
index defca4e6e5..0000000000
Binary files a/web/src/main/java/com/gitplex/server/web/assets/image/add.png and /dev/null differ
diff --git a/web/src/main/java/com/gitplex/server/web/assets/image/delete.png b/web/src/main/java/com/gitplex/server/web/assets/image/delete.png
deleted file mode 100644
index 90afb42931..0000000000
Binary files a/web/src/main/java/com/gitplex/server/web/assets/image/delete.png and /dev/null differ
diff --git a/web/src/main/java/com/gitplex/server/web/assets/image/error.png b/web/src/main/java/com/gitplex/server/web/assets/image/error.png
deleted file mode 100644
index dbfda22975..0000000000
Binary files a/web/src/main/java/com/gitplex/server/web/assets/image/error.png and /dev/null differ
diff --git a/web/src/main/java/com/gitplex/server/web/assets/image/move.png b/web/src/main/java/com/gitplex/server/web/assets/image/move.png
deleted file mode 100644
index 7c22d21be2..0000000000
Binary files a/web/src/main/java/com/gitplex/server/web/assets/image/move.png and /dev/null differ
diff --git a/web/src/main/java/com/gitplex/server/web/behavior/BranchPatternAssistBehavior.java b/web/src/main/java/com/gitplex/server/web/behavior/BranchPatternAssistBehavior.java
new file mode 100644
index 0000000000..b651a5df70
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/behavior/BranchPatternAssistBehavior.java
@@ -0,0 +1,68 @@
+package com.gitplex.server.web.behavior;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.model.IModel;
+
+import com.gitplex.codeassist.InputCompletion;
+import com.gitplex.codeassist.InputStatus;
+import com.gitplex.codeassist.InputSuggestion;
+import com.gitplex.jsymbol.Range;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.web.behavior.inputassist.InputAssistBehavior;
+import com.gitplex.server.web.util.SuggestionUtils;
+import com.google.common.collect.Lists;
+
+@SuppressWarnings("serial")
+public class BranchPatternAssistBehavior extends InputAssistBehavior {
+
+ private final IModel<Depot> depotModel;
+
+ public BranchPatternAssistBehavior(IModel<Depot> depotModel) {
+ this.depotModel = depotModel;
+ }
+
+ @Override
+ public void detach(Component component) {
+ super.detach(component);
+ depotModel.detach();
+ }
+
+ @Override
+ protected List<InputCompletion> getSuggestions(InputStatus inputStatus, int count) {
+ List<InputCompletion> completions = new ArrayList<>();
+ for (InputSuggestion suggestion: SuggestionUtils.suggestBranch(depotModel.getObject(),
+ inputStatus.getContentBeforeCaret().trim(), count)) {
+ int caret = suggestion.getCaret();
+ if (caret == -1)
+ caret = suggestion.getContent().length();
+ InputCompletion completion = new InputCompletion(0, inputStatus.getContent().length(),
+ suggestion.getContent(), caret, suggestion.getLabel(),
+ null, suggestion.getMatchRange());
+ completions.add(completion);
+ }
+ return completions;
+ }
+
+ @Override
+ protected List<String> getHints(InputStatus inputStatus) {
+ return Lists.newArrayList("Use * to match any part of the branch");
+ }
+
+ @Override
+ protected List<Range> getErrors(String inputContent) {
+ return null;
+ }
+
+ @Override
+ protected int getAnchor(String content) {
+ for (int i=0; i<content.length(); i++) {
+ if (!Character.isWhitespace(content.charAt(i)))
+ return i;
+ }
+ return content.length();
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/behavior/PathPatternAssistBehavior.java b/web/src/main/java/com/gitplex/server/web/behavior/PathPatternAssistBehavior.java
new file mode 100644
index 0000000000..8af7369b11
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/behavior/PathPatternAssistBehavior.java
@@ -0,0 +1,68 @@
+package com.gitplex.server.web.behavior;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.model.IModel;
+
+import com.gitplex.codeassist.InputCompletion;
+import com.gitplex.codeassist.InputStatus;
+import com.gitplex.codeassist.InputSuggestion;
+import com.gitplex.jsymbol.Range;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.web.behavior.inputassist.InputAssistBehavior;
+import com.gitplex.server.web.util.SuggestionUtils;
+import com.google.common.collect.Lists;
+
+@SuppressWarnings("serial")
+public class PathPatternAssistBehavior extends InputAssistBehavior {
+
+ private final IModel<Depot> depotModel;
+
+ public PathPatternAssistBehavior(IModel<Depot> depotModel) {
+ this.depotModel = depotModel;
+ }
+
+ @Override
+ public void detach(Component component) {
+ super.detach(component);
+ depotModel.detach();
+ }
+
+ @Override
+ protected List<InputCompletion> getSuggestions(InputStatus inputStatus, int count) {
+ List<InputCompletion> completions = new ArrayList<>();
+ for (InputSuggestion suggestion: SuggestionUtils.suggestPath(depotModel.getObject(),
+ inputStatus.getContentBeforeCaret().trim(), count)) {
+ int caret = suggestion.getCaret();
+ if (caret == -1)
+ caret = suggestion.getContent().length();
+ InputCompletion completion = new InputCompletion(0, inputStatus.getContent().length(),
+ suggestion.getContent(), caret, suggestion.getLabel(),
+ null, suggestion.getMatchRange());
+ completions.add(completion);
+ }
+ return completions;
+ }
+
+ @Override
+ protected List<String> getHints(InputStatus inputStatus) {
+ return Lists.newArrayList("Use * to match any part of the path");
+ }
+
+ @Override
+ protected List<Range> getErrors(String inputContent) {
+ return null;
+ }
+
+ @Override
+ protected int getAnchor(String content) {
+ for (int i=0; i<content.length(); i++) {
+ if (!Character.isWhitespace(content.charAt(i)))
+ return i;
+ }
+ return content.length();
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/behavior/TagPatternAssistBehavior.java b/web/src/main/java/com/gitplex/server/web/behavior/TagPatternAssistBehavior.java
new file mode 100644
index 0000000000..2d86e44ca5
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/behavior/TagPatternAssistBehavior.java
@@ -0,0 +1,68 @@
+package com.gitplex.server.web.behavior;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.model.IModel;
+
+import com.gitplex.codeassist.InputCompletion;
+import com.gitplex.codeassist.InputStatus;
+import com.gitplex.codeassist.InputSuggestion;
+import com.gitplex.jsymbol.Range;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.web.behavior.inputassist.InputAssistBehavior;
+import com.gitplex.server.web.util.SuggestionUtils;
+import com.google.common.collect.Lists;
+
+@SuppressWarnings("serial")
+public class TagPatternAssistBehavior extends InputAssistBehavior {
+
+ private final IModel<Depot> depotModel;
+
+ public TagPatternAssistBehavior(IModel<Depot> depotModel) {
+ this.depotModel = depotModel;
+ }
+
+ @Override
+ public void detach(Component component) {
+ super.detach(component);
+ depotModel.detach();
+ }
+
+ @Override
+ protected List<InputCompletion> getSuggestions(InputStatus inputStatus, int count) {
+ List<InputCompletion> completions = new ArrayList<>();
+ for (InputSuggestion suggestion: SuggestionUtils.suggestTag(depotModel.getObject(),
+ inputStatus.getContentBeforeCaret().trim(), count)) {
+ int caret = suggestion.getCaret();
+ if (caret == -1)
+ caret = suggestion.getContent().length();
+ InputCompletion completion = new InputCompletion(0, inputStatus.getContent().length(),
+ suggestion.getContent(), caret, suggestion.getLabel(),
+ null, suggestion.getMatchRange());
+ completions.add(completion);
+ }
+ return completions;
+ }
+
+ @Override
+ protected List<String> getHints(InputStatus inputStatus) {
+ return Lists.newArrayList("Use * to match any part of the tag");
+ }
+
+ @Override
+ protected List<Range> getErrors(String inputContent) {
+ return null;
+ }
+
+ @Override
+ protected int getAnchor(String content) {
+ for (int i=0; i<content.length(); i++) {
+ if (!Character.isWhitespace(content.charAt(i)))
+ return i;
+ }
+ return content.length();
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/component/accountchoice/AccountChoiceProvider.java b/web/src/main/java/com/gitplex/server/web/component/accountchoice/AccountChoiceProvider.java
index 22deb5aa63..1b7d835222 100644
--- a/web/src/main/java/com/gitplex/server/web/component/accountchoice/AccountChoiceProvider.java
+++ b/web/src/main/java/com/gitplex/server/web/component/accountchoice/AccountChoiceProvider.java
@@ -1,5 +1,7 @@
package com.gitplex.server.web.component.accountchoice;
+import java.util.ArrayList;
+import java.util.Comparator;
import java.util.List;
import org.hibernate.criterion.Criterion;
@@ -9,39 +11,61 @@ import org.hibernate.criterion.Restrictions;
import com.gitplex.server.GitPlex;
import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
import com.gitplex.server.persistence.dao.Dao;
import com.gitplex.server.persistence.dao.EntityCriteria;
+import com.gitplex.server.security.SecurityUtils;
+import com.gitplex.server.security.privilege.DepotPrivilege;
+import com.gitplex.server.util.editable.annotation.AccountChoice;
import com.gitplex.server.web.WebConstants;
import com.gitplex.server.web.component.select2.Response;
+import com.gitplex.server.web.component.select2.ResponseFiller;
+import com.gitplex.server.web.page.depot.DepotPage;
+import com.gitplex.server.web.util.WicketUtils;
public class AccountChoiceProvider extends AbstractAccountChoiceProvider {
private static final long serialVersionUID = 1L;
- private final boolean organization;
+ private final AccountChoice.Type type;
- public AccountChoiceProvider(boolean organization) {
- this.organization = organization;
+ public AccountChoiceProvider(AccountChoice.Type type) {
+ this.type = type;
}
@Override
public void query(String term, int page, Response<Account> response) {
- Dao dao = GitPlex.getInstance(Dao.class);
- int first = page * WebConstants.DEFAULT_PAGE_SIZE;
- Criterion criterion = Restrictions.and(Restrictions.or(
- Restrictions.ilike("name", term, MatchMode.ANYWHERE),
- Restrictions.ilike("fullName", term, MatchMode.ANYWHERE)));
- EntityCriteria<Account> criteria = EntityCriteria.of(Account.class);
- criteria.add(criterion);
- criteria.add(Restrictions.eq("organization", organization));
- criteria.addOrder(Order.asc("name"));
- List<Account> accounts = dao.findRange(criteria, first, WebConstants.DEFAULT_PAGE_SIZE + 1);
+ if (type == AccountChoice.Type.ORGANIZATION || type == AccountChoice.Type.USER) {
+ Dao dao = GitPlex.getInstance(Dao.class);
+ int first = page * WebConstants.DEFAULT_PAGE_SIZE;
+ Criterion criterion = Restrictions.and(Restrictions.or(
+ Restrictions.ilike("name", term, MatchMode.ANYWHERE),
+ Restrictions.ilike("fullName", term, MatchMode.ANYWHERE)));
+ EntityCriteria<Account> criteria = EntityCriteria.of(Account.class);
+ criteria.add(criterion);
+ criteria.add(Restrictions.eq("organization", type == AccountChoice.Type.ORGANIZATION));
+ criteria.addOrder(Order.asc("name"));
+ List<Account> accounts = dao.findRange(criteria, first, WebConstants.DEFAULT_PAGE_SIZE + 1);
- if (accounts.size() <= WebConstants.DEFAULT_PAGE_SIZE) {
- response.addAll(accounts);
+ if (accounts.size() <= WebConstants.DEFAULT_PAGE_SIZE) {
+ response.addAll(accounts);
+ } else {
+ response.addAll(accounts.subList(0, WebConstants.DEFAULT_PAGE_SIZE));
+ response.setHasMore(true);
+ }
} else {
- response.addAll(accounts.subList(0, WebConstants.DEFAULT_PAGE_SIZE));
- response.setHasMore(true);
+ Depot depot = ((DepotPage) WicketUtils.getPage()).getDepot();
+ List<Account> choices;
+ if (type == AccountChoice.Type.DEPOT_READER)
+ choices = new ArrayList<Account>(SecurityUtils.findUsersCan(depot, DepotPrivilege.READ));
+ else if (type == AccountChoice.Type.DEPOT_WRITER)
+ choices = new ArrayList<Account>(SecurityUtils.findUsersCan(depot, DepotPrivilege.WRITE));
+ else
+ choices = new ArrayList<Account>(SecurityUtils.findUsersCan(depot, DepotPrivilege.ADMIN));
+
+ choices.sort(Comparator.comparing(Account::getName));
+
+ new ResponseFiller<Account>(response).fill(choices, page, WebConstants.DEFAULT_PAGE_SIZE);
}
}
diff --git a/web/src/main/java/com/gitplex/server/web/component/avatar/Avatar.java b/web/src/main/java/com/gitplex/server/web/component/avatar/Avatar.java
index c9e43e664c..59f0722ed5 100644
--- a/web/src/main/java/com/gitplex/server/web/component/avatar/Avatar.java
+++ b/web/src/main/java/com/gitplex/server/web/component/avatar/Avatar.java
@@ -7,17 +7,13 @@ import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebComponent;
-import org.apache.wicket.model.Model;
import org.eclipse.jgit.lib.PersonIdent;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.model.Account;
-import com.gitplex.server.web.behavior.TooltipBehavior;
import com.gitplex.server.web.util.avatar.AvatarManager;
-import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
-
@SuppressWarnings("serial")
public class Avatar extends WebComponent {
@@ -25,35 +21,21 @@ public class Avatar extends WebComponent {
private String url;
- private final String name;
-
- private final TooltipConfig tooltipConfig;
-
public Avatar(String id, @Nullable Account account) {
- this(id, account, null);
- }
-
- public Avatar(String id, @Nullable Account account, @Nullable TooltipConfig tooltipConfig) {
super(id);
AvatarManager avatarManager = GitPlex.getInstance(AvatarManager.class);
- if (account != null) {
- accountId = account.getId();
- url = avatarManager.getAvatarUrl(account);
- name = account.getDisplayName();
- } else {
+ if (account == null) {
accountId = null;
- url = avatarManager.getAvatarUrl(account);
- name = "Unknown";
+ } else if (account.getId() == null) {
+ accountId = null;
+ } else {
+ accountId = account.getId();
}
- this.tooltipConfig = tooltipConfig;
+ url = avatarManager.getAvatarUrl(account);
}
public Avatar(String id, PersonIdent person) {
- this(id, person, null);
- }
-
- public Avatar(String id, PersonIdent person, @Nullable TooltipConfig tooltipConfig) {
super(id);
AvatarManager avatarManager = GitPlex.getInstance(AvatarManager.class);
@@ -62,13 +44,10 @@ public class Avatar extends WebComponent {
if (account != null) {
accountId = account.getId();
url = avatarManager.getAvatarUrl(account);
- name = account.getDisplayName();
} else {
accountId = null;
url = avatarManager.getAvatarUrl(person);
- name = person.getName();
}
- this.tooltipConfig = tooltipConfig;
}
@Override
@@ -88,10 +67,6 @@ public class Avatar extends WebComponent {
@Override
protected void onInitialize() {
super.onInitialize();
-
- if (tooltipConfig != null)
- add(new TooltipBehavior(Model.of(name), tooltipConfig));
-
setOutputMarkupId(true);
}
diff --git a/web/src/main/java/com/gitplex/server/web/component/avatar/AvatarChanged.java b/web/src/main/java/com/gitplex/server/web/component/avatar/AvatarChanged.java
index a060ce6277..42254043ef 100644
--- a/web/src/main/java/com/gitplex/server/web/component/avatar/AvatarChanged.java
+++ b/web/src/main/java/com/gitplex/server/web/component/avatar/AvatarChanged.java
@@ -3,9 +3,9 @@ package com.gitplex.server.web.component.avatar;
import org.apache.wicket.ajax.AjaxRequestTarget;
import com.gitplex.server.model.Account;
-import com.gitplex.server.web.util.AjaxEvent;
+import com.gitplex.server.web.util.AjaxPayload;
-public class AvatarChanged extends AjaxEvent {
+public class AvatarChanged extends AjaxPayload {
private final Account account;
diff --git a/web/src/main/java/com/gitplex/server/web/component/avatar/AvatarLink.java b/web/src/main/java/com/gitplex/server/web/component/avatar/AvatarLink.java
index 87d01498c0..b63c11de62 100644
--- a/web/src/main/java/com/gitplex/server/web/component/avatar/AvatarLink.java
+++ b/web/src/main/java/com/gitplex/server/web/component/avatar/AvatarLink.java
@@ -29,32 +29,44 @@ public class AvatarLink extends ViewStateAwarePageLink<Void> {
private final PageParameters params;
- private String url;
-
- private final String name;
+ private final String tooltip;
- private final TooltipConfig tooltipConfig;
+ private String url;
- public AvatarLink(String id, Account user) {
- this(id, user, null);
+ public AvatarLink(String id, @Nullable Account account) {
+ this(id, account, false);
}
- public AvatarLink(String id, Account account, @Nullable TooltipConfig tooltipConfig) {
+ public AvatarLink(String id, @Nullable Account account, boolean showTooltip) {
super(id, AccountOverviewPage.class);
AvatarManager avatarManager = GitPlex.getInstance(AvatarManager.class);
- accountId = account.getId();
- params = AccountPage.paramsOf(account);
- name = account.getDisplayName();
+ if (account == null) {
+ accountId = null;
+ params = new PageParameters();
+ } else if (account.getId() == null) {
+ accountId = null;
+ params = new PageParameters();
+ } else {
+ accountId = account.getId();
+ params = AccountPage.paramsOf(account);
+ }
+ if (showTooltip) {
+ if (account != null)
+ tooltip = account.getDisplayName();
+ else
+ tooltip = GitPlex.NAME;
+ } else {
+ tooltip = null;
+ }
url = avatarManager.getAvatarUrl(account);
- this.tooltipConfig = tooltipConfig;
}
public AvatarLink(String id, PersonIdent person) {
- this(id, person, null);
+ this(id, person, false);
}
- public AvatarLink(String id, PersonIdent person, @Nullable TooltipConfig tooltipConfig) {
+ public AvatarLink(String id, PersonIdent person, boolean showTooltip) {
super(id, AccountOverviewPage.class);
AvatarManager avatarManager = GitPlex.getInstance(AvatarManager.class);
@@ -64,14 +76,16 @@ public class AvatarLink extends ViewStateAwarePageLink<Void> {
accountId = account.getId();
params = AccountPage.paramsOf(account);
url = avatarManager.getAvatarUrl(account);
- name = account.getDisplayName();
} else {
accountId = null;
params = new PageParameters();
url = avatarManager.getAvatarUrl(person);
- name = person.getName();
}
- this.tooltipConfig = tooltipConfig;
+
+ if (showTooltip)
+ tooltip = person.getName();
+ else
+ tooltip = null;
}
@Override
@@ -119,8 +133,8 @@ public class AvatarLink extends ViewStateAwarePageLink<Void> {
setEnabled(!params.isEmpty());
setEscapeModelStrings(false);
- if (tooltipConfig != null)
- add(new TooltipBehavior(Model.of(name), tooltipConfig));
+ if (tooltip != null)
+ add(new TooltipBehavior(Model.of(tooltip), new TooltipConfig()));
setOutputMarkupId(true);
}
diff --git a/web/src/main/java/com/gitplex/server/web/component/avatar/ContributorAvatars.java b/web/src/main/java/com/gitplex/server/web/component/avatar/ContributorAvatars.java
index be8488849b..9b801b49c7 100644
--- a/web/src/main/java/com/gitplex/server/web/component/avatar/ContributorAvatars.java
+++ b/web/src/main/java/com/gitplex/server/web/component/avatar/ContributorAvatars.java
@@ -1,46 +1,34 @@
package com.gitplex.server.web.component.avatar;
-import javax.annotation.Nullable;
-
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;
import org.eclipse.jgit.lib.PersonIdent;
-import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
-
@SuppressWarnings("serial")
public class ContributorAvatars extends Panel {
private final PersonIdent author;
private final PersonIdent committer;
-
- private final TooltipConfig tooltipConfig;
public ContributorAvatars(String id, PersonIdent author, PersonIdent committer) {
- this(id, author, committer, null);
- }
-
- public ContributorAvatars(String id, PersonIdent author, PersonIdent committer,
- @Nullable TooltipConfig tooltipConfig) {
super(id);
this.author = author;
this.committer = committer;
- this.tooltipConfig = tooltipConfig;
}
@Override
protected void onInitialize() {
super.onInitialize();
- add(new AvatarLink("author", author, tooltipConfig));
+ add(new AvatarLink("author", author));
if (committer.getEmailAddress().equals(author.getEmailAddress())
&& committer.getName().equals(author.getName())) {
add(new WebMarkupContainer("committer").setVisible(false));
} else {
- add(new AvatarLink("committer", committer, tooltipConfig));
+ add(new AvatarLink("committer", committer));
}
}
diff --git a/web/src/main/java/com/gitplex/server/web/component/avatar/RemoveableAvatar.html b/web/src/main/java/com/gitplex/server/web/component/avatar/RemoveableAvatar.html
deleted file mode 100644
index 8efe0e22e2..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/avatar/RemoveableAvatar.html
+++ /dev/null
@@ -1,3 +0,0 @@
-<wicket:panel>
- <a wicket:id="remove" data-html="true" class="removeable-avatar"><img wicket:id="avatar"></img><i class="fa fa-times"></i></a>
-</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/component/avatar/RemoveableAvatar.java b/web/src/main/java/com/gitplex/server/web/component/avatar/RemoveableAvatar.java
deleted file mode 100644
index 234510833e..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/avatar/RemoveableAvatar.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package com.gitplex.server.web.component.avatar;
-
-import org.apache.commons.lang3.StringEscapeUtils;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.head.CssHeaderItem;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.web.behavior.TooltipBehavior;
-import com.gitplex.server.web.util.avatar.AvatarManager;
-
-@SuppressWarnings("serial")
-public abstract class RemoveableAvatar extends AjaxLink<Account> {
-
- public RemoveableAvatar(String id, IModel<Account> model) {
- super(id, model);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- configure();
-
- Account user = getModelObject();
- String tooltip;
- // Force nowrap here when display tooltip as otherwise user name will be wrapped inside
- // an element with position set to relative
- if (isEnabled()) {
- tooltip = "Remove reviewer " + user.getDisplayName();
- } else {
- tooltip = user.getDisplayName();
- }
- add(new TooltipBehavior(Model.of("<span style='white-space: nowrap;'>"
- + StringEscapeUtils.escapeHtml4(tooltip) + "</span>")));
- add(AttributeAppender.append("class", "removeable-avatar"));
- add(AttributeAppender.append("data-html", "true"));
-
- setEscapeModelStrings(false);
- }
-
- @Override
- public IModel<?> getBody() {
- String url = GitPlex.getInstance(AvatarManager.class).getAvatarUrl(getModelObject());
- return Model.of("<img src='" + url + "' class='avatar'></img> <i class='fa fa-times'></i>");
- }
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
- if (!isEnabled())
- tag.setName("span");
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(CssHeaderItem.forReference(new AvatarResourceReference()));
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/avatar/avatar.css b/web/src/main/java/com/gitplex/server/web/component/avatar/avatar.css
index e6c2859002..386a77e24b 100644
--- a/web/src/main/java/com/gitplex/server/web/component/avatar/avatar.css
+++ b/web/src/main/java/com/gitplex/server/web/component/avatar/avatar.css
@@ -17,23 +17,3 @@ img.avatar {
left: 22px;
top: 13px;
}
-
-.removeable-avatar {
- position: relative;
- display: block;
-}
-.removeable-avatar img {
- width: 32px !important;
- height: 32px !important;
-}
-.removeable-avatar i {
- display: none;
- color: red;
- font-size: 30px;
- position: absolute;
- left: 4px;
- top: 1px;
-}
-a.removeable-avatar:hover i {
- display: inline;
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/branchmatch/BranchMatchBehavior.java b/web/src/main/java/com/gitplex/server/web/component/branchmatch/BranchMatchBehavior.java
deleted file mode 100644
index 9f276be0f5..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/branchmatch/BranchMatchBehavior.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.gitplex.server.web.component.branchmatch;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.model.IModel;
-
-import com.gitplex.codeassist.FenceAware;
-import com.gitplex.codeassist.InputSuggestion;
-import com.gitplex.codeassist.ParentedElement;
-import com.gitplex.codeassist.grammar.ElementSpec;
-import com.gitplex.codeassist.grammar.LexerRuleRefElementSpec;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.includeexclude.IncludeExcludeParser;
-import com.gitplex.server.web.behavior.inputassist.ANTLRAssistBehavior;
-import com.gitplex.server.web.util.SuggestionUtils;
-
-@SuppressWarnings("serial")
-public class BranchMatchBehavior extends ANTLRAssistBehavior {
-
- private final IModel<Depot> depotModel;
-
- private static final String VALUE_OPEN = "(";
-
- private static final String VALUE_CLOSE = ")";
-
- public BranchMatchBehavior(IModel<Depot> depotModel) {
- super(IncludeExcludeParser.class, "match");
- this.depotModel = depotModel;
- }
-
- @Override
- public void detach(Component component) {
- super.detach(component);
- depotModel.detach();
- }
-
- @Override
- protected List<InputSuggestion> suggest(final ParentedElement expectedElement, String matchWith, int count) {
- if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
- LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
- if (spec.getRuleName().equals("Value")) {
- return new FenceAware(codeAssist.getGrammar(), VALUE_OPEN, VALUE_CLOSE) {
-
- @Override
- protected List<InputSuggestion> match(String unfencedMatchWith, int count) {
- return SuggestionUtils.suggestBranch(depotModel.getObject(), unfencedMatchWith, count,
- null, "any branch");
- }
-
- @Override
- protected String getFencingDescription() {
- return "value needs to be enclosed in brackets";
- }
-
- }.suggest(expectedElement.getSpec(), matchWith, count);
- }
- }
- return null;
- }
-
- @Override
- protected List<String> getHints(ParentedElement expectedElement, String matchWith) {
- List<String> hints = new ArrayList<>();
- if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
- LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
- if (spec.getRuleName().equals("Value") && !matchWith.contains(VALUE_CLOSE)) {
- hints.add("Use * to match any part of branch");
- }
- }
- return hints;
- }
-
- @Override
- protected int getEndOfMatch(ElementSpec spec, String content) {
- if (content.startsWith(VALUE_OPEN+VALUE_CLOSE))
- return 2;
- else
- return super.getEndOfMatch(spec, content);
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentFilter.java b/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentFilter.java
index 02022e81c6..0cab51f7ae 100644
--- a/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentFilter.java
+++ b/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentFilter.java
@@ -16,7 +16,7 @@ import com.gitplex.server.persistence.dao.EntityCriteria;
import com.gitplex.server.util.editable.annotation.AccountChoice;
import com.gitplex.server.util.editable.annotation.Editable;
import com.gitplex.server.util.editable.annotation.FileChoice;
-import com.gitplex.server.util.match.WildcardUtils;
+import com.gitplex.server.util.stringmatch.WildcardUtils;
@Editable
public class CodeCommentFilter implements Serializable {
diff --git a/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentListPanel.java b/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentListPanel.java
index 8816e5493a..3bdc7509ff 100644
--- a/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentListPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentListPanel.java
@@ -33,6 +33,7 @@ import org.hibernate.criterion.Restrictions;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.CodeCommentManager;
+import com.gitplex.server.model.Account;
import com.gitplex.server.model.CodeComment;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
@@ -166,7 +167,7 @@ public abstract class CodeCommentListPanel extends Panel {
titleLink.add(new Label("label", StringUtils.abbreviate(comment.getContent(), TITLE_LEN)));
fragment.add(titleLink);
fragment.add(new WebMarkupContainer("resolved").setVisible(comment.isResolved()));
- fragment.add(new AccountLink("user", comment.getUser()));
+ fragment.add(new AccountLink("user", Account.getForDisplay(comment.getUser(), comment.getUserName())));
Link<Void> fileLink = new Link<Void>("file") {
@@ -185,10 +186,10 @@ public abstract class CodeCommentListPanel extends Panel {
if (comment.getLastEvent() != null) {
String description = comment.getLastEvent().getType();
lastEventContainer.add(new Label("description", description));
- if (comment.getLastEvent().getUser() != null)
- lastEventContainer.add(new AccountLink("user", comment.getLastEvent().getUser()));
- else
- lastEventContainer.add(new WebMarkupContainer("user").setVisible(false));
+
+ Account userForDisplay = Account.getForDisplay(comment.getLastEvent().getUser(),
+ comment.getLastEvent().getUserName());
+ lastEventContainer.add(new AccountLink("user", userForDisplay));
lastEventContainer.add(new Label("date", DateUtils.formatAge(comment.getLastEvent().getDate())));
} else {
lastEventContainer.add(new WebMarkupContainer("description"));
diff --git a/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentPanel.java b/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentPanel.java
index 4efd4ec65a..0017b2f800 100644
--- a/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/component/comment/CodeCommentPanel.java
@@ -103,8 +103,9 @@ public abstract class CodeCommentPanel extends Panel {
}));
- commentContainer.add(new AvatarLink("userAvatar", getComment().getUser()));
- commentContainer.add(new AccountLink("userName", getComment().getUser()));
+ Account userForDisplay = Account.getForDisplay(getComment().getUser(), getComment().getUserName());
+ commentContainer.add(new AvatarLink("userAvatar", userForDisplay));
+ commentContainer.add(new AccountLink("userName", userForDisplay));
commentContainer.add(new Label("activityDescription", "commented"));
commentContainer.add(new Label("activityDate", DateUtils.formatAge(getComment().getDate())));
commentContainer.add(new Link<Void>("compareContext") {
@@ -319,8 +320,10 @@ public abstract class CodeCommentPanel extends Panel {
activityContainer.setMarkupId(activity.getAnchor());
activityContainer.add(AttributeAppender.append("name", activity.getAnchor()));
- activityContainer.add(new AvatarLink("userAvatar", activity.getUser()));
- activityContainer.add(new AccountLink("userName", activity.getUser()));
+ Account userForDisplay = Account.getForDisplay(activity.getUser(), activity.getUserName());
+ activityContainer.add(new AvatarLink("userAvatar", userForDisplay));
+ activityContainer.add(new AccountLink("userName", userForDisplay));
+
String activityDescription;
if (activity instanceof CodeCommentStatusChange) {
CodeCommentStatusChange statusChange = (CodeCommentStatusChange) activity;
diff --git a/web/src/main/java/com/gitplex/server/web/component/comment/code-comment.css b/web/src/main/java/com/gitplex/server/web/component/comment/code-comment.css
index 0d9b7297f2..c6f41ae92b 100644
--- a/web/src/main/java/com/gitplex/server/web/component/comment/code-comment.css
+++ b/web/src/main/java/com/gitplex/server/web/component/comment/code-comment.css
@@ -25,10 +25,7 @@
padding-left: 40px;
}
.code-comment>.section>.detail>.head .user-name {
- color: #999;
-}
-.code-comment>.section>.detail>.head .user-name:hover {
- color: #333;
+ color: #666;
}
.code-comment>.section>.detail>.head .activity {
font-size: 12px;
diff --git a/web/src/main/java/com/gitplex/server/web/component/createbranch/CreateBranchLink.java b/web/src/main/java/com/gitplex/server/web/component/createbranch/CreateBranchLink.java
index de1ee2edce..3b568b6713 100644
--- a/web/src/main/java/com/gitplex/server/web/component/createbranch/CreateBranchLink.java
+++ b/web/src/main/java/com/gitplex/server/web/component/createbranch/CreateBranchLink.java
@@ -3,8 +3,6 @@ package com.gitplex.server.web.component.createbranch;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
import com.gitplex.server.model.Depot;
import com.gitplex.server.security.SecurityUtils;
@@ -25,12 +23,9 @@ public abstract class CreateBranchLink extends ModalLink {
this.revision = revision;
}
- @Override
protected void onConfigure() {
super.onConfigure();
-
- ObjectId commitId = depotModel.getObject().getRevCommit(revision);
- setVisible(SecurityUtils.canPushRef(depotModel.getObject(), Constants.R_HEADS, ObjectId.zeroId(), commitId));
+ setVisible(SecurityUtils.canWrite(depotModel.getObject()));
}
@Override
diff --git a/web/src/main/java/com/gitplex/server/web/component/createbranch/CreateBranchPanel.java b/web/src/main/java/com/gitplex/server/web/component/createbranch/CreateBranchPanel.java
index 5eaffa759b..08b8a7f979 100644
--- a/web/src/main/java/com/gitplex/server/web/component/createbranch/CreateBranchPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/component/createbranch/CreateBranchPanel.java
@@ -8,16 +8,10 @@ import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
import com.gitplex.server.git.GitUtils;
-import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.security.SecurityUtils;
-import com.google.common.base.Joiner;
-import com.google.common.base.Preconditions;
import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
@@ -83,19 +77,8 @@ abstract class CreateBranchPanel extends Panel {
target.focusComponent(nameInput);
target.add(form);
} else {
- Depot depot = depotModel.getObject();
- ObjectId commitId = depot.getRevCommit(revision);
- Account user = Preconditions.checkNotNull(SecurityUtils.getAccount());
- GateCheckResult checkResult = depot.getGateKeeper().checkPush(user,
- depot, Constants.R_HEADS + branchName, ObjectId.zeroId(), commitId);
- if (!checkResult.isPassedOrIgnored()) {
- form.error(Joiner.on(", ").join(checkResult.getReasons()));
- target.focusComponent(nameInput);
- target.add(form);
- } else {
- depot.createBranch(branchName, revision);
- onCreate(target, branchName);
- }
+ depotModel.getObject().createBranch(branchName, revision);
+ onCreate(target, branchName);
}
}
diff --git a/web/src/main/java/com/gitplex/server/web/component/createtag/CreateTagLink.java b/web/src/main/java/com/gitplex/server/web/component/createtag/CreateTagLink.java
index dec0a48237..2a079deddf 100644
--- a/web/src/main/java/com/gitplex/server/web/component/createtag/CreateTagLink.java
+++ b/web/src/main/java/com/gitplex/server/web/component/createtag/CreateTagLink.java
@@ -4,7 +4,6 @@ import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
import com.gitplex.server.model.Depot;
import com.gitplex.server.security.SecurityUtils;
@@ -29,9 +28,7 @@ public abstract class CreateTagLink extends ModalLink {
protected void onConfigure() {
super.onConfigure();
- ObjectId commit = depotModel.getObject().getRevCommit(revision);
- setVisible(SecurityUtils.canPushRef(depotModel.getObject(), Constants.R_TAGS,
- ObjectId.zeroId(), commit));
+ setVisible(SecurityUtils.canCreateTag(depotModel.getObject(), Constants.R_TAGS));
}
@Override
diff --git a/web/src/main/java/com/gitplex/server/web/component/createtag/CreateTagPanel.java b/web/src/main/java/com/gitplex/server/web/component/createtag/CreateTagPanel.java
index e94caea00a..b50b9255b9 100644
--- a/web/src/main/java/com/gitplex/server/web/component/createtag/CreateTagPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/component/createtag/CreateTagPanel.java
@@ -9,15 +9,13 @@ import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
-import com.gitplex.server.gatekeeper.checkresult.GateCheckResult;
import com.gitplex.server.git.GitUtils;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.support.TagProtection;
import com.gitplex.server.security.SecurityUtils;
-import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
@@ -104,18 +102,20 @@ abstract class CreateTagPanel extends Panel {
target.add(form);
} else {
Depot depot = depotModel.getObject();
- ObjectId commitId = depot.getRevCommit(revision);
Account user = Preconditions.checkNotNull(SecurityUtils.getAccount());
- GateCheckResult checkResult = depot.getGateKeeper().checkPush(user,
- depot, Constants.R_TAGS + tagName, ObjectId.zeroId(), commitId);
- if (!checkResult.isPassedOrIgnored()) {
- form.error(Joiner.on(", ").join(checkResult.getReasons()));
+
+ String errorMessage = null;
+ TagProtection protection = depot.getTagProtection(tagName);
+ if (protection != null)
+ errorMessage = protection.getTagCreator().getNotMatchMessage(depot, user);
+ if (errorMessage != null) {
+ form.error("Unable to create protected tag: " + errorMessage);
target.focusComponent(nameInput);
target.add(form);
- } else {
+ } else {
depot.tag(tagName, revision, user.asPerson(), tagMessage);
onCreate(target, tagName);
- }
+ }
}
}
diff --git a/web/src/main/java/com/gitplex/server/web/component/datatable/SelectionColumn.java b/web/src/main/java/com/gitplex/server/web/component/datatable/SelectionColumn.java
index 62cf6a7bf5..d3d9504de4 100644
--- a/web/src/main/java/com/gitplex/server/web/component/datatable/SelectionColumn.java
+++ b/web/src/main/java/com/gitplex/server/web/component/datatable/SelectionColumn.java
@@ -111,7 +111,7 @@ public class SelectionColumn<T, S> implements IStyledColumn<T, S> {
protected void respond(AjaxRequestTarget target) {
final boolean checked = RequestCycle.get()
.getRequest()
- .getQueryParameters()
+ .getPostParameters()
.getParameterValue("checked")
.toBoolean();
findParent(DataTable.class).visitChildren(
@@ -187,7 +187,7 @@ public class SelectionColumn<T, S> implements IStyledColumn<T, S> {
protected void respond(final AjaxRequestTarget target) {
boolean checked = RequestCycle.get()
.getRequest()
- .getQueryParameters()
+ .getPostParameters()
.getParameterValue("checked")
.toBoolean();
if (checked)
@@ -214,11 +214,13 @@ public class SelectionColumn<T, S> implements IStyledColumn<T, S> {
super.renderHead(component, response);
response.render(JavaScriptHeaderItem.forReference(WicketAjaxJQueryResourceReference.get()));
- CallbackParameter param = CallbackParameter.resolved("checked", "this.checked");
- CharSequence callbackFunc = getCallbackFunction(param);
- String template = "$('#%s').change(%s)";
- String checkboxMarkupId = RowSelector.this.get("checkbox").getMarkupId();
- String script = String.format(template, checkboxMarkupId, callbackFunc);
+ CallbackParameter param = CallbackParameter.explicit("checked");
+ String script = String.format(""
+ + "$('#%s').change(function() {\n"
+ + " var checked = this.checked;\n"
+ + " %s;\n"
+ + "});\n",
+ RowSelector.this.get("checkbox").getMarkupId(), getCallbackFunctionBody(param));
response.render(OnDomReadyHeaderItem.forScript(script));
}
diff --git a/web/src/main/java/com/gitplex/server/web/component/diff/blob/text/TextDiffPanel.java b/web/src/main/java/com/gitplex/server/web/component/diff/blob/text/TextDiffPanel.java
index 7917f34132..d65cca7f52 100644
--- a/web/src/main/java/com/gitplex/server/web/component/diff/blob/text/TextDiffPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/component/diff/blob/text/TextDiffPanel.java
@@ -77,7 +77,7 @@ import com.gitplex.server.web.page.depot.blob.RequestCompareInfo;
import com.gitplex.server.web.page.depot.blob.render.BlobRenderContext.Mode;
import com.gitplex.server.web.page.depot.commit.CommitDetailPage;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
-import com.gitplex.server.web.page.depot.pullrequest.requestdetail.integrationpreview.IntegrationPreviewPage;
+import com.gitplex.server.web.page.depot.pullrequest.requestdetail.mergepreview.MergePreviewPage;
import com.gitplex.server.web.util.DateUtils;
import com.google.common.base.Preconditions;
@@ -211,7 +211,7 @@ public class TextDiffPanel extends Panel implements SourceAware {
&& request.getSource() != null
&& request.getSource().getObjectName(false) != null
&& SecurityUtils.canModify(request.getSourceDepot(), request.getSourceBranch(), change.getPath())
- && (getPage() instanceof RequestChangesPage || getPage() instanceof IntegrationPreviewPage)) {
+ && (getPage() instanceof RequestChangesPage || getPage() instanceof MergePreviewPage)) {
// we are in context of a pull request and pull request source branch exists, so we edit in source branch instead
Link<Void> editLink = new Link<Void>("editFile") {
@@ -227,7 +227,7 @@ public class TextDiffPanel extends Panel implements SourceAware {
RequestChangesPage page = (RequestChangesPage) getPage();
editState.requestCompareInfo.compareState = page.getState();
} else {
- IntegrationPreviewPage page = (IntegrationPreviewPage) getPage();
+ MergePreviewPage page = (MergePreviewPage) getPage();
editState.requestCompareInfo.previewState = page.getState();
}
PageParameters params = DepotBlobPage.paramsOf(request.getSourceDepot(), editState);
diff --git a/web/src/main/java/com/gitplex/server/web/component/diff/revision/RevisionDiffPanel.java b/web/src/main/java/com/gitplex/server/web/component/diff/revision/RevisionDiffPanel.java
index 79b26f69b3..0c2f15bd9a 100644
--- a/web/src/main/java/com/gitplex/server/web/component/diff/revision/RevisionDiffPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/component/diff/revision/RevisionDiffPanel.java
@@ -71,7 +71,7 @@ import com.gitplex.server.security.SecurityUtils;
import com.gitplex.server.util.StringUtils;
import com.gitplex.server.util.diff.DiffUtils;
import com.gitplex.server.util.diff.WhitespaceOption;
-import com.gitplex.server.util.match.WildcardUtils;
+import com.gitplex.server.util.stringmatch.WildcardUtils;
import com.gitplex.server.web.WebConstants;
import com.gitplex.server.web.behavior.inputassist.InputAssistBehavior;
import com.gitplex.server.web.component.comment.CodeCommentPanel;
@@ -562,7 +562,7 @@ public class RevisionDiffPanel extends Panel {
@Override
protected List<String> getHints(InputStatus inputStatus) {
- return Lists.newArrayList("Use * to match any string in the path");
+ return Lists.newArrayList("Use * to match any part of the path");
}
@Override
diff --git a/web/src/main/java/com/gitplex/server/web/component/floating/FloatingPanel.java b/web/src/main/java/com/gitplex/server/web/component/floating/FloatingPanel.java
index 91a0d870c9..42ef9f7764 100644
--- a/web/src/main/java/com/gitplex/server/web/component/floating/FloatingPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/component/floating/FloatingPanel.java
@@ -76,7 +76,8 @@ public abstract class FloatingPanel extends Panel {
String script = String.format("gitplex.server.floating.close($('#%s'), false);", getMarkupId(true));
target.appendJavaScript(script);
}
- remove();
+ if (getParent() != null)
+ remove();
onClosed();
}
diff --git a/web/src/main/java/com/gitplex/server/web/component/fullbranchmatch/FullBranchMatchBehavior.java b/web/src/main/java/com/gitplex/server/web/component/fullbranchmatch/FullBranchMatchBehavior.java
deleted file mode 100644
index 551f779a38..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/fullbranchmatch/FullBranchMatchBehavior.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package com.gitplex.server.web.component.fullbranchmatch;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.model.IModel;
-
-import com.gitplex.codeassist.InputSuggestion;
-import com.gitplex.codeassist.ParentedElement;
-import com.gitplex.codeassist.grammar.LexerRuleRefElementSpec;
-import com.gitplex.codeassist.parser.Element;
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.manager.DepotManager;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchParser;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.web.behavior.inputassist.ANTLRAssistBehavior;
-import com.gitplex.server.web.page.depot.DepotPage;
-import com.gitplex.server.web.util.SuggestionUtils;
-
-@SuppressWarnings("serial")
-public class FullBranchMatchBehavior extends ANTLRAssistBehavior {
-
- private final IModel<Depot> depotModel;
-
- public FullBranchMatchBehavior(IModel<Depot> depotModel) {
- super(FullBranchMatchParser.class, "match");
- this.depotModel = depotModel;
- }
-
- @Override
- public void detach(Component component) {
- super.detach(component);
- depotModel.detach();
- }
-
- @Override
- protected List<InputSuggestion> suggest(final ParentedElement expectedElement, String matchWith, final int count) {
- if (expectedElement.getState() != null) {
- String ruleName = expectedElement.getState().getRuleSpec().getName();
- if (ruleName.equals("branchMatch")) {
- DepotPage page = (DepotPage) getComponent().getPage();
- Depot depot = page.getDepot();
- ParentedElement criteriaElement = expectedElement.findParentByRule("criteria");
- List<Element> children = criteriaElement.findChildrenByRule("fullDepotMatch", true);
- if (children.isEmpty()) {
- return SuggestionUtils.suggestBranch(depot, matchWith, count,
- "branch in current repository", "any branch in current repository");
- } else {
- String depotFQN = children.get(0).getMatchedText().trim();
- Depot branchDepot;
- DepotManager depotManager = GitPlex.getInstance(DepotManager.class);
- if (depotFQN.indexOf("/") == -1) {
- branchDepot = depotManager.find(depot.getAccount(), depotFQN);
- } else {
- branchDepot = depotManager.find(depotFQN);
- }
- if (branchDepot != null) {
- return SuggestionUtils.suggestBranch(branchDepot, matchWith, count,
- "branch in selected repository", "any branch in selected repository");
- } else {
- return new ArrayList<>();
- }
- }
- } else if (ruleName.equals("fullDepotMatch")) {
- List<InputSuggestion> suggestions = new ArrayList<>();
- DepotPage page = (DepotPage) getComponent().getPage();
- Depot depot = page.getDepot();
- suggestions.addAll(SuggestionUtils.suggestAffinals(depot, matchWith, count,
- "select branch in this repository", "any repository"));
- return suggestions;
- }
- }
- return null;
- }
-
- @Override
- protected List<String> getHints(ParentedElement expectedElement, String matchWith) {
- List<String> hints = new ArrayList<>();
- if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
- LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
- if (spec.getRuleName().equals("Value")) {
- hints.add("Use * to do wildcard match");
- }
- }
- return hints;
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/fullbranchmatch/FullBranchMatchInput.java b/web/src/main/java/com/gitplex/server/web/component/fullbranchmatch/FullBranchMatchInput.java
deleted file mode 100644
index a97173bced..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/fullbranchmatch/FullBranchMatchInput.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.gitplex.server.web.component.fullbranchmatch;
-
-import java.io.Serializable;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.validation.IErrorMessageSource;
-import org.apache.wicket.validation.IValidatable;
-import org.apache.wicket.validation.IValidationError;
-import org.apache.wicket.validation.IValidator;
-
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.fullbranchmatch.FullBranchMatchUtils;
-
-@SuppressWarnings("serial")
-public class FullBranchMatchInput extends TextField<String> {
-
- private final IModel<Depot> depotModel;
-
- public FullBranchMatchInput(String id, IModel<Depot> depotModel, IModel<String> fullBranchMatchModel) {
- super(id, fullBranchMatchModel);
-
- this.depotModel = depotModel;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new FullBranchMatchBehavior(depotModel));
- add(new IValidator<String>() {
-
- @Override
- public void validate(IValidatable<String> validatable) {
- try {
- FullBranchMatchUtils.validate(validatable.getValue());
- } catch (final Exception e) {
- validatable.error(new IValidationError() {
-
- @Override
- public Serializable getErrorMessage(IErrorMessageSource messageSource) {
- if (StringUtils.isNotBlank(e.getMessage()))
- return e.getMessage();
- else
- return "Syntax error";
- }
-
- });
- }
- }
-
- });
- }
-
- @Override
- protected void onDetach() {
- depotModel.detach();
- super.onDetach();
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/link/AccountLink.java b/web/src/main/java/com/gitplex/server/web/component/link/AccountLink.java
index 08c2643ea2..6ce0cfa2bf 100644
--- a/web/src/main/java/com/gitplex/server/web/component/link/AccountLink.java
+++ b/web/src/main/java/com/gitplex/server/web/component/link/AccountLink.java
@@ -1,5 +1,7 @@
package com.gitplex.server.web.component.link;
+import javax.annotation.Nullable;
+
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
@@ -19,17 +21,25 @@ public class AccountLink extends ViewStateAwarePageLink<Void> {
private final String name;
- public AccountLink(String id, Account account) {
+ public AccountLink(String id, @Nullable Account account) {
super(id, AccountOverviewPage.class);
- params = AccountPage.paramsOf(account);
- name = account.getDisplayName();
+ if (account == null) {
+ params = new PageParameters();
+ name = GitPlex.NAME;
+ } else if (account.getId() == null) {
+ params = new PageParameters();
+ name = account.getDisplayName();
+ } else {
+ params = AccountPage.paramsOf(account);
+ name = account.getDisplayName();
+ }
}
public AccountLink(String id, PersonIdent person) {
super(id, AccountOverviewPage.class);
- name = person.getName();
Account account = GitPlex.getInstance(AccountManager.class).find(person);
+ name = person.getName();
if (account != null) {
params = AccountPage.paramsOf(account);
} else {
diff --git a/web/src/main/java/com/gitplex/server/web/component/markdown/markdown.css b/web/src/main/java/com/gitplex/server/web/component/markdown/markdown.css
index 4e38816300..2f49c0a883 100644
--- a/web/src/main/java/com/gitplex/server/web/component/markdown/markdown.css
+++ b/web/src/main/java/com/gitplex/server/web/component/markdown/markdown.css
@@ -27,6 +27,7 @@ body.fullscreen {
margin: 4px;
}
.markdown-editor>.head {
+ background: white;
border: 1px solid #CCC;
border-bottom: none;
border-radius: 4px 4px 0 0;
@@ -148,6 +149,7 @@ body.fullscreen {
width: 100%;
display: block;
resize: none;
+ padding: 8px;
}
.markdown-editor>.body>.preview>.markdown-rendered {
overflow: auto;
diff --git a/web/src/main/java/com/gitplex/server/web/component/pathmatch/PathMatchBehavior.java b/web/src/main/java/com/gitplex/server/web/component/pathmatch/PathMatchBehavior.java
deleted file mode 100644
index b77b04e166..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pathmatch/PathMatchBehavior.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.gitplex.server.web.component.pathmatch;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.model.IModel;
-
-import com.gitplex.codeassist.FenceAware;
-import com.gitplex.codeassist.InputSuggestion;
-import com.gitplex.codeassist.ParentedElement;
-import com.gitplex.codeassist.grammar.ElementSpec;
-import com.gitplex.codeassist.grammar.LexerRuleRefElementSpec;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.includeexclude.IncludeExcludeParser;
-import com.gitplex.server.web.behavior.inputassist.ANTLRAssistBehavior;
-import com.gitplex.server.web.util.SuggestionUtils;
-
-@SuppressWarnings("serial")
-public class PathMatchBehavior extends ANTLRAssistBehavior {
-
- private final IModel<Depot> depotModel;
-
- private static final String VALUE_OPEN = "(";
-
- private static final String VALUE_CLOSE = ")";
-
- public PathMatchBehavior(IModel<Depot> depotModel) {
- super(IncludeExcludeParser.class, "match");
- this.depotModel = depotModel;
- }
-
- @Override
- public void detach(Component component) {
- super.detach(component);
- depotModel.detach();
- }
-
- @Override
- protected List<InputSuggestion> suggest(final ParentedElement expectedElement, String matchWith, int count) {
- if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
- LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
- if (spec.getRuleName().equals("Value")) {
- return new FenceAware(codeAssist.getGrammar(), VALUE_OPEN, VALUE_CLOSE) {
-
- @Override
- protected List<InputSuggestion> match(String unfencedMatchWith, int count) {
- return SuggestionUtils.suggestPath(depotModel.getObject(), unfencedMatchWith, count);
- }
-
- @Override
- protected String getFencingDescription() {
- return "value needs to be enclosed in brackets";
- }
-
- }.suggest(expectedElement.getSpec(), matchWith, count);
- }
- }
- return null;
- }
-
- @Override
- protected List<String> getHints(ParentedElement expectedElement, String matchWith) {
- List<String> hints = new ArrayList<>();
- if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
- LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
- if (spec.getRuleName().equals("Value") && !matchWith.contains(VALUE_CLOSE)) {
- hints.add("Use * to match any part of path");
- hints.add("Folder (path ending with '/') matches all files under it");
- }
- }
- return hints;
- }
-
- @Override
- protected int getEndOfMatch(ElementSpec spec, String content) {
- if (content.startsWith(VALUE_OPEN+VALUE_CLOSE))
- return 2;
- else
- return super.getEndOfMatch(spec, content);
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pathmatch/PathMatchInput.java b/web/src/main/java/com/gitplex/server/web/component/pathmatch/PathMatchInput.java
deleted file mode 100644
index 16fd43d745..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pathmatch/PathMatchInput.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.gitplex.server.web.component.pathmatch;
-
-import java.io.Serializable;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.validation.IErrorMessageSource;
-import org.apache.wicket.validation.IValidatable;
-import org.apache.wicket.validation.IValidationError;
-import org.apache.wicket.validation.IValidator;
-
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.includeexclude.IncludeExcludeUtils;
-
-@SuppressWarnings("serial")
-public class PathMatchInput extends TextField<String> {
-
- private final IModel<Depot> depotModel;
-
- public PathMatchInput(String id, IModel<Depot> depotModel, IModel<String> pathMatchModel) {
- super(id, pathMatchModel);
-
- this.depotModel = depotModel;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new PathMatchBehavior(depotModel));
- add(new IValidator<String>() {
-
- @Override
- public void validate(IValidatable<String> validatable) {
- try {
- IncludeExcludeUtils.parse(validatable.getValue());
- } catch (final Exception e) {
- validatable.error(new IValidationError() {
-
- @Override
- public Serializable getErrorMessage(IErrorMessageSource messageSource) {
- if (StringUtils.isNotBlank(e.getMessage()))
- return e.getMessage();
- else
- return "Syntax error";
- }
-
- });
- }
- }
-
- });
- }
-
- @Override
- protected void onDetach() {
- depotModel.detach();
- super.onDetach();
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestassignee/Assignee.java b/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestassignee/Assignee.java
deleted file mode 100644
index 9659e28f57..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestassignee/Assignee.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.gitplex.server.web.component.pullrequest.requestassignee;
-
-import java.io.Serializable;
-
-import javax.annotation.Nullable;
-
-import com.gitplex.server.model.Account;
-
-@SuppressWarnings("serial")
-public class Assignee implements Serializable {
-
- private final Account user;
-
- private final String alias;
-
- public Assignee(Account user, @Nullable String alias) {
- this.user = user;
- this.alias = alias;
- }
-
- public Account getUser() {
- return user;
- }
-
- @Nullable
- public String getAlias() {
- return alias;
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestassignee/AssigneeChoice.java b/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestassignee/AssigneeChoice.java
deleted file mode 100644
index 3b9d0fe06b..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestassignee/AssigneeChoice.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.gitplex.server.web.component.pullrequest.requestassignee;
-
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.head.JavaScriptHeaderItem;
-import org.apache.wicket.model.IModel;
-
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.web.component.accountchoice.AccountChoiceResourceReference;
-import com.gitplex.server.web.component.select2.Select2Choice;
-
-@SuppressWarnings("serial")
-public class AssigneeChoice extends Select2Choice<Assignee> {
-
- public AssigneeChoice(String id, IModel<Depot> depotModel, final IModel<Account> assigneeModel) {
- super(id, new IModel<Assignee>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public Assignee getObject() {
- Account user = assigneeModel.getObject();
- if (user != null)
- return new Assignee(user, null);
- else
- return null;
- }
-
- @Override
- public void setObject(Assignee object) {
- if (object != null)
- assigneeModel.setObject(object.getUser());
- else
- assigneeModel.setObject(null);
- }
-
- }, new AssigneeProvider(depotModel));
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- // getSettings().setMinimumInputLength(1);
- getSettings().setPlaceholder("Type to find an assignee");
- getSettings().setFormatResult("gitplex.server.accountChoiceFormatter.formatResult");
- getSettings().setFormatSelection("gitplex.server.accountChoiceFormatter.formatSelection");
- getSettings().setEscapeMarkup("gitplex.server.accountChoiceFormatter.escapeMarkup");
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
-
- response.render(JavaScriptHeaderItem.forReference(new AccountChoiceResourceReference()));
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestassignee/AssigneeProvider.java b/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestassignee/AssigneeProvider.java
deleted file mode 100644
index dc6cfcb3b3..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestassignee/AssigneeProvider.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package com.gitplex.server.web.component.pullrequest.requestassignee;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.commons.lang3.StringEscapeUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.wicket.model.IModel;
-import org.json.JSONException;
-import org.json.JSONWriter;
-
-import com.google.common.collect.Lists;
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.manager.AccountManager;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.persistence.dao.Dao;
-import com.gitplex.server.security.ObjectPermission;
-import com.gitplex.server.security.SecurityUtils;
-import com.gitplex.server.security.privilege.DepotPrivilege;
-import com.gitplex.server.web.WebConstants;
-import com.gitplex.server.web.component.select2.ChoiceProvider;
-import com.gitplex.server.web.component.select2.Response;
-import com.gitplex.server.web.util.avatar.AvatarManager;
-
-public class AssigneeProvider extends ChoiceProvider<Assignee> {
-
- private static final long serialVersionUID = 1L;
-
- private final IModel<Depot> depotModel;
-
- public AssigneeProvider(IModel<Depot> depotModel) {
- this.depotModel = depotModel;
- }
-
- @Override
- public void query(String term, int page, Response<Assignee> response) {
- Depot depot = depotModel.getObject();
- List<Assignee> assignees = new ArrayList<>();
- for (Account user: SecurityUtils.findUsersCan(depot, DepotPrivilege.WRITE)) {
- if (user.matches(term)) {
- assignees.add(new Assignee(user, null));
- }
- }
- assignees.sort((assignee1, assignee2)
- -> assignee1.getUser().getDisplayName().compareTo(assignee2.getUser().getDisplayName()));
- if (StringUtils.isBlank(term)) {
- if (!depot.getAccount().isOrganization())
- assignees.add(0, new Assignee(depot.getAccount(), "Repository Owner"));
- ObjectPermission writePermission = ObjectPermission.ofDepotWrite(depotModel.getObject());
- Account currentUser = GitPlex.getInstance(AccountManager.class).getCurrent();
- if (currentUser != null && currentUser.asSubject().isPermitted(writePermission))
- assignees.add(0, new Assignee(currentUser, "Me"));
- }
-
- int first = page * WebConstants.DEFAULT_PAGE_SIZE;
- int last = first + WebConstants.DEFAULT_PAGE_SIZE;
- if (last > assignees.size()) {
- response.addAll(assignees.subList(first, assignees.size()));
- } else {
- response.addAll(assignees.subList(first, last));
- response.setHasMore(last < assignees.size());
- }
- }
-
- @Override
- public void toJson(Assignee choice, JSONWriter writer) throws JSONException {
- writer.key("id").value(choice.getUser().getId())
- .key("name").value(StringEscapeUtils.escapeHtml4(choice.getUser().getName()));
- if (choice.getUser().getFullName() != null)
- writer.key("fullName").value(StringEscapeUtils.escapeHtml4(choice.getUser().getFullName()));
- writer.key("email").value(StringEscapeUtils.escapeHtml4(choice.getUser().getEmail()));
- String avatarUrl = GitPlex.getInstance(AvatarManager.class).getAvatarUrl(choice.getUser());
- writer.key("avatar").value(avatarUrl);
- if (choice.getAlias() != null)
- writer.key("alias").value(StringEscapeUtils.escapeHtml4(choice.getAlias()));
- }
-
- @Override
- public Collection<Assignee> toChoices(Collection<String> ids) {
- List<Assignee> assignees = Lists.newArrayList();
- Dao dao = GitPlex.getInstance(Dao.class);
- for (String each : ids) {
- Long id = Long.valueOf(each);
- assignees.add(new Assignee(dao.load(Account.class, id), null));
- }
-
- return assignees;
- }
-
- @Override
- public void detach() {
- depotModel.detach();
-
- super.detach();
- }
-
-}
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestreviewer/ReviewerAvatar.java b/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestreviewer/ReviewerAvatar.java
deleted file mode 100644
index 3f1e753cf0..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestreviewer/ReviewerAvatar.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package com.gitplex.server.web.component.pullrequest.requestreviewer;
-
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.model.IModel;
-
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.manager.PullRequestReviewInvitationManager;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReviewInvitation;
-import com.gitplex.server.security.SecurityUtils;
-import com.gitplex.server.web.component.avatar.RemoveableAvatar;
-import com.gitplex.server.web.util.model.EntityModel;
-import com.gitplex.server.web.util.model.UserModel;
-
-@SuppressWarnings("serial")
-public class ReviewerAvatar extends RemoveableAvatar {
-
- private final PullRequestReviewInvitation invitation;
-
- private final IModel<PullRequest> requestModel;
-
- public ReviewerAvatar(String id, PullRequestReviewInvitation invitation) {
- super(id, new UserModel(invitation.getUser()));
-
- this.invitation = invitation;
- requestModel = new EntityModel<PullRequest>(invitation.getRequest());
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = requestModel.getObject();
- setEnabled(request.isOpen() && SecurityUtils.canModify(request));
- }
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- Date now = new Date();
- PullRequest request = requestModel.getObject();
- Set<Account> prevInvited = new HashSet<>();
- for (PullRequestReviewInvitation each: request.getReviewInvitations()) {
- if (each.getStatus() != PullRequestReviewInvitation.Status.EXCLUDED)
- prevInvited.add(each.getUser());
- if (each.getUser().equals(invitation.getUser())) {
- each.setStatus(PullRequestReviewInvitation.Status.EXCLUDED);
- each.setDate(new Date());
- }
- }
- request.checkGates(true);
-
- Set<Account> nowInvited = new HashSet<>();
- for (PullRequestReviewInvitation each: request.getReviewInvitations()) {
- if (each.getStatus() != PullRequestReviewInvitation.Status.EXCLUDED)
- nowInvited.add(each.getUser());
- }
-
- if (nowInvited.contains(invitation.getUser())) {
- getSession().warn("Reviewer '" + invitation.getUser().getDisplayName()
- + "' is required by gatekeeper and can not be removed");
- } else {
- nowInvited.removeAll(prevInvited);
- if (!nowInvited.isEmpty()) {
- getSession().warn("Reviewer '" + invitation.getUser().getDisplayName()
- + "' is removed and user '" + nowInvited.iterator().next().getDisplayName()
- + "' is added as reviewer automatically to satisfy gatekeeper requirement.");
- }
- }
- if (!request.isNew()) {
- PullRequestReviewInvitationManager reviewInvitationManager =
- GitPlex.getInstance(PullRequestReviewInvitationManager.class);
- reviewInvitationManager.update(request.getReviewInvitations(), now);
- }
- }
-
- @Override
- protected void onDetach() {
- requestModel.detach();
-
- super.onDetach();
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultIcon.java b/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultIcon.java
deleted file mode 100644
index 1342d0b66e..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultIcon.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.gitplex.server.web.component.pullrequest.reviewresult;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.markup.head.CssHeaderItem;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.html.WebComponent;
-import org.apache.wicket.model.IModel;
-
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.web.behavior.dropdown.DropdownHover;
-import com.gitplex.server.web.component.floating.AlignPlacement;
-
-@SuppressWarnings("serial")
-public class ReviewResultIcon extends WebComponent {
-
- private final IModel<PullRequestReview> model;
-
- public ReviewResultIcon(String id, IModel<PullRequestReview> model) {
- super(id);
- this.model = model;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- PullRequestReview review = model.getObject();
- String css;
- if (review.getUpdate().equals(review.getUpdate().getRequest().getLatestUpdate())) {
- if (review.getResult() == PullRequestReview.Result.APPROVE) {
- css = " review-result approved current fa fa-check-circle";
- } else {
- css = " review-result disapproved current fa fa-times-circle";
- }
- } else if (review.getResult() == PullRequestReview.Result.APPROVE) {
- css = " review-result approved previous fa fa-check-circle";
- } else {
- css = " review-result disapproved previous fa fa-times-circle";
- }
- add(AttributeAppender.append("class", css));
-
- add(new DropdownHover(new AlignPlacement(100, 0, 0, 100, 0)) {
-
- @Override
- protected Component newContent(String id) {
- return new ReviewResultTooltip(id, model);
- }
- });
- }
-
- @Override
- protected void onDetach() {
- model.detach();
- super.onDetach();
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(CssHeaderItem.forReference(new ReviewResultResourceReference()));
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultResourceReference.java b/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultResourceReference.java
deleted file mode 100644
index 820017f567..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultResourceReference.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gitplex.server.web.component.pullrequest.reviewresult;
-
-import org.apache.wicket.request.resource.CssResourceReference;
-
-public class ReviewResultResourceReference extends CssResourceReference {
-
- private static final long serialVersionUID = 1L;
-
- public ReviewResultResourceReference() {
- super(ReviewResultResourceReference.class, "review-result.css");
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultTooltip.html b/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultTooltip.html
deleted file mode 100644
index d3c5b9ca0d..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultTooltip.html
+++ /dev/null
@@ -1,9 +0,0 @@
-<wicket:panel>
- <div class="review-result-tooltip">
- <span wicket:id="description"></span>
- <wicket:enclosure child="withdraw">
- <span class="middot"></span>
- <a wicket:id="withdraw">withdraw</a>
- </wicket:enclosure>
- </div>
-</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultTooltip.java b/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultTooltip.java
deleted file mode 100644
index a9c724b916..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/ReviewResultTooltip.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.gitplex.server.web.component.pullrequest.reviewresult;
-
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.markup.html.panel.GenericPanel;
-import org.apache.wicket.model.IModel;
-
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.manager.PullRequestReviewManager;
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.security.SecurityUtils;
-
-@SuppressWarnings("serial")
-class ReviewResultTooltip extends GenericPanel<PullRequestReview> {
-
- public ReviewResultTooltip(String id, IModel<PullRequestReview> model) {
- super(id, model);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- PullRequestReview review = getModelObject();
- String description;
- if (review.getUpdate().equals(review.getUpdate().getRequest().getLatestUpdate())) {
- if (review.getResult() == PullRequestReview.Result.APPROVE) {
- description = "Approved";
- } else {
- description = "Disapproved";
- }
- } else if (review.getResult() == PullRequestReview.Result.APPROVE) {
- description = "Approved on a previous update";
- } else {
- description = "Disapproved on a previous update";
- }
-
- add(new Label("description", description));
-
- add(new Link<Void>("withdraw") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- PullRequestReview review = ReviewResultTooltip.this.getModelObject();
- setVisible(review.getUser().equals(SecurityUtils.getAccount())
- || SecurityUtils.canManage(review.getUpdate().getRequest().getTargetDepot()));
- }
-
- @Override
- public void onClick() {
- PullRequestReview review = ReviewResultTooltip.this.getModelObject();
- PullRequest request = review.getUpdate().getRequest();
- GitPlex.getInstance(PullRequestReviewManager.class).deleteAll(review.getUser(), request);
- }
-
- });
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/review-result.css b/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/review-result.css
deleted file mode 100644
index 50ed3267d3..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/reviewresult/review-result.css
+++ /dev/null
@@ -1,23 +0,0 @@
-.review-result {
- font-size: 16px;
- position: absolute;
- left: 30px;
- top: -11px;
- cursor: pointer;
- opacity: 100;
-}
-.review-result.current.approved {
- color: #35A612;
-}
-.review-result.current.disapproved {
- color: #F93333;
-}
-.review-result.previous.approved, .review-result.previous.disapproved {
- color: #888;
-}
-
-.review-result-tooltip {
- padding: 4px 8px;
-}
-.review-result-tooltip a {
-}
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/VerificationStatusPanel.html b/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/VerificationStatusPanel.html
deleted file mode 100644
index 7626e38a62..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/VerificationStatusPanel.html
+++ /dev/null
@@ -1,20 +0,0 @@
-<wicket:panel>
- <a wicket:id="link" class="verification-status"><i wicket:id="icon"></i><i class="caret"></i></a>
- <wicket:fragment wicket:id="detailFrag">
- <table class="verifications table table-striped">
- <thead>
- <tr>
- <th>Configuration</th>
- <th>Message</th>
- </tr>
- </thead>
- <tbody>
- <tr wicket:id="verifications">
- <td wicket:id="configuration"></td>
- <td><span class="fa fa-check"></span><span class="fa fa-times"></span><span class="fa fa-cog"></span>
- <span wicket:id="message"></span></td>
- </tr>
- </tbody>
- </table>
- </wicket:fragment>
-</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/VerificationStatusPanel.java b/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/VerificationStatusPanel.java
deleted file mode 100644
index d43687abce..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/VerificationStatusPanel.java
+++ /dev/null
@@ -1,177 +0,0 @@
-package com.gitplex.server.web.component.pullrequest.verificationstatus;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.markup.head.CssHeaderItem;
-import org.apache.wicket.markup.head.IHeaderResponse;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
-import org.apache.wicket.markup.html.panel.Fragment;
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.AbstractReadOnlyModel;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.LoadableDetachableModel;
-
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestVerification;
-import com.gitplex.server.web.component.floating.FloatingPanel;
-import com.gitplex.server.web.component.link.DropdownLink;
-
-@SuppressWarnings("serial")
-public class VerificationStatusPanel extends Panel {
-
- private final IModel<PullRequest> requestModel;
-
- private final IModel<String> commitHashModel;
-
- public VerificationStatusPanel(String id, IModel<PullRequest> requestModel, IModel<String> commitHashModel) {
- super(id);
-
- this.requestModel = requestModel;
- this.commitHashModel = commitHashModel;
- }
-
- private List<PullRequestVerification> getVerifications() {
- List<PullRequestVerification> verifications = new ArrayList<>();
- for (PullRequestVerification verification: requestModel.getObject().getVerifications()) {
- if (verification.getCommit().equals(commitHashModel.getObject()))
- verifications.add(verification);
- }
- return verifications;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- DropdownLink link = new DropdownLink("link") {
-
- @Override
- protected Component newContent(String id, FloatingPanel dropdown) {
- Fragment fragment = new Fragment(id, "detailFrag", VerificationStatusPanel.this);
-
- IModel<List<PullRequestVerification>> model = new AbstractReadOnlyModel<List<PullRequestVerification>>() {
-
- @Override
- public List<PullRequestVerification> getObject() {
- return getVerifications();
- }
-
- };
- fragment.add(new ListView<PullRequestVerification>("verifications", model) {
-
- @Override
- protected void populateItem(ListItem<PullRequestVerification> item) {
- PullRequestVerification verification = item.getModelObject();
- item.add(new Label("configuration", verification.getConfiguration()));
- item.add(new Label("message", verification.getMessage()).setEscapeModelStrings(false));
-
- if (verification.getStatus() == PullRequestVerification.Status.FAILED)
- item.add(AttributeAppender.append("class", "failed"));
- else if (verification.getStatus() == PullRequestVerification.Status.SUCCESSFUL)
- item.add(AttributeAppender.append("class", "successful"));
- else
- item.add(AttributeAppender.append("class", "running"));
- }
-
- });
-
- return fragment;
- }
-
- };
- add(link);
-
- link.add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {
-
- @Override
- protected String load() {
- PullRequestVerification.Status overallStatus = getOverallStatus();
- if (overallStatus == PullRequestVerification.Status.SUCCESSFUL) {
- return "successful";
- } else if (overallStatus == PullRequestVerification.Status.FAILED) {
- return "failed";
- } else {
- return "running";
- }
- }
-
- }));
- link.add(AttributeAppender.append("title", new LoadableDetachableModel<String>() {
-
- @Override
- protected String load() {
- PullRequestVerification.Status overallStatus = getOverallStatus();
- if (overallStatus == PullRequestVerification.Status.SUCCESSFUL) {
- return "Builds are successful";
- } else if (overallStatus == PullRequestVerification.Status.FAILED) {
- return "At least one build is failed";
- } else {
- return "Builds are running";
- }
- }
-
- }));
-
- WebMarkupContainer icon = new WebMarkupContainer("icon");
- link.add(icon);
- icon.add(AttributeAppender.append("class", new LoadableDetachableModel<String>() {
-
- @Override
- protected String load() {
- PullRequestVerification.Status overallStatus = getOverallStatus();
- if (overallStatus == PullRequestVerification.Status.SUCCESSFUL) {
- return "fa fa-check";
- } else if (overallStatus == PullRequestVerification.Status.FAILED) {
- return "fa fa-times";
- } else {
- return "fa fa-clock-o";
- }
- }
-
- }));
-
- setOutputMarkupPlaceholderTag(true);
- }
-
- private PullRequestVerification.Status getOverallStatus() {
- PullRequestVerification.Status overallStatus = null;
- for (PullRequestVerification verification: getVerifications()) {
- if (verification.getStatus() == PullRequestVerification.Status.FAILED) {
- overallStatus = PullRequestVerification.Status.FAILED;
- break;
- } else if (verification.getStatus() == PullRequestVerification.Status.RUNNING) {
- overallStatus = PullRequestVerification.Status.RUNNING;
- } else if (overallStatus == null) {
- overallStatus = PullRequestVerification.Status.SUCCESSFUL;
- }
- }
- return overallStatus;
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
-
- response.render(CssHeaderItem.forReference(new VerificationStatusResourceReference()));
- }
-
- @Override
- protected void onDetach() {
- requestModel.detach();
- commitHashModel.detach();
- super.onDetach();
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(!getVerifications().isEmpty());
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/VerificationStatusResourceReference.java b/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/VerificationStatusResourceReference.java
deleted file mode 100644
index 4b94bf0473..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/VerificationStatusResourceReference.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gitplex.server.web.component.pullrequest.verificationstatus;
-
-import org.apache.wicket.request.resource.CssResourceReference;
-
-public class VerificationStatusResourceReference extends CssResourceReference {
-
- private static final long serialVersionUID = 1L;
-
- public VerificationStatusResourceReference() {
- super(VerificationStatusResourceReference.class, "verification-status.css");
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/verification-status.css b/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/verification-status.css
deleted file mode 100644
index 29e2d5603d..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/verificationstatus/verification-status.css
+++ /dev/null
@@ -1,35 +0,0 @@
-.verification-status {
- text-decoration: none !important;
-}
-.verification-status.successful {
- color: #5CB85C !important;
-}
-.verification-status.failed {
- color: #D9534F !important;
-}
-.verification-status.running {
- color: #F0AD4E !important;
-}
-
-table.verifications td {
- white-space: nowrap;
- color: #444;
-}
-table.verifications {
- margin-bottom: 1px;
-}
-table.verifications .fa {
- display: none;
-}
-table.verifications tr.successful .fa-check {
- display: inline;
- color: #5CB85C;
-}
-table.verifications tr.failed .fa-times {
- display: inline;
- color: #D9534F;
-}
-table.verifications tr.running .fa-cog {
- display: inline;
- color: #F0AD4E;
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/refmatch/RefMatchBehavior.java b/web/src/main/java/com/gitplex/server/web/component/refmatch/RefMatchBehavior.java
deleted file mode 100644
index c29c18ed64..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/refmatch/RefMatchBehavior.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package com.gitplex.server.web.component.refmatch;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.model.IModel;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.Ref;
-
-import com.gitplex.codeassist.FenceAware;
-import com.gitplex.codeassist.InputSuggestion;
-import com.gitplex.codeassist.ParentedElement;
-import com.gitplex.codeassist.grammar.ElementSpec;
-import com.gitplex.codeassist.grammar.LexerRuleRefElementSpec;
-import com.gitplex.jsymbol.Range;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.includeexclude.IncludeExcludeParser;
-import com.gitplex.server.web.behavior.inputassist.ANTLRAssistBehavior;
-
-@SuppressWarnings("serial")
-public class RefMatchBehavior extends ANTLRAssistBehavior {
-
- private final IModel<Depot> depotModel;
-
- private static final String VALUE_OPEN = "(";
-
- private static final String VALUE_CLOSE = ")";
-
- private static final String ANY_BRANCH = "refs/heads/*";
-
- private static final String ANY_TAG = "refs/tags/*";
-
- public RefMatchBehavior(IModel<Depot> depotModel) {
- super(IncludeExcludeParser.class, "match");
- this.depotModel = depotModel;
- }
-
- @Override
- public void detach(Component component) {
- super.detach(component);
- depotModel.detach();
- }
-
- @Override
- protected List<InputSuggestion> suggest(final ParentedElement expectedElement, String matchWith, int count) {
- if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
- LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
- if (spec.getRuleName().equals("Value")) {
- return new FenceAware(codeAssist.getGrammar(), VALUE_OPEN, VALUE_CLOSE) {
-
- @Override
- protected List<InputSuggestion> match(String unfencedMatchWith, int count) {
- List<InputSuggestion> suggestions = new ArrayList<>();
-
- Depot depot = depotModel.getObject();
-
- String lowerCaseMatchWith = unfencedMatchWith.toLowerCase();
- int numSuggestions = 0;
- Collection<String> suggestedValues = new ArrayList<>();
- suggestedValues.add(ANY_BRANCH);
- suggestedValues.add(ANY_TAG);
- for (Ref ref: depot.getRefs(Constants.R_HEADS).values())
- suggestedValues.add(ref.getName());
- for (Ref ref: depot.getRefs(Constants.R_TAGS).values())
- suggestedValues.add(ref.getName());
-
- for (String suggestedValue: suggestedValues) {
- int index = suggestedValue.toLowerCase().indexOf(lowerCaseMatchWith);
- if (index != -1 && numSuggestions++<count) {
- Range matchRange = new Range(index, index+lowerCaseMatchWith.length());
- if (suggestedValue.equals(ANY_BRANCH)) {
- suggestions.add(new InputSuggestion(suggestedValue, "any branch", matchRange));
- } else if (suggestedValue.equals(ANY_TAG)) {
- suggestions.add(new InputSuggestion(suggestedValue, "any tag", matchRange));
- } else {
- suggestions.add(new InputSuggestion(suggestedValue, matchRange));
- }
- }
- }
-
- if (numSuggestions++<count
- && !unfencedMatchWith.contains(VALUE_CLOSE)
- && unfencedMatchWith.length() != 0) {
- String fenced = VALUE_OPEN + unfencedMatchWith + VALUE_CLOSE;
- Range matchRange = new Range(0, fenced.length());
- suggestions.add(new InputSuggestion(fenced, -1, true, getFencingDescription(), matchRange));
- }
- return suggestions;
- }
-
- @Override
- protected String getFencingDescription() {
- return "value needs to be enclosed in brackets";
- }
-
- }.suggest(expectedElement.getSpec(), matchWith, count);
- }
- }
- return null;
- }
-
- @Override
- protected List<String> getHints(ParentedElement expectedElement, String matchWith) {
- List<String> hints = new ArrayList<>();
- if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
- LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
- if (spec.getRuleName().equals("Value") && !matchWith.contains(VALUE_CLOSE)) {
- hints.add("Use * to match any part of ref");
- }
- }
- return hints;
- }
-
- @Override
- protected int getEndOfMatch(ElementSpec spec, String content) {
- if (content.startsWith(VALUE_OPEN+VALUE_CLOSE))
- return 2;
- else
- return super.getEndOfMatch(spec, content);
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/refmatch/RefMatchInput.java b/web/src/main/java/com/gitplex/server/web/component/refmatch/RefMatchInput.java
deleted file mode 100644
index 703aafcc76..0000000000
--- a/web/src/main/java/com/gitplex/server/web/component/refmatch/RefMatchInput.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package com.gitplex.server.web.component.refmatch;
-
-import java.io.Serializable;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.wicket.markup.html.form.TextField;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.validation.IErrorMessageSource;
-import org.apache.wicket.validation.IValidatable;
-import org.apache.wicket.validation.IValidationError;
-import org.apache.wicket.validation.IValidator;
-
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.includeexclude.IncludeExcludeUtils;
-
-@SuppressWarnings("serial")
-public class RefMatchInput extends TextField<String> {
-
- private final IModel<Depot> depotModel;
-
- public RefMatchInput(String id, IModel<Depot> depotModel, IModel<String> refMatchModel) {
- super(id, refMatchModel);
-
- this.depotModel = depotModel;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new RefMatchBehavior(depotModel));
- add(new IValidator<String>() {
-
- @Override
- public void validate(IValidatable<String> validatable) {
- try {
- IncludeExcludeUtils.parse(validatable.getValue());
- } catch (final Exception e) {
- validatable.error(new IValidationError() {
-
- @Override
- public Serializable getErrorMessage(IErrorMessageSource messageSource) {
- if (StringUtils.isNotBlank(e.getMessage()))
- return e.getMessage();
- else
- return "Syntax error";
- }
-
- });
- }
- }
-
- });
- }
-
- @Override
- protected void onDetach() {
- depotModel.detach();
- super.onDetach();
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestreviewer/ReviewerChoice.java b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerChoice.java
similarity index 65%
rename from web/src/main/java/com/gitplex/server/web/component/pullrequest/requestreviewer/ReviewerChoice.java
rename to web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerChoice.java
index 7d9a4be792..8f27b2f5ea 100644
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestreviewer/ReviewerChoice.java
+++ b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerChoice.java
@@ -1,6 +1,4 @@
-package com.gitplex.server.web.component.pullrequest.requestreviewer;
-
-import java.util.Date;
+package com.gitplex.server.web.component.requestreviewer;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.head.IHeaderResponse;
@@ -8,11 +6,10 @@ import org.apache.wicket.markup.head.JavaScriptHeaderItem;
import org.apache.wicket.model.IModel;
import com.gitplex.server.GitPlex;
-import com.gitplex.server.manager.PullRequestReviewInvitationManager;
+import com.gitplex.server.manager.ReviewInvitationManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReviewInvitation;
-import com.gitplex.server.security.SecurityUtils;
+import com.gitplex.server.model.ReviewInvitation;
import com.gitplex.server.web.component.accountchoice.AccountChoiceResourceReference;
import com.gitplex.server.web.component.select2.SelectToAddChoice;
@@ -27,16 +24,6 @@ public abstract class ReviewerChoice extends SelectToAddChoice<Account> {
this.requestModel = requestModel;
}
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = requestModel.getObject();
- setVisible(request.isOpen()
- && !request.getPotentialReviewers().isEmpty()
- && SecurityUtils.canModify(request));
- }
-
@Override
protected void onInitialize() {
super.onInitialize();
@@ -61,24 +48,28 @@ public abstract class ReviewerChoice extends SelectToAddChoice<Account> {
super.onDetach();
}
+ @Override
protected void onSelect(AjaxRequestTarget target, Account user) {
PullRequest request = requestModel.getObject();
- PullRequestReviewInvitation invitation = null;
- for(PullRequestReviewInvitation each: request.getReviewInvitations()) {
+ ReviewInvitation invitation = null;
+ for(ReviewInvitation each: request.getReviewInvitations()) {
if (each.getUser().equals(user)) {
invitation = each;
break;
}
}
if (invitation == null) {
- invitation = new PullRequestReviewInvitation();
+ invitation = new ReviewInvitation();
invitation.setRequest(request);
invitation.setUser(user);
request.getReviewInvitations().add(invitation);
}
- invitation.setStatus(PullRequestReviewInvitation.Status.ADDED_MANUALLY);
- invitation.setDate(new Date());
+ invitation.setType(ReviewInvitation.Type.MANUAL);
+
+ request.clearReviewCheckStatus();
+
if (!request.isNew())
- GitPlex.getInstance(PullRequestReviewInvitationManager.class).save(invitation);
+ GitPlex.getInstance(ReviewInvitationManager.class).invite(invitation);
};
+
}
diff --git a/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerListCssResourceReference.java b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerListCssResourceReference.java
new file mode 100644
index 0000000000..bc25596c1c
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerListCssResourceReference.java
@@ -0,0 +1,13 @@
+package com.gitplex.server.web.component.requestreviewer;
+
+import com.gitplex.server.web.page.base.BaseDependentCssResourceReference;
+
+public class ReviewerListCssResourceReference extends BaseDependentCssResourceReference {
+
+ private static final long serialVersionUID = 1L;
+
+ public ReviewerListCssResourceReference() {
+ super(ReviewerListCssResourceReference.class, "reviewer-list.css");
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerListPanel.html b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerListPanel.html
new file mode 100644
index 0000000000..317740c6d8
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerListPanel.html
@@ -0,0 +1,30 @@
+<wicket:panel>
+ <table class="reviewers">
+ <tr wicket:id="reviewers">
+ <td class="reviewer">
+ <a wicket:id="avatar"></a> <a wicket:id="name"></a>
+ </td>
+ <td class="result">
+ <span wicket:id="result"></span>
+ </td>
+ <td class="actions">
+ <a wicket:id="withdraw" title="Withdraw this review"><i class="fa fa-undo"></i></a>
+ <a wicket:id="delete" title="Remove this reviewer"><i class="fa fa-trash"></i></a>
+ </td>
+ </tr>
+ <wicket:container wicket:id="noReviewers">
+ <tr>
+ <td class="no-reviewers" colspan="3">
+ <i>No reviewers specified</i>
+ </td>
+ </tr>
+ </wicket:container>
+ <wicket:enclosure child="addReviewer">
+ <tr>
+ <td ckass="add-reviewer" colspan="3">
+ <input wicket:id="addReviewer" type="hidden"></input>
+ </td>
+ </tr>
+ </wicket:enclosure>
+ </table>
+</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerListPanel.java b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerListPanel.java
new file mode 100644
index 0000000000..dfc131ca1f
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerListPanel.java
@@ -0,0 +1,259 @@
+package com.gitplex.server.web.component.requestreviewer;
+
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.event.Broadcast;
+import org.apache.wicket.event.IEvent;
+import org.apache.wicket.markup.head.CssHeaderItem;
+import org.apache.wicket.markup.head.IHeaderResponse;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.GenericPanel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+
+import com.gitplex.server.GitPlex;
+import com.gitplex.server.manager.MarkdownManager;
+import com.gitplex.server.manager.ReviewInvitationManager;
+import com.gitplex.server.manager.ReviewManager;
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.PullRequest;
+import com.gitplex.server.model.Review;
+import com.gitplex.server.model.ReviewInvitation;
+import com.gitplex.server.security.SecurityUtils;
+import com.gitplex.server.util.ReviewCheckStatus;
+import com.gitplex.server.web.behavior.dropdown.DropdownHover;
+import com.gitplex.server.web.component.avatar.AvatarLink;
+import com.gitplex.server.web.component.link.AccountLink;
+import com.gitplex.server.web.util.ajaxlistener.ConfirmListener;
+import com.gitplex.server.web.websocket.PullRequestChanged;
+
+@SuppressWarnings("serial")
+public class ReviewerListPanel extends GenericPanel<PullRequest> {
+
+ public ReviewerListPanel(String id, IModel<PullRequest> model) {
+ super(id, model);
+ }
+
+ private PullRequest getPullRequest() {
+ return getModelObject();
+ }
+
+ @Override
+ public void onEvent(IEvent<?> event) {
+ super.onEvent(event);
+
+ if (event.getPayload() instanceof PullRequestChanged) {
+ PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
+ pullRequestChanged.getPartialPageRequestHandler().add(this);
+ }
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ IModel<List<Account>> reviewersModel = new LoadableDetachableModel<List<Account>>() {
+
+ @Override
+ protected List<Account> load() {
+ PullRequest request = getPullRequest();
+ List<Account> reviewers = new ArrayList<>();
+
+ List<Review> reviews = new ArrayList<>(request.getReviewCheckStatus().getEffectiveReviews().values());
+ reviews.sort(Comparator.comparing(Review::getDate));
+
+ for (Review review: reviews)
+ reviewers.add(review.getUser());
+
+ for (Account awaitingReviewer: request.getReviewCheckStatus().getAwaitingReviewers())
+ reviewers.add(awaitingReviewer);
+
+ return reviewers;
+ }
+
+ };
+ add(new ListView<Account>("reviewers", reviewersModel) {
+
+ @Override
+ protected void populateItem(ListItem<Account> item) {
+ item.add(new AvatarLink("avatar", item.getModelObject()));
+ item.add(new AccountLink("name", item.getModelObject()));
+
+ PullRequest request = getPullRequest();
+ Review review = request.getReviewCheckStatus().getEffectiveReviews().get(item.getModelObject());
+
+ WebMarkupContainer result = new WebMarkupContainer("result");
+ if (review != null) {
+ if (review.isApproved()) {
+ result.add(AttributeAppender.append("class", "approved fa fa-thumbs-up"));
+ if (review.getNote() == null)
+ result.add(AttributeAppender.append("title", "Approved"));
+ } else {
+ result.add(AttributeAppender.append("class", "disapproved fa fa-thumbs-down"));
+ if (review.getNote() == null)
+ result.add(AttributeAppender.append("title", "Disapproved"));
+ }
+ String reviewNote = review.getNote();
+ if (reviewNote != null) {
+ result.add(new DropdownHover() {
+
+ @Override
+ protected Component newContent(String id) {
+ MarkdownManager markdownManager = GitPlex.getInstance(MarkdownManager.class);
+ Label label = new Label(id, markdownManager.render(reviewNote, null, true));
+ label.add(AttributeAppender.append("class", "review-note"));
+ label.setEscapeModelStrings(false);
+ return label;
+ }
+
+ });
+ }
+ } else {
+ result.add(AttributeAppender.append("class", "awaiting fa fa-clock-o"));
+ result.add(AttributeAppender.append("title", "Waiting for review"));
+ }
+ result.setVisible(!request.isNew());
+
+ item.add(result);
+
+ item.add(new AjaxLink<Void>("delete") {
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ if (!getPullRequest().isNew()) {
+ attributes.getAjaxCallListeners().add(new ConfirmListener("Do you really want to remove '"
+ + item.getModelObject().getDisplayName() + "' from reviewer list?"));
+ }
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ PullRequest request = getPullRequest();
+
+ Account reviewer = item.getModelObject();
+ ReviewInvitation invitation = null;
+ for (ReviewInvitation each: request.getReviewInvitations()) {
+ if (each.getUser().equals(reviewer)) {
+ invitation = each;
+ break;
+ }
+ }
+
+ if (invitation != null) {
+ request.clearReviewCheckStatus();
+ boolean removed;
+ if (request.isNew()) {
+ invitation.setType(ReviewInvitation.Type.EXCLUDE);
+ removed = !request.getReviewCheckStatus().getAwaitingReviewers().contains(reviewer);
+ } else {
+ removed = GitPlex.getInstance(ReviewInvitationManager.class).exclude(invitation);
+ }
+ if (!removed) {
+ getSession().warn("Reviewer '" + reviewer.getDisplayName()
+ + "' is required by branch protection setting and can not be removed");
+ }
+ reviewersModel.detach();
+
+ send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target));
+ }
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+ Account currentUser = SecurityUtils.getAccount();
+ setVisible(request.isOpen() &&
+ (currentUser != null && currentUser.equals(request.getSubmitter())
+ || SecurityUtils.canManage(request.getTargetDepot())));
+ }
+
+ });
+ item.add(new AjaxLink<Void>("withdraw") {
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.getAjaxCallListeners().add(new ConfirmListener("Do you really want to withdraw "
+ + "reviews of '" + item.getModelObject().getDisplayName() + "'?"));
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+ Account reviewer = item.getModelObject();
+ Review review = request.getReviewCheckStatus().getEffectiveReviews().get(reviewer);
+ setVisible(request.isOpen() && review != null
+ && (reviewer.equals(SecurityUtils.getAccount())
+ || SecurityUtils.canManage(request.getTargetDepot())));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ PullRequest request = getPullRequest();
+ Account reviewer = item.getModelObject();
+ request.clearReviewCheckStatus();
+ GitPlex.getInstance(ReviewManager.class).delete(reviewer, request);
+ reviewersModel.detach();
+ send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target));
+ }
+
+ });
+ }
+
+ });
+
+ add(new WebMarkupContainer("noReviewers") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ ReviewCheckStatus reviewCheckStatus = getPullRequest().getReviewCheckStatus();
+ setVisible(reviewCheckStatus.getAwaitingReviewers().isEmpty()
+ && reviewCheckStatus.getEffectiveReviews().isEmpty());
+ }
+
+ });
+
+ add(new ReviewerChoice("addReviewer", getModel()) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+ setVisible(request.isOpen() && SecurityUtils.canModify(request));
+ }
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Account user) {
+ super.onSelect(target, user);
+ send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target));
+ }
+
+ });
+
+ setOutputMarkupId(true);
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+ response.render(CssHeaderItem.forReference(new ReviewerListCssResourceReference()));
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestreviewer/ReviewerProvider.java b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerProvider.java
similarity index 90%
rename from web/src/main/java/com/gitplex/server/web/component/pullrequest/requestreviewer/ReviewerProvider.java
rename to web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerProvider.java
index 1f990bfeb8..93b0f9dbb0 100644
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requestreviewer/ReviewerProvider.java
+++ b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/ReviewerProvider.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.component.pullrequest.requestreviewer;
+package com.gitplex.server.web.component.requestreviewer;
import java.util.Iterator;
import java.util.List;
@@ -23,7 +23,7 @@ public class ReviewerProvider extends AbstractAccountChoiceProvider {
@Override
public void query(String term, int page, Response<Account> response) {
- List<Account> reviewers = requestModel.getObject().getPotentialReviewers();
+ List<Account> reviewers = requestModel.getObject().getRemainingReviewers();
for (Iterator<Account> it = reviewers.iterator(); it.hasNext();) {
Account user = it.next();
diff --git a/web/src/main/java/com/gitplex/server/web/component/requestreviewer/reviewer-list.css b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/reviewer-list.css
new file mode 100644
index 0000000000..aca300925a
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/component/requestreviewer/reviewer-list.css
@@ -0,0 +1,31 @@
+table.reviewers a {
+ color: #333;
+}
+table.reviewers>tbody>tr>td {
+ padding: 0 12px 12px 0;
+}
+table.reviewers>tbody>tr>td.result, table.reviewers>tbody>tr>td.actions {
+ font-size: 16px;
+}
+table.reviewers>tbody>tr>td.result span.awaiting {
+ color: #DCB412;
+}
+table.reviewers>tbody>tr>td.result span.approved {
+ color: #35A612;
+}
+table.reviewers>tbody>tr>td.result span.disapproved {
+ color: #F93333;
+}
+
+table.reviewers>tbody>tr:last-child>td {
+ padding-bottom: 0;
+}
+table.reviewers>tbody>tr>td.no-reviewers {
+ font-size: 16px;
+}
+table.reviewers .immediate-accept-notice .alert-warning {
+ margin-bottom: 0;
+}
+.review-note {
+ padding: 8px 8px 0 8px;
+}
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requeststatus/RequestStatusPanel.html b/web/src/main/java/com/gitplex/server/web/component/requeststatus/RequestStatusPanel.html
similarity index 100%
rename from web/src/main/java/com/gitplex/server/web/component/pullrequest/requeststatus/RequestStatusPanel.html
rename to web/src/main/java/com/gitplex/server/web/component/requeststatus/RequestStatusPanel.html
diff --git a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requeststatus/RequestStatusPanel.java b/web/src/main/java/com/gitplex/server/web/component/requeststatus/RequestStatusPanel.java
similarity index 50%
rename from web/src/main/java/com/gitplex/server/web/component/pullrequest/requeststatus/RequestStatusPanel.java
rename to web/src/main/java/com/gitplex/server/web/component/requeststatus/RequestStatusPanel.java
index 73986be261..06fbd56313 100644
--- a/web/src/main/java/com/gitplex/server/web/component/pullrequest/requeststatus/RequestStatusPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/component/requeststatus/RequestStatusPanel.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.component.pullrequest.requeststatus;
+package com.gitplex.server.web.component.requeststatus;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.markup.html.basic.Label;
@@ -7,18 +7,13 @@ import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequest.Status;
import com.gitplex.server.model.support.CloseInfo;
@SuppressWarnings("serial")
public class RequestStatusPanel extends Panel {
- private final boolean checkGateKeeper;
-
- public RequestStatusPanel(String id, IModel<PullRequest> requestModel, boolean checkGateKeeper) {
+ public RequestStatusPanel(String id, IModel<PullRequest> requestModel) {
super(id, requestModel);
-
- this.checkGateKeeper = checkGateKeeper;
}
@Override
@@ -30,15 +25,11 @@ public class RequestStatusPanel extends Panel {
@Override
public String getObject() {
PullRequest request = getPullRequest();
- if (checkGateKeeper) {
- return request.getStatus().toString();
- } else {
- CloseInfo closeInfo = request.getCloseInfo();
- if (closeInfo == null)
- return "OPEN";
- else
- return closeInfo.getCloseStatus().toString();
- }
+ CloseInfo closeInfo = request.getCloseInfo();
+ if (closeInfo == null)
+ return "OPEN";
+ else
+ return closeInfo.getCloseStatus().toString();
}
}).add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
@@ -46,23 +37,13 @@ public class RequestStatusPanel extends Panel {
@Override
public String getObject() {
PullRequest request = getPullRequest();
- if (checkGateKeeper) {
- Status status = request.getStatus();
- if (status == Status.DISCARDED)
- return "label-danger";
- else if (status == Status.INTEGRATED)
- return "label-success";
- else
- return "label-warning";
- } else {
- CloseInfo closeInfo = request.getCloseInfo();
- if (closeInfo == null)
- return "label-warning";
- else if (closeInfo.getCloseStatus() == CloseInfo.Status.INTEGRATED)
- return "label-success";
- else
- return "label-danger";
- }
+ CloseInfo closeInfo = request.getCloseInfo();
+ if (closeInfo == null)
+ return "label-warning";
+ else if (closeInfo.getCloseStatus() == CloseInfo.Status.MERGED)
+ return "label-success";
+ else
+ return "label-danger";
}
})));
diff --git a/web/src/main/java/com/gitplex/server/web/component/reviewappointment/ReviewAppointmentAssistBehavior.java b/web/src/main/java/com/gitplex/server/web/component/reviewappointment/ReviewAppointmentAssistBehavior.java
new file mode 100644
index 0000000000..529feceec1
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/component/reviewappointment/ReviewAppointmentAssistBehavior.java
@@ -0,0 +1,124 @@
+package com.gitplex.server.web.component.reviewappointment;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.model.IModel;
+
+import com.gitplex.codeassist.FenceAware;
+import com.gitplex.codeassist.InputSuggestion;
+import com.gitplex.codeassist.ParentedElement;
+import com.gitplex.codeassist.grammar.ElementSpec;
+import com.gitplex.codeassist.grammar.LexerRuleRefElementSpec;
+import com.gitplex.codeassist.grammar.RuleRefElementSpec;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.security.privilege.DepotPrivilege;
+import com.gitplex.server.util.reviewappointment.ReviewAppointmentParser;
+import com.gitplex.server.web.behavior.inputassist.ANTLRAssistBehavior;
+import com.gitplex.server.web.util.SuggestionUtils;
+
+@SuppressWarnings("serial")
+public class ReviewAppointmentAssistBehavior extends ANTLRAssistBehavior {
+
+ private final IModel<Depot> depotModel;
+
+ private static final String VALUE_OPEN = "(";
+
+ private static final String VALUE_CLOSE = ")";
+
+ public ReviewAppointmentAssistBehavior(IModel<Depot> depotModel) {
+ super(ReviewAppointmentParser.class, "expr");
+ this.depotModel = depotModel;
+ }
+
+ @Override
+ public void detach(Component component) {
+ super.detach(component);
+ depotModel.detach();
+ }
+
+ @Override
+ protected List<InputSuggestion> suggest(final ParentedElement expectedElement, String matchWith, int count) {
+ if (expectedElement.getSpec() instanceof LexerRuleRefElementSpec) {
+ LexerRuleRefElementSpec spec = (LexerRuleRefElementSpec) expectedElement.getSpec();
+ if (spec.getRuleName().equals("Value")) {
+ return new FenceAware(codeAssist.getGrammar(), VALUE_OPEN, VALUE_CLOSE) {
+
+ @Override
+ protected List<InputSuggestion> match(String unfencedMatchWith, int count) {
+ if (expectedElement.findParentByRule("userCriteria") != null) {
+ return SuggestionUtils.suggestUser(depotModel.getObject(), DepotPrivilege.READ,
+ unfencedMatchWith, count);
+ } else {
+ return SuggestionUtils.suggestTeam(depotModel.getObject(), unfencedMatchWith, count);
+ }
+ }
+
+ @Override
+ protected String getFencingDescription() {
+ return "value needs to be enclosed in brackets";
+ }
+
+ }.suggest(expectedElement.getSpec(), matchWith, count);
+ } else if (spec.getRuleName().equals("DIGIT")) {
+ List<InputSuggestion> suggestions = new ArrayList<>();
+ suggestions.add(new InputSuggestion("1", "require one review from the team", null));
+ suggestions.add(new InputSuggestion("2", "require two reviews from the team", null));
+ suggestions.add(new InputSuggestion("3", "require three reviews from the team", null));
+
+ for (Iterator<InputSuggestion> it = suggestions.iterator(); it.hasNext();) {
+ InputSuggestion suggestion = it.next();
+ if (!suggestion.getContent().startsWith(matchWith) || suggestion.getContent().equals(matchWith))
+ it.remove();
+ }
+
+ return suggestions;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected List<String> getHints(ParentedElement expectedElement, String matchWith) {
+ List<String> hints = new ArrayList<>();
+ if (expectedElement.getSpec() instanceof RuleRefElementSpec) {
+ RuleRefElementSpec spec = (RuleRefElementSpec) expectedElement.getSpec();
+ if (spec.getRuleName().equals("count")) {
+ hints.add("Specify required reviews from the team");
+ hints.add("If not specified, one review is required from the team");
+ }
+ }
+ return hints;
+ }
+
+ @Override
+ protected InputSuggestion wrapAsSuggestion(ParentedElement expectedElement, String suggestedLiteral,
+ boolean complete) {
+ String description;
+ switch (suggestedLiteral) {
+ case "all":
+ description = "require reviews from all members of the team";
+ break;
+ case ":":
+ description = "number of required reviews from the team";
+ break;
+ case " ":
+ description = "space";
+ break;
+ default:
+ description = null;
+ }
+ return new InputSuggestion(suggestedLiteral, description, null);
+ }
+
+ @Override
+ protected int getEndOfMatch(ElementSpec spec, String content) {
+ if (content.startsWith(VALUE_OPEN+VALUE_CLOSE))
+ return 2;
+ else
+ return super.getEndOfMatch(spec, content);
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/component/branchmatch/BranchMatchInput.java b/web/src/main/java/com/gitplex/server/web/component/reviewappointment/ReviewAppointmentInput.java
similarity index 73%
rename from web/src/main/java/com/gitplex/server/web/component/branchmatch/BranchMatchInput.java
rename to web/src/main/java/com/gitplex/server/web/component/reviewappointment/ReviewAppointmentInput.java
index 80513bead9..3d738c3625 100644
--- a/web/src/main/java/com/gitplex/server/web/component/branchmatch/BranchMatchInput.java
+++ b/web/src/main/java/com/gitplex/server/web/component/reviewappointment/ReviewAppointmentInput.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.component.branchmatch;
+package com.gitplex.server.web.component.reviewappointment;
import java.io.Serializable;
@@ -11,15 +11,15 @@ import org.apache.wicket.validation.IValidationError;
import org.apache.wicket.validation.IValidator;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.includeexclude.IncludeExcludeUtils;
+import com.gitplex.server.util.reviewappointment.ReviewAppointment;
@SuppressWarnings("serial")
-public class BranchMatchInput extends TextField<String> {
+public class ReviewAppointmentInput extends TextField<String> {
private final IModel<Depot> depotModel;
- public BranchMatchInput(String id, IModel<Depot> depotModel, IModel<String> branchMatchModel) {
- super(id, branchMatchModel);
+ public ReviewAppointmentInput(String id, IModel<Depot> depotModel, IModel<String> exprModel) {
+ super(id, exprModel);
this.depotModel = depotModel;
}
@@ -28,13 +28,13 @@ public class BranchMatchInput extends TextField<String> {
protected void onInitialize() {
super.onInitialize();
- add(new BranchMatchBehavior(depotModel));
+ add(new ReviewAppointmentAssistBehavior(depotModel));
add(new IValidator<String>() {
@Override
public void validate(IValidatable<String> validatable) {
try {
- IncludeExcludeUtils.parse(validatable.getValue());
+ ReviewAppointment.parse(validatable.getValue());
} catch (Exception e) {
validatable.error(new IValidationError() {
diff --git a/web/src/main/java/com/gitplex/server/web/component/revisionpicker/RevisionSelector.java b/web/src/main/java/com/gitplex/server/web/component/revisionpicker/RevisionSelector.java
index 668d1f2d97..f69f320b4b 100644
--- a/web/src/main/java/com/gitplex/server/web/component/revisionpicker/RevisionSelector.java
+++ b/web/src/main/java/com/gitplex/server/web/component/revisionpicker/RevisionSelector.java
@@ -34,7 +34,6 @@ import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.unbescape.html.HtmlEscape;
@@ -116,9 +115,8 @@ public abstract class RevisionSelector extends Panel {
this.revision = revision;
if (canCreateRef) {
Depot depot = depotModel.getObject();
- ObjectId commitId = depot.getRevCommit(revision);
- canCreateBranch = SecurityUtils.canPushRef(depot, Constants.R_HEADS, ObjectId.zeroId(), commitId);
- canCreateTag = SecurityUtils.canPushRef(depot, Constants.R_TAGS, ObjectId.zeroId(), commitId);
+ canCreateBranch = SecurityUtils.canWrite(depot);
+ canCreateTag = SecurityUtils.canCreateTag(depot, Constants.R_TAGS);
} else {
canCreateBranch = false;
canCreateTag = false;
@@ -278,15 +276,12 @@ public abstract class RevisionSelector extends Panel {
itemValues.add(COMMIT_FLAG + revInput);
} else if (branchesActive) {
if (canCreateBranch) {
- String refName = Constants.R_HEADS + revInput;
- if (SecurityUtils.canPushRef(depot, refName, ObjectId.zeroId(), depot.getRevCommit(revision))) {
+ if (SecurityUtils.canWrite(depot))
itemValues.add(ADD_FLAG + revInput);
- }
}
} else {
if (canCreateTag) {
- String refName = Constants.R_TAGS + revInput;
- if (SecurityUtils.canPushRef(depot, refName, ObjectId.zeroId(), depot.getRevCommit(revision))) {
+ if (SecurityUtils.canCreateTag(depot, revInput)) {
itemValues.add(ADD_FLAG + revInput);
}
}
diff --git a/web/src/main/java/com/gitplex/server/web/editable/EditorChanged.java b/web/src/main/java/com/gitplex/server/web/editable/EditorChanged.java
index 39e658464e..8bcc46b27d 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/EditorChanged.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/EditorChanged.java
@@ -2,9 +2,9 @@ package com.gitplex.server.web.editable;
import org.apache.wicket.ajax.AjaxRequestTarget;
-import com.gitplex.server.web.util.AjaxEvent;
+import com.gitplex.server.web.util.AjaxPayload;
-public class EditorChanged extends AjaxEvent {
+public class EditorChanged extends AjaxPayload {
public EditorChanged(AjaxRequestTarget target) {
super(target);
diff --git a/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountEditSupport.java b/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountEditSupport.java
index 60309d1901..1df033625e 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountEditSupport.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountEditSupport.java
@@ -56,7 +56,7 @@ public class AccountEditSupport implements EditSupport {
@Override
public PropertyEditor<List<String>> renderForEdit(String componentId, IModel<List<String>> model) {
- return new AccountMultiChoiceEditor(componentId, this, model, accountChoice.organization());
+ return new AccountMultiChoiceEditor(componentId, this, model, accountChoice.type());
}
};
@@ -81,7 +81,7 @@ public class AccountEditSupport implements EditSupport {
@Override
public PropertyEditor<String> renderForEdit(String componentId, IModel<String> model) {
- return new AccountSingleChoiceEditor(componentId, this, model, accountChoice.organization());
+ return new AccountSingleChoiceEditor(componentId, this, model, accountChoice.type());
}
};
diff --git a/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountMultiChoiceEditor.java b/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountMultiChoiceEditor.java
index b007a3e100..be99dba92b 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountMultiChoiceEditor.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountMultiChoiceEditor.java
@@ -12,6 +12,7 @@ import org.apache.wicket.util.convert.ConversionException;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.model.Account;
+import com.gitplex.server.util.editable.annotation.AccountChoice;
import com.gitplex.server.web.component.accountchoice.AccountChoiceProvider;
import com.gitplex.server.web.component.accountchoice.AccountMultiChoice;
import com.gitplex.server.web.editable.ErrorContext;
@@ -24,12 +25,12 @@ public class AccountMultiChoiceEditor extends PropertyEditor<List<String>> {
private AccountMultiChoice input;
- private final boolean organization;
+ private final AccountChoice.Type type;
public AccountMultiChoiceEditor(String id, PropertyDescriptor propertyDescriptor,
- IModel<List<String>> propertyModel, boolean organization) {
+ IModel<List<String>> propertyModel, AccountChoice.Type type) {
super(id, propertyDescriptor, propertyModel);
- this.organization = organization;
+ this.type = type;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@@ -47,7 +48,7 @@ public class AccountMultiChoiceEditor extends PropertyEditor<List<String>> {
}
}
- input = new AccountMultiChoice("input", new Model((Serializable)accounts), new AccountChoiceProvider(organization));
+ input = new AccountMultiChoice("input", new Model((Serializable)accounts), new AccountChoiceProvider(type));
input.setConvertEmptyInputStringToNull(true);
add(input);
diff --git a/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountSingleChoiceEditor.java b/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountSingleChoiceEditor.java
index a61707380c..5479f04f74 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountSingleChoiceEditor.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/accountchoice/AccountSingleChoiceEditor.java
@@ -7,6 +7,7 @@ import org.apache.wicket.util.convert.ConversionException;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.model.Account;
+import com.gitplex.server.util.editable.annotation.AccountChoice;
import com.gitplex.server.web.component.accountchoice.AccountChoiceProvider;
import com.gitplex.server.web.component.accountchoice.AccountSingleChoice;
import com.gitplex.server.web.editable.ErrorContext;
@@ -19,12 +20,12 @@ public class AccountSingleChoiceEditor extends PropertyEditor<String> {
private AccountSingleChoice input;
- private boolean organization;
+ private AccountChoice.Type type;
public AccountSingleChoiceEditor(String id, PropertyDescriptor propertyDescriptor,
- IModel<String> propertyModel, boolean organization) {
+ IModel<String> propertyModel, AccountChoice.Type type) {
super(id, propertyDescriptor, propertyModel);
- this.organization = organization;
+ this.type = type;
}
@Override
@@ -37,7 +38,7 @@ public class AccountSingleChoiceEditor extends PropertyEditor<String> {
else
account = null;
- input = new AccountSingleChoice("input", Model.of(account), new AccountChoiceProvider(organization));
+ input = new AccountSingleChoice("input", Model.of(account), new AccountChoiceProvider(type));
input.setConvertEmptyInputStringToNull(true);
// add this to control allowClear flag of select2
diff --git a/web/src/main/java/com/gitplex/server/web/editable/refmatch/RefMatchEditSupport.java b/web/src/main/java/com/gitplex/server/web/editable/branchpattern/BranchPatternEditSupport.java
similarity index 81%
rename from web/src/main/java/com/gitplex/server/web/editable/refmatch/RefMatchEditSupport.java
rename to web/src/main/java/com/gitplex/server/web/editable/branchpattern/BranchPatternEditSupport.java
index 1a72fa2c91..27069929f3 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/refmatch/RefMatchEditSupport.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/branchpattern/BranchPatternEditSupport.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.editable.refmatch;
+package com.gitplex.server.web.editable.branchpattern;
import java.lang.reflect.Method;
import java.util.Set;
@@ -7,7 +7,7 @@ import org.apache.wicket.Component;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
-import com.gitplex.server.util.editable.annotation.RefMatch;
+import com.gitplex.server.util.editable.annotation.BranchPattern;
import com.gitplex.server.web.editable.BeanContext;
import com.gitplex.server.web.editable.EditSupport;
import com.gitplex.server.web.editable.NotDefinedLabel;
@@ -17,7 +17,7 @@ import com.gitplex.server.web.editable.PropertyEditor;
import com.gitplex.server.web.editable.PropertyViewer;
@SuppressWarnings("serial")
-public class RefMatchEditSupport implements EditSupport {
+public class BranchPatternEditSupport implements EditSupport {
@Override
public BeanContext<?> getBeanEditContext(Class<?> beanClass, Set<String> excludeProperties) {
@@ -28,9 +28,9 @@ public class RefMatchEditSupport implements EditSupport {
public PropertyContext<?> getPropertyEditContext(Class<?> beanClass, String propertyName) {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(beanClass, propertyName);
Method propertyGetter = propertyDescriptor.getPropertyGetter();
- if (propertyGetter.getAnnotation(RefMatch.class) != null) {
+ if (propertyGetter.getAnnotation(BranchPattern.class) != null) {
if (propertyGetter.getReturnType() != String.class) {
- throw new RuntimeException("Annotation 'RefMatch' should be applied to property "
+ throw new RuntimeException("Annotation 'BranchPattern' should be applied to property "
+ "with type 'String'.");
}
return new PropertyContext<String>(propertyDescriptor) {
@@ -54,7 +54,7 @@ public class RefMatchEditSupport implements EditSupport {
@Override
public PropertyEditor<String> renderForEdit(String componentId, IModel<String> model) {
- return new RefMatchEditor(componentId, this, model);
+ return new BranchPatternEditor(componentId, this, model);
}
};
diff --git a/web/src/main/java/com/gitplex/server/web/editable/branchmatch/BranchMatchEditor.html b/web/src/main/java/com/gitplex/server/web/editable/branchpattern/BranchPatternEditor.html
similarity index 100%
rename from web/src/main/java/com/gitplex/server/web/editable/branchmatch/BranchMatchEditor.html
rename to web/src/main/java/com/gitplex/server/web/editable/branchpattern/BranchPatternEditor.html
diff --git a/web/src/main/java/com/gitplex/server/web/editable/fullbranchmatch/FullBranchMatchEditor.java b/web/src/main/java/com/gitplex/server/web/editable/branchpattern/BranchPatternEditor.java
similarity index 69%
rename from web/src/main/java/com/gitplex/server/web/editable/fullbranchmatch/FullBranchMatchEditor.java
rename to web/src/main/java/com/gitplex/server/web/editable/branchpattern/BranchPatternEditor.java
index d9cfab9f5e..eecd5ddf9f 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/fullbranchmatch/FullBranchMatchEditor.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/branchpattern/BranchPatternEditor.java
@@ -1,13 +1,14 @@
-package com.gitplex.server.web.editable.fullbranchmatch;
+package com.gitplex.server.web.editable.branchpattern;
import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.convert.ConversionException;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.web.component.fullbranchmatch.FullBranchMatchInput;
+import com.gitplex.server.web.behavior.BranchPatternAssistBehavior;
import com.gitplex.server.web.editable.ErrorContext;
import com.gitplex.server.web.editable.PathSegment;
import com.gitplex.server.web.editable.PropertyDescriptor;
@@ -15,11 +16,11 @@ import com.gitplex.server.web.editable.PropertyEditor;
import com.gitplex.server.web.page.depot.DepotPage;
@SuppressWarnings("serial")
-public class FullBranchMatchEditor extends PropertyEditor<String> {
+public class BranchPatternEditor extends PropertyEditor<String> {
- private FullBranchMatchInput input;
+ private TextField<String> input;
- public FullBranchMatchEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
+ public BranchPatternEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -27,14 +28,15 @@ public class FullBranchMatchEditor extends PropertyEditor<String> {
protected void onInitialize() {
super.onInitialize();
- input = new FullBranchMatchInput("input", new AbstractReadOnlyModel<Depot>() {
+ input = new TextField<String>("input", getModel());
+ input.add(new BranchPatternAssistBehavior(new AbstractReadOnlyModel<Depot>() {
@Override
public Depot getObject() {
- return ((DepotPage) getPage()).getDepot();
+ return ((DepotPage)getPage()).getDepot();
}
- }, getModel());
+ }));
add(input);
diff --git a/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.html b/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.html
index e8960f21c8..b9a1db1e0e 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.html
+++ b/web/src/main/java/com/gitplex/server/web/editable/list/concrete/ConcreteListPropertyEditor.html
@@ -22,14 +22,14 @@
<div wicket:id="feedback"></div>
</td>
<td class="actions">
- <a wicket:id="deleteElement" title="Delete this element"><span class="delete icon"></span></a>
- <span class="handle move icon" title="Drag to reorder elements"></span>
+ <a wicket:id="deleteElement" title="Delete this element"><span class="fa fa-trash delete"></span></a>
+ <span class="handle fa fa-arrows" title="Drag to reorder elements"></span>
</td>
</tr>
</tbody>
<tfoot>
<tr class="add-element">
- <td wicket:id="newRow" class="add-element"><a wicket:id="addElement" title="Add new element"><span class="add icon"></span></a></td>
+ <td wicket:id="newRow" class="add-element"><a wicket:id="addElement" title="Add new element"><span class="fa fa-plus-circle add"></span></a></td>
</tr>
</tfoot>
</table>
diff --git a/web/src/main/java/com/gitplex/server/web/editable/branchmatch/BranchMatchEditSupport.java b/web/src/main/java/com/gitplex/server/web/editable/pathpattern/PathPatternEditSupport.java
similarity index 83%
rename from web/src/main/java/com/gitplex/server/web/editable/branchmatch/BranchMatchEditSupport.java
rename to web/src/main/java/com/gitplex/server/web/editable/pathpattern/PathPatternEditSupport.java
index 229f59fa5f..bcb4698598 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/branchmatch/BranchMatchEditSupport.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/pathpattern/PathPatternEditSupport.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.editable.branchmatch;
+package com.gitplex.server.web.editable.pathpattern;
import java.lang.reflect.Method;
import java.util.Set;
@@ -7,7 +7,7 @@ import org.apache.wicket.Component;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
-import com.gitplex.server.util.editable.annotation.BranchMatch;
+import com.gitplex.server.util.editable.annotation.PathPattern;
import com.gitplex.server.web.editable.BeanContext;
import com.gitplex.server.web.editable.EditSupport;
import com.gitplex.server.web.editable.NotDefinedLabel;
@@ -17,7 +17,7 @@ import com.gitplex.server.web.editable.PropertyEditor;
import com.gitplex.server.web.editable.PropertyViewer;
@SuppressWarnings("serial")
-public class BranchMatchEditSupport implements EditSupport {
+public class PathPatternEditSupport implements EditSupport {
@Override
public BeanContext<?> getBeanEditContext(Class<?> beanClass, Set<String> excludeProperties) {
@@ -28,9 +28,9 @@ public class BranchMatchEditSupport implements EditSupport {
public PropertyContext<?> getPropertyEditContext(Class<?> beanClass, String propertyName) {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(beanClass, propertyName);
Method propertyGetter = propertyDescriptor.getPropertyGetter();
- if (propertyGetter.getAnnotation(BranchMatch.class) != null) {
+ if (propertyGetter.getAnnotation(PathPattern.class) != null) {
if (propertyGetter.getReturnType() != String.class) {
- throw new RuntimeException("Annotation 'BranchMatch' should be applied to property "
+ throw new RuntimeException("Annotation 'PathPattern' should be applied to property "
+ "with type 'String'.");
}
return new PropertyContext<String>(propertyDescriptor) {
@@ -54,7 +54,7 @@ public class BranchMatchEditSupport implements EditSupport {
@Override
public PropertyEditor<String> renderForEdit(String componentId, IModel<String> model) {
- return new BranchMatchEditor(componentId, this, model);
+ return new PathPatternEditor(componentId, this, model);
}
};
diff --git a/web/src/main/java/com/gitplex/server/web/editable/fullbranchmatch/FullBranchMatchEditor.html b/web/src/main/java/com/gitplex/server/web/editable/pathpattern/PathPatternEditor.html
similarity index 100%
rename from web/src/main/java/com/gitplex/server/web/editable/fullbranchmatch/FullBranchMatchEditor.html
rename to web/src/main/java/com/gitplex/server/web/editable/pathpattern/PathPatternEditor.html
diff --git a/web/src/main/java/com/gitplex/server/web/editable/pathmatch/PathMatchEditor.java b/web/src/main/java/com/gitplex/server/web/editable/pathpattern/PathPatternEditor.java
similarity index 71%
rename from web/src/main/java/com/gitplex/server/web/editable/pathmatch/PathMatchEditor.java
rename to web/src/main/java/com/gitplex/server/web/editable/pathpattern/PathPatternEditor.java
index e9509fda7d..06a8ec3c45 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/pathmatch/PathMatchEditor.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/pathpattern/PathPatternEditor.java
@@ -1,13 +1,14 @@
-package com.gitplex.server.web.editable.pathmatch;
+package com.gitplex.server.web.editable.pathpattern;
import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.convert.ConversionException;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.web.component.pathmatch.PathMatchInput;
+import com.gitplex.server.web.behavior.PathPatternAssistBehavior;
import com.gitplex.server.web.editable.ErrorContext;
import com.gitplex.server.web.editable.PathSegment;
import com.gitplex.server.web.editable.PropertyDescriptor;
@@ -15,11 +16,11 @@ import com.gitplex.server.web.editable.PropertyEditor;
import com.gitplex.server.web.page.depot.DepotPage;
@SuppressWarnings("serial")
-public class PathMatchEditor extends PropertyEditor<String> {
+public class PathPatternEditor extends PropertyEditor<String> {
- private PathMatchInput input;
+ private TextField<String> input;
- public PathMatchEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
+ public PathPatternEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -27,14 +28,15 @@ public class PathMatchEditor extends PropertyEditor<String> {
protected void onInitialize() {
super.onInitialize();
- input = new PathMatchInput("input", new AbstractReadOnlyModel<Depot>() {
+ input = new TextField<String>("input", getModel());
+ input.add(new PathPatternAssistBehavior(new AbstractReadOnlyModel<Depot>() {
@Override
public Depot getObject() {
return ((DepotPage) getPage()).getDepot();
}
- }, getModel());
+ }));
add(input);
diff --git a/web/src/main/java/com/gitplex/server/web/editable/reflection/ReflectionBeanEditor.java b/web/src/main/java/com/gitplex/server/web/editable/reflection/ReflectionBeanEditor.java
index fb382a8b6d..60085b412a 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/reflection/ReflectionBeanEditor.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/reflection/ReflectionBeanEditor.java
@@ -85,10 +85,12 @@ public class ReflectionBeanEditor extends BeanEditor<Serializable> {
nameLabel.setVisible(false);
String required;
- if (propertyContext.isPropertyRequired() && propertyContext.getPropertyClass() != boolean.class)
+ if (propertyContext.isPropertyRequired() && propertyContext.getPropertyClass() != boolean.class
+ && propertyContext.getPropertyClass() != List.class) {
required = "*";
- else
+ } else {
required = "&nbsp;";
+ }
item.add(new Label("required", required).setEscapeModelStrings(false));
diff --git a/web/src/main/java/com/gitplex/server/web/editable/fullbranchmatch/FullBranchMatchEditSupport.java b/web/src/main/java/com/gitplex/server/web/editable/reviewappointment/ReviewAppointmentEditSupport.java
similarity index 75%
rename from web/src/main/java/com/gitplex/server/web/editable/fullbranchmatch/FullBranchMatchEditSupport.java
rename to web/src/main/java/com/gitplex/server/web/editable/reviewappointment/ReviewAppointmentEditSupport.java
index ccbf933419..14f70e69a3 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/fullbranchmatch/FullBranchMatchEditSupport.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/reviewappointment/ReviewAppointmentEditSupport.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.editable.fullbranchmatch;
+package com.gitplex.server.web.editable.reviewappointment;
import java.lang.reflect.Method;
import java.util.Set;
@@ -7,7 +7,7 @@ import org.apache.wicket.Component;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
-import com.gitplex.server.util.editable.annotation.FullBranchMatch;
+import com.gitplex.server.util.editable.annotation.ReviewAppointment;
import com.gitplex.server.web.editable.BeanContext;
import com.gitplex.server.web.editable.EditSupport;
import com.gitplex.server.web.editable.NotDefinedLabel;
@@ -17,7 +17,7 @@ import com.gitplex.server.web.editable.PropertyEditor;
import com.gitplex.server.web.editable.PropertyViewer;
@SuppressWarnings("serial")
-public class FullBranchMatchEditSupport implements EditSupport {
+public class ReviewAppointmentEditSupport implements EditSupport {
@Override
public BeanContext<?> getBeanEditContext(Class<?> beanClass, Set<String> excludeProperties) {
@@ -28,9 +28,9 @@ public class FullBranchMatchEditSupport implements EditSupport {
public PropertyContext<?> getPropertyEditContext(Class<?> beanClass, String propertyName) {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(beanClass, propertyName);
Method propertyGetter = propertyDescriptor.getPropertyGetter();
- if (propertyGetter.getAnnotation(FullBranchMatch.class) != null) {
+ if (propertyGetter.getAnnotation(ReviewAppointment.class) != null) {
if (propertyGetter.getReturnType() != String.class) {
- throw new RuntimeException("Annotation 'FullBranchMatch' should be applied to property "
+ throw new RuntimeException("Annotation 'ReviewAppointment' should be applied to property "
+ "with type 'String'.");
}
return new PropertyContext<String>(propertyDescriptor) {
@@ -41,9 +41,9 @@ public class FullBranchMatchEditSupport implements EditSupport {
@Override
protected Component newContent(String id, PropertyDescriptor propertyDescriptor) {
- String refMatch = model.getObject();
- if (refMatch != null) {
- return new Label(id, refMatch);
+ String expr = model.getObject();
+ if (expr != null) {
+ return new Label(id, expr);
} else {
return new NotDefinedLabel(id);
}
@@ -54,7 +54,7 @@ public class FullBranchMatchEditSupport implements EditSupport {
@Override
public PropertyEditor<String> renderForEdit(String componentId, IModel<String> model) {
- return new FullBranchMatchEditor(componentId, this, model);
+ return new ReviewAppointmentEditor(componentId, this, model);
}
};
diff --git a/web/src/main/java/com/gitplex/server/web/editable/pathmatch/PathMatchEditor.html b/web/src/main/java/com/gitplex/server/web/editable/reviewappointment/ReviewAppointmentEditor.html
similarity index 100%
rename from web/src/main/java/com/gitplex/server/web/editable/pathmatch/PathMatchEditor.html
rename to web/src/main/java/com/gitplex/server/web/editable/reviewappointment/ReviewAppointmentEditor.html
diff --git a/web/src/main/java/com/gitplex/server/web/editable/branchmatch/BranchMatchEditor.java b/web/src/main/java/com/gitplex/server/web/editable/reviewappointment/ReviewAppointmentEditor.java
similarity index 74%
rename from web/src/main/java/com/gitplex/server/web/editable/branchmatch/BranchMatchEditor.java
rename to web/src/main/java/com/gitplex/server/web/editable/reviewappointment/ReviewAppointmentEditor.java
index eec13c3251..cfc9763637 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/branchmatch/BranchMatchEditor.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/reviewappointment/ReviewAppointmentEditor.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.editable.branchmatch;
+package com.gitplex.server.web.editable.reviewappointment;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.model.AbstractReadOnlyModel;
@@ -7,7 +7,7 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.convert.ConversionException;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.web.component.branchmatch.BranchMatchInput;
+import com.gitplex.server.web.component.reviewappointment.ReviewAppointmentInput;
import com.gitplex.server.web.editable.ErrorContext;
import com.gitplex.server.web.editable.PathSegment;
import com.gitplex.server.web.editable.PropertyDescriptor;
@@ -15,11 +15,11 @@ import com.gitplex.server.web.editable.PropertyEditor;
import com.gitplex.server.web.page.depot.DepotPage;
@SuppressWarnings("serial")
-public class BranchMatchEditor extends PropertyEditor<String> {
+public class ReviewAppointmentEditor extends PropertyEditor<String> {
- private BranchMatchInput input;
+ private ReviewAppointmentInput input;
- public BranchMatchEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
+ public ReviewAppointmentEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -27,7 +27,7 @@ public class BranchMatchEditor extends PropertyEditor<String> {
protected void onInitialize() {
super.onInitialize();
- input = new BranchMatchInput("input", new AbstractReadOnlyModel<Depot>() {
+ input = new ReviewAppointmentInput("input", new AbstractReadOnlyModel<Depot>() {
@Override
public Depot getObject() {
diff --git a/web/src/main/java/com/gitplex/server/web/editable/string/StringEditSupport.java b/web/src/main/java/com/gitplex/server/web/editable/string/StringEditSupport.java
index 621df57bcb..befab75785 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/string/StringEditSupport.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/string/StringEditSupport.java
@@ -7,9 +7,14 @@ import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
+import com.gitplex.server.util.editable.annotation.AccountChoice;
+import com.gitplex.server.util.editable.annotation.BranchPattern;
import com.gitplex.server.util.editable.annotation.Markdown;
import com.gitplex.server.util.editable.annotation.Multiline;
import com.gitplex.server.util.editable.annotation.Password;
+import com.gitplex.server.util.editable.annotation.PathPattern;
+import com.gitplex.server.util.editable.annotation.TagPattern;
+import com.gitplex.server.util.editable.annotation.TeamChoice;
import com.gitplex.server.web.component.MultilineLabel;
import com.gitplex.server.web.component.markdown.MarkdownViewer;
import com.gitplex.server.web.editable.BeanContext;
@@ -33,7 +38,13 @@ public class StringEditSupport implements EditSupport {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(beanClass, propertyName);
Class<?> propertyClass = propertyDescriptor.getPropertyGetter().getReturnType();
- if (propertyClass == String.class && propertyDescriptor.getPropertyGetter().getAnnotation(Password.class) == null) {
+ if (propertyClass == String.class
+ && propertyDescriptor.getPropertyGetter().getAnnotation(Password.class) == null
+ && propertyDescriptor.getPropertyGetter().getAnnotation(BranchPattern.class) == null
+ && propertyDescriptor.getPropertyGetter().getAnnotation(TagPattern.class) == null
+ && propertyDescriptor.getPropertyGetter().getAnnotation(TeamChoice.class) == null
+ && propertyDescriptor.getPropertyGetter().getAnnotation(AccountChoice.class) == null
+ && propertyDescriptor.getPropertyGetter().getAnnotation(PathPattern.class) == null) {
return new PropertyContext<String>(propertyDescriptor) {
@Override
diff --git a/web/src/main/java/com/gitplex/server/web/editable/pathmatch/PathMatchEditSupport.java b/web/src/main/java/com/gitplex/server/web/editable/tagpattern/TagPatternEditSupport.java
similarity index 82%
rename from web/src/main/java/com/gitplex/server/web/editable/pathmatch/PathMatchEditSupport.java
rename to web/src/main/java/com/gitplex/server/web/editable/tagpattern/TagPatternEditSupport.java
index e1d3da8cd2..4b1b84a538 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/pathmatch/PathMatchEditSupport.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/tagpattern/TagPatternEditSupport.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.editable.pathmatch;
+package com.gitplex.server.web.editable.tagpattern;
import java.lang.reflect.Method;
import java.util.Set;
@@ -7,7 +7,7 @@ import org.apache.wicket.Component;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.IModel;
-import com.gitplex.server.util.editable.annotation.PathMatch;
+import com.gitplex.server.util.editable.annotation.TagPattern;
import com.gitplex.server.web.editable.BeanContext;
import com.gitplex.server.web.editable.EditSupport;
import com.gitplex.server.web.editable.NotDefinedLabel;
@@ -17,7 +17,7 @@ import com.gitplex.server.web.editable.PropertyEditor;
import com.gitplex.server.web.editable.PropertyViewer;
@SuppressWarnings("serial")
-public class PathMatchEditSupport implements EditSupport {
+public class TagPatternEditSupport implements EditSupport {
@Override
public BeanContext<?> getBeanEditContext(Class<?> beanClass, Set<String> excludeProperties) {
@@ -28,9 +28,9 @@ public class PathMatchEditSupport implements EditSupport {
public PropertyContext<?> getPropertyEditContext(Class<?> beanClass, String propertyName) {
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(beanClass, propertyName);
Method propertyGetter = propertyDescriptor.getPropertyGetter();
- if (propertyGetter.getAnnotation(PathMatch.class) != null) {
+ if (propertyGetter.getAnnotation(TagPattern.class) != null) {
if (propertyGetter.getReturnType() != String.class) {
- throw new RuntimeException("Annotation 'PathMatch' should be applied to property "
+ throw new RuntimeException("Annotation 'TagPattern' should be applied to property "
+ "with type 'String'.");
}
return new PropertyContext<String>(propertyDescriptor) {
@@ -54,7 +54,7 @@ public class PathMatchEditSupport implements EditSupport {
@Override
public PropertyEditor<String> renderForEdit(String componentId, IModel<String> model) {
- return new PathMatchEditor(componentId, this, model);
+ return new TagPatternEditor(componentId, this, model);
}
};
diff --git a/web/src/main/java/com/gitplex/server/web/editable/refmatch/RefMatchEditor.html b/web/src/main/java/com/gitplex/server/web/editable/tagpattern/TagPatternEditor.html
similarity index 100%
rename from web/src/main/java/com/gitplex/server/web/editable/refmatch/RefMatchEditor.html
rename to web/src/main/java/com/gitplex/server/web/editable/tagpattern/TagPatternEditor.html
diff --git a/web/src/main/java/com/gitplex/server/web/editable/refmatch/RefMatchEditor.java b/web/src/main/java/com/gitplex/server/web/editable/tagpattern/TagPatternEditor.java
similarity index 71%
rename from web/src/main/java/com/gitplex/server/web/editable/refmatch/RefMatchEditor.java
rename to web/src/main/java/com/gitplex/server/web/editable/tagpattern/TagPatternEditor.java
index 5dda9b3f51..4f7b0838eb 100644
--- a/web/src/main/java/com/gitplex/server/web/editable/refmatch/RefMatchEditor.java
+++ b/web/src/main/java/com/gitplex/server/web/editable/tagpattern/TagPatternEditor.java
@@ -1,13 +1,14 @@
-package com.gitplex.server.web.editable.refmatch;
+package com.gitplex.server.web.editable.tagpattern;
import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.util.convert.ConversionException;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.web.component.refmatch.RefMatchInput;
+import com.gitplex.server.web.behavior.TagPatternAssistBehavior;
import com.gitplex.server.web.editable.ErrorContext;
import com.gitplex.server.web.editable.PathSegment;
import com.gitplex.server.web.editable.PropertyDescriptor;
@@ -15,11 +16,11 @@ import com.gitplex.server.web.editable.PropertyEditor;
import com.gitplex.server.web.page.depot.DepotPage;
@SuppressWarnings("serial")
-public class RefMatchEditor extends PropertyEditor<String> {
+public class TagPatternEditor extends PropertyEditor<String> {
- private RefMatchInput input;
+ private TextField<String> input;
- public RefMatchEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
+ public TagPatternEditor(String id, PropertyDescriptor propertyDescriptor, IModel<String> propertyModel) {
super(id, propertyDescriptor, propertyModel);
}
@@ -27,14 +28,16 @@ public class RefMatchEditor extends PropertyEditor<String> {
protected void onInitialize() {
super.onInitialize();
- input = new RefMatchInput("input", new AbstractReadOnlyModel<Depot>() {
+ input = new TextField<String>("input", getModel());
+
+ input.add(new TagPatternAssistBehavior(new AbstractReadOnlyModel<Depot>() {
@Override
public Depot getObject() {
return ((DepotPage) getPage()).getDepot();
}
- }, getModel());
+ }));
add(input);
diff --git a/web/src/main/java/com/gitplex/server/web/page/account/AccountLayoutPage.java b/web/src/main/java/com/gitplex/server/web/page/account/AccountLayoutPage.java
index 2e080f57fa..c5c6d5b858 100644
--- a/web/src/main/java/com/gitplex/server/web/page/account/AccountLayoutPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/account/AccountLayoutPage.java
@@ -54,7 +54,7 @@ public abstract class AccountLayoutPage extends AccountPage {
avatarLink.setEnabled(false);
}
add(avatarLink);
- avatarLink.add(new Avatar("avatar", accountModel.getObject(), null));
+ avatarLink.add(new Avatar("avatar", accountModel.getObject()));
List<PageTab> tabs = new ArrayList<>();
diff --git a/web/src/main/java/com/gitplex/server/web/page/account/members/NonMemberChoiceProvider.java b/web/src/main/java/com/gitplex/server/web/page/account/members/NonMemberChoiceProvider.java
index fce4016634..75e4e00e8d 100644
--- a/web/src/main/java/com/gitplex/server/web/page/account/members/NonMemberChoiceProvider.java
+++ b/web/src/main/java/com/gitplex/server/web/page/account/members/NonMemberChoiceProvider.java
@@ -16,6 +16,7 @@ import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.OrganizationMembership;
import com.gitplex.server.persistence.dao.EntityCriteria;
+import com.gitplex.server.util.editable.annotation.AccountChoice;
import com.gitplex.server.web.WebConstants;
import com.gitplex.server.web.component.accountchoice.AccountChoiceProvider;
import com.gitplex.server.web.component.select2.Response;
@@ -28,7 +29,7 @@ public class NonMemberChoiceProvider extends AccountChoiceProvider {
private final IModel<Account> organizationModel;
public NonMemberChoiceProvider(IModel<Account> organizationModel) {
- super(false);
+ super(AccountChoice.Type.USER);
this.organizationModel = organizationModel;
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/account/tasks/TaskListPage.html b/web/src/main/java/com/gitplex/server/web/page/account/tasks/TaskListPage.html
index 3928e604ec..24ea05fa9a 100644
--- a/web/src/main/java/com/gitplex/server/web/page/account/tasks/TaskListPage.html
+++ b/web/src/main/java/com/gitplex/server/web/page/account/tasks/TaskListPage.html
@@ -8,7 +8,7 @@
</div>
</wicket:enclosure>
</div>
- <wicket:fragment wicket:id="requestFrag">
+ <wicket:fragment wicket:id="linkFrag">
<a wicket:id="link"></a>
</wicket:fragment>
</wicket:extend>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/account/tasks/TaskListPage.java b/web/src/main/java/com/gitplex/server/web/page/account/tasks/TaskListPage.java
index 6d1515e1bb..d11970d2ca 100644
--- a/web/src/main/java/com/gitplex/server/web/page/account/tasks/TaskListPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/account/tasks/TaskListPage.java
@@ -9,7 +9,6 @@ import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColu
import org.apache.wicket.extensions.markup.html.repeater.data.table.DataTable;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
-import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
@@ -68,6 +67,7 @@ public class TaskListPage extends AccountLayoutPage {
selectionColumn = new SelectionColumn<PullRequestTask, String>();
if (getAccount().equals(getLoginUser()))
columns.add(selectionColumn);
+
columns.add(new AbstractColumn<PullRequestTask, String>(Model.of("Pull Request"), "request") {
@Override
@@ -75,7 +75,7 @@ public class TaskListPage extends AccountLayoutPage {
Item<ICellPopulator<PullRequestTask>> cellItem,
String componentId, IModel<PullRequestTask> rowModel) {
PullRequestTask task = rowModel.getObject();
- Fragment fragment = new Fragment(componentId, "requestFrag", TaskListPage.this);
+ Fragment fragment = new Fragment(componentId, "linkFrag", TaskListPage.this);
fragment.add(new ViewStateAwarePageLink<Void>("link", RequestOverviewPage.class,
RequestOverviewPage.paramsOf(task.getRequest())) {
@@ -89,26 +89,20 @@ public class TaskListPage extends AccountLayoutPage {
}
});
- columns.add(new AbstractColumn<PullRequestTask, String>(Model.of("To Branch")) {
+ columns.add(new AbstractColumn<PullRequestTask, String>(Model.of("Target Branch")) {
@Override
public void populateItem(
Item<ICellPopulator<PullRequestTask>> cellItem,
String componentId, IModel<PullRequestTask> rowModel) {
PullRequest request = rowModel.getObject().getRequest();
- cellItem.add(new BranchLink(componentId, request.getTarget()) {
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
- tag.setName("a");
- }
-
- });
+ Fragment fragment = new Fragment(componentId, "linkFrag", TaskListPage.this);
+ fragment.add(new BranchLink("link", request.getTarget()));
+ cellItem.add(fragment);
}
});
- columns.add(new AbstractColumn<PullRequestTask, String>(Model.of("From Branch")) {
+ columns.add(new AbstractColumn<PullRequestTask, String>(Model.of("Source Branch")) {
@Override
public void populateItem(
@@ -116,22 +110,16 @@ public class TaskListPage extends AccountLayoutPage {
String componentId, IModel<PullRequestTask> rowModel) {
PullRequest request = rowModel.getObject().getRequest();
if (request.getSource() != null) {
- cellItem.add(new BranchLink(componentId, request.getSource()) {
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
- tag.setName("a");
- }
-
- });
+ Fragment fragment = new Fragment(componentId, "linkFrag", TaskListPage.this);
+ fragment.add(new BranchLink("link", request.getSource()));
+ cellItem.add(fragment);
} else {
cellItem.add(new Label(componentId, request.getSource().getFQN()));
}
}
});
- columns.add(new AbstractColumn<PullRequestTask, String>(Model.of("Type"), "type") {
+ columns.add(new AbstractColumn<PullRequestTask, String>(Model.of("Task"), "type") {
@Override
public void populateItem(
diff --git a/web/src/main/java/com/gitplex/server/web/page/account/teams/MemberChoiceProvider.java b/web/src/main/java/com/gitplex/server/web/page/account/teams/MemberChoiceProvider.java
index e4389f21cb..92572f09cd 100644
--- a/web/src/main/java/com/gitplex/server/web/page/account/teams/MemberChoiceProvider.java
+++ b/web/src/main/java/com/gitplex/server/web/page/account/teams/MemberChoiceProvider.java
@@ -7,6 +7,7 @@ import org.apache.wicket.model.IModel;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.OrganizationMembership;
+import com.gitplex.server.util.editable.annotation.AccountChoice;
import com.gitplex.server.web.WebConstants;
import com.gitplex.server.web.component.accountchoice.AccountChoiceProvider;
import com.gitplex.server.web.component.select2.Response;
@@ -18,7 +19,7 @@ public class MemberChoiceProvider extends AccountChoiceProvider {
private final IModel<Account> organizationModel;
public MemberChoiceProvider(IModel<Account> organizationModel) {
- super(false);
+ super(AccountChoice.Type.USER);
this.organizationModel = organizationModel;
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/account/teams/TeamDepotListPage.java b/web/src/main/java/com/gitplex/server/web/page/account/teams/TeamDepotListPage.java
index 9914a43565..74b1ecf70b 100644
--- a/web/src/main/java/com/gitplex/server/web/page/account/teams/TeamDepotListPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/account/teams/TeamDepotListPage.java
@@ -46,7 +46,7 @@ import com.gitplex.server.web.component.privilegeselection.PrivilegeSelectionPan
import com.gitplex.server.web.component.select2.Response;
import com.gitplex.server.web.component.select2.ResponseFiller;
import com.gitplex.server.web.component.select2.SelectToAddChoice;
-import com.gitplex.server.web.page.depot.setting.authorization.DepotTeamListPage;
+import com.gitplex.server.web.page.depot.setting.authorization.DepotTeamAuthorizationPage;
import com.gitplex.server.web.util.depotaccess.DepotAccess;
import com.google.common.base.Preconditions;
@@ -272,8 +272,8 @@ public class TeamDepotListPage extends TeamPage {
protected void populateItem(ListItem<TeamAuthorization> item) {
TeamAuthorization authorization = item.getModelObject();
- Link<Void> link = new ViewStateAwarePageLink<Void>("link", DepotTeamListPage.class,
- DepotTeamListPage.paramsOf(authorization.getDepot()));
+ Link<Void> link = new ViewStateAwarePageLink<Void>("link", DepotTeamAuthorizationPage.class,
+ DepotTeamAuthorizationPage.paramsOf(authorization.getDepot()));
link.add(new Label("name", authorization.getDepot().getName()));
item.add(link);
diff --git a/web/src/main/java/com/gitplex/server/web/page/account/teams/TeamListPage.java b/web/src/main/java/com/gitplex/server/web/page/account/teams/TeamListPage.java
index fad6eed400..4ea151288e 100644
--- a/web/src/main/java/com/gitplex/server/web/page/account/teams/TeamListPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/account/teams/TeamListPage.java
@@ -32,8 +32,6 @@ import com.gitplex.server.web.page.account.overview.AccountOverviewPage;
import com.gitplex.server.web.util.ajaxlistener.ConfirmListener;
import com.google.common.base.Preconditions;
-import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
-
@SuppressWarnings("serial")
public class TeamListPage extends AccountLayoutPage {
@@ -130,7 +128,7 @@ public class TeamListPage extends AccountLayoutPage {
for (TeamMembership teamMembership: teamMembershipsModel.getObject()) {
if (teamMembership.getTeam().equals(team) && count++<MAX_DISPLAY_MEMBERS) {
WebMarkupContainer child = new WebMarkupContainer(membersView.newChildId());
- child.add(new AvatarLink("member", teamMembership.getUser(), new TooltipConfig()));
+ child.add(new AvatarLink("member", teamMembership.getUser(), true));
membersView.add(child);
}
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/admin/account/UserListPage.java b/web/src/main/java/com/gitplex/server/web/page/admin/account/UserListPage.java
index 769105b17d..b513851277 100644
--- a/web/src/main/java/com/gitplex/server/web/page/admin/account/UserListPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/admin/account/UserListPage.java
@@ -109,7 +109,7 @@ public class UserListPage extends AdministrationPage {
protected void populateItem(ListItem<Account> item) {
Account account = item.getModelObject();
- item.add(new AvatarLink("avatarLink", item.getModelObject(), null));
+ item.add(new AvatarLink("avatarLink", item.getModelObject()));
item.add(new AccountLink("nameLink", item.getModelObject()));
item.add(new Label("email", account.getEmail()));
diff --git a/web/src/main/java/com/gitplex/server/web/page/base/BasePage.html b/web/src/main/java/com/gitplex/server/web/page/base/BasePage.html
index ad1b6cc905..4d2a606a73 100644
--- a/web/src/main/java/com/gitplex/server/web/page/base/BasePage.html
+++ b/web/src/main/java/com/gitplex/server/web/page/base/BasePage.html
@@ -20,8 +20,8 @@
<!-- Two divs are used here in order to make overlay works in IE. -->
<div id="ajax-loading-overlay"><div></div></div>
<div wicket:id="keepSessionAlive" style="display:none;"></div>
- <a id="websocket-error" href="javascript: location.reload();"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
- Page is in error, refresh to recover</a>
+ <a id="websocket-error" href="javascript: location.reload();">
+ <span class="fa fa-warning"></span> Page is in error, refresh to recover</a>
<div wicket:id="rootComponents"></div>
</body>
</html>
diff --git a/web/src/main/java/com/gitplex/server/web/page/base/base.css b/web/src/main/java/com/gitplex/server/web/page/base/base.css
index af998b809b..6676aa0dbc 100644
--- a/web/src/main/java/com/gitplex/server/web/page/base/base.css
+++ b/web/src/main/java/com/gitplex/server/web/page/base/base.css
@@ -32,13 +32,14 @@ html body {
/* FEEDBACK */
#session-feedback {
- position:absolute;
- max-width:75%;
+ position: fixed;
+ max-width: 75%;
padding: 6px 12px;
- z-index:10000;
- border-radius:0 0 4px 4px;
+ z-index: 10000;
+ border-radius: 0 0 4px 4px;
border: 1px solid;
border-top: none;
+ top: 0;
display: none;
}
#session-feedback.success {
@@ -143,13 +144,9 @@ form>.test-feedback {
.editable table.list {
margin-bottom: 0;
}
-.editable table.list>tbody>tr>td, .editable table.list>tfoot>tr>td {
- border-top-style: dotted;
- border-top-width: 2px;
-}
.editable table.list>tfoot>tr.add-element>td {
- border-bottom: 2px dotted #DDD;
- padding: 0;
+ padding: 4px 0;
+ vertical-align: middle;
}
.editable table.list>tfoot>tr.add-element>td>a {
display: block;
@@ -157,15 +154,12 @@ form>.test-feedback {
padding: 4px 8px;
}
-.editable table.list>tbody>tr.no-elements>td {
- font-style: italic;
-}
-.editable table.list>tbody>tr.no-elements>td:hover {
- background: inherit;
-}
.editable table.list>tfoot>tr.add-element>td:hover {
background-color: #F2F2F2;
}
+.editable table.list>tbody>tr.no-elements>td {
+ font-style: italic;
+}
.editable>.reflection>table {
width: 100%;
@@ -219,17 +213,16 @@ form>.test-feedback {
display: none;
}
-.editor>table.concrete.list>tbody>tr>td.actions {
- width: 76px;
+.editor>table.list>tbody>tr>td.actions {
+ text-align: right;
}
-.editor>table.concrete.list>tbody>tr>td.actions a {
- margin-right: 8px;
+.editor>table.list>tbody>tr>td.actions .fa, .editor>table.list>tfoot>tr>td.add-element .fa {
+ vertical-align: center;
+ font-size: 20px;
+ color: #666;
}
.editor>table.list>tbody>tr>td.actions .handle {
- color: #666;
cursor: move;
- font-size: 22px;
- margin-top: 4px;
}
.editor>table.list .sort-helper {
border: 2px solid #DDD;
@@ -311,20 +304,6 @@ form>.test-feedback {
background: rgba(255,255,255,0.0); /* IE ignores this since it's not supported */
}
-/* ICONS */
-span.add.icon {
- padding: 12px;
- background: url("/assets/image/add.png") no-repeat 50% 50%;
-}
-span.delete.icon {
- padding: 12px;
- background: url("/assets/image/delete.png") no-repeat 50% 50%;
-}
-span.move.icon {
- padding: 12px;
- background: url("/assets/image/move.png") no-repeat 50% 50%;
-}
-
/* WEB SOCKET ERROR */
#websocket-error {
display: none;
@@ -338,9 +317,7 @@ span.move.icon {
margin-left: -120px;
}
#websocket-error span {
- width: 16px;
- height: 16px;
- background: url("/assets/image/error.png") 0 0 no-repeat;
+ color: #F54D4D;
}
/* FILE INPUT */
diff --git a/web/src/main/java/com/gitplex/server/web/page/base/base.js b/web/src/main/java/com/gitplex/server/web/page/base/base.js
index 0fae1bb74c..2405f16152 100644
--- a/web/src/main/java/com/gitplex/server/web/page/base/base.js
+++ b/web/src/main/java/com/gitplex/server/web/page/base/base.js
@@ -334,9 +334,7 @@ gitplex.server = {
showSessionFeedback: function() {
if ($("#session-feedback li").length != 0) {
var feedback = $("#session-feedback");
- var x = ($(window).width() - feedback.outerWidth()) / 2;
- feedback.css("left", x+$(window).scrollLeft());
- feedback.css("top", $(window).scrollTop());
+ feedback.css("left", ($(window).width()-feedback.outerWidth()) / 2);
feedback.slideDown("slow");
var body = $("body");
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/blob/BlobUploadPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/blob/BlobUploadPanel.java
index c4cd8b2d2c..df17fcb260 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/blob/BlobUploadPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/blob/BlobUploadPanel.java
@@ -27,7 +27,9 @@ import com.gitplex.server.git.exception.NotTreeException;
import com.gitplex.server.git.exception.ObjectAlreadyExistsException;
import com.gitplex.server.git.exception.ObsoleteCommitException;
import com.gitplex.server.manager.AccountManager;
+import com.gitplex.server.manager.ReviewManager;
import com.gitplex.server.model.Account;
+import com.gitplex.server.security.SecurityUtils;
import com.gitplex.server.web.component.dropzonefield.DropzoneField;
import com.gitplex.server.web.page.depot.blob.render.BlobRenderContext;
import com.google.common.base.Preconditions;
@@ -83,11 +85,20 @@ abstract class BlobUploadPanel extends Panel {
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
super.onSubmit(target, form);
+ ReviewManager reviewManager = GitPlex.getInstance(ReviewManager.class);
Map<String, BlobContent> newBlobs = new HashMap<>();
for (FileUpload upload: uploads) {
String blobPath = upload.getClientFileName();
if (context.getBlobIdent().path != null)
blobPath = context.getBlobIdent().path + "/" + blobPath;
+
+ if (!reviewManager.canModify(SecurityUtils.getAccount(), context.getDepot(),
+ context.getBlobIdent().revision, blobPath)) {
+ form.error("Adding of file '" + blobPath + "' need to be reviewed. "
+ + "Please submit pull request instead");
+ target.add(feedback);
+ return;
+ }
BlobContent blobContent = new BlobContent.Immutable(upload.getBytes(), FileMode.REGULAR_FILE);
newBlobs.put(blobPath, blobContent);
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/blob/DepotBlobPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/blob/DepotBlobPage.java
index 825848b974..c5fb46e6f0 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/blob/DepotBlobPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/blob/DepotBlobPage.java
@@ -88,7 +88,7 @@ import com.gitplex.server.web.page.depot.blob.search.quick.QuickSearchPanel;
import com.gitplex.server.web.page.depot.blob.search.result.SearchResultPanel;
import com.gitplex.server.web.page.depot.commit.DepotCommitsPage;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
-import com.gitplex.server.web.page.depot.pullrequest.requestdetail.integrationpreview.IntegrationPreviewPage;
+import com.gitplex.server.web.page.depot.pullrequest.requestdetail.mergepreview.MergePreviewPage;
import com.gitplex.server.web.util.resource.RawBlobResourceReference;
import com.gitplex.server.web.websocket.CodeCommentChangedRegion;
import com.gitplex.server.web.websocket.CommitIndexedRegion;
@@ -404,9 +404,7 @@ public class DepotBlobPage extends DepotPage implements BlobRenderContext {
protected void onConfigure() {
super.onConfigure();
setVisible((state.mode == Mode.VIEW || state.mode == Mode.BLAME)
- && isOnBranch()
- && state.blobIdent.isTree()
- && SecurityUtils.canModify(getDepot(), state.blobIdent.revision, state.blobIdent.path));
+ && isOnBranch() && state.blobIdent.isTree() && SecurityUtils.canWrite(getDepot()));
}
});
@@ -643,7 +641,7 @@ public class DepotBlobPage extends DepotPage implements BlobRenderContext {
.load(state.requestCompareInfo.requestId);
for (PullRequestUpdate update: request.getUpdates()) {
if (update.getHeadCommitHash().equals(newCommitId.name())) {
- setResponsePage(RequestChangesPage.class, IntegrationPreviewPage.paramsOf(request));
+ setResponsePage(RequestChangesPage.class, MergePreviewPage.paramsOf(request));
break;
}
}
@@ -999,9 +997,9 @@ public class DepotBlobPage extends DepotPage implements BlobRenderContext {
state.requestCompareInfo.compareState);
setResponsePage(RequestChangesPage.class, params);
} else {
- PageParameters params = IntegrationPreviewPage.paramsOf(request,
+ PageParameters params = MergePreviewPage.paramsOf(request,
state.requestCompareInfo.previewState);
- setResponsePage(IntegrationPreviewPage.class, params);
+ setResponsePage(MergePreviewPage.class, params);
}
} else {
/*
@@ -1101,8 +1099,8 @@ public class DepotBlobPage extends DepotPage implements BlobRenderContext {
@Override
public void onEvent(IEvent<?> event) {
super.onEvent(event);
- if (event.getPayload() instanceof RevisionResolveEvent) {
- RevisionResolveEvent revisionResolveEvent = (RevisionResolveEvent) event.getPayload();
+ if (event.getPayload() instanceof RevisionResolved) {
+ RevisionResolved revisionResolveEvent = (RevisionResolved) event.getPayload();
resolvedRevision = revisionResolveEvent.getResolvedRevision();
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/blob/RequestCompareInfo.java b/web/src/main/java/com/gitplex/server/web/page/depot/blob/RequestCompareInfo.java
index 45f0c479f5..ac4615691c 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/blob/RequestCompareInfo.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/blob/RequestCompareInfo.java
@@ -12,7 +12,7 @@ import javax.annotation.Nullable;
import com.gitplex.server.model.support.CommentPos;
import com.gitplex.server.util.diff.WhitespaceOption;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
-import com.gitplex.server.web.page.depot.pullrequest.requestdetail.integrationpreview.IntegrationPreviewPage;
+import com.gitplex.server.web.page.depot.pullrequest.requestdetail.mergepreview.MergePreviewPage;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
@@ -25,7 +25,7 @@ public class RequestCompareInfo implements Serializable {
public RequestChangesPage.State compareState;
- public IntegrationPreviewPage.State previewState;
+ public MergePreviewPage.State previewState;
@Override
public String toString() {
@@ -104,7 +104,7 @@ public class RequestCompareInfo implements Serializable {
compareInfo.compareState.mark = CommentPos.fromString(decode(fields.get(8)));
compareInfo.compareState.whitespaceOption = WhitespaceOption.ofNullableName(decode(fields.get(9)));
} else {
- compareInfo.previewState = new IntegrationPreviewPage.State();
+ compareInfo.previewState = new MergePreviewPage.State();
compareInfo.previewState.pathFilter = decode(fields.get(2));
compareInfo.previewState.whitespaceOption = WhitespaceOption.ofNullableName(decode(fields.get(3)));
compareInfo.previewState.blameFile = decode(fields.get(4));
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/blob/RevisionResolveEvent.java b/web/src/main/java/com/gitplex/server/web/page/depot/blob/RevisionResolved.java
similarity index 63%
rename from web/src/main/java/com/gitplex/server/web/page/depot/blob/RevisionResolveEvent.java
rename to web/src/main/java/com/gitplex/server/web/page/depot/blob/RevisionResolved.java
index 6c5b67e14a..3e3627e847 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/blob/RevisionResolveEvent.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/blob/RevisionResolved.java
@@ -3,13 +3,13 @@ package com.gitplex.server.web.page.depot.blob;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
import org.eclipse.jgit.lib.ObjectId;
-import com.gitplex.server.web.util.AjaxEvent;
+import com.gitplex.server.web.util.AjaxPayload;
-public class RevisionResolveEvent extends AjaxEvent {
+public class RevisionResolved extends AjaxPayload {
private final ObjectId resolvedRevision;
- public RevisionResolveEvent(IPartialPageRequestHandler partialPageRequestHandler, ObjectId resolvedRevision) {
+ public RevisionResolved(IPartialPageRequestHandler partialPageRequestHandler, ObjectId resolvedRevision) {
super(partialPageRequestHandler);
this.resolvedRevision = resolvedRevision;
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/blob/navigator/BlobNameChanging.java b/web/src/main/java/com/gitplex/server/web/page/depot/blob/navigator/BlobNameChanging.java
index c468dac0a9..7d1de88874 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/blob/navigator/BlobNameChanging.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/blob/navigator/BlobNameChanging.java
@@ -2,9 +2,9 @@ package com.gitplex.server.web.page.depot.blob.navigator;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
-import com.gitplex.server.web.util.AjaxEvent;
+import com.gitplex.server.web.util.AjaxPayload;
-public class BlobNameChanging extends AjaxEvent {
+public class BlobNameChanging extends AjaxPayload {
public BlobNameChanging(IPartialPageRequestHandler partialPageRequestHandler) {
super(partialPageRequestHandler);
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/commitoption/CommitOptionPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/commitoption/CommitOptionPanel.java
index 4ea424f3d3..ff5b17ff33 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/commitoption/CommitOptionPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/commitoption/CommitOptionPanel.java
@@ -49,15 +49,17 @@ import com.gitplex.server.git.exception.NotTreeException;
import com.gitplex.server.git.exception.ObjectAlreadyExistsException;
import com.gitplex.server.git.exception.ObsoleteCommitException;
import com.gitplex.server.manager.AccountManager;
+import com.gitplex.server.manager.ReviewManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
+import com.gitplex.server.security.SecurityUtils;
import com.gitplex.server.util.Provider;
import com.gitplex.server.util.diff.WhitespaceOption;
import com.gitplex.server.web.component.diff.blob.BlobDiffPanel;
import com.gitplex.server.web.component.diff.revision.DiffViewMode;
import com.gitplex.server.web.component.link.ViewStateAwareAjaxLink;
-import com.gitplex.server.web.page.depot.blob.RevisionResolveEvent;
+import com.gitplex.server.web.page.depot.blob.RevisionResolved;
import com.gitplex.server.web.page.depot.blob.navigator.BlobNameChanging;
import com.gitplex.server.web.page.depot.blob.render.BlobRenderContext;
import com.gitplex.server.web.page.depot.blob.render.BlobRenderContext.Mode;
@@ -315,6 +317,15 @@ public class CommitOptionPanel extends Panel {
Map<String, BlobContent> newBlobs = new HashMap<>();
if (newContentProvider != null) {
+
+ if (!GitPlex.getInstance(ReviewManager.class).canModify(SecurityUtils.getAccount(), context.getDepot(),
+ context.getBlobIdent().revision, context.getNewPath())) {
+ CommitOptionPanel.this.error("Adding of file '" + context.getNewPath() + "' need to be reviewed. "
+ + "Please submit pull request instead");
+ target.add(feedback);
+ return false;
+ }
+
newBlobs.put(context.getNewPath(), new BlobContent() {
@Override
@@ -350,7 +361,7 @@ public class CommitOptionPanel extends Panel {
} catch (ObsoleteCommitException e) {
try (RevWalk revWalk = new RevWalk(repository)) {
RevCommit prevCommit = revWalk.parseCommit(prevCommitId);
- send(this, Broadcast.BUBBLE, new RevisionResolveEvent(target, e.getOldCommitId()));
+ send(this, Broadcast.BUBBLE, new RevisionResolved(target, e.getOldCommitId()));
RevCommit currentCommit = revWalk.parseCommit(e.getOldCommitId());
prevCommitId = e.getOldCommitId();
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/FolderViewPanel.html b/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/FolderViewPanel.html
index 25341e3a14..bf481ade09 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/FolderViewPanel.html
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/FolderViewPanel.html
@@ -18,7 +18,7 @@
</table>
<div wicket:id="readme" class="readme">
<div class="head">
- <span wicket:id="title"></span> <a wicket:id="edit"><i class="fa fa-pencil"></i></a>
+ <span wicket:id="title"></span>
</div>
<div wicket:id="body" class="body"></div>
</div>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/FolderViewPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/FolderViewPanel.java
index a14c6e33e5..72d261e3fa 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/FolderViewPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/FolderViewPanel.java
@@ -31,13 +31,10 @@ import org.eclipse.jgit.treewalk.TreeWalk;
import com.gitplex.server.git.Blob;
import com.gitplex.server.git.BlobIdent;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.security.SecurityUtils;
import com.gitplex.server.web.component.link.ViewStateAwareAjaxLink;
import com.gitplex.server.web.component.markdown.MarkdownViewer;
import com.gitplex.server.web.page.depot.blob.DepotBlobPage;
import com.gitplex.server.web.page.depot.blob.render.BlobRenderContext;
-import com.gitplex.server.web.page.depot.blob.render.BlobRenderContext.Mode;
import com.google.common.base.Preconditions;
@SuppressWarnings("serial")
@@ -228,25 +225,6 @@ public class FolderViewPanel extends Panel {
}));
- readmeContainer.add(new ViewStateAwareAjaxLink<Void>("edit") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- DepotBlobPage.State state = new DepotBlobPage.State(readmeModel.getObject());
- state.mode = Mode.EDIT;
- setResponsePage(DepotBlobPage.class, DepotBlobPage.paramsOf(context.getDepot(), state));
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- Depot depot = context.getDepot();
- BlobIdent blobIdent = readmeModel.getObject();
- setVisible(depot.getBranchRef(blobIdent.revision) != null
- && SecurityUtils.canModify(depot, blobIdent.revision, blobIdent.path));
- }
-
- });
readmeContainer.add(new MarkdownViewer("body", new LoadableDetachableModel<String>() {
@Override
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/folder-view.css b/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/folder-view.css
index 4d9132564f..746ade0e51 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/folder-view.css
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/blob/render/renderers/folder/folder-view.css
@@ -42,10 +42,6 @@
font-weight: bold;
border-bottom: 1px solid #BBB;
}
-.folder-view>.readme>.head a {
- color: #333;
- margin-left: 4px;
-}
.folder-view>.readme>.body {
padding: 20px;
max-width: 900px;
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/branches/DepotBranchesPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/branches/DepotBranchesPage.html
index 29f3422190..765e26e2fd 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/branches/DepotBranchesPage.html
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/branches/DepotBranchesPage.html
@@ -50,21 +50,17 @@
</div>
</td>
<td wicket:id="actions" class="actions">
+ <a wicket:id="effectiveRequest" class="btn"><i class="fa fa-ext fa-branch-compare"></i> <span wicket:id="label"></span></a>
<span class="btn-group">
- <a wicket:id="unwatchRequests" class="btn btn-default" title="You are watching pull requests of this branch, click to unwatch"><i class="fa fa-eye"></i></a>
- <a wicket:id="watchRequests" class="btn btn-default" title="You are not watching pull requests of this branch, click to watch"><i class="fa fa-eye-slash"></i></a>
- <a wicket:id="delete" class="btn btn-default" title="Delete this branch"><i class="fa fa-trash"></i></a>
+ <a wicket:id="unwatchRequests" class="btn btn-default" title="You are watching pull requests of this branch, click to unwatch"><i class="fa fa-eye"></i> Unwatch</a>
+ <a wicket:id="watchRequests" class="btn btn-default" title="You are not watching pull requests of this branch, click to watch"><i class="fa fa-eye-slash"></i> Watch</a>
+ <a wicket:id="delete" class="btn btn-default" title="Delete this branch"><i class="fa fa-trash"></i> Delete</a>
</span>
</td>
</tr>
</table>
<div class="center"><ul wicket:id="branchesPageNav"></ul></div>
<div wicket:id="noBranches" class="alert alert-warning">No branches found</div>
- <div class="help-block">
- <i class="fa fa-info-circle"></i> Yellow bars
- <span class="bar request">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>
- represent ahead/behind commits with a pull request opening.
- </div>
<div id="searching-branches" class="ajax-indicator">
<wicket:link>
<img src="ajax-indicator.gif"></img>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/branches/DepotBranchesPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/branches/DepotBranchesPage.java
index 288400d92b..3d3b685fc6 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/branches/DepotBranchesPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/branches/DepotBranchesPage.java
@@ -29,6 +29,7 @@ import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.AbstractLink;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.PageableListView;
@@ -196,36 +197,6 @@ public class DepotBranchesPage extends DepotPage {
};
- private final IModel<Map<String, PullRequest>> aheadOpenRequestsModel =
- new LoadableDetachableModel<Map<String, PullRequest>>() {
-
- @Override
- protected Map<String, PullRequest> load() {
- Map<String, PullRequest> requests = new HashMap<>();
- PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
- DepotAndBranch depotAndBranch = new DepotAndBranch(getDepot(), baseBranch);
- for (PullRequest request: pullRequestManager.findAllOpenTo(depotAndBranch, getDepot()))
- requests.put(request.getSource().getBranch(), request);
- return requests;
- }
-
- };
-
- private final IModel<Map<String, PullRequest>> behindOpenRequestsModel =
- new LoadableDetachableModel<Map<String, PullRequest>>() {
-
- @Override
- protected Map<String, PullRequest> load() {
- Map<String, PullRequest> requests = new HashMap<>();
- PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
- DepotAndBranch depotAndBranch = new DepotAndBranch(getDepot(), baseBranch);
- for (PullRequest request: pullRequestManager.findAllOpenFrom(depotAndBranch, getDepot()))
- requests.put(request.getTarget().getBranch(), request);
- return requests;
- }
-
- };
-
private final IModel<Map<String, BranchWatch>> branchWatchesModel =
new LoadableDetachableModel<Map<String, BranchWatch>>() {
@@ -310,8 +281,7 @@ public class DepotBranchesPage extends DepotPage {
protected void onConfigure() {
super.onConfigure();
- ObjectId commit = getDepot().getObjectId(branchRevision);
- setVisible(SecurityUtils.canPushRef(getDepot(), Constants.R_HEADS, ObjectId.zeroId(), commit));
+ setVisible(SecurityUtils.canWrite(getDepot()));
}
private RevisionPicker newRevisionPicker() {
@@ -486,40 +456,23 @@ public class DepotBranchesPage extends DepotPage {
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
- if (behindOpenRequestsModel.getObject().get(item.getModelObject()) != null) {
- tag.put("title", "" + ab.getBehind() + " commits behind of base branch, and there is an "
- + "open pull request fetching those commits");
- } else {
- tag.put("title", "" + ab.getBehind() + " commits ahead of base branch");
- }
+ tag.put("title", "" + ab.getBehind() + " commits ahead of base branch");
if (ab.getBehind() == 0)
tag.setName("span");
}
@Override
public void onClick() {
- PullRequest request = behindOpenRequestsModel.getObject().get(branch);
- if (request != null) {
- setResponsePage(RequestOverviewPage.class, RequestOverviewPage.paramsOf(request));
- } else {
- RevisionComparePage.State state = new RevisionComparePage.State();
- state.leftSide = new DepotAndBranch(getDepot(), branch);
- state.rightSide = new DepotAndBranch(getDepot(), baseBranch);
- PageParameters params = RevisionComparePage.paramsOf(getDepot(), state);
- setResponsePage(RevisionComparePage.class, params);
- }
+ RevisionComparePage.State state = new RevisionComparePage.State();
+ state.leftSide = new DepotAndBranch(getDepot(), branch);
+ state.rightSide = new DepotAndBranch(getDepot(), baseBranch);
+ PageParameters params = RevisionComparePage.paramsOf(getDepot(), state);
+ setResponsePage(RevisionComparePage.class, params);
}
});
item.add(new Label("behindBar") {
- @Override
- protected void onInitialize() {
- super.onInitialize();
- if (behindOpenRequestsModel.getObject().get(branch) != null)
- add(AttributeAppender.append("class", " request"));
- }
-
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
@@ -547,40 +500,23 @@ public class DepotBranchesPage extends DepotPage {
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
- if (aheadOpenRequestsModel.getObject().get(branch) != null) {
- tag.put("title", "" + ab.getAhead() + " commits ahead of base branch, and there is an "
- + "open pull request sending these commits to base branch");
- } else {
- tag.put("title", "" + ab.getAhead() + " commits ahead of base branch");
- }
+ tag.put("title", "" + ab.getAhead() + " commits ahead of base branch");
if (ab.getAhead() == 0)
tag.setName("span");
}
@Override
public void onClick() {
- PullRequest request = aheadOpenRequestsModel.getObject().get(branch);
- if (request != null) {
- setResponsePage(RequestOverviewPage.class, RequestOverviewPage.paramsOf(request));
- } else {
- RevisionComparePage.State state = new RevisionComparePage.State();
- state.leftSide = new DepotAndBranch(getDepot(), baseBranch);
- state.rightSide = new DepotAndBranch(getDepot(), branch);
- PageParameters params = RevisionComparePage.paramsOf(getDepot(), state);
- setResponsePage(RevisionComparePage.class, params);
- }
+ RevisionComparePage.State state = new RevisionComparePage.State();
+ state.leftSide = new DepotAndBranch(getDepot(), baseBranch);
+ state.rightSide = new DepotAndBranch(getDepot(), branch);
+ PageParameters params = RevisionComparePage.paramsOf(getDepot(), state);
+ setResponsePage(RevisionComparePage.class, params);
}
});
item.add(new Label("aheadBar") {
- @Override
- protected void onInitialize() {
- super.onInitialize();
- if (aheadOpenRequestsModel.getObject().get(branch) != null)
- add(AttributeAppender.append("class", " request"));
- }
-
@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);
@@ -592,6 +528,31 @@ public class DepotBranchesPage extends DepotPage {
WebMarkupContainer actionsContainer = new WebMarkupContainer("actions");
item.add(actionsContainer.setOutputMarkupId(true));
+
+ PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
+ PullRequest effectiveRequest = pullRequestManager.findEffective(
+ new DepotAndBranch(getDepot(), baseBranch),
+ new DepotAndBranch(getDepot(), branch));
+ WebMarkupContainer requestLink;
+ if (effectiveRequest != null && ab.getAhead() != 0) {
+ requestLink = new BookmarkablePageLink<Void>("effectiveRequest",
+ RequestOverviewPage.class, RequestOverviewPage.paramsOf(effectiveRequest));
+ if (effectiveRequest.isOpen()) {
+ requestLink.add(new Label("label", "Open"));
+ requestLink.add(AttributeAppender.append("title", "A pull request is open for this change"));
+ requestLink.add(AttributeAppender.append("class", "btn-warning"));
+ } else {
+ requestLink.add(new Label("label", "Merged"));
+ requestLink.add(AttributeAppender.append("title",
+ "This change is squashed/rebased onto base branch via a pull request"));
+ requestLink.add(AttributeAppender.append("class", "btn-success"));
+ }
+ } else {
+ requestLink = new WebMarkupContainer("effectiveRequest");
+ requestLink.setVisible(false);
+ requestLink.add(new WebMarkupContainer("label"));
+ }
+ actionsContainer.add(requestLink);
actionsContainer.add(new AjaxLink<Void>("unwatchRequests") {
@@ -681,9 +642,8 @@ public class DepotBranchesPage extends DepotPage {
protected void onConfigure() {
super.onConfigure();
- RefInfo ref = item.getModelObject();
if (!getDepot().getDefaultBranch().equals(branch)
- && SecurityUtils.canPushRef(getDepot(), ref.getRef().getName(), ref.getRef().getObjectId(), ObjectId.zeroId())) {
+ && SecurityUtils.canDeleteBranch(getDepot(), branch)) {
setVisible(true);
} else {
setVisible(false);
@@ -728,8 +688,6 @@ public class DepotBranchesPage extends DepotPage {
@Override
public void onDetach() {
branchesModel.detach();
- aheadOpenRequestsModel.detach();
- behindOpenRequestsModel.detach();
branchWatchesModel.detach();
aheadBehindsModel.detach();
aheadBehindWidthModel.detach();
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/branches/depot-branches.css b/web/src/main/java/com/gitplex/server/web/page/depot/branches/depot-branches.css
index 4ddcb87682..3b57a25978 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/branches/depot-branches.css
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/branches/depot-branches.css
@@ -56,26 +56,14 @@
background: #ccc;
border-radius: 0 2px 2px 0;
}
-#repo-branches>.list>table .ahead .bar.request {
- background: #F1D763;
-}
#repo-branches>.list>table .behind .bar {
background: #ccc;
border-radius: 2px 0 0 2px;
}
-#repo-branches>.list>table .behind .bar.request {
- background: #F1D763;
-}
-#repo-branches>.list>.help-block .bar.request {
- background: #F1D763;
- font-size: 6px;
- border-radius: 2px;
- vertical-align: middle;
-}
#repo-branches>.list>table td.actions {
text-align: right;
- width: 90px;
+ width: 300px;
}
#searching-branches {
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/commit/QueryAssistBehavior.java b/web/src/main/java/com/gitplex/server/web/page/depot/commit/QueryAssistBehavior.java
index 0881b902f9..ef9c95cc81 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/commit/QueryAssistBehavior.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/commit/QueryAssistBehavior.java
@@ -19,8 +19,8 @@ import com.gitplex.server.git.NameAndEmail;
import com.gitplex.server.manager.CommitInfoManager;
import com.gitplex.server.model.Depot;
import com.gitplex.server.util.StringUtils;
-import com.gitplex.server.util.match.PatternApplied;
-import com.gitplex.server.util.match.WildcardUtils;
+import com.gitplex.server.util.stringmatch.PatternApplied;
+import com.gitplex.server.util.stringmatch.WildcardUtils;
import com.gitplex.server.web.WebConstants;
import com.gitplex.server.web.behavior.inputassist.ANTLRAssistBehavior;
import com.gitplex.server.web.util.SuggestionUtils;
@@ -65,7 +65,7 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {
Depot depot = depotModel.getObject();
switch (tokenType) {
case CommitQueryParser.BRANCH:
- suggestions.addAll(SuggestionUtils.suggestBranch(depot, unfencedMatchWith, count, null, null));
+ suggestions.addAll(SuggestionUtils.suggestBranch(depot, unfencedMatchWith, count));
break;
case CommitQueryParser.TAG:
suggestions.addAll(SuggestionUtils.suggestTag(depot, unfencedMatchWith, count));
@@ -82,7 +82,8 @@ public class QueryAssistBehavior extends ANTLRAssistBehavior {
else
content = contributor.getName();
content = content.trim();
- PatternApplied applied = WildcardUtils.applyPattern(unfencedLowerCaseMatchWith, content, false);
+ PatternApplied applied = WildcardUtils.applyPattern(unfencedLowerCaseMatchWith, content,
+ false);
if (applied != null) {
suggestedInputs.put(applied.getText(), applied.getMatchRange());
if (suggestedInputs.size() == count)
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/compare/RevisionComparePage.html b/web/src/main/java/com/gitplex/server/web/page/depot/compare/RevisionComparePage.html
index 455ad99b60..801da0c7c0 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/compare/RevisionComparePage.html
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/compare/RevisionComparePage.html
@@ -32,8 +32,8 @@
</td>
</tr>
</table>
- <div wicket:id="openedRequest" class="alert alert-info">
- <div>Pull request #<span wicket:id="no"></span> is already open for this comparison:</div>
+ <div wicket:id="effectiveRequest" class="alert alert-info">
+ <div wicket:id="description"></div>
<b><a wicket:id="link"><span wicket:id="label"></span></a></b>
</div>
<div>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/compare/RevisionComparePage.java b/web/src/main/java/com/gitplex/server/web/page/depot/compare/RevisionComparePage.java
index 1915bbbc77..fb440067f7 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/compare/RevisionComparePage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/compare/RevisionComparePage.java
@@ -207,9 +207,13 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
@Override
protected PullRequest load() {
- DepotAndBranch left = new DepotAndBranch(state.leftSide.toString());
- DepotAndBranch right = new DepotAndBranch(state.rightSide.toString());
- return GitPlex.getInstance(PullRequestManager.class).findOpen(left, right);
+ if (state.leftSide.getBranch() != null && state.rightSide.getBranch() != null) {
+ DepotAndBranch left = new DepotAndBranch(state.leftSide.toString());
+ DepotAndBranch right = new DepotAndBranch(state.rightSide.toString());
+ return GitPlex.getInstance(PullRequestManager.class).findEffective(left, right);
+ } else {
+ return null;
+ }
}
};
@@ -402,27 +406,32 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
});
- add(new WebMarkupContainer("openedRequest") {
+ add(new WebMarkupContainer("effectiveRequest") {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(requestModel.getObject() != null);
+ PullRequest request = requestModel.getObject();
+ setVisible(request != null && (request.isOpen() || !request.isMergeIntoTarget()));
}
@Override
protected void onInitialize() {
super.onInitialize();
-
- add(new Label("no", new AbstractReadOnlyModel<String>() {
+
+ add(new Label("description", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
- return String.valueOf(requestModel.getObject().getNumber());
+ if (requestModel.getObject().isOpen())
+ return "This change is already opened for merge by a pull request";
+ else
+ return "This change is squashed/rebased onto base branch via a pull request";
}
}));
+
add(new Link<Void>("link") {
@Override
@@ -432,7 +441,8 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
@Override
public String getObject() {
- return requestModel.getObject().getTitle();
+ PullRequest request = requestModel.getObject();
+ return "#" + request.getNumber() + " " + request.getTitle();
}
}));
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/NewRequestPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/NewRequestPage.html
index ca93aaf62d..12eb2f8250 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/NewRequestPage.html
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/NewRequestPage.html
@@ -32,9 +32,9 @@
<div wicket:id="tabPanel" class="tab-panel"></div>
</div>
</div>
- <wicket:fragment wicket:id="openedFrag">
+ <wicket:fragment wicket:id="effectiveFrag">
<div class="alert alert-info">
- <div>Pull request #<span wicket:id="no"></span> is already open for this comparison:</div>
+ <div wicket:id="description"></div>
<b><a wicket:id="link"><span wicket:id="label"></span></a></b>
</div>
</wicket:fragment>
@@ -42,11 +42,11 @@
<div class="alert alert-warning">
<div class="summary">
<span class="fa fa-lg fa-warning"></span>
- <span>Please select different branches to integrate.</span>
+ <span>Please select different branches to merge.</span>
</div>
</div>
</wicket:fragment>
- <wicket:fragment wicket:id="integratedFrag">
+ <wicket:fragment wicket:id="mergedFrag">
<div class="alert alert-success">
<div class="summary">
<span class="fa fa-lg fa-check"></span>
@@ -76,7 +76,7 @@
</wicket:fragment>
<wicket:fragment wicket:id="canSendFrag">
<div class="can-send">
- <form wicket:id="form">
+ <form wicket:id="form" class="leave-confirm">
<table>
<tr class="title">
<td class="name">Title <span class="required"></span></td>
@@ -89,37 +89,24 @@
<td class="name">Description</td>
<td class="value"><div wicket:id="comment"></div></td>
</tr>
- <tr class="assignee">
- <td class="name">Assignee <span class="required"></span></td>
- <td wicket:id="assignee" class="value">
- <input wicket:id="assignee" type="hidden"></input>
- <div wicket:id="feedback"></div>
- <div class="help-block">
- <i class="fa fa-info-circle"></i> Assignee is responsible for integration of the
- pull request after it passes gatekeeper check.
- </div>
+ <tr class="merge-strategy">
+ <td class="name">Merge Strategy</td>
+ <td class="value">
+ <select wicket:id="mergeStrategy" class="form-control"></select>
+ <div wicket:id="mergeStrategyHelp" class="help-block"></div>
</td>
</tr>
<tr class="reviewers">
<td class="name">Reviewers</td>
- <td wicket:id="reviewers" class="value">
- <ul class="clearfix list-unstyled">
- <li wicket:id="reviewers" class="pull-left">
- <a wicket:id="avatar"></a>
- </li>
- <wicket:enclosure child="addReviewer">
- <li class="pull-left"><input wicket:id="addReviewer" type="hidden"></input></li>
- </wicket:enclosure>
- </ul>
- <div wicket:id="prePopulateHint" class="help-block">
- <i class="fa fa-info-circle"></i> GitPlex pre-populated some reviewers above as suggested
- by gatekeeper of the repository. You may adjust the list by removing existing (hovering mouse
- over reviewer avatar) or adding more.
- </div>
- </td>
+ <td class="value"><div wicket:id="reviewers"></div></td>
</tr>
</table>
- <input wicket:id="send" type="submit" class="btn btn-primary" value="Send Pull Request"></input>
+ <div class="clearfix">
+ <input wicket:id="send" type="submit" class="btn btn-primary pull-left" value="Create Pull Request"></input>
+ <div wicket:id="immediateMergeNote" class="alert alert-warning pull-left immediate-merge">
+ <i class="fa fa-warning"></i> This pull request will be merged immediately after being created
+ </div>
+ </div>
</form>
</div>
</wicket:fragment>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/NewRequestPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/NewRequestPage.java
index 0bf2563f46..6b723d98b7 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/NewRequestPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/NewRequestPage.java
@@ -1,34 +1,34 @@
package com.gitplex.server.web.page.depot.pullrequest.newrequest;
-import static com.gitplex.server.model.PullRequest.Status.INTEGRATED;
-import static com.gitplex.server.model.PullRequest.Status.PENDING_UPDATE;
-
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Date;
import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
import org.apache.wicket.Component;
import org.apache.wicket.RestartResponseAtInterceptPageException;
import org.apache.wicket.RestartResponseException;
import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.event.Broadcast;
+import org.apache.wicket.event.IEvent;
import org.apache.wicket.markup.head.CssHeaderItem;
import org.apache.wicket.markup.head.IHeaderResponse;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
+import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
-import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -42,15 +42,14 @@ import com.gitplex.server.model.Account;
import com.gitplex.server.model.CodeComment;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequest.IntegrationStrategy;
-import com.gitplex.server.model.PullRequest.Status;
-import com.gitplex.server.model.PullRequestReviewInvitation;
import com.gitplex.server.model.PullRequestUpdate;
+import com.gitplex.server.model.ReviewInvitation;
import com.gitplex.server.model.support.CloseInfo;
import com.gitplex.server.model.support.CommentPos;
import com.gitplex.server.model.support.DepotAndBranch;
+import com.gitplex.server.model.support.MergeStrategy;
import com.gitplex.server.persistence.dao.Dao;
-import com.gitplex.server.security.ObjectPermission;
+import com.gitplex.server.security.SecurityUtils;
import com.gitplex.server.util.diff.WhitespaceOption;
import com.gitplex.server.web.component.branchpicker.AffinalBranchPicker;
import com.gitplex.server.web.component.comment.CommentInput;
@@ -61,9 +60,7 @@ import com.gitplex.server.web.component.diff.revision.RevisionDiffPanel;
import com.gitplex.server.web.component.link.BranchLink;
import com.gitplex.server.web.component.link.ViewStateAwarePageLink;
import com.gitplex.server.web.component.markdown.AttachmentSupport;
-import com.gitplex.server.web.component.pullrequest.requestassignee.AssigneeChoice;
-import com.gitplex.server.web.component.pullrequest.requestreviewer.ReviewerAvatar;
-import com.gitplex.server.web.component.pullrequest.requestreviewer.ReviewerChoice;
+import com.gitplex.server.web.component.requestreviewer.ReviewerListPanel;
import com.gitplex.server.web.component.tabbable.AjaxActionTab;
import com.gitplex.server.web.component.tabbable.Tab;
import com.gitplex.server.web.component.tabbable.Tabbable;
@@ -76,7 +73,7 @@ import com.gitplex.server.web.page.depot.pullrequest.requestdetail.RequestDetail
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
import com.gitplex.server.web.page.depot.pullrequest.requestlist.RequestListPage;
import com.gitplex.server.web.page.security.LoginPage;
-import com.gitplex.server.web.util.model.ReviewersModel;
+import com.gitplex.server.web.websocket.PullRequestChanged;
import com.google.common.base.Preconditions;
import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
@@ -154,49 +151,54 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
}
}
- PullRequest pullRequest;
+ AtomicReference<PullRequest> pullRequestRef = new AtomicReference<>(null);
if (prevRequest != null && source.equals(prevRequest.getSource()) && target.equals(prevRequest.getTarget()) && prevRequest.isOpen())
- pullRequest = prevRequest;
+ pullRequestRef.set(prevRequest);
else
- pullRequest = GitPlex.getInstance(PullRequestManager.class).findOpen(target, source);
+ pullRequestRef.set(GitPlex.getInstance(PullRequestManager.class).findEffective(target, source));
- if (pullRequest == null) {
+ if (pullRequestRef.get() == null) {
ObjectId baseCommitId = GitUtils.getMergeBase(
target.getDepot().getRepository(), target.getObjectId(),
source.getDepot().getRepository(), source.getObjectId(),
GitUtils.branch2ref(source.getBranch()));
if (baseCommitId != null) {
- pullRequest = new PullRequest();
- pullRequest.setTarget(target);
- pullRequest.setSource(source);
- pullRequest.setSubmitter(currentUser);
+ pullRequestRef.set(new PullRequest());
+ pullRequestRef.get().setTarget(target);
+ pullRequestRef.get().setSource(source);
+ pullRequestRef.get().setSubmitter(currentUser);
- PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
- List<IntegrationStrategy> strategies = pullRequestManager.getApplicableIntegrationStrategies(pullRequest);
- Preconditions.checkState(!strategies.isEmpty());
- pullRequest.setIntegrationStrategy(strategies.get(0));
+ pullRequestRef.get().setMergeStrategy(MergeStrategy.ALWAYS_MERGE);
- ObjectPermission writePermission = ObjectPermission.ofDepotWrite(target.getDepot());
- if (currentUser.asSubject().isPermitted(writePermission))
- pullRequest.setAssignee(currentUser);
-
- pullRequest.setBaseCommitHash(baseCommitId.name());
- if (pullRequest.getBaseCommitHash().equals(source.getObjectName())) {
+ pullRequestRef.get().setBaseCommitHash(baseCommitId.name());
+ if (pullRequestRef.get().getBaseCommitHash().equals(source.getObjectName())) {
CloseInfo closeInfo = new CloseInfo();
closeInfo.setCloseDate(new Date());
- closeInfo.setCloseStatus(CloseInfo.Status.INTEGRATED);
- pullRequest.setCloseInfo(closeInfo);
+ closeInfo.setCloseStatus(CloseInfo.Status.MERGED);
+ pullRequestRef.get().setCloseInfo(closeInfo);
}
PullRequestUpdate update = new PullRequestUpdate();
- pullRequest.addUpdate(update);
- update.setRequest(pullRequest);
+ pullRequestRef.get().addUpdate(update);
+ update.setRequest(pullRequestRef.get());
update.setHeadCommitHash(source.getObjectName());
- update.setMergeCommitHash(pullRequest.getBaseCommitHash());
+ update.setMergeBaseCommitHash(pullRequestRef.get().getBaseCommitHash());
}
- requestModel = Model.of(pullRequest);
+ requestModel = new LoadableDetachableModel<PullRequest>() {
+
+ @Override
+ protected PullRequest load() {
+ if (pullRequestRef.get() != null) {
+ pullRequestRef.get().setTarget(target);
+ pullRequestRef.get().setSource(source);
+ pullRequestRef.get().setSubmitter(SecurityUtils.getAccount());
+ }
+ return pullRequestRef.get();
+ }
+
+ };
} else {
- Long requestId = pullRequest.getId();
+ Long requestId = pullRequestRef.get().getId();
requestModel = new LoadableDetachableModel<PullRequest>() {
@Override
@@ -205,8 +207,8 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
}
};
- requestModel.setObject(pullRequest);
}
+ requestModel.setObject(pullRequestRef.get());
commitsModel = new LoadableDetachableModel<List<RevCommit>>() {
@@ -280,19 +282,18 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
});
Fragment fragment;
- if (getPullRequest() == null) {
+ PullRequest request = getPullRequest();
+ if (request == null) {
fragment = newUnrelatedHistoryFrag();
- } else if (getPullRequest().getId() != null) {
- fragment = newOpenedFrag();
- } else if (getPullRequest().getSource().equals(getPullRequest().getTarget())) {
+ } else if (request.getId() != null && (request.isOpen() || !request.isMergeIntoTarget())) {
+ fragment = newEffectiveFrag();
+ } else if (request.getSource().equals(request.getTarget())) {
fragment = newSameBranchFrag();
- } else if (getPullRequest().getStatus() == INTEGRATED) {
- fragment = newIntegratedFrag();
- } else if (getPullRequest().getStatus() == PENDING_UPDATE) {
- fragment = newRejectedFrag();
- } else {
+ } else if (request.isMerged()) {
+ fragment = newAcceptedFrag();
+ } else {
fragment = newCanSendFrag();
- }
+ }
add(fragment);
if (getPullRequest() != null) {
@@ -325,8 +326,7 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
@Override
protected void onConfigure() {
super.onConfigure();
-
- setVisible(getPullRequest().getStatus() != INTEGRATED);
+ setVisible(!getPullRequest().isMerged());
}
});
@@ -344,7 +344,7 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().getStatus() != INTEGRATED);
+ setVisible(!getPullRequest().isMerged());
}
}.setOutputMarkupId(true);
@@ -430,7 +430,7 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().getStatus() != INTEGRATED);
+ setVisible(!getPullRequest().isMerged());
}
};
@@ -438,15 +438,21 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
return diffPanel;
}
- private Fragment newOpenedFrag() {
- Fragment fragment = new Fragment("status", "openedFrag", this);
- fragment.add(new Label("no", new AbstractReadOnlyModel<String>() {
+ private Fragment newEffectiveFrag() {
+ Fragment fragment = new Fragment("status", "effectiveFrag", this);
+
+ fragment.add(new Label("description", new AbstractReadOnlyModel<String>() {
@Override
public String getObject() {
- return getPullRequest().getId().toString();
+ if (requestModel.getObject().isOpen())
+ return "This change is already opened for merge by a pull request";
+ else
+ return "This change is squashed/rebased onto base branch via a pull request";
}
+
}));
+
fragment.add(new Link<Void>("link") {
@Override
@@ -456,8 +462,10 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
@Override
public String getObject() {
- return getPullRequest().getTitle();
+ PullRequest request = getPullRequest();
+ return "#" + request.getNumber() + " " + request.getTitle();
}
+
}));
}
@@ -480,8 +488,8 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
return new Fragment("status", "unrelatedHistoryFrag", this);
}
- private Fragment newIntegratedFrag() {
- Fragment fragment = new Fragment("status", "integratedFrag", this);
+ private Fragment newAcceptedFrag() {
+ Fragment fragment = new Fragment("status", "mergedFrag", this);
fragment.add(new BranchLink("sourceBranch", getPullRequest().getSource()));
fragment.add(new BranchLink("targetBranch", getPullRequest().getTarget()));
fragment.add(new Link<Void>("swapBranches") {
@@ -497,27 +505,6 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
return fragment;
}
- private Fragment newRejectedFrag() {
- Fragment fragment = new Fragment("status", "rejectedFrag", this);
- fragment.add(new ListView<String>("reasons", new LoadableDetachableModel<List<String>>() {
-
- @Override
- protected List<String> load() {
- return getPullRequest().checkGates(false).getReasons();
- }
-
- }) {
-
- @Override
- protected void populateItem(ListItem<String> item) {
- item.add(new Label("reason", item.getModelObject()));
- }
-
- });
-
- return fragment;
- }
-
private Fragment newCanSendFrag() {
Fragment fragment = new Fragment("status", "canSendFrag", this);
Form<?> form = new Form<Void>("form");
@@ -541,11 +528,9 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
} else {
getPullRequest().setSource(source);
getPullRequest().setTarget(target);
- for (PullRequestReviewInvitation invitation: getPullRequest().getReviewInvitations())
+ for (ReviewInvitation invitation: getPullRequest().getReviewInvitations())
invitation.setUser(dao.load(Account.class, invitation.getUser().getId()));
- getPullRequest().setAssignee(dao.load(Account.class, getPullRequest().getAssignee().getId()));
-
GitPlex.getInstance(PullRequestManager.class).open(getPullRequest());
PageParameters params = RequestOverviewPage.paramsOf(getPullRequest());
@@ -554,9 +539,32 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
}
}
-
});
+ form.add(new WebMarkupContainer("immediateMergeNote") {
+
+ @Override
+ public void onEvent(IEvent<?> event) {
+ super.onEvent(event);
+
+ if (event.getPayload() instanceof PullRequestChanged) {
+ PullRequestChanged payload = (PullRequestChanged) event.getPayload();
+ payload.getPartialPageRequestHandler().add(this);
+ }
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ PullRequest request = getPullRequest();
+
+ setVisible(request.getMergeStrategy() != MergeStrategy.DO_NOT_MERGE
+ && request.getReviewCheckStatus().getAwaitingReviewers().isEmpty());
+ }
+
+ }.setOutputMarkupPlaceholderTag(true));
+
WebMarkupContainer titleContainer = new WebMarkupContainer("title");
form.add(titleContainer);
final TextField<String> titleInput = new TextField<String>("title", new IModel<String>() {
@@ -567,15 +575,18 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
@Override
public String getObject() {
- if (getPullRequest().getTitle() == null) {
+ PullRequest request = getPullRequest();
+ if (request.getTitle() == null) {
List<RevCommit> commits = commitsModel.getObject();
Preconditions.checkState(!commits.isEmpty());
- if (commits.size() == 1)
- getPullRequest().setTitle(commits.get(0).getShortMessage());
- else
- getPullRequest().setTitle(getPullRequest().getSource().getBranch());
+ if (commits.size() == 1) {
+ request.setTitle(commits.get(0).getShortMessage());
+ } else if (!request.getSourceBranch().equals("master")
+ && !request.getSourceBranch().equals(request.getTargetBranch())) {
+ request.setTitle(request.getSourceBranch());
+ }
}
- return getPullRequest().getTitle();
+ return request.getTitle();
}
@Override
@@ -633,81 +644,49 @@ public class NewRequestPage extends DepotPage implements CommentSupport {
});
- WebMarkupContainer assigneeContainer = new WebMarkupContainer("assignee");
- form.add(assigneeContainer);
- IModel<Account> assigneeModel = new PropertyModel<>(getPullRequest(), "assignee");
- AssigneeChoice assigneeChoice = new AssigneeChoice("assignee", new AbstractReadOnlyModel<Depot>() {
+ IModel<MergeStrategy> mergeStrategyModel = new IModel<MergeStrategy>() {
@Override
- public Depot getObject() {
- return target.getDepot();
+ public void detach() {
}
-
- }, assigneeModel);
- assigneeChoice.setRequired(true);
- assigneeContainer.add(assigneeChoice);
-
- assigneeContainer.add(new NotificationPanel("feedback", assigneeChoice));
-
- assigneeContainer.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
@Override
- public String getObject() {
- return !assigneeChoice.isValid()?" has-error":"";
+ public MergeStrategy getObject() {
+ return getPullRequest().getMergeStrategy();
}
-
- }));
-
- WebMarkupContainer reviewersContainer = new WebMarkupContainer("reviewers") {
@Override
- protected void onBeforeRender() {
- super.onBeforeRender();
+ public void setObject(MergeStrategy object) {
+ getPullRequest().setMergeStrategy(object);
}
};
- reviewersContainer.setOutputMarkupId(true);
- form.add(reviewersContainer);
- reviewersContainer.add(new ListView<PullRequestReviewInvitation>("reviewers", new ReviewersModel(requestModel)) {
-
- @Override
- protected void populateItem(ListItem<PullRequestReviewInvitation> item) {
- PullRequestReviewInvitation invitation = item.getModelObject();
-
- item.add(new ReviewerAvatar("avatar", invitation) {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- super.onClick(target);
-
- target.add(reviewersContainer);
- }
-
- });
- }
-
- });
- reviewersContainer.add(new ReviewerChoice("addReviewer", requestModel) {
+ List<MergeStrategy> mergeStrategies = Arrays.asList(MergeStrategy.values());
+ DropDownChoice<MergeStrategy> mergeStrategyDropdown =
+ new DropDownChoice<MergeStrategy>("mergeStrategy", mergeStrategyModel, mergeStrategies);
+ mergeStrategyDropdown.add(new OnChangeAjaxBehavior() {
+
@Override
- protected void onSelect(AjaxRequestTarget target, Account user) {
- super.onSelect(target, user);
-
- target.add(reviewersContainer);
+ protected void onUpdate(AjaxRequestTarget target) {
+ send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target));
}
});
- reviewersContainer.add(new WebMarkupContainer("prePopulateHint") {
+ form.add(mergeStrategyDropdown);
+
+ form.add(new Label("mergeStrategyHelp", new AbstractReadOnlyModel<String>() {
@Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.PENDING_APPROVAL);
+ public String getObject() {
+ return getPullRequest().getMergeStrategy().getDescription();
}
- });
+ }));
+
+ form.add(new ReviewerListPanel("reviewers", requestModel));
return fragment;
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/new-request.css b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/new-request.css
index 828c905922..8f7f293bd4 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/new-request.css
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/newrequest/new-request.css
@@ -38,16 +38,13 @@
margin-bottom: 8px;
}
-#new-request>.body>.status>.can-send form>table td {
+#new-request>.body>.status>.can-send form>table>tbody>tr>td {
padding: 16px 0;
border-top: 1px dashed #BBB;
border-bottom: 1px dashed #BBB;
}
-#new-request>.body>.status>.can-send form>table tr.description td {
- padding-bottom: 8px;
-}
#new-request>.body>.status>.can-send form>table td.name {
- width: 120px;
+ width: 160px;
font-size: 18px;
padding-right: 8px;
}
@@ -57,29 +54,28 @@
#new-request>.body>.status>.can-send form>table {
margin-bottom: 16px;
}
-#new-request>.body>.status>.can-send form>table .select2-container {
- min-width: 250px;
-}
#new-request>.body>.status>.can-send form>table td.name .required:BEFORE {
content: "*";
color: red;
}
-#new-request>.body>.status>.can-send form>table .reviewers li {
- margin-right: 10px;
-}
-#new-request>.body>.status>.can-send form>table .reviewers li a:hover {
- text-decoration: none;
+#new-request table.reviewers {
+ width: auto;
}
#new-request>.body>.status>.can-send form .alert-danger {
margin-bottom: 0;
margin-top: 16px;
}
-#new-request>.body>.status>.can-send form .assignee .help-block {
- margin-top: 12px;
-}
#new-request>.body>.status>.can-send form .help-block {
margin-bottom: 0;
}
+#new-request>.body>.status>.can-send form select {
+ width: auto;
+}
+#new-request .immediate-merge.alert {
+ margin-bottom: 0;
+ padding: 6px;
+ margin-left: 8px;
+}
#new-request>.body>.nav-tabs {
margin-bottom: 20px;
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/PullRequestOperation.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/PullRequestOperation.java
index 126de9bee5..be162043d8 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/PullRequestOperation.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/PullRequestOperation.java
@@ -1,60 +1,23 @@
package com.gitplex.server.web.page.depot.pullrequest.requestdetail;
-import static com.gitplex.server.model.PullRequest.Status.PENDING_INTEGRATE;
-
import javax.annotation.Nullable;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.LoadableDetachableModel;
-import org.eclipse.jgit.lib.ObjectId;
import com.gitplex.server.GitPlex;
import com.gitplex.server.git.GitUtils;
import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.manager.PullRequestManager;
-import com.gitplex.server.manager.PullRequestReviewManager;
+import com.gitplex.server.manager.ReviewManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.model.PullRequestReviewInvitation;
-import com.gitplex.server.model.PullRequest.Status;
-import com.gitplex.server.model.support.IntegrationPreview;
+import com.gitplex.server.model.support.MergePreview;
import com.gitplex.server.security.SecurityUtils;
@SuppressWarnings("serial")
public enum PullRequestOperation {
- INTEGRATE {
-
- @Override
- public boolean canOperate(PullRequest request) {
- if (!SecurityUtils.canWrite(request.getTargetDepot()) || request.getStatus() != PENDING_INTEGRATE) {
- return false;
- } else {
- IntegrationPreview integrationPreview = request.getIntegrationPreview();
- return integrationPreview != null && integrationPreview.getIntegrated() != null;
- }
- }
-
- @Override
- public void operate(PullRequest request, String comment) {
- GitPlex.getInstance(PullRequestManager.class).integrate(request, comment);
- }
-
- @Override
- public Component newHinter(String id, PullRequest request) {
- Long requestId = request.getId();
- return new IntegrationHintPanel(id, new LoadableDetachableModel<PullRequest>() {
-
- @Override
- protected PullRequest load() {
- return GitPlex.getInstance(PullRequestManager.class).load(requestId);
- }
-
- });
- }
-
- },
DISCARD {
@Override
@@ -80,7 +43,7 @@ public enum PullRequestOperation {
@Override
public void operate(PullRequest request, String comment) {
- GitPlex.getInstance(PullRequestReviewManager.class).review(request, PullRequestReview.Result.APPROVE, comment);
+ GitPlex.getInstance(ReviewManager.class).review(request, true, comment);
}
@Override
@@ -106,7 +69,7 @@ public enum PullRequestOperation {
@Override
public void operate(PullRequest request, String comment) {
- GitPlex.getInstance(PullRequestReviewManager.class).review(request, PullRequestReview.Result.DISAPPROVE, comment);
+ GitPlex.getInstance(ReviewManager.class).review(request, false, comment);
}
},
@@ -115,18 +78,14 @@ public enum PullRequestOperation {
@Override
public boolean canOperate(PullRequest request) {
PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
- if (request.isOpen()
- || !SecurityUtils.canModify(request)
- || request.getTarget().getObjectName(false) == null
- || request.getSourceDepot() == null
- || request.getSource().getObjectName(false) == null
- || pullRequestManager.findOpen(request.getTarget(), request.getSource()) != null) {
- return false;
- }
-
- // now check if source branch is integrated into target branch
- return !GitUtils.isMergedInto(request.getTargetDepot().getRepository(),
- request.getSource().getObjectId(), request.getTarget().getObjectId());
+ return (!request.isOpen()
+ && SecurityUtils.canModify(request)
+ && request.getTarget().getObjectName(false) != null
+ && request.getSourceDepot() != null
+ && request.getSource().getObjectName(false) != null
+ && pullRequestManager.findEffective(request.getTarget(), request.getSource()) == null
+ && !GitUtils.isMergedInto(request.getTargetDepot().getRepository(),
+ request.getSource().getObjectId(), request.getTarget().getObjectId()));
}
@Override
@@ -144,18 +103,18 @@ public enum PullRequestOperation {
@Override
public boolean canOperate(PullRequest request) {
- IntegrationPreview preview = request.getLastIntegrationPreview();
+ MergePreview preview = request.getLastMergePreview();
PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
- return request.getStatus() == Status.INTEGRATED
+ return request.isMerged()
&& request.getSourceDepot() != null
&& request.getSource().getObjectName(false) != null
&& !request.getSource().isDefault()
&& preview != null
&& (request.getSource().getObjectName().equals(preview.getRequestHead())
- || request.getSource().getObjectName().equals(preview.getIntegrated()))
+ || request.getSource().getObjectName().equals(preview.getMerged()))
&& SecurityUtils.canModify(request)
- && SecurityUtils.canPushRef(request.getSourceDepot(), request.getSourceRef(), request.getSource().getObjectId(), ObjectId.zeroId())
- && pullRequestManager.findAllOpenTo(request.getSource(), null).isEmpty();
+ && SecurityUtils.canDeleteBranch(request.getSourceDepot(), request.getSourceBranch())
+ && pullRequestManager.findAllOpenTo(request.getSource()).isEmpty();
}
},
@@ -171,7 +130,7 @@ public enum PullRequestOperation {
return request.getSourceDepot() != null
&& request.getSource().getObjectName(false) == null
&& SecurityUtils.canModify(request)
- && SecurityUtils.canPushRef(request.getSourceDepot(), request.getSourceRef(), ObjectId.zeroId(), ObjectId.fromString(request.getHeadCommitHash()));
+ && SecurityUtils.canWrite(request.getSourceDepot());
}
};
@@ -179,20 +138,7 @@ public enum PullRequestOperation {
private static boolean canReview(PullRequest request) {
Account user = GitPlex.getInstance(AccountManager.class).getCurrent();
- // call request.getStatus() in order to trigger generation of review
- // integrations which will be used in else condition
- if (user == null
- || request.getStatus() == PullRequest.Status.INTEGRATED
- || request.getStatus() == PullRequest.Status.DISCARDED
- || request.isReviewEffective(user)) {
- return false;
- } else {
- for (PullRequestReviewInvitation invitation: request.getReviewInvitations()) {
- if (invitation.getStatus() != PullRequestReviewInvitation.Status.EXCLUDED && invitation.getUser().equals(user))
- return true;
- }
- return false;
- }
+ return request.getReviewCheckStatus().getAwaitingReviewers().contains(user);
}
public abstract void operate(PullRequest request, @Nullable String comment);
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/RequestDetailPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/RequestDetailPage.html
index 69f6f2e8a3..30bd2018b0 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/RequestDetailPage.html
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/RequestDetailPage.html
@@ -13,7 +13,7 @@
<div wicket:id="statusAndBranches" class="status-and-branches clearfix">
<div wicket:id="status" class="label pull-left status"></div>
<div class="pull-left branches">
- <a wicket:id="user"></a> <span wicket:id="action"></span> into <a wicket:id="target" class="branch"></a>
+ <a wicket:id="user"></a> wants to merge into <a wicket:id="target" class="branch"></a>
from <a wicket:id="source" class="branch"></a> <span wicket:id="date"></span>
</div>
</div>
@@ -21,74 +21,49 @@
<div wicket:id="discardedNote">
<i class="fa fa-info-circle"></i> This pull request has been discarded.
</div>
- <div wicket:id="pendingUpdateNote" class="note with-status-reasons">
- <i class="fa fa-info-circle"></i> This pull request does not pass gatekeeper
- checks below, and needs to be updated with new commits.
- </div>
- <div wicket:id="pendingApprovalNote" class="note with-status-reasons">
- <i class="fa fa-info-circle"></i> This pull request needs to be approved/verified as below, before it can be integrated
- </div>
- <div wicket:id="integratedNote" class="integrated-note">
+ <div wicket:id="mergedNote" class="merged-note">
<div wicket:id="fastForwarded">
- <i class="fa fa-info-circle"></i> Target branch was fast-forwarded to source branch.
+ <i class="fa fa-info-circle"></i> Target branch was fast-forwarded to source branch
</div>
<div wicket:id="merged">
- <i class="fa fa-info-circle"></i> Target branch was merged with source branch.
+ <i class="fa fa-info-circle"></i> Commits were merged into target branch
</div>
<div wicket:id="mergedOutside">
- <i class="fa fa-info-circle"></i> Target branch was merged with source branch by someone outside of this pull request.
+ <i class="fa fa-info-circle"></i> Commits were merged into target branch by someone outside of this pull request
</div>
<div wicket:id="squashed">
- <p><i class="fa fa-info-circle"></i> Per integration strategy, pending commits in source branch was squashed
- before merging into target branch. Run this command if you want to sync local
- branch with the source branch:
- <kbd>git fetch origin && git rebase</kbd>
- </p>
- </div>
- <div wicket:id="sourceRebased">
- <p><i class="fa fa-info-circle"></i> Per integration strategy, pending commits in source branch was rebased
- before merging into target branch. Run this command if you want to sync local
- branch with the source branch:
- <kbd>git fetch origin && git rebase</kbd>
- </p>
+ <i class="fa fa-info-circle"></i> Commits were squashed into a single commit in target branch
</div>
- <div wicket:id="targetRebased">
- <p><i class="fa fa-info-circle"></i> Per integration strategy, target branch was rebased on top of source branch.
- Run this command if you want to sync local branch with the target branch:
- <kbd>git fetch origin && git rebase</kbd>
- </p>
+ <div wicket:id="rebased">
+ <i class="fa fa-info-circle"></i> Commits were rebased onto target branch
</div>
</div>
- <div wicket:id="statusReasons" class="status-reasons">
- <ul><li wicket:id="reasons" class="reason"><span wicket:id="reason"></span></li></ul>
- </div>
- <div wicket:id="integrationPreview" class="integration-preview">
+ <div wicket:id="mergePreview" class="merge-preview">
<div wicket:id="calculating">
<wicket:link>
- <img src="ajax-indicator.gif"></img> Calculating integration preview...
+ <img src="ajax-indicator.gif"></img> Calculating merge preview...
</wicket:link>
</div>
<div wicket:id="noConflict" class="no-conflict">
- <label><i class="fa fa-check-circle"></i> Able to integrate without conflicts</label>
- <wicket:enclosure child="preview">
- <span class="middot"></span> <span><a wicket:id="preview">Preview</a> the integration result</span>
- </wicket:enclosure>
- <wicket:enclosure child="verification">
- <span class="middot"></span> <span>Integration build verification <span wicket:id="verification"></span></span>
+ <label><i class="fa fa-check-circle"></i> Able to merge without conflicts</label>
+ <wicket:enclosure child="mergePreview">
+ <span class="middot"></span> Target branch will be updated to the <a wicket:id="mergePreview">merge result</a> upon approvals of all reviewers
</wicket:enclosure>
</div>
<div wicket:id="conflict" class="conflict">
- <span><i class="fa fa-warning"></i> There are integration conflicts.</span>
+ <span><i class="fa fa-warning"></i> There are merge conflicts.</span>
<wicket:enclosure child="resolveInstructionsTrigger">
Please follow <a wicket:id="resolveInstructionsTrigger" href="javascript:void(0);">this instruction</a> to resolve the conflicts.
</wicket:enclosure>
</div>
</div>
+ <div wicket:id="doNotMerge" class="do-not-merge">
+ This pull request is for review only and does not need to be merged
+ </div>
<div wicket:id="operations" class="operations">
<div class="buttons">
<a wicket:id="approve" class="btn btn-primary">Approve</a>
<a wicket:id="disapprove" class="btn btn-primary">Disapprove</a>
- <a wicket:id="integrate" class="btn btn-success">Integrate</a>
<a wicket:id="discard" class="btn btn-danger">Discard</a>
<a wicket:id="reopen" class="btn btn-primary">Reopen</a>
<a wicket:id="deleteSourceBranch" class="btn btn-primary">Delete source branch</a>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java
index dc4bc41d7e..8a2251e6de 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/RequestDetailPage.java
@@ -1,15 +1,13 @@
package com.gitplex.server.web.page.depot.pullrequest.requestdetail;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.MERGE_ALWAYS;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.MERGE_IF_NECESSARY;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
+import static com.gitplex.server.model.support.MergeStrategy.ALWAYS_MERGE;
+import static com.gitplex.server.model.support.MergeStrategy.MERGE_IF_NECESSARY;
+import static com.gitplex.server.model.support.MergeStrategy.REBASE_MERGE;
+import static com.gitplex.server.model.support.MergeStrategy.SQUASH_MERGE;
import static com.gitplex.server.web.page.depot.pullrequest.requestdetail.PullRequestOperation.APPROVE;
import static com.gitplex.server.web.page.depot.pullrequest.requestdetail.PullRequestOperation.DELETE_SOURCE_BRANCH;
import static com.gitplex.server.web.page.depot.pullrequest.requestdetail.PullRequestOperation.DISAPPROVE;
import static com.gitplex.server.web.page.depot.pullrequest.requestdetail.PullRequestOperation.DISCARD;
-import static com.gitplex.server.web.page.depot.pullrequest.requestdetail.PullRequestOperation.INTEGRATE;
import static com.gitplex.server.web.page.depot.pullrequest.requestdetail.PullRequestOperation.REOPEN;
import static com.gitplex.server.web.page.depot.pullrequest.requestdetail.PullRequestOperation.RESTORE_SOURCE_BRANCH;
@@ -42,8 +40,6 @@ import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.FormComponent;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
@@ -58,12 +54,12 @@ import org.apache.wicket.util.visit.IVisitor;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.PullRequestManager;
import com.gitplex.server.manager.VisitInfoManager;
+import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequest.Status;
-import com.gitplex.server.model.PullRequestUpdate;
import com.gitplex.server.model.support.DepotAndBranch;
-import com.gitplex.server.model.support.IntegrationPreview;
+import com.gitplex.server.model.support.MergePreview;
+import com.gitplex.server.model.support.MergeStrategy;
import com.gitplex.server.persistence.dao.Dao;
import com.gitplex.server.security.SecurityUtils;
import com.gitplex.server.web.component.comment.CommentInput;
@@ -74,7 +70,6 @@ import com.gitplex.server.web.component.link.BranchLink;
import com.gitplex.server.web.component.link.DropdownLink;
import com.gitplex.server.web.component.link.ViewStateAwarePageLink;
import com.gitplex.server.web.component.markdown.AttachmentSupport;
-import com.gitplex.server.web.component.pullrequest.verificationstatus.VerificationStatusPanel;
import com.gitplex.server.web.component.tabbable.PageTab;
import com.gitplex.server.web.component.tabbable.PageTabLink;
import com.gitplex.server.web.component.tabbable.Tab;
@@ -84,7 +79,7 @@ import com.gitplex.server.web.page.depot.DepotPage;
import com.gitplex.server.web.page.depot.NoBranchesPage;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.codecomments.RequestCodeCommentsPage;
-import com.gitplex.server.web.page.depot.pullrequest.requestdetail.integrationpreview.IntegrationPreviewPage;
+import com.gitplex.server.web.page.depot.pullrequest.requestdetail.mergepreview.MergePreviewPage;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
import com.gitplex.server.web.util.DateUtils;
import com.gitplex.server.web.util.WicketUtils;
@@ -288,12 +283,20 @@ public abstract class RequestDetailPage extends DepotPage {
add(summaryContainer);
summaryContainer.add(newDiscardedNoteContainer());
- summaryContainer.add(newPendingUpdateNoteContainer());
- summaryContainer.add(newPendingApprovalNoteContainer());
- summaryContainer.add(newIntegratedNoteContainer());
- summaryContainer.add(newStatusReasonsContainer());
- summaryContainer.add(newIntegrationPreviewContainer());
+ summaryContainer.add(newMergedNoteContainer());
+ summaryContainer.add(newMergePreviewContainer());
+ summaryContainer.add(new WebMarkupContainer("doNotMerge") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getMergeStrategy() == MergeStrategy.DO_NOT_MERGE);
+ }
+
+ }.setOutputMarkupPlaceholderTag(true));
+
summaryContainer.add(newOperationsContainer());
+
WicketUtils.markLastVisibleChild(summaryContainer);
List<Tab> tabs = new ArrayList<>();
@@ -301,7 +304,7 @@ public abstract class RequestDetailPage extends DepotPage {
tabs.add(new RequestTab("Overview", RequestOverviewPage.class));
tabs.add(new RequestTab("File Changes", RequestChangesPage.class));
tabs.add(new RequestTab("Code Comments", RequestCodeCommentsPage.class));
- tabs.add(new RequestTab("Integration Preview", IntegrationPreviewPage.class));
+ tabs.add(new RequestTab("Merge Preview", MergePreviewPage.class));
add(new Tabbable("requestTabs", tabs).setOutputMarkupId(true));
@@ -330,7 +333,11 @@ public abstract class RequestDetailPage extends DepotPage {
@Override
public String getObject() {
- return getPullRequest().getStatus().toString();
+ PullRequest request = getPullRequest();
+ if (request.isOpen())
+ return "OPEN";
+ else
+ return request.getCloseInfo().getCloseStatus().toString();
}
}) {
@@ -345,10 +352,10 @@ public abstract class RequestDetailPage extends DepotPage {
@Override
public String getObject() {
- PullRequest.Status status = getPullRequest().getStatus();
- if (status == Status.DISCARDED)
+ PullRequest request = getPullRequest();
+ if (request.isDiscarded())
return " label-danger";
- else if (status == Status.INTEGRATED)
+ else if (request.isMerged())
return " label-success";
else
return " label-warning";
@@ -369,23 +376,9 @@ public abstract class RequestDetailPage extends DepotPage {
});
- if (request.getStatus() == Status.INTEGRATED) {
- if (request.getCloseInfo().getClosedBy() != null)
- statusAndBranchesContainer.add(new AccountLink("user", request.getCloseInfo().getClosedBy()));
- else
- statusAndBranchesContainer.add(new WebMarkupContainer("user").setVisible(false));
-
- int commitCount = 0;
- for (PullRequestUpdate update: request.getUpdates())
- commitCount += update.getCommits().size();
-
- statusAndBranchesContainer.add(new Label("action", "integrated " + commitCount + " commits"));
- statusAndBranchesContainer.add(new Label("date", DateUtils.formatAge(request.getCloseInfo().getCloseDate())));
- } else {
- statusAndBranchesContainer.add(new AccountLink("user", request.getSubmitter()));
- statusAndBranchesContainer.add(new Label("action", "wants to integrate"));
- statusAndBranchesContainer.add(new Label("date", DateUtils.formatAge(request.getSubmitDate())));
- }
+ statusAndBranchesContainer.add(new AccountLink("user",
+ Account.getForDisplay(request.getSubmitter(), request.getSubmitterName())));
+ statusAndBranchesContainer.add(new Label("date", DateUtils.formatAge(request.getSubmitDate())));
statusAndBranchesContainer.add(new BranchLink("target", request.getTarget()));
if (request.getSourceDepot() != null) {
@@ -403,29 +396,31 @@ public abstract class RequestDetailPage extends DepotPage {
}
return statusAndBranchesContainer;
}
-
- private WebMarkupContainer newIntegrationPreviewContainer() {
- WebMarkupContainer integrationPreviewContainer = new WebMarkupContainer("integrationPreview") {
+
+ private WebMarkupContainer newMergePreviewContainer() {
+ WebMarkupContainer mergePreviewContainer = new WebMarkupContainer("mergePreview") {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().isOpen());
+
+ PullRequest request = getPullRequest();
+ setVisible(request.isOpen() && request.getMergeStrategy() != MergeStrategy.DO_NOT_MERGE);
}
};
- integrationPreviewContainer.setOutputMarkupPlaceholderTag(true);
+ mergePreviewContainer.setOutputMarkupPlaceholderTag(true);
- integrationPreviewContainer.add(new WebMarkupContainer("calculating") {
+ mergePreviewContainer.add(new WebMarkupContainer("calculating") {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().getIntegrationPreview() == null);
+ setVisible(getPullRequest().getMergePreview() == null);
}
});
- integrationPreviewContainer.add(new WebMarkupContainer("conflict") {
+ mergePreviewContainer.add(new WebMarkupContainer("conflict") {
@Override
protected void onInitialize() {
@@ -450,54 +445,40 @@ public abstract class RequestDetailPage extends DepotPage {
@Override
protected void onConfigure() {
super.onConfigure();
- IntegrationPreview preview = getPullRequest().getIntegrationPreview();
- setVisible(preview != null && preview.getIntegrated() == null);
+ MergePreview preview = getPullRequest().getMergePreview();
+ setVisible(preview != null && preview.getMerged() == null);
}
});
- integrationPreviewContainer.add(new WebMarkupContainer("noConflict") {
+ mergePreviewContainer.add(new WebMarkupContainer("noConflict") {
@Override
protected void onInitialize() {
super.onInitialize();
- Link<Void> link = new Link<Void>("preview") {
+ Link<Void> link = new Link<Void>("mergePreview") {
@Override
public void onClick() {
PullRequest request = getPullRequest();
- PageParameters params = IntegrationPreviewPage.paramsOf(request);
- setResponsePage(IntegrationPreviewPage.class, params);
+ PageParameters params = MergePreviewPage.paramsOf(request);
+ setResponsePage(MergePreviewPage.class, params);
}
-
+
};
add(link);
-
- add(new VerificationStatusPanel("verification", requestModel, new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getIntegrationPreview();
- if (preview != null)
- return preview.getIntegrated();
- else
- return null;
- }
-
- }));
}
@Override
protected void onConfigure() {
super.onConfigure();
- IntegrationPreview preview = getPullRequest().getIntegrationPreview();
- setVisible(preview != null && preview.getIntegrated() != null);
+ MergePreview preview = getPullRequest().getMergePreview();
+ setVisible(preview != null && preview.getMerged() != null);
}
});
- return integrationPreviewContainer;
+ return mergePreviewContainer;
}
private WebMarkupContainer newOperationsContainer() {
@@ -560,23 +541,6 @@ public abstract class RequestDetailPage extends DepotPage {
});
- operationsContainer.add(new AjaxLink<Void>("integrate") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- operationsContainer.replace(newOperationConfirm(confirmId, INTEGRATE, operationsContainer));
- target.add(operationsContainer);
- target.appendJavaScript("$(window).resize();");
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(INTEGRATE.canOperate(getPullRequest()) && !operationsContainer.get(confirmId).isVisible());
- }
-
- });
-
operationsContainer.add(new AjaxLink<Void>("discard") {
@Override
@@ -716,9 +680,7 @@ public abstract class RequestDetailPage extends DepotPage {
@Override
public String getObject() {
- if (operation == INTEGRATE)
- return "btn-success";
- else if (operation == DISCARD)
+ if (operation == DISCARD)
return "btn-danger";
else
return "btn-primary";
@@ -751,7 +713,7 @@ public abstract class RequestDetailPage extends DepotPage {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.DISCARDED);
+ setVisible(getPullRequest().isDiscarded());
}
};
@@ -759,166 +721,90 @@ public abstract class RequestDetailPage extends DepotPage {
return discardedNoteContainer;
}
- private WebMarkupContainer newPendingUpdateNoteContainer() {
- WebMarkupContainer pendingUpdateNoteContainer = new WebMarkupContainer("pendingUpdateNote") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.PENDING_UPDATE);
- }
-
- };
- pendingUpdateNoteContainer.setOutputMarkupPlaceholderTag(true);
- return pendingUpdateNoteContainer;
- }
-
- private WebMarkupContainer newPendingApprovalNoteContainer() {
- WebMarkupContainer pendingApprovalNoteContainer = new WebMarkupContainer("pendingApprovalNote") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.PENDING_APPROVAL);
- }
-
- };
- pendingApprovalNoteContainer.setOutputMarkupPlaceholderTag(true);
- return pendingApprovalNoteContainer;
- }
-
private String getOperationName(PullRequestOperation operation) {
return WordUtils.capitalizeFully(operation.name()).replace("_", " ").toLowerCase();
}
- private WebMarkupContainer newIntegratedNoteContainer() {
- WebMarkupContainer integratedNoteContainer = new WebMarkupContainer("integratedNote") {
+ private WebMarkupContainer newMergedNoteContainer() {
+ WebMarkupContainer mergedNoteContainer = new WebMarkupContainer("mergedNote") {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.INTEGRATED);
+ setVisible(getPullRequest().isMerged());
}
};
- integratedNoteContainer.setOutputMarkupPlaceholderTag(true);
+ mergedNoteContainer.setOutputMarkupPlaceholderTag(true);
- integratedNoteContainer.add(new WebMarkupContainer("fastForwarded") {
+ mergedNoteContainer.add(new WebMarkupContainer("fastForwarded") {
@Override
protected void onConfigure() {
super.onConfigure();
PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
- setVisible(preview != null && preview.getRequestHead().equals(preview.getIntegrated()));
+ MergePreview preview = request.getLastMergePreview();
+ setVisible(preview != null && preview.getRequestHead().equals(preview.getMerged()));
}
});
- integratedNoteContainer.add(new WebMarkupContainer("merged") {
+ mergedNoteContainer.add(new WebMarkupContainer("merged") {
@Override
protected void onConfigure() {
super.onConfigure();
PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
+ MergePreview preview = request.getLastMergePreview();
setVisible(preview != null
- && !preview.getRequestHead().equals(preview.getIntegrated())
- && (preview.getIntegrationStrategy() == MERGE_ALWAYS || preview.getIntegrationStrategy() == MERGE_IF_NECESSARY));
+ && !preview.getRequestHead().equals(preview.getMerged())
+ && (preview.getMergeStrategy() == ALWAYS_MERGE || preview.getMergeStrategy() == MERGE_IF_NECESSARY));
}
});
- integratedNoteContainer.add(new WebMarkupContainer("mergedOutside") {
+ mergedNoteContainer.add(new WebMarkupContainer("mergedOutside") {
@Override
protected void onConfigure() {
super.onConfigure();
- setVisible(getPullRequest().getLastIntegrationPreview() == null);
+ setVisible(getPullRequest().getLastMergePreview() == null);
}
});
- integratedNoteContainer.add(new WebMarkupContainer("squashed") {
+ mergedNoteContainer.add(new WebMarkupContainer("squashed") {
@Override
protected void onConfigure() {
super.onConfigure();
PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
+ MergePreview preview = request.getLastMergePreview();
setVisible(preview != null
- && !preview.getRequestHead().equals(preview.getIntegrated())
- && preview.getIntegrationStrategy() == MERGE_WITH_SQUASH);
+ && !preview.getRequestHead().equals(preview.getMerged())
+ && preview.getMergeStrategy() == SQUASH_MERGE);
}
});
-
- integratedNoteContainer.add(new WebMarkupContainer("sourceRebased") {
+ mergedNoteContainer.add(new WebMarkupContainer("rebased") {
@Override
protected void onConfigure() {
super.onConfigure();
PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
+ MergePreview preview = request.getMergePreview();
setVisible(preview != null
- && !preview.getRequestHead().equals(preview.getIntegrated())
- && preview.getIntegrationStrategy() == REBASE_SOURCE_ONTO_TARGET);
+ && !preview.getRequestHead().equals(preview.getMerged())
+ && preview.getMergeStrategy() == REBASE_MERGE);
}
});
- integratedNoteContainer.add(new WebMarkupContainer("targetRebased") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = getPullRequest();
- IntegrationPreview preview = request.getLastIntegrationPreview();
- setVisible(preview != null
- && !preview.getRequestHead().equals(preview.getIntegrated())
- && preview.getIntegrationStrategy() == REBASE_TARGET_ONTO_SOURCE);
- }
-
- });
-
- return integratedNoteContainer;
+ return mergedNoteContainer;
}
- private WebMarkupContainer newStatusReasonsContainer() {
- WebMarkupContainer statusReasonsContainer = new WebMarkupContainer("statusReasons") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- PullRequest.Status status = getPullRequest().getStatus();
- setVisible(status == Status.PENDING_APPROVAL || status == Status.PENDING_UPDATE);
- }
-
- };
- statusReasonsContainer.setOutputMarkupPlaceholderTag(true);
-
- statusReasonsContainer.add(new ListView<String>("reasons", new AbstractReadOnlyModel<List<String>>() {
-
- @Override
- public List<String> getObject() {
- return getPullRequest().checkGates(false).getReasons();
- }
-
- }) {
-
- @Override
- protected void populateItem(ListItem<String> item) {
- item.add(new Label("reason", item.getModelObject()));
- }
-
- });
-
- return statusReasonsContainer;
- }
-
@Override
protected void onDetach() {
requestModel.detach();
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/ResolveConflictInstructionPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/ResolveConflictInstructionPanel.java
index dc3d3a5ac5..a64b933c1f 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/ResolveConflictInstructionPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/ResolveConflictInstructionPanel.java
@@ -1,9 +1,8 @@
package com.gitplex.server.web.page.depot.pullrequest.requestdetail;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.MERGE_ALWAYS;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
-import static com.gitplex.server.model.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
+import static com.gitplex.server.model.support.MergeStrategy.ALWAYS_MERGE;
+import static com.gitplex.server.model.support.MergeStrategy.SQUASH_MERGE;
+import static com.gitplex.server.model.support.MergeStrategy.REBASE_MERGE;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
@@ -17,8 +16,8 @@ import com.gitplex.server.manager.AccountManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequest.IntegrationStrategy;
-import com.gitplex.server.model.support.IntegrationPreview;
+import com.gitplex.server.model.support.MergePreview;
+import com.gitplex.server.model.support.MergeStrategy;
import com.gitplex.server.security.SecurityUtils;
@SuppressWarnings("serial")
@@ -36,10 +35,10 @@ class ResolveConflictInstructionPanel extends Panel {
Fragment fragment;
Depot targetDepot = request.getTarget().getDepot();
Account user = GitPlex.getInstance(AccountManager.class).getCurrent();
- IntegrationPreview preview = request.getIntegrationPreview();
- IntegrationStrategy strategy = request.getIntegrationStrategy();
+ MergePreview preview = request.getMergePreview();
+ MergeStrategy strategy = request.getMergeStrategy();
boolean sameRepo = request.getTarget().getDepot().equals(request.getSource().getDepot());
- if (strategy == MERGE_WITH_SQUASH || strategy == REBASE_SOURCE_ONTO_TARGET) {
+ if (strategy == SQUASH_MERGE || strategy == REBASE_MERGE) {
fragment = new Fragment("content", "rebaseInSourceFrag", this);
fragment.add(new Label("srcRepoName", request.getSource().getDepot()));
fragment.add(new Label("srcBranchNameForCheckout", request.getSourceBranch()));
@@ -53,34 +52,19 @@ class ResolveConflictInstructionPanel extends Panel {
differentRepoContainer.add(new Label("destBranchName", request.getTargetBranch()));
differentRepoContainer.setVisible(!sameRepo);
fragment.add(differentRepoContainer);
- } else if (strategy == REBASE_TARGET_ONTO_SOURCE) {
- fragment = new Fragment("content", "rebaseInTargetFrag", this);
- fragment.add(new Label("destRepoName", request.getTarget().getDepot()));
- fragment.add(new Label("destBranchNameForCheckout", request.getTargetBranch()));
- fragment.add(new Label("destBranchNameForPush", request.getTargetBranch()));
- WebMarkupContainer sameRepoContainer = new WebMarkupContainer("sameRepo");
- sameRepoContainer.add(new Label("srcBranchName", request.getSourceBranch()));
- sameRepoContainer.setVisible(sameRepo);
- fragment.add(sameRepoContainer);
- WebMarkupContainer differentRepoContainer = new WebMarkupContainer("differentRepo");
- differentRepoContainer.add(new Label("srcRepoUrl", request.getSource().getDepot().getUrl()));
- differentRepoContainer.add(new Label("srcBranchName", request.getSourceBranch()));
- differentRepoContainer.setVisible(!sameRepo);
- fragment.add(differentRepoContainer);
} else if (user != null
- && SecurityUtils.canWrite(targetDepot)
- && targetDepot.getGateKeeper().checkPush(user, request.getTargetDepot(), request.getTargetRef(), request.getTarget().getObjectId(), ObjectId.fromString(preview.getRequestHead())).isPassedOrIgnored()) {
+ && SecurityUtils.canPush(targetDepot, request.getTargetBranch(), request.getTarget().getObjectId(), ObjectId.fromString(preview.getRequestHead()))) {
fragment = new Fragment("content", "mergeInTargetFrag", this);
fragment.add(new Label("destRepoName", request.getTarget().getDepot()));
fragment.add(new Label("destBranchNameForCheckout", request.getTargetBranch()));
fragment.add(new Label("destBranchNameForPush", request.getTargetBranch()));
WebMarkupContainer sameRepoContainer = new WebMarkupContainer("sameRepo");
- sameRepoContainer.add(new Label("ffOption", strategy==MERGE_ALWAYS?"--no-ff":""));
+ sameRepoContainer.add(new Label("ffOption", strategy==ALWAYS_MERGE?"--no-ff":""));
sameRepoContainer.add(new Label("srcBranchName", request.getSourceBranch()));
sameRepoContainer.setVisible(sameRepo);
fragment.add(sameRepoContainer);
WebMarkupContainer differentRepoContainer = new WebMarkupContainer("differentRepo");
- differentRepoContainer.add(new Label("ffOption", strategy==MERGE_ALWAYS?"--no-ff":""));
+ differentRepoContainer.add(new Label("ffOption", strategy==ALWAYS_MERGE?"--no-ff":""));
differentRepoContainer.add(new Label("srcRepoUrl", request.getSource().getDepot().getUrl()));
differentRepoContainer.add(new Label("srcBranchName", request.getSourceBranch()));
differentRepoContainer.setVisible(!sameRepo);
@@ -91,12 +75,12 @@ class ResolveConflictInstructionPanel extends Panel {
fragment.add(new Label("srcBranchNameForCheckout", request.getSourceBranch()));
fragment.add(new Label("srcBranchNameForPush", request.getSourceBranch()));
WebMarkupContainer sameRepoContainer = new WebMarkupContainer("sameRepo");
- sameRepoContainer.add(new Label("ffOption", strategy==MERGE_ALWAYS?"--no-ff":""));
+ sameRepoContainer.add(new Label("ffOption", strategy==ALWAYS_MERGE?"--no-ff":""));
sameRepoContainer.add(new Label("destBranchName", request.getTargetBranch()));
sameRepoContainer.setVisible(sameRepo);
fragment.add(sameRepoContainer);
WebMarkupContainer differentRepoContainer = new WebMarkupContainer("differentRepo");
- differentRepoContainer.add(new Label("ffOption", strategy==MERGE_ALWAYS?"--no-ff":""));
+ differentRepoContainer.add(new Label("ffOption", strategy==ALWAYS_MERGE?"--no-ff":""));
differentRepoContainer.add(new Label("destRepoUrl", request.getTarget().getDepot().getUrl()));
differentRepoContainer.add(new Label("destBranchName", request.getTargetBranch()));
differentRepoContainer.setVisible(!sameRepo);
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/IntegrationPreviewResourceReference.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/IntegrationPreviewResourceReference.java
deleted file mode 100644
index 20ebc2fdee..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/IntegrationPreviewResourceReference.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.gitplex.server.web.page.depot.pullrequest.requestdetail.integrationpreview;
-
-import org.apache.wicket.request.resource.CssResourceReference;
-
-public class IntegrationPreviewResourceReference extends CssResourceReference {
-
- private static final long serialVersionUID = 1L;
-
- public IntegrationPreviewResourceReference() {
- super(IntegrationPreviewResourceReference.class, "integration-preview.css");
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/integration-preview.css b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/integration-preview.css
deleted file mode 100644
index daf21e4b11..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/integration-preview.css
+++ /dev/null
@@ -1,13 +0,0 @@
-#request-detail>.integration-preview>.available>.head {
- margin-bottom: 20px;
- font-size: 16px;
-}
-#request-detail>.integration-preview>.available>.head .out-dated {
- margin-left: 20px;
-}
-#request-detail>.integration-preview>.available>.head .out-dated a {
- color: #666;
-}
-#request-detail>.integration-preview>.not-available {
- font-size: 16px;
-}
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/IntegrationPreviewPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/MergePreviewPage.html
similarity index 51%
rename from web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/IntegrationPreviewPage.html
rename to web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/MergePreviewPage.html
index 18b6f048ab..c54bfaab80 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/IntegrationPreviewPage.html
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/MergePreviewPage.html
@@ -1,19 +1,19 @@
<wicket:extend>
- <div wicket:id="content" class="integration-preview"></div>
+ <div wicket:id="content" class="merge-preview"></div>
<wicket:fragment wicket:id="availableFrag">
<div class="available">
<div class="head clearfix">
<div class="title pull-left">
- Comparison of target branch and integrated commit
+ Comparison of target branch and merged commit
</div>
<div class="out-dated pull-left">
- <a wicket:id="refresh"><i class="fa fa-warning"></i> Integration preview is out dated, click to refresh</a>
+ <a wicket:id="refresh"><i class="fa fa-warning"></i> Merge preview is out dated, click to refresh</a>
</div>
</div>
<div wicket:id="revisionDiff" class="body"></div>
</div>
</wicket:fragment>
<wicket:fragment wicket:id="notAvailableFrag">
- <div class="not-available"><i class="fa fa-info-circle"></i> Integration preview is not available yet</div>
+ <div class="not-available"><i class="fa fa-info-circle"></i> Merge preview is not available yet</div>
</wicket:fragment>
</wicket:extend>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/IntegrationPreviewPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/MergePreviewPage.java
similarity index 88%
rename from web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/IntegrationPreviewPage.java
rename to web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/MergePreviewPage.java
index b212dee3e5..438233f7ac 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/integrationpreview/IntegrationPreviewPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/MergePreviewPage.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.page.depot.pullrequest.requestdetail.integrationpreview;
+package com.gitplex.server.web.page.depot.pullrequest.requestdetail.mergepreview;
import java.io.Serializable;
@@ -18,7 +18,7 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.support.IntegrationPreview;
+import com.gitplex.server.model.support.MergePreview;
import com.gitplex.server.util.diff.WhitespaceOption;
import com.gitplex.server.web.component.diff.revision.RevisionDiffPanel;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.RequestDetailPage;
@@ -26,7 +26,7 @@ import com.gitplex.server.web.page.depot.pullrequest.requestlist.RequestListPage
import com.gitplex.server.web.websocket.PullRequestChanged;
@SuppressWarnings("serial")
-public class IntegrationPreviewPage extends RequestDetailPage {
+public class MergePreviewPage extends RequestDetailPage {
private static final String PARAM_WHITESPACE_OPTION = "whitespace-option";
@@ -36,7 +36,7 @@ public class IntegrationPreviewPage extends RequestDetailPage {
private State state = new State();
- public IntegrationPreviewPage(PageParameters params) {
+ public MergePreviewPage(PageParameters params) {
super(params);
state.pathFilter = params.get(PARAM_PATH_FILTER).toString();
@@ -75,8 +75,8 @@ public class IntegrationPreviewPage extends RequestDetailPage {
private void newContent(IPartialPageRequestHandler target) {
Fragment fragment;
- IntegrationPreview preview = getPullRequest().getIntegrationPreview();
- if (getPullRequest().isOpen() && preview != null && preview.getIntegrated() != null) {
+ MergePreview preview = getPullRequest().getMergePreview();
+ if (getPullRequest().isOpen() && preview != null && preview.getMerged() != null) {
fragment = new Fragment("content", "availableFrag", this);
fragment.add(new AjaxLink<Void>("refresh") {
@@ -93,12 +93,12 @@ public class IntegrationPreviewPage extends RequestDetailPage {
@Override
protected void onConfigure() {
super.onConfigure();
- IntegrationPreview latestPreview = getPullRequest().getIntegrationPreview();
+ MergePreview latestPreview = getPullRequest().getMergePreview();
setVisible(!getPullRequest().isOpen()
|| latestPreview == null
- || latestPreview.getIntegrated() == null
+ || latestPreview.getMerged() == null
|| !latestPreview.getTargetHead().equals(preview.getTargetHead())
- || !latestPreview.getIntegrated().equals(preview.getIntegrated()));
+ || !latestPreview.getMerged().equals(preview.getMerged()));
}
@Override
@@ -164,7 +164,7 @@ public class IntegrationPreviewPage extends RequestDetailPage {
};
Component revisionDiff = new RevisionDiffPanel("revisionDiff", depotModel,
- requestModel, preview.getTargetHead(), preview.getIntegrated(), pathFilterModel,
+ requestModel, preview.getTargetHead(), preview.getMerged(), pathFilterModel,
whitespaceOptionModel, blameModel, null);
revisionDiff.setOutputMarkupId(true);
fragment.add(revisionDiff);
@@ -204,14 +204,14 @@ public class IntegrationPreviewPage extends RequestDetailPage {
private void pushState(IPartialPageRequestHandler partialPageRequestHandler) {
PageParameters params = paramsOf(getPullRequest(), state);
- CharSequence url = RequestCycle.get().urlFor(IntegrationPreviewPage.class, params);
+ CharSequence url = RequestCycle.get().urlFor(MergePreviewPage.class, params);
pushState(partialPageRequestHandler, url.toString(), state);
}
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
- response.render(CssHeaderItem.forReference(new IntegrationPreviewResourceReference()));
+ response.render(CssHeaderItem.forReference(new MergePreviewResourceReference()));
}
public static class State implements Serializable {
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/MergePreviewResourceReference.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/MergePreviewResourceReference.java
new file mode 100644
index 0000000000..0bb04b51e5
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/MergePreviewResourceReference.java
@@ -0,0 +1,13 @@
+package com.gitplex.server.web.page.depot.pullrequest.requestdetail.mergepreview;
+
+import org.apache.wicket.request.resource.CssResourceReference;
+
+public class MergePreviewResourceReference extends CssResourceReference {
+
+ private static final long serialVersionUID = 1L;
+
+ public MergePreviewResourceReference() {
+ super(MergePreviewResourceReference.class, "merge-preview.css");
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/merge-preview.css b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/merge-preview.css
new file mode 100644
index 0000000000..3cd84cb05c
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/mergepreview/merge-preview.css
@@ -0,0 +1,13 @@
+#request-detail>.merge-preview>.available>.head {
+ margin-bottom: 20px;
+ font-size: 16px;
+}
+#request-detail>.merge-preview>.available>.head .out-dated {
+ margin-left: 20px;
+}
+#request-detail>.merge-preview>.available>.head .out-dated a {
+ color: #666;
+}
+#request-detail>.merge-preview>.not-available {
+ font-size: 16px;
+}
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.html
index 169036d492..6f5fae3a61 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.html
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.html
@@ -21,41 +21,28 @@
</td>
<td class="info">
<div class="well">
- <div wicket:id="assignee" class="assignee"></div>
- <div wicket:id="reviewers" class="reviewers">
+ <div class="reviewers">
<label>Reviewers:</label>
- <ul class="clearfix list-unstyled">
- <li wicket:id="reviewers" class="pull-left">
- <a wicket:id="avatar"></a>
- <span wicket:id="result"></span>
- </li>
- </ul>
- <wicket:enclosure child="addReviewer">
- <div>
- <input wicket:id="addReviewer" type="hidden"></input>
- </div>
- </wicket:enclosure>
+ <div wicket:id="reviewers"></div>
</div>
- <div wicket:id="integrationStrategy" class="integration-strategy">
- <label>
- Integration Strategy:
- <span wicket:id="help" class="fa fa-question-circle pointer small"></span>
- </label>
+ <div wicket:id="mergeStrategy" class="merge-strategy">
<div>
+ <label>Merge Strategy:</label>
<select wicket:id="editor"></select>
<span wicket:id="viewer"></span>
</div>
+ <div wicket:id="help" class="help-block"></div>
</div>
<div wicket:id="watch" class="watch">
<div>
<label>Watch Status:</label>
<select wicket:id="option"></select>
</div>
- <div class="help-block"><i class="fa fa-info-circle small"></i> <span wicket:id="help"></span></div>
+ <div wicket:id="help" class="help-block"></div>
</div>
<div wicket:id="manage" class="manage">
<a wicket:id="synchronize" class="check btn btn-default">Synchronize</a>
- <p class="help-block"><i class="fa fa-info-circle"></i> In case the pull request status is out of sync with underlying
+ <p class="help-block">In case the pull request status is out of sync with underlying
repository, you may synchronize them manually here</p>
<a wicket:id="delete" class="delete btn btn-danger">Delete</a>
</div>
@@ -63,19 +50,6 @@
</td>
</tr>
</table>
- <wicket:fragment wicket:id="assigneeEditFrag">
- <label>Assigned To: <span wicket:id="help" class="fa fa-question-circle pointer small"></span></label>
- <div>
- <input wicket:id="assignee" type="hidden"></input>
- </div>
- </wicket:fragment>
- <wicket:fragment wicket:id="assigneeViewFrag">
- <label>Assigned To: <span wicket:id="help" class="fa fa-question-circle pointer small"></span></label>
- <span wicket:id="assignee" class="avatar"></span>
- </wicket:fragment>
- <wicket:fragment wicket:id="noAssigneeFrag">
- This pull request will be integrated automatically as long as it passes gatekeeper check.
- </wicket:fragment>
<wicket:fragment wicket:id="sinceChangesRowContentFrag">
<div>
<span class="icon fa fa-ext fa-file-diff"></span> <a wicket:id="sinceChanges">Changes since last visit</a>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java
index 7e214e1d91..e04e11ae35 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java
@@ -9,7 +9,6 @@ import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
import org.apache.wicket.behavior.AttributeAppender;
@@ -24,8 +23,6 @@ import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.IChoiceRenderer;
import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.AbstractReadOnlyModel;
@@ -41,27 +38,19 @@ import com.gitplex.server.manager.PullRequestManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequest.IntegrationStrategy;
import com.gitplex.server.model.PullRequestComment;
import com.gitplex.server.model.PullRequestReference;
-import com.gitplex.server.model.PullRequestReview;
-import com.gitplex.server.model.PullRequestReviewInvitation;
import com.gitplex.server.model.PullRequestStatusChange;
import com.gitplex.server.model.PullRequestUpdate;
import com.gitplex.server.model.PullRequestWatch;
+import com.gitplex.server.model.support.MergeStrategy;
import com.gitplex.server.persistence.dao.Dao;
-import com.gitplex.server.security.ObjectPermission;
import com.gitplex.server.security.SecurityUtils;
-import com.gitplex.server.web.behavior.TooltipBehavior;
-import com.gitplex.server.web.component.avatar.Avatar;
import com.gitplex.server.web.component.avatar.AvatarLink;
import com.gitplex.server.web.component.comment.CommentInput;
import com.gitplex.server.web.component.comment.DepotAttachmentSupport;
import com.gitplex.server.web.component.markdown.AttachmentSupport;
-import com.gitplex.server.web.component.pullrequest.requestassignee.AssigneeChoice;
-import com.gitplex.server.web.component.pullrequest.requestreviewer.ReviewerAvatar;
-import com.gitplex.server.web.component.pullrequest.requestreviewer.ReviewerChoice;
-import com.gitplex.server.web.component.pullrequest.reviewresult.ReviewResultIcon;
+import com.gitplex.server.web.component.requestreviewer.ReviewerListPanel;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.RequestDetailPage;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.activity.CommentedActivity;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.activity.OpenedActivity;
@@ -71,23 +60,14 @@ import com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.acti
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.activity.UpdatedActivity;
import com.gitplex.server.web.page.depot.pullrequest.requestlist.RequestListPage;
import com.gitplex.server.web.util.ConfirmOnClick;
-import com.gitplex.server.web.util.model.EntityModel;
-import com.gitplex.server.web.util.model.ReviewersModel;
import com.gitplex.server.web.websocket.PullRequestChanged;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
-import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
-import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig.Placement;
@SuppressWarnings("serial")
public class RequestOverviewPage extends RequestDetailPage {
- private static final String ASSIGNEE_HELP = "Assignee has write permission to the "
- + "repository and is resonsible for integrating the pull request into "
- + "target branch after it passes gatekeeper check.";
-
private enum WatchStatus {
WATCHING("Watching"),
NOT_WATCHING("Not Watching"),
@@ -140,10 +120,13 @@ public class RequestOverviewPage extends RequestDetailPage {
if (activity instanceof OpenedActivity) {
row.add(AttributeAppender.append("class", " discussion"));
- avatarColumn.add(new AvatarLink("avatar", ((OpenedActivity)activity).getRequest().getSubmitter(), null));
+ PullRequest request = ((OpenedActivity)activity).getRequest();
+ avatarColumn.add(new AvatarLink("avatar",
+ Account.getForDisplay(request.getSubmitter(), request.getSubmitterName())));
} else if (activity instanceof CommentedActivity) {
row.add(AttributeAppender.append("class", " discussion"));
- avatarColumn.add(new AvatarLink("avatar", ((CommentedActivity)activity).getComment().getUser(), null));
+ PullRequestComment comment = ((CommentedActivity)activity).getComment();
+ avatarColumn.add(new AvatarLink("avatar", Account.getForDisplay(comment.getUser(), comment.getUserName())));
} else {
row.add(AttributeAppender.append("class", " non-discussion"));
avatarColumn.add(new WebMarkupContainer("avatar"));
@@ -386,9 +369,8 @@ public class RequestOverviewPage extends RequestDetailPage {
});
- add(newIntegrationStrategyContainer());
- add(newAssigneeContainer());
- add(newReviewersContainer());
+ add(newMergeStrategyContainer());
+ add(new ReviewerListPanel("reviewers", requestModel));
add(newWatchContainer());
add(newManageContainer());
}
@@ -400,7 +382,7 @@ public class RequestOverviewPage extends RequestDetailPage {
@Override
public void onClick() {
- GitPlex.getInstance(PullRequestManager.class).check(getPullRequest());
+ GitPlex.getInstance(PullRequestManager.class).checkStatus(getPullRequest());
Session.get().success("Pull request is synchronized");
}
@@ -419,52 +401,50 @@ public class RequestOverviewPage extends RequestDetailPage {
return container;
}
- private WebMarkupContainer newIntegrationStrategyContainer() {
- WebMarkupContainer integrationStrategyContainer = new WebMarkupContainer("integrationStrategy") {
+ private WebMarkupContainer newMergeStrategyContainer() {
+ WebMarkupContainer mergeStrategyContainer = new WebMarkupContainer("mergeStrategy") {
@Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().isOpen());
+ public void onEvent(IEvent<?> event) {
+ super.onEvent(event);
+
+ if (event.getPayload() instanceof PullRequestChanged) {
+ PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
+ IPartialPageRequestHandler partialPageRequestHandler = pullRequestChanged.getPartialPageRequestHandler();
+ partialPageRequestHandler.add(this);
+ }
+
}
-
};
+ mergeStrategyContainer.setOutputMarkupId(true);
- PullRequest request = getPullRequest();
-
- final List<IntegrationStrategy> strategies =
- GitPlex.getInstance(PullRequestManager.class).getApplicableIntegrationStrategies(request);
- if (!strategies.contains(request.getIntegrationStrategy())) {
- request.setIntegrationStrategy(strategies.get(0));
- GitPlex.getInstance(Dao.class).persist(request);
- }
- IModel<IntegrationStrategy> strategyModel = new IModel<IntegrationStrategy>() {
+ IModel<MergeStrategy> mergeStrategyModel = new IModel<MergeStrategy>() {
@Override
public void detach() {
}
@Override
- public IntegrationStrategy getObject() {
- return getPullRequest().getIntegrationStrategy();
+ public MergeStrategy getObject() {
+ return getPullRequest().getMergeStrategy();
}
@Override
- public void setObject(IntegrationStrategy object) {
- getPullRequest().setIntegrationStrategy(object);
+ public void setObject(MergeStrategy object) {
+ getPullRequest().setMergeStrategy(object);
}
};
- DropDownChoice<IntegrationStrategy> editor =
- new DropDownChoice<IntegrationStrategy>("editor", strategyModel, strategies) {
+ List<MergeStrategy> mergeStrategies = Arrays.asList(MergeStrategy.values());
+ DropDownChoice<MergeStrategy> editor =
+ new DropDownChoice<MergeStrategy>("editor", mergeStrategyModel, mergeStrategies) {
@Override
protected void onConfigure() {
super.onConfigure();
- ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());
- setVisible(SecurityUtils.getSubject().isPermitted(writePermission) && strategies.size() > 1);
+ setVisible(SecurityUtils.canModify(getPullRequest()));
}
};
@@ -472,46 +452,41 @@ public class RequestOverviewPage extends RequestDetailPage {
@Override
protected void onUpdate(AjaxRequestTarget target) {
- GitPlex.getInstance(Dao.class).persist(getPullRequest());
+ GitPlex.getInstance(PullRequestManager.class).saveMergeStrategy(getPullRequest());
send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target));
}
});
- integrationStrategyContainer.add(editor);
+ mergeStrategyContainer.add(editor);
- integrationStrategyContainer.add(new Label("viewer", request.getIntegrationStrategy()) {
+ mergeStrategyContainer.add(new Label("viewer", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return getPullRequest().getMergeStrategy().getDisplayName();
+ }
+
+ }) {
@Override
protected void onConfigure() {
super.onConfigure();
- ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());
- setVisible(!SecurityUtils.getSubject().isPermitted(writePermission) || strategies.size() == 1);
+ setVisible(!SecurityUtils.canModify(getPullRequest()));
}
});
- ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());
+ mergeStrategyContainer.add(new Label("help", new AbstractReadOnlyModel<String>() {
- if (!SecurityUtils.getSubject().isPermitted(writePermission) || strategies.size() == 1) {
- integrationStrategyContainer.add(new WebMarkupContainer("help").add(
- new TooltipBehavior(Model.of(getPullRequest().getIntegrationStrategy().getDescription()))));
- } else {
- StringBuilder strategyHelp = new StringBuilder("<dl class='integration-strategy-help'>");
-
- for (IntegrationStrategy strategy: strategies) {
- strategyHelp.append("<dt>").append(strategy.toString()).append("</dt>");
- strategyHelp.append("<dd>").append(strategy.getDescription()).append("</dd>");
+ @Override
+ public String getObject() {
+ return getPullRequest().getMergeStrategy().getDescription();
}
-
- strategyHelp.append("</dl>");
- integrationStrategyContainer.add(new WebMarkupContainer("help")
- .add(AttributeAppender.append("data-html", "true"))
- .add(new TooltipBehavior(Model.of(strategyHelp.toString()), new TooltipConfig().withPlacement(Placement.left))));
- }
+ }));
- return integrationStrategyContainer;
+ return mergeStrategyContainer;
}
private WebMarkupContainer newWatchContainer() {
@@ -629,130 +604,6 @@ public class RequestOverviewPage extends RequestDetailPage {
return watchContainer;
}
- private Component newAssigneeContainer() {
- PullRequest request = getPullRequest();
-
- Fragment assigneeContainer;
- Account assignee = request.getAssignee();
- boolean canChangeAssignee = request.isOpen() && SecurityUtils.canModify(request);
- if (assignee != null) {
- if (canChangeAssignee) {
- assigneeContainer = new Fragment("assignee", "assigneeEditFrag", this);
- assigneeContainer.add(new WebMarkupContainer("help").add(new TooltipBehavior(Model.of(ASSIGNEE_HELP))));
-
- AssigneeChoice choice = new AssigneeChoice("assignee", new AbstractReadOnlyModel<Depot>() {
-
- @Override
- public Depot getObject() {
- return getPullRequest().getTargetDepot();
- }
-
- }, new IModel<Account>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public Account getObject() {
- return getPullRequest().getAssignee();
- }
-
- @Override
- public void setObject(Account object) {
- getPullRequest().setAssignee(object);
- }
-
- });
- choice.setRequired(true);
- assigneeContainer.add(choice);
- choice.add(new AjaxFormComponentUpdatingBehavior("change") {
-
- @Override
- protected void onUpdate(AjaxRequestTarget target) {
- Preconditions.checkNotNull(getPullRequest().getAssignee());
- GitPlex.getInstance(PullRequestManager.class).changeAssignee(getPullRequest());
- }
-
- });
- } else {
- assigneeContainer = new Fragment("assignee", "assigneeViewFrag", this);
- assigneeContainer.add(new WebMarkupContainer("help").add(new TooltipBehavior(Model.of(ASSIGNEE_HELP))));
- assigneeContainer.add(new Avatar("assignee", assignee, new TooltipConfig()));
- }
- } else {
- assigneeContainer = new Fragment("assignee", "noAssigneeFrag", this);
- }
-
- return assigneeContainer;
- }
-
- private WebMarkupContainer newReviewersContainer() {
- WebMarkupContainer reviewersContainer = new WebMarkupContainer("reviewers") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- PullRequest request = getPullRequest();
- if (request.getReviewInvitations().isEmpty()) {
- setVisible(request.isOpen()
- && !request.getPotentialReviewers().isEmpty()
- && SecurityUtils.canModify(request));
- } else {
- setVisible(true);
- }
- }
-
- };
- reviewersContainer.setOutputMarkupId(true);
- reviewersContainer.add(new ListView<PullRequestReviewInvitation>("reviewers", new ReviewersModel(requestModel)) {
-
- @Override
- protected void populateItem(ListItem<PullRequestReviewInvitation> item) {
- PullRequestReviewInvitation invitation = item.getModelObject();
- item.add(new ReviewerAvatar("avatar", invitation) {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- super.onClick(target);
-
- target.add(reviewersContainer);
- send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target));
- }
-
- });
-
- List<PullRequestReview> userReviews = new ArrayList<>();
- for (PullRequestReview review: getPullRequest().getReviews()) {
- if (review.getUser().equals(invitation.getUser()))
- userReviews.add(review);
- }
- if (!userReviews.isEmpty()) {
- PullRequestReview review = userReviews.get(userReviews.size()-1);
- item.add(new ReviewResultIcon("result", new EntityModel<PullRequestReview>(review)));
- } else {
- item.add(new WebMarkupContainer("result").setVisible(false));
- }
- }
-
- });
-
- reviewersContainer.add(new ReviewerChoice("addReviewer", requestModel) {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Account user) {
- super.onSelect(target, user);
-
- target.add(reviewersContainer);
- send(getPage(), Broadcast.BREADTH, new PullRequestChanged(target));
- }
-
- });
-
- return reviewersContainer;
- }
-
@Override
protected void onSelect(AjaxRequestTarget target, Depot depot) {
setResponsePage(RequestListPage.class, paramsOf(depot));
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/CommentedPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/CommentedPanel.java
index ce44ac772c..69bc3c0131 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/CommentedPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/CommentedPanel.java
@@ -18,6 +18,7 @@ import org.hibernate.StaleStateException;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.PullRequestCommentManager;
+import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
import com.gitplex.server.model.PullRequestComment;
@@ -46,7 +47,7 @@ class CommentedPanel extends GenericPanel<PullRequestComment> {
protected void onInitialize() {
super.onInitialize();
- add(new AccountLink("user", getComment().getUser()));
+ add(new AccountLink("user", Account.getForDisplay(getComment().getUser(), getComment().getUserName())));
add(new Label("age", DateUtils.formatAge(getComment().getDate())));
add(new SinceChangesLink("changes", new AbstractReadOnlyModel<PullRequest>() {
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/OpenedPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/OpenedPanel.java
index 8dae38f61e..27888c45a5 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/OpenedPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/OpenedPanel.java
@@ -17,6 +17,7 @@ import org.hibernate.StaleStateException;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.PullRequestManager;
+import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
import com.gitplex.server.persistence.dao.Dao;
@@ -179,8 +180,9 @@ class OpenedPanel extends GenericPanel<PullRequest> {
protected void onInitialize() {
super.onInitialize();
- add(new AccountLink("user", getPullRequest().getSubmitter()));
- add(new Label("age", DateUtils.formatAge(getPullRequest().getSubmitDate())));
+ PullRequest request = getPullRequest();
+ add(new AccountLink("user", Account.getForDisplay(request.getSubmitter(), request.getSubmitterName())));
+ add(new Label("age", DateUtils.formatAge(request.getSubmitDate())));
add(newViewer());
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/ReferencedPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/ReferencedPanel.java
index e7b7b98275..543e03c79f 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/ReferencedPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/ReferencedPanel.java
@@ -5,12 +5,13 @@ import org.apache.wicket.markup.html.panel.GenericPanel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.apache.wicket.model.IModel;
+import com.gitplex.server.model.Account;
import com.gitplex.server.model.PullRequest;
import com.gitplex.server.model.PullRequestReference;
import com.gitplex.server.web.component.avatar.AvatarLink;
import com.gitplex.server.web.component.link.AccountLink;
import com.gitplex.server.web.component.link.ViewStateAwarePageLink;
-import com.gitplex.server.web.component.pullrequest.requeststatus.RequestStatusPanel;
+import com.gitplex.server.web.component.requeststatus.RequestStatusPanel;
import com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
import com.gitplex.server.web.util.DateUtils;
@@ -26,8 +27,10 @@ class ReferencedPanel extends GenericPanel<PullRequestReference> {
super.onInitialize();
PullRequestReference reference = getModelObject();
- add(new AvatarLink("avatar", reference.getUser(), null));
- add(new AccountLink("name", reference.getUser()));
+
+ Account userForDisplay = Account.getForDisplay(reference.getUser(), reference.getUserName());
+ add(new AvatarLink("avatar", userForDisplay));
+ add(new AccountLink("name", userForDisplay));
add(new Label("age", DateUtils.formatAge(reference.getDate())));
ViewStateAwarePageLink<Void> link = new ViewStateAwarePageLink<Void>("link",
@@ -43,7 +46,7 @@ class ReferencedPanel extends GenericPanel<PullRequestReference> {
return ReferencedPanel.this.getModelObject().getReferencedBy();
}
- }, false));
+ }));
}
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/RequestCommentDeleted.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/RequestCommentDeleted.java
index d1dfd48ba2..13cd2f1e35 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/RequestCommentDeleted.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/RequestCommentDeleted.java
@@ -2,9 +2,9 @@ package com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.act
import org.apache.wicket.ajax.AjaxRequestTarget;
-import com.gitplex.server.web.util.AjaxEvent;
+import com.gitplex.server.web.util.AjaxPayload;
-public class RequestCommentDeleted extends AjaxEvent {
+public class RequestCommentDeleted extends AjaxPayload {
public RequestCommentDeleted(AjaxRequestTarget target) {
super(target);
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangePanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangePanel.java
index 94987be44d..d69847be68 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangePanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangePanel.java
@@ -19,6 +19,7 @@ import org.hibernate.StaleStateException;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.PullRequestStatusChangeManager;
+import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
import com.gitplex.server.model.PullRequest;
import com.gitplex.server.model.PullRequestStatusChange;
@@ -196,8 +197,9 @@ class StatusChangePanel extends GenericPanel<PullRequestStatusChange> {
if (iconClass != null)
icon.add(AttributeAppender.append("class", iconClass));
- container.add(new AvatarLink("userAvatar", statusChange.getUser(), null));
- container.add(new AccountLink("userName", statusChange.getUser()));
+ Account userForDisplay = Account.getForDisplay(statusChange.getUser(), statusChange.getUserName());
+ container.add(new AvatarLink("userAvatar", userForDisplay));
+ container.add(new AccountLink("userName", userForDisplay));
container.add(new Label("eventName", statusChange.getType().getName()));
container.add(new Label("eventDate", DateUtils.formatAge(statusChange.getDate())));
container.add(new SinceChangesLink("changes", new LoadableDetachableModel<PullRequest>() {
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedPanel.html b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedPanel.html
index 5ae52e7e82..34297e3be6 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedPanel.html
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedPanel.html
@@ -18,7 +18,6 @@
<a wicket:id="copyHash" class="btn btn-xs btn-default"><i class="fa fa-clipboard"></i></a>
</span>
</div>
- <div wicket:id="verification" class="pull-right"></div>
</td>
</tr>
</table>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedPanel.java
index dc7a07b2b6..730cb21e06 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedPanel.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedPanel.java
@@ -3,7 +3,6 @@ package com.gitplex.server.web.page.depot.pullrequest.requestdetail.overview.act
import java.util.List;
import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.event.IEvent;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
@@ -15,27 +14,20 @@ import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
-import org.apache.wicket.util.visit.IVisit;
-import org.apache.wicket.util.visit.IVisitor;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.revwalk.RevCommit;
import com.gitplex.server.git.BlobIdent;
import com.gitplex.server.git.GitUtils;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.PullRequest;
import com.gitplex.server.model.PullRequestUpdate;
import com.gitplex.server.web.WebConstants;
import com.gitplex.server.web.behavior.clipboard.CopyClipboardBehavior;
import com.gitplex.server.web.component.avatar.AvatarLink;
import com.gitplex.server.web.component.commitmessage.ExpandableCommitMessagePanel;
import com.gitplex.server.web.component.link.ViewStateAwarePageLink;
-import com.gitplex.server.web.component.pullrequest.verificationstatus.VerificationStatusPanel;
import com.gitplex.server.web.page.depot.blob.DepotBlobPage;
import com.gitplex.server.web.page.depot.commit.CommitDetailPage;
-import com.gitplex.server.web.websocket.PullRequestChanged;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
@SuppressWarnings("serial")
class UpdatedPanel extends GenericPanel<PullRequestUpdate> {
@@ -44,23 +36,6 @@ class UpdatedPanel extends GenericPanel<PullRequestUpdate> {
super(id, model);
}
- @Override
- public void onEvent(IEvent<?> event) {
- super.onEvent(event);
-
- if (event.getPayload() instanceof PullRequestChanged) {
- PullRequestChanged pullRequestChanged = (PullRequestChanged) event.getPayload();
- visitChildren(VerificationStatusPanel.class, new IVisitor<VerificationStatusPanel, Void>() {
-
- @Override
- public void component(VerificationStatusPanel object, IVisit<Void> visit) {
- pullRequestChanged.getPartialPageRequestHandler().add(object);
- }
-
- });
- }
- }
-
@Override
protected void onInitialize() {
super.onInitialize();
@@ -92,7 +67,7 @@ class UpdatedPanel extends GenericPanel<PullRequestUpdate> {
protected void populateItem(final ListItem<RevCommit> item) {
RevCommit commit = item.getModelObject();
- item.add(new AvatarLink("author", commit.getAuthorIdent(), new TooltipConfig()));
+ item.add(new AvatarLink("author", commit.getAuthorIdent(), true));
IModel<Depot> depotModel = new AbstractReadOnlyModel<Depot>() {
@@ -104,16 +79,6 @@ class UpdatedPanel extends GenericPanel<PullRequestUpdate> {
};
item.add(new ExpandableCommitMessagePanel("message", depotModel, item.getModel()));
- IModel<PullRequest> requestModel = new AbstractReadOnlyModel<PullRequest>() {
-
- @Override
- public PullRequest getObject() {
- return getUpdate().getRequest();
- }
-
- };
- item.add(new VerificationStatusPanel("verification", requestModel, Model.of(commit.name())));
-
CommitDetailPage.State commitState = new CommitDetailPage.State();
commitState.revision = commit.name();
PageParameters params = CommitDetailPage.paramsOf(depotModel.getObject(), commitState);
@@ -129,8 +94,8 @@ class UpdatedPanel extends GenericPanel<PullRequestUpdate> {
if (getUpdate().getRequest().getTarget().getObjectId(false) != null) {
if (getUpdate().getRequest().getMergedCommits().contains(commit)) {
- item.add(AttributeAppender.append("class", " integrated"));
- item.add(AttributeAppender.append("title", "This commit has been integrated"));
+ item.add(AttributeAppender.append("class", " merged"));
+ item.add(AttributeAppender.append("title", "This commit has been merged"));
} else if (!getUpdate().getRequest().getPendingCommits().contains(commit)) {
item.add(AttributeAppender.append("class", " rebased"));
item.add(AttributeAppender.append("title", "This commit has been rebased"));
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/request-overview.css b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/request-overview.css
index 0c200a5ae6..df47b137f4 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/request-overview.css
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/overview/request-overview.css
@@ -186,7 +186,7 @@
#request-detail .activities tr.activity>.content>.update tr:hover td {
background: #F5F5F5;
}
-#request-detail .activities tr.activity>.content>.update tr.integrated td.icon .fa {
+#request-detail .activities tr.activity>.content>.update tr.merged td.icon .fa {
color: #35A612;
}
#request-detail .activities tr.activity>.content>.update tr.rebased td a {
@@ -198,43 +198,41 @@
#request-detail .activities tr.activity>.content>.update tr.rebased img.avatar {
opacity: 0.5;
}
-#request-detail .activities tr.activity>.content>.update td.status .successful {
- color: #35A612;
-}
-#request-detail .activities tr.activity>.content>.update td.status .failed {
- color: #F93333;
-}
-#request-detail .activities tr.activity>.content>.update td.status .running {
- color: #AFAD1F;
-}
#request-detail .activities tr.activity.new>.avatar {
border-color: #4667EE;
}
-#request-detail .activities tr.activity>.content>.assigned>.head>.icon {
- padding-left: 8px;
-}
#request-detail .activities tr.activity>.content>.discarded>.head>.icon {
background: #F93333;
padding-left: 7px;
}
-#request-detail .activities tr.activity>.content>.integrated>.head>.icon {
- background: #35A612;
-}
-#request-detail .activities tr.activity>.content>.approved>.head>.icon,
-#request-detail .activities tr.activity>.content>.completed-verification-successful>.head>.icon {
+#request-detail .activities tr.activity>.content>.merged>.head>.icon {
background: #35A612;
}
-#request-detail .activities tr.activity>.content>.disapproved>.head>.icon,
-#request-detail .activities tr.activity>.content>.completed-verification-failed>.head>.icon {
- background: #F93333;
-}
#request-detail .activities tr.activity>.content>.deleted-review>.head>.icon,
-#request-detail .activities tr.activity>.content>.deleted-verification>.head>.icon,
#request-detail .activities tr.activity>.content>.deleted-source-branch>.head>.icon {
padding-top: 6px;
padding-left: 8px;
}
+#request-detail .activities tr.activity>.content>.approved>.head>.icon {
+ background: #35A612;
+ padding-top: 6px;
+ padding-left: 8px;
+}
+#request-detail .activities tr.activity>.content>.disapproved>.head>.icon {
+ background: #F93333;
+ padding-top: 6px;
+ padding-left: 8px;
+}
+#request-detail .activities tr.activity>.content>.changed-merge-strategy>.head>.icon {
+ padding-top: 6px;
+ padding-left: 8px;
+}
+#request-detail .activities tr.activity>.content>.added-reviewer>.head>.icon,
+#request-detail .activities tr.activity>.content>.removed-reviewer>.head>.icon {
+ padding-top: 7px;
+ padding-left: 8px;
+}
#request-detail .activities tr.activity>.content>.restored-source-branch>.head>.icon,
#request-detail .activities tr.activity>.content>.reopened>.head>.icon {
padding-left: 8px;
@@ -271,10 +269,14 @@
border-bottom: none;
margin-bottom: 0;
}
-#request-detail .info>div>.assignee, #request-detail .info>div>.reviewers>div,
-#request-detail .info>div>.integration-strategy, #request-detail .info>div>.watch {
+#request-detail .info>div>.reviewers>div,
+#request-detail .info>div>.merge-strategy,
+#request-detail .info>div>.watch {
padding-bottom: 20px;
}
+#request-detail .info>div>.reviewers .no-reviewers {
+ font-size: 14px;
+}
#request-detail .info .help-block {
margin-bottom: 0;
@@ -285,8 +287,8 @@
vertical-align: middle;
}
#request-detail .info label {
- margin-right: 4px;
- font-weight: normal;
+ margin: 0 4px 8px 0;
+ font-size: 16px;
}
#request-detail .info .select2-container {
width: 100%;
@@ -300,21 +302,6 @@
height: 20px;
}
-#request-detail .info .reviewers ul {
- margin-bottom: 0;
-}
-#request-detail .info .reviewers li {
- margin-right: 16px;
- margin-bottom: 20px;
- position: relative;
-}
-#request-detail .info .reviewers li a:hover {
- text-decoration: none;
-}
-
-#request-detail .info .reviewers .review-result {
- top: -4px;
-}
#request-detail .info .manage .help-block {
margin-bottom: 12px;
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/request-detail.css b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/request-detail.css
index 33b35630e9..f8e0cf0065 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/request-detail.css
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestdetail/request-detail.css
@@ -10,6 +10,9 @@
#request-detail>.summary .md-editor {
margin-bottom: 20px;
}
+#request-detail>.summary .merged-note, #request-detail>.summary .do-not-merge {
+ font-size: 16px;
+}
#request-detail>.head {
font-size: 24px;
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestlist/RequestListPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestlist/RequestListPage.java
index 91cc8f9fc3..5bc008b630 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestlist/RequestListPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestlist/RequestListPage.java
@@ -45,7 +45,7 @@ import com.gitplex.server.web.component.link.BranchLink;
import com.gitplex.server.web.component.link.ViewStateAwarePageLink;
import com.gitplex.server.web.component.menu.MenuItem;
import com.gitplex.server.web.component.menu.MenuLink;
-import com.gitplex.server.web.component.pullrequest.requeststatus.RequestStatusPanel;
+import com.gitplex.server.web.component.requeststatus.RequestStatusPanel;
import com.gitplex.server.web.editable.BeanContext;
import com.gitplex.server.web.page.depot.DepotPage;
import com.gitplex.server.web.page.depot.pullrequest.newrequest.NewRequestPage;
@@ -92,30 +92,6 @@ public class RequestListPage extends DepotPage {
Account currentUser = GitPlex.getInstance(AccountManager.class).getCurrent();
if (currentUser != null) {
String userName = currentUser.getName();
- menuItems.add(new MenuItem() {
-
- @Override
- public String getLabel() {
- return "Open requests assigned to me";
- }
-
- @Override
- public AbstractLink newLink(String id) {
- return new Link<Void>(id) {
-
- @Override
- public void onClick() {
- searchOption = new SearchOption();
- searchOption.setStatus(Status.OPEN);
- searchOption.setAssigneeName(userName);
-
- setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
- }
-
- };
- }
-
- });
menuItems.add(new MenuItem() {
@Override
@@ -303,8 +279,9 @@ public class RequestListPage extends DepotPage {
});
- fragment.add(new RequestStatusPanel("status", rowModel, false));
- fragment.add(new AccountLink("submitter", rowModel.getObject().getSubmitter()));
+ fragment.add(new RequestStatusPanel("status", rowModel));
+ fragment.add(new AccountLink("submitter", Account.getForDisplay(request.getSubmitter(),
+ request.getSubmitterName())));
fragment.add(new BranchLink("target", request.getTarget()));
if (request.getSource() != null)
fragment.add(new BranchLink("source", request.getSource()));
@@ -315,10 +292,9 @@ public class RequestListPage extends DepotPage {
WebMarkupContainer lastEventContainer = new WebMarkupContainer("lastEvent");
if (request.getLastEvent() != null) {
- if (request.getLastEvent().getUser() != null)
- lastEventContainer.add(new AccountLink("user", request.getLastEvent().getUser()));
- else
- lastEventContainer.add(new WebMarkupContainer("user").setVisible(false));
+ Account userForDisplay = Account.getForDisplay(request.getLastEvent().getUser(),
+ request.getLastEvent().getUserName());
+ lastEventContainer.add(new AccountLink("user", userForDisplay));
String description = request.getLastEvent().getType();
lastEventContainer.add(new Label("description", description));
lastEventContainer.add(new Label("date", DateUtils.formatAge(request.getLastEvent().getDate())));
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestlist/SearchOption.java b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestlist/SearchOption.java
index 82d2a83954..e13f40a6f9 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestlist/SearchOption.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/pullrequest/requestlist/SearchOption.java
@@ -29,8 +29,6 @@ public class SearchOption implements Serializable {
private static final String PARAM_STATUS = "status";
- private static final String PARAM_ASSIGNEE = "assignee";
-
private static final String PARAM_SUBMITTER = "submitter";
private static final String PARAM_BRANCH = "branch";
@@ -49,8 +47,6 @@ public class SearchOption implements Serializable {
private Status status = Status.OPEN;
- private String assigneeName;
-
private String submitterName;
private String branch;
@@ -81,16 +77,6 @@ public class SearchOption implements Serializable {
this.status = status;
}
- @Editable(order=200, name="Assigned To")
- @AccountChoice
- public String getAssigneeName() {
- return assigneeName;
- }
-
- public void setAssigneeName(String assigneeName) {
- this.assigneeName = assigneeName;
- }
-
@Editable(order=300, name="Submitted By")
@AccountChoice
public String getSubmitterName() {
@@ -150,8 +136,6 @@ public class SearchOption implements Serializable {
if (value != null)
status = Status.valueOf(value);
- assigneeName = params.get(PARAM_ASSIGNEE).toString();
-
submitterName = params.get(PARAM_SUBMITTER).toString();
branch = params.get(PARAM_BRANCH).toString();
@@ -194,9 +178,6 @@ public class SearchOption implements Serializable {
if (submitterName != null) {
criteria.createCriteria("submitter").add(Restrictions.eq("name", submitterName));
}
- if (assigneeName != null) {
- criteria.createCriteria("assignee").add(Restrictions.eq("name", assigneeName));
- }
if (title != null)
criteria.add(Restrictions.ilike("title", "%" + title + "%"));
if (beginDate != null)
@@ -209,8 +190,6 @@ public class SearchOption implements Serializable {
public void fillPageParams(PageParameters params) {
params.set(PARAM_DIRECTION, direction.name());
params.set(PARAM_STATUS, status.name());
- if (assigneeName != null)
- params.set(PARAM_ASSIGNEE, assigneeName);
if (submitterName != null)
params.set(PARAM_SUBMITTER, submitterName);
if (branch != null)
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/DepotSettingPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/DepotSettingPage.java
index e1fca2a5d1..9b3fe46d88 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/DepotSettingPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/DepotSettingPage.java
@@ -14,11 +14,11 @@ import com.gitplex.server.web.component.tabbable.Tabbable;
import com.gitplex.server.web.page.depot.DepotPage;
import com.gitplex.server.web.page.depot.setting.authorization.DepotCollaboratorListPage;
import com.gitplex.server.web.page.depot.setting.authorization.DepotEffectivePrivilegePage;
-import com.gitplex.server.web.page.depot.setting.authorization.DepotTeamListPage;
+import com.gitplex.server.web.page.depot.setting.authorization.DepotTeamAuthorizationPage;
+import com.gitplex.server.web.page.depot.setting.branchprotection.BranchProtectionPage;
import com.gitplex.server.web.page.depot.setting.commitmessagetransform.CommitMessageTransformPage;
-import com.gitplex.server.web.page.depot.setting.gatekeeper.GateKeeperPage;
import com.gitplex.server.web.page.depot.setting.general.GeneralSettingPage;
-import com.gitplex.server.web.page.depot.setting.integrationpolicy.IntegrationPolicyPage;
+import com.gitplex.server.web.page.depot.setting.tagprotection.TagProtectionPage;
@SuppressWarnings("serial")
public abstract class DepotSettingPage extends DepotPage {
@@ -39,7 +39,7 @@ public abstract class DepotSettingPage extends DepotPage {
List<PageTab> tabs = new ArrayList<>();
tabs.add(new DepotSettingTab("General Setting", "fa fa-fw fa-sliders", GeneralSettingPage.class));
if (getAccount().isOrganization()) {
- tabs.add(new DepotSettingTab("Teams", "fa fa-fw fa-group", DepotTeamListPage.class));
+ tabs.add(new DepotSettingTab("Team Authorizations", "fa fa-fw fa-group", DepotTeamAuthorizationPage.class));
tabs.add(new DepotSettingTab("Collaborators", "fa fa-fw fa-user", DepotCollaboratorListPage.class));
tabs.add(new DepotSettingTab("Effective Privileges", "fa fa-fw fa-key", DepotEffectivePrivilegePage.class));
} else {
@@ -54,8 +54,8 @@ public abstract class DepotSettingPage extends DepotPage {
tabs.add(new DepotSettingTab("Collaborators", "fa fa-fw fa-user", DepotCollaboratorListPage.class));
}
tabs.add(new DepotSettingTab("Commit Message Transform", "fa fa-fw fa-exchange", CommitMessageTransformPage.class));
- tabs.add(new DepotSettingTab("Gatekeepers", "fa fa-fw fa-eye", GateKeeperPage.class));
- tabs.add(new DepotSettingTab("Integration Policies", "fa fa-fw fa-puzzle-piece", IntegrationPolicyPage.class));
+ tabs.add(new DepotSettingTab("Branch Protection", "fa fa-fw fa-lock", BranchProtectionPage.class));
+ tabs.add(new DepotSettingTab("Tag Protection", "fa fa-fw fa-lock", TagProtectionPage.class));
add(new Tabbable("depotSettingTabs", tabs));
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamListPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamAuthorizationPage.html
similarity index 100%
rename from web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamListPage.html
rename to web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamAuthorizationPage.html
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamListPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamAuthorizationPage.java
similarity index 98%
rename from web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamListPage.java
rename to web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamAuthorizationPage.java
index 18bb348022..1d34302573 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamListPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/authorization/DepotTeamAuthorizationPage.java
@@ -48,7 +48,7 @@ import com.gitplex.server.web.page.depot.setting.DepotSettingPage;
import com.gitplex.server.web.util.depotaccess.DepotAccess;
@SuppressWarnings("serial")
-public class DepotTeamListPage extends DepotSettingPage {
+public class DepotTeamAuthorizationPage extends DepotSettingPage {
private ListView<TeamAuthorization> teamsView;
@@ -60,7 +60,7 @@ public class DepotTeamListPage extends DepotSettingPage {
private Set<Long> pendingRemovals = new HashSet<>();
- public DepotTeamListPage(PageParameters params) {
+ public DepotTeamAuthorizationPage(PageParameters params) {
super(params);
}
@@ -398,7 +398,7 @@ public class DepotTeamListPage extends DepotSettingPage {
@Override
protected void onSelect(AjaxRequestTarget target, Depot depot) {
if (depot.getAccount().isOrganization())
- setResponsePage(DepotTeamListPage.class, DepotTeamListPage.paramsOf(depot));
+ setResponsePage(DepotTeamAuthorizationPage.class, DepotTeamAuthorizationPage.paramsOf(depot));
else
setResponsePage(DepotCollaboratorListPage.class, DepotCollaboratorListPage.paramsOf(depot));
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyEditor.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionEditor.html
similarity index 100%
rename from web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyEditor.html
rename to web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionEditor.html
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionEditor.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionEditor.java
new file mode 100644
index 0000000000..5401d1b2a7
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionEditor.java
@@ -0,0 +1,138 @@
+package com.gitplex.server.web.page.depot.setting.branchprotection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.panel.Panel;
+
+import com.gitplex.server.model.Account;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.support.BranchProtection;
+import com.gitplex.server.model.support.FileProtection;
+import com.gitplex.server.util.reviewappointment.ReviewAppointment;
+import com.gitplex.server.web.editable.BeanContext;
+import com.gitplex.server.web.page.depot.DepotPage;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
+@SuppressWarnings("serial")
+abstract class BranchProtectionEditor extends Panel {
+
+ private final BranchProtection protection;
+
+ public BranchProtectionEditor(String id, BranchProtection protection) {
+ super(id);
+
+ this.protection = protection;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ setOutputMarkupId(true);
+
+ Form<?> form = new Form<Void>("form");
+ form.add(new NotificationPanel("feedback", form));
+
+ TeamlessBranchProtection teamlessProtection = new TeamlessBranchProtection();
+ teamlessProtection.setBranch(protection.getBranch());
+ teamlessProtection.setFileProtections(protection.getFileProtections());
+ teamlessProtection.setNoDeletion(protection.isNoDeletion());
+ teamlessProtection.setNoForcedPush(protection.isNoForcedPush());
+
+ Depot depot = ((DepotPage) getPage()).getDepot();
+
+ List<String> reviewerNames = new ArrayList<>();
+ ReviewAppointment reviewAppointment = protection.getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Account user: reviewAppointment.getUsers())
+ reviewerNames.add(user.getName());
+ }
+ teamlessProtection.setReviewerNames(reviewerNames);
+
+ for (FileProtection fileProtection: teamlessProtection.getFileProtections()) {
+ TeamlessFileProtection teamlessFileProtection = new TeamlessFileProtection();
+ teamlessFileProtection.setPath(fileProtection.getPath());
+
+ reviewerNames = new ArrayList<>();
+ reviewAppointment = fileProtection.getReviewAppointment(depot);
+ if (reviewAppointment != null) {
+ for (Account user: reviewAppointment.getUsers())
+ reviewerNames.add(user.getName());
+ }
+ teamlessFileProtection.setReviewerNames(reviewerNames);
+
+ teamlessProtection.getTeamlessFileProtections().add(teamlessFileProtection);
+ }
+
+ if (depot.getAccount().isOrganization())
+ form.add(BeanContext.editBean("editor", protection));
+ else
+ form.add(BeanContext.editBean("editor", teamlessProtection));
+
+ form.add(new AjaxButton("save") {
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ super.onSubmit(target, form);
+
+ Depot depot = ((DepotPage) getPage()).getDepot();
+ if (!depot.getAccount().isOrganization()) {
+ protection.setBranch(teamlessProtection.getBranch());
+ protection.setFileProtections(teamlessProtection.getFileProtections());
+ protection.setNoDeletion(teamlessProtection.isNoDeletion());
+ protection.setNoForcedPush(teamlessProtection.isNoForcedPush());
+
+ StringBuilder builder = new StringBuilder();
+ for (String userName: teamlessProtection.getReviewerNames())
+ builder.append("user(").append(userName).append(") ");
+ if (builder.length() != 0)
+ protection.setReviewAppointmentExpr(builder.toString().trim());
+ else
+ protection.setReviewAppointmentExpr(null);
+
+ protection.getFileProtections().clear();
+ for (TeamlessFileProtection teamlessFileProtection: teamlessProtection.getTeamlessFileProtections()) {
+ FileProtection fileProtection = new FileProtection();
+ fileProtection.setPath(teamlessFileProtection.getPath());
+
+ builder = new StringBuilder();
+ for (String userName: teamlessFileProtection.getReviewerNames())
+ builder.append("user(").append(userName).append(") ");
+ if (builder.length() != 0)
+ fileProtection.setReviewAppointmentExpr(builder.toString().trim());
+
+ protection.getFileProtections().add(fileProtection);
+ }
+ }
+
+ onSave(target, protection);
+ }
+
+ @Override
+ protected void onError(AjaxRequestTarget target, Form<?> form) {
+ super.onError(target, form);
+ target.add(form);
+ }
+
+ });
+ form.add(new AjaxLink<Void>("cancel") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ onCancel(target);
+ }
+
+ });
+ add(form);
+ }
+
+ protected abstract void onSave(AjaxRequestTarget target, BranchProtection protection);
+
+ protected abstract void onCancel(AjaxRequestTarget target);
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPage.html
new file mode 100644
index 0000000000..b2fdba35fa
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPage.html
@@ -0,0 +1,23 @@
+<wicket:extend>
+ <div wicket:id="branchProtectionSetting" class="panel-list">
+ <ul class="list-unstyled protections">
+ <li wicket:id="protections" class="protection"><div wicket:id="protection"></div></li>
+ </ul>
+ <div wicket:id="newProtection"></div>
+ <div class="help-block">
+ <i class="fa fa-info-circle"></i> Specify branch protection settings here. For a given branch, the first matching protection
+ setting will be used
+ </div>
+ </div>
+ <wicket:fragment wicket:id="editNewFrag">
+ <div class="protection panel panel-default">
+ <div class="panel-heading"><div class="panel-title">Edit Protection</div></div>
+ <div class="panel-body">
+ <div wicket:id="editor"></div>
+ </div>
+ </div>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="addNewLinkFrag">
+ <a wicket:id="link" class="add-new">Add Protection<i class="fa fa-plus-circle fa-lg"></i></a>
+ </wicket:fragment>
+</wicket:extend>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPage.java
new file mode 100644
index 0000000000..e69db58bc3
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPage.java
@@ -0,0 +1,126 @@
+package com.gitplex.server.web.page.depot.setting.branchprotection;
+
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.list.ListItem;
+import org.apache.wicket.markup.html.list.ListView;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+import com.gitplex.server.GitPlex;
+import com.gitplex.server.manager.DepotManager;
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.support.BranchProtection;
+import com.gitplex.server.web.behavior.sortable.SortBehavior;
+import com.gitplex.server.web.behavior.sortable.SortPosition;
+import com.gitplex.server.web.page.depot.setting.DepotSettingPage;
+
+@SuppressWarnings("serial")
+public class BranchProtectionPage extends DepotSettingPage {
+
+ private WebMarkupContainer container;
+
+ public BranchProtectionPage(PageParameters params) {
+ super(params);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ container = new WebMarkupContainer("branchProtectionSetting");
+ container.setOutputMarkupId(true);
+ add(container);
+ container.add(new ListView<BranchProtection>("protections", new AbstractReadOnlyModel<List<BranchProtection>>() {
+
+ @Override
+ public List<BranchProtection> getObject() {
+ return getDepot().getBranchProtections();
+ }
+ }) {
+
+ @Override
+ protected void populateItem(final ListItem<BranchProtection> item) {
+ item.add(new BranchProtectionPanel("protection", item.getModelObject()) {
+
+ @Override
+ protected void onDelete(AjaxRequestTarget target) {
+ getDepot().getBranchProtections().remove(item.getIndex());
+ GitPlex.getInstance(DepotManager.class).save(getDepot(), null, null);
+ target.add(container);
+ }
+
+ @Override
+ protected void onSave(AjaxRequestTarget target, BranchProtection protection) {
+ getDepot().getBranchProtections().set(item.getIndex(), protection);
+ GitPlex.getInstance(DepotManager.class).save(getDepot(), null, null);
+ }
+
+ });
+ }
+
+ });
+
+ container.add(new SortBehavior() {
+
+ @Override
+ protected void onSort(AjaxRequestTarget target, SortPosition from, SortPosition to) {
+ List<BranchProtection> protections = getDepot().getBranchProtections();
+ BranchProtection protection = protections.get(from.getItemIndex());
+ protections.set(from.getItemIndex(), protections.set(to.getItemIndex(), protection));
+ GitPlex.getInstance(DepotManager.class).save(getDepot(), null, null);
+
+ target.add(container);
+ }
+
+ }.handle(".drag-handle").items("li.protection"));
+
+ container.add(newAddNewFrag());
+ }
+
+ private Component newAddNewFrag() {
+ Fragment fragment = new Fragment("newProtection", "addNewLinkFrag", this);
+ fragment.add(new AjaxLink<Void>("link") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ Fragment fragment = new Fragment("newProtection", "editNewFrag", getPage());
+ fragment.setOutputMarkupId(true);
+ fragment.add(new BranchProtectionEditor("editor", new BranchProtection()) {
+
+ @Override
+ protected void onSave(AjaxRequestTarget target, BranchProtection protection) {
+ getDepot().getBranchProtections().add(protection);
+ GitPlex.getInstance(DepotManager.class).save(getDepot(), null, null);
+ container.replace(newAddNewFrag());
+ target.add(container);
+ }
+
+ @Override
+ protected void onCancel(AjaxRequestTarget target) {
+ Component newAddNewFrag = newAddNewFrag();
+ container.replace(newAddNewFrag);
+ target.add(newAddNewFrag);
+ }
+
+ });
+ container.replace(fragment);
+ target.add(fragment);
+ }
+
+ });
+ fragment.setOutputMarkupId(true);
+ return fragment;
+ }
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Depot depot) {
+ setResponsePage(BranchProtectionPage.class, BranchProtectionPage.paramsOf(depot));
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPanel.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPanel.html
new file mode 100644
index 0000000000..0e0dad270e
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPanel.html
@@ -0,0 +1,12 @@
+<wicket:panel>
+ <div class="branch-protection panel panel-default">
+ <div class="panel-heading">
+ <span class="drag-handle" title="Drag to reorder protections"><i class="fa fa-arrows"></i></span>
+ <a wicket:id="edit" title="Edit this protection"><i class="fa fa-pencil"></i></a>
+ <a wicket:id="delete" title="Delete this protection"><i class="fa fa-trash"></i></a>
+ </div>
+ <div class="panel-body">
+ <div wicket:id="protection"></div>
+ </div>
+ </div>
+</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPanel.java
new file mode 100644
index 0000000000..c9ccc64ca0
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/BranchProtectionPanel.java
@@ -0,0 +1,78 @@
+package com.gitplex.server.web.page.depot.setting.branchprotection;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.panel.Panel;
+
+import com.gitplex.server.model.support.BranchProtection;
+import com.gitplex.server.web.editable.BeanContext;
+import com.gitplex.server.web.util.ajaxlistener.ConfirmListener;
+
+@SuppressWarnings("serial")
+abstract class BranchProtectionPanel extends Panel {
+
+ private final BranchProtection protection;
+
+ public BranchProtectionPanel(String id, BranchProtection protection) {
+ super(id);
+
+ this.protection = protection;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new AjaxLink<Void>("edit") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ BranchProtectionEditor editor = new BranchProtectionEditor("protection", protection) {
+
+ @Override
+ protected void onSave(AjaxRequestTarget target, BranchProtection protection) {
+ BranchProtectionPanel.this.onSave(target, protection);
+ Component protectionViewer = BeanContext.viewBean("protection", protection).setOutputMarkupId(true);
+ BranchProtectionPanel.this.replace(protectionViewer);
+ target.add(protectionViewer);
+ }
+
+ @Override
+ protected void onCancel(AjaxRequestTarget target) {
+ Component protectionViewer = BeanContext.viewBean("protection", protection).setOutputMarkupId(true);
+ BranchProtectionPanel.this.replace(protectionViewer);
+ target.add(protectionViewer);
+ }
+
+ };
+ BranchProtectionPanel.this.replace(editor);
+ target.add(editor);
+ }
+
+ });
+
+ add(new AjaxLink<Void>("delete") {
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.getAjaxCallListeners().add(new ConfirmListener("Do you really want to delete this protection?"));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ onDelete(target);
+ }
+
+ });
+
+ add(BeanContext.viewBean("protection", protection).setOutputMarkupId(true));
+ }
+
+ protected abstract void onDelete(AjaxRequestTarget target);
+
+ protected abstract void onSave(AjaxRequestTarget target, BranchProtection protection);
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/TeamlessBranchProtection.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/TeamlessBranchProtection.java
new file mode 100644
index 0000000000..48613d89bf
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/TeamlessBranchProtection.java
@@ -0,0 +1,55 @@
+package com.gitplex.server.web.page.depot.setting.branchprotection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.validation.constraints.NotNull;
+
+import com.gitplex.server.model.support.BranchProtection;
+import com.gitplex.server.model.support.FileProtection;
+import com.gitplex.server.util.editable.annotation.AccountChoice;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable
+public class TeamlessBranchProtection extends BranchProtection {
+
+ private static final long serialVersionUID = 1L;
+
+ private List<String> reviewerNames;
+
+ private List<TeamlessFileProtection> teamlessFileProtections = new ArrayList<>();
+
+ @Override
+ public String getReviewAppointmentExpr() {
+ return super.getReviewAppointmentExpr();
+ }
+
+ @Override
+ public List<FileProtection> getFileProtections() {
+ return super.getFileProtections();
+ }
+
+ @Editable(order=400, name="Reviewers", description="Optionally specify required reviewers for changes of "
+ + "specified branch. Note that the user submitting the change is considered to reviewed the change "
+ + "automatically")
+ @AccountChoice(type=AccountChoice.Type.DEPOT_READER)
+ public List<String> getReviewerNames() {
+ return reviewerNames;
+ }
+
+ public void setReviewerNames(List<String> reviewerNames) {
+ this.reviewerNames = reviewerNames;
+ }
+
+ @Editable(order=500, name="File Protections", description="Optionally specify additional users to review particular paths. For each changed file, "
+ + "the first matched file protection setting will be used")
+ @NotNull
+ public List<TeamlessFileProtection> getTeamlessFileProtections() {
+ return teamlessFileProtections;
+ }
+
+ public void setTeamlessFileProtections(List<TeamlessFileProtection> teamlessFileProtections) {
+ this.teamlessFileProtections = teamlessFileProtections;
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/TeamlessFileProtection.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/TeamlessFileProtection.java
new file mode 100644
index 0000000000..a2138687b1
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/branchprotection/TeamlessFileProtection.java
@@ -0,0 +1,34 @@
+package com.gitplex.server.web.page.depot.setting.branchprotection;
+
+import java.util.List;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import com.gitplex.server.model.support.FileProtection;
+import com.gitplex.server.util.editable.annotation.AccountChoice;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable
+public class TeamlessFileProtection extends FileProtection {
+
+ private static final long serialVersionUID = 1L;
+
+ private List<String> reviewerNames;
+
+ public String getReviewAppointmentExpr() {
+ return super.getReviewAppointmentExpr();
+ }
+
+ @Editable(order=200, name="Reviewers", description="Optionally specify required reviewers if specified path is "
+ + "changed. Note that the user submitting the change is considered to reviewed the change automatically")
+ @AccountChoice(type=AccountChoice.Type.DEPOT_READER)
+ @NotEmpty
+ public List<String> getReviewerNames() {
+ return reviewerNames;
+ }
+
+ public void setReviewerNames(List<String> reviewerNames) {
+ this.reviewerNames = reviewerNames;
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/depot-setting.css b/web/src/main/java/com/gitplex/server/web/page/depot/setting/depot-setting.css
index 8b4924d671..b2df5fb8ba 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/depot-setting.css
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/depot-setting.css
@@ -29,14 +29,14 @@
#depot-setting .drag-handle {
cursor: move;
}
-.integration-policy-setting .drag-handle {
+#depot-setting .panel-list .drag-handle {
margin-right: 8px;
}
-.integration-policy-setting .panel-heading a {
+#depot-setting .panel-list .panel-heading a {
color: #444;
margin-right: 8px;
}
-.integration-policy-setting .add-new {
+#depot-setting .panel-list .add-new {
display: block;
padding: 16px;
background: #F2F2F2;
@@ -46,146 +46,18 @@
color: #444;
margin-bottom: 16px;
}
-.integration-policy-setting a.add-new:hover {
+#depot-setting .panel-list a.add-new:hover {
text-decoration: none;
background-color: #EBEBEB;
border-color: #ADADAD;
}
-.integration-policy-setting a.add-new .fa {
+#depot-setting .panel-list a.add-new .fa {
margin-left: 8px;
}
-
-.gate-keeper-add.well {
- font-size:16px;
-}
-.gate-keeper-add .fa {
- margin-left: 8px;
-}
-.gate-keeper-add:hover, .gate-keeper-add:focus {
- background-color: #EBEBEB;
- border-color: #ADADAD;
- cursor: pointer;
-}
-.gate-keeper-selector.floating {
- border-radius: 0;
-}
-.gate-keeper-selector.floating {
- max-width: 600px;
-}
-.gate-keeper-selector .panel {
- border: none;
- border-radius: 0;
-}
-.gate-keeper-selector .panel-heading {
- border-top: 1px solid #CCCCCC;
- border-radius: 0;
-}
-.gate-keeper-selector .panel-group>.panel:first-child>.panel-heading {
- border-top: none;
-}
-.gate-keeper-selector .panel-heading.collapsed:hover, .gate-keeper-selector .panel-heading.collapsed:focus {
- border-color: #999999;
- background-color: #E0E0E0;
- cursor: pointer;
-}
-.gate-keeper-selector .panel-group .panel + .panel {
- margin-top: 0px;
-}
-.gate-keeper-selector .fa {
- width: 20px;
-}
-.gate-keeper-description {
- font-size: 13px;
- color: #888888;
-}
-.gate-keeper-item {
- margin-bottom: 6px;
-}
-.gate-keeper-item>div {
- padding: 4px;
- border: 1px solid white;
-}
-.gate-keeper-item>div:hover, .gate-keeper-item>div:focus {
- background-color: #EBEBEB;
- cursor: pointer;
- border: 1px solid #ADADAD;
- border-radius: 4px;
-}
-.gate-keeper-name {
- font-size: 15px;
- margin-top: -4px;
-}
-.gate-keeper-editor {
- max-height: 600px;
- overflow: auto;
-}
-.gate-keeper-editor .gate-keeper-name {
- font-weight: bold;
- font-size: 16px;
- margin-top: 0;
- margin-bottom: 4px;
-}
-.gate-keeper-editor .modal-header .fa {
- width: 20px;
- 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;
-}
-.gate-keeper .panel-heading {
- padding: 8px;
-}
-.gate-keeper .fa {
- margin-left: 8px;
- cursor: pointer;
-}
-.gate-keeper .gate-keeper-add {
- margin: 0px;
- padding: 8px;
- font-size: 14px;
-}
-.gate-keeper .reflection {
- margin-bottom: 0;
-}
-
-.gate-keeper.panel.odd, .gate-keeper.panel.odd>.panel-heading {
- border-color: #198317;
-}
-.gate-keeper.panel.even, .gate-keeper.panel.even>.panel-heading {
- border-color: #CA0606;
-}
-
-.gate-keeper.panel.disabled {
- opacity: 0.5;
-}
-.gate-keeper table.viewer {
- font-size: 13px !important;
- color: #444444;
-}
-.gate-keeper td.child {
- padding-right: 12px;
-}
-.gate-keeper table.children>tbody>tr>td.child:last-child {
- padding-right: 0;
-}
-.gate-keeper.panel .panel-body {
- overflow:auto;
-}
-.gate-keeper.panel table.ifthen>tbody>tr.if>td {
- padding-bottom: 16px;
-}
-.gate-keeper.panel table.ifthen>tbody>tr>td>div>div.panel {
- margin-bottom: 0;
-}
-.not>div>.gate-keeper.panel {
- margin-bottom: 0;
+#depot-setting .panel-list .concrete.list td.path,
+#depot-setting .panel-list .concrete.list td.reviewerNames,
+#depot-setting .panel-list .concrete.list td.reviewAppointment {
+ width: 45%;
}
#depot-setting .authorization .list table td.actions {
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperDropBehavior.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperDropBehavior.java
deleted file mode 100644
index 0f0d01626f..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperDropBehavior.java
+++ /dev/null
@@ -1,157 +0,0 @@
-package com.gitplex.server.web.page.depot.setting.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-
-import com.google.common.base.Preconditions;
-import com.google.common.base.Splitter;
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.gatekeeper.AndGateKeeper;
-import com.gitplex.server.gatekeeper.AndOrGateKeeper;
-import com.gitplex.server.gatekeeper.CompositeGateKeeper;
-import com.gitplex.server.gatekeeper.ConditionalGateKeeper;
-import com.gitplex.server.gatekeeper.DefaultGateKeeper;
-import com.gitplex.server.gatekeeper.GateKeeper;
-import com.gitplex.server.gatekeeper.NotGateKeeper;
-import com.gitplex.server.manager.DepotManager;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.web.behavior.dragdrop.DropBehavior;
-
-abstract class GateKeeperDropBehavior extends DropBehavior {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- public void onDropped(AjaxRequestTarget target, String dragData) {
- List<Integer> dragPosition = Splitter.on(":").splitToList(dragData)
- .stream()
- .mapToInt(Integer::parseInt)
- .boxed()
- .collect(Collectors.toList());
- List<Integer> dropPosition = getPosition();
- GateKeeperPage page = (GateKeeperPage) getComponent().getPage();
- Depot depot = page.getDepot();
- AndGateKeeper root = (AndGateKeeper) depot.getGateKeeper();
- GateKeeper dragParent = getParentGateKeeper(root, dragPosition);
- GateKeeper dropParent = getParentGateKeeper(root, dropPosition);
- int dragIndex = dragPosition.get(dragPosition.size()-1);
- int dropIndex = dropPosition.get(dropPosition.size()-1);
- GateKeeper drag = getGateKeeper(dragParent, dragIndex);
- GateKeeper drop = getGateKeeper(dropParent, dropIndex);
- if (drop instanceof DefaultGateKeeper) {
- if (dragParent instanceof AndOrGateKeeper) {
- AndOrGateKeeper andOrGateKeeper = (AndOrGateKeeper) dragParent;
- andOrGateKeeper.getGateKeepers().remove(dragIndex);
- } else if (dragParent instanceof ConditionalGateKeeper) {
- ConditionalGateKeeper conditionalGateKeeper = (ConditionalGateKeeper) dragParent;
- if (dragIndex == 0)
- conditionalGateKeeper.setIfGate(new DefaultGateKeeper());
- else
- conditionalGateKeeper.setThenGate(new DefaultGateKeeper());
- } else {
- NotGateKeeper notGateKeeper = (NotGateKeeper) dragParent;
- notGateKeeper.setGateKeeper(new DefaultGateKeeper());
- }
- if (dropParent instanceof AndOrGateKeeper) {
- AndOrGateKeeper andOrGateKeeper = (AndOrGateKeeper) dropParent;
- andOrGateKeeper.getGateKeepers().add(drag);
- } else if (dropParent instanceof ConditionalGateKeeper) {
- ConditionalGateKeeper conditionalGateKeeper = (ConditionalGateKeeper) dropParent;
- if (dropIndex == 0)
- conditionalGateKeeper.setIfGate(drag);
- else
- conditionalGateKeeper.setThenGate(drag);
- } else {
- NotGateKeeper notGateKeeper = (NotGateKeeper) dropParent;
- notGateKeeper.setGateKeeper(drag);
- }
- } else {
- if (dragParent instanceof AndOrGateKeeper) {
- AndOrGateKeeper andOrGateKeeper = (AndOrGateKeeper) dragParent;
- andOrGateKeeper.getGateKeepers().set(dragIndex, drop);
- } else if (dragParent instanceof ConditionalGateKeeper) {
- ConditionalGateKeeper conditionalGateKeeper = (ConditionalGateKeeper) dragParent;
- if (dragIndex == 0)
- conditionalGateKeeper.setIfGate(drop);
- else
- conditionalGateKeeper.setThenGate(drop);
- } else {
- NotGateKeeper notGateKeeper = (NotGateKeeper) dragParent;
- notGateKeeper.setGateKeeper(drop);
- }
- if (dropParent instanceof AndOrGateKeeper) {
- AndOrGateKeeper andOrGateKeeper = (AndOrGateKeeper) dropParent;
- andOrGateKeeper.getGateKeepers().set(dropIndex, drag);
- } else if (dropParent instanceof ConditionalGateKeeper) {
- ConditionalGateKeeper conditionalGateKeeper = (ConditionalGateKeeper) dropParent;
- if (dropIndex == 0)
- conditionalGateKeeper.setIfGate(drag);
- else
- conditionalGateKeeper.setThenGate(drag);
- } else {
- NotGateKeeper notGateKeeper = (NotGateKeeper) dropParent;
- notGateKeeper.setGateKeeper(drag);
- }
- }
- depot.setGateKeepers((ArrayList<GateKeeper>) root.getGateKeepers());
- GitPlex.getInstance(DepotManager.class).save(depot, null, null);
- page.onGateKeeperChanged(target);
- }
-
- private GateKeeper getParentGateKeeper(GateKeeper rootGateKeeper, List<Integer> position) {
- Preconditions.checkArgument(!position.isEmpty() && rootGateKeeper instanceof CompositeGateKeeper);
- if (position.size() == 1) {
- return rootGateKeeper;
- } else if (rootGateKeeper instanceof AndOrGateKeeper) {
- AndOrGateKeeper andOrGateKeeper = (AndOrGateKeeper) rootGateKeeper;
- return getParentGateKeeper(andOrGateKeeper.getGateKeepers().get(position.get(0)), position.subList(1, position.size()));
- } else if (rootGateKeeper instanceof ConditionalGateKeeper) {
- ConditionalGateKeeper conditionalGateKeeper = (ConditionalGateKeeper) rootGateKeeper;
- if (position.get(0) == 0)
- return getParentGateKeeper(conditionalGateKeeper.getIfGate(), position.subList(1, position.size()));
- else
- return getParentGateKeeper(conditionalGateKeeper.getThenGate(), position.subList(1, position.size()));
- } else {
- NotGateKeeper notGateKeeper = (NotGateKeeper) rootGateKeeper;
- return getParentGateKeeper(notGateKeeper.getGateKeeper(), position.subList(1, position.size()));
- }
- }
-
- private GateKeeper getGateKeeper(GateKeeper parentGateKeeper, int index) {
- if (parentGateKeeper instanceof AndOrGateKeeper) {
- AndOrGateKeeper andOrGateKeeper = (AndOrGateKeeper) parentGateKeeper;
- if (index < andOrGateKeeper.getGateKeepers().size())
- return andOrGateKeeper.getGateKeepers().get(index);
- else
- return new DefaultGateKeeper();
- } else if (parentGateKeeper instanceof ConditionalGateKeeper) {
- ConditionalGateKeeper conditionalGateKeeper = (ConditionalGateKeeper) parentGateKeeper;
- if (index == 0)
- return conditionalGateKeeper.getIfGate();
- else
- return conditionalGateKeeper.getThenGate();
- } else {
- NotGateKeeper notGateKeeper = (NotGateKeeper) parentGateKeeper;
- return notGateKeeper.getGateKeeper();
- }
- }
-
- protected abstract List<Integer> getPosition();
-
- @Override
- protected String getAccept() {
- return String.format("function(draggable) {"
- + " var $drag = $(draggable).parent().parent();"
- + " if ($drag.hasClass('gate-keeper')) {"
- + " var $drop = $('#%s');"
- + " return !jQuery.contains($drag[0], $drop[0]) && !jQuery.contains($drop[0], $drag[0]);"
- + " } else {"
- + " return false;"
- + " }"
- + "}", getComponent().getMarkupId(true));
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperEditor.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperEditor.html
deleted file mode 100644
index 65a5c9d707..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperEditor.html
+++ /dev/null
@@ -1,19 +0,0 @@
-<wicket:panel>
- <div class="gate-keeper-editor">
- <div class="modal-header">
- <div class="clearfix">
- <div wicket:id="icon" class="pull-left fa fa-lg "></div>
- <div wicket:id="name" class="gate-keeper-name pull-left"></div>
- </div>
- <div wicket:id="description" class="gate-keeper-description"></div>
- </div>
- <form wicket:id="form" onsubmit="return false" class="leave-confirm">
- <div wicket:id="feedback" class="feedback"></div>
- <div wicket:id="beanEditor" class="modal-body"></div>
- <div class="modal-footer">
- <input type="submit" wicket:id="save" class="btn btn-primary dirty-aware" value="Save"></input>
- <a wicket:id="cancel" class="btn btn-default">Cancel</a>
- </div>
- </form>
- </div>
-</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperEditor.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperEditor.java
deleted file mode 100644
index 6135ffac68..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperEditor.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.gitplex.server.web.page.depot.setting.gatekeeper;
-
-import org.apache.commons.lang3.SerializationUtils;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.panel.Panel;
-
-import com.gitplex.server.gatekeeper.GateKeeper;
-import com.gitplex.server.util.editable.EditableUtils;
-import com.gitplex.server.web.editable.BeanContext;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
-
-@SuppressWarnings("serial")
-abstract class GateKeeperEditor extends Panel {
-
- private GateKeeper gateKeeper;
-
- public GateKeeperEditor(String id, GateKeeper gateKeeper) {
- super(id);
- this.gateKeeper = SerializationUtils.clone(gateKeeper);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- String iconClass = EditableUtils.getIcon(gateKeeper.getClass());
- if (iconClass == null)
- iconClass = "fa-lock";
- add(new WebMarkupContainer("icon").add(AttributeAppender.append("class", iconClass)));
- add(new Label("name", EditableUtils.getName(gateKeeper.getClass())));
- add(new Label("description", EditableUtils.getDescription(gateKeeper.getClass())).setEscapeModelStrings(false));
-
- 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") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- onCancel(target);
- }
-
- });
-
- form.add(new AjaxButton("save") {
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
- super.onSubmit(target, form);
- onSave(target, gateKeeper);
- }
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
- tag.getAttributes().put("type", "submit");
- }
-
- @Override
- protected void onError(AjaxRequestTarget target, Form<?> form) {
- super.onError(target, form);
- target.add(GateKeeperEditor.this);
- }
-
- });
-
- setOutputMarkupId(true);
- }
-
- protected abstract void onCancel(AjaxRequestTarget target);
-
- protected abstract void onSave(AjaxRequestTarget target, GateKeeper gateKeeper);
-}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperLink.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperLink.java
deleted file mode 100644
index a063a8d1ba..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperLink.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.gitplex.server.web.page.depot.setting.gatekeeper;
-
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.behavior.AttributeAppender;
-
-import com.gitplex.server.gatekeeper.GateKeeper;
-import com.gitplex.server.web.component.floating.AlignPlacement;
-import com.gitplex.server.web.component.floating.FloatingPanel;
-import com.gitplex.server.web.component.link.DropdownLink;
-
-@SuppressWarnings("serial")
-abstract class GateKeeperLink extends DropdownLink {
-
- public GateKeeperLink(String id) {
- super(id, true, new AlignPlacement(50, 50, 50, 50));
- }
-
- @Override
- protected void onInitialize(FloatingPanel dropdown) {
- super.onInitialize(dropdown);
- dropdown.add(AttributeAppender.append("class", "gate-keeper-selector"));
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new GateKeeperDropBehavior() {
-
- @Override
- protected List<Integer> getPosition() {
- return GateKeeperLink.this.getPosition();
- }
-
- });
- }
-
- @Override
- protected Component newContent(String id, FloatingPanel dropdown) {
- return new GateKeeperSelector(id) {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Class<? extends GateKeeper> gateKeeperClass) {
- dropdown.close();
- GateKeeperLink.this.onSelect(target, gateKeeperClass);
- }
- };
- }
-
- protected abstract void onSelect(AjaxRequestTarget target, Class<? extends GateKeeper> gateKeeperClass);
-
- protected abstract List<Integer> getPosition();
-}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPage.html
deleted file mode 100644
index 172f12a5b8..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPage.html
+++ /dev/null
@@ -1,19 +0,0 @@
-<wicket:extend>
- <div class="gate-keeper-setting">
- <div wicket:id="gateKeeperSetting">
- <div wicket:id="gateKeepers">
- <div wicket:id="gateKeeper"></div>
- </div>
- <div wicket:id="gateKeeperDropdownTrigger" class="well gate-keeper-add">Add Gatekeeper <i class="fa fa-lg fa-plus-circle"></i></div>
- </div>
- <div class="help-block">
- <ul>
- <li>Commits have to pass all Gatekeepers defined here in order to be accepted by the repository</li>
- <li>If a gatekeeper is dragged and dropped on another gatekeeper, their positions will be swapped</li>
- <li>If a gatekeeper is dragged and dropped on <i>Add/Define</i> placeholder, it will be moved to the placeholder position</li>
- <li>A gatekeeper can not be dragged to a position containing itself or contained by itself</li>
- <li>Check out <a wicket:id="gateKeeperDocLink">examples here</a> to get better understanding of gatekeepers</li>
- </ul>
- </div>
- </div>
-</wicket:extend>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPage.java
deleted file mode 100644
index e6835b4d35..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPage.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package com.gitplex.server.web.page.depot.setting.gatekeeper;
-
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.link.ExternalLink;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.gatekeeper.GateKeeper;
-import com.gitplex.server.manager.DepotManager;
-import com.gitplex.server.model.Depot;
-import com.gitplex.server.util.ReflectionUtils;
-import com.gitplex.server.util.editable.EditableUtils;
-import com.gitplex.server.web.component.modal.ModalPanel;
-import com.gitplex.server.web.page.depot.setting.DepotSettingPage;
-
-import jersey.repackaged.com.google.common.collect.Lists;
-
-@SuppressWarnings("serial")
-public class GateKeeperPage extends DepotSettingPage {
-
- private static final String CONTAINER_ID = "gateKeeperSetting";
-
- public GateKeeperPage(PageParameters params) {
- super(params);
- }
-
- private WebMarkupContainer newContent() {
- WebMarkupContainer content = new WebMarkupContainer(CONTAINER_ID);
- content.setOutputMarkupId(true);
-
- content.add(new ListView<GateKeeper>("gateKeepers", getDepot().getGateKeepers()) {
-
- @Override
- protected void populateItem(ListItem<GateKeeper> item) {
- item.add(new GateKeeperPanel("gateKeeper", item.getModelObject(), Lists.newArrayList(item.getIndex())) {
-
- @Override
- protected void onDelete(AjaxRequestTarget target) {
- getDepot().getGateKeepers().remove(item.getIndex());
- onGateKeeperChanged(target);
- }
-
- @Override
- protected void onChange(AjaxRequestTarget target, GateKeeper gateKeeper) {
- getDepot().getGateKeepers().set(item.getIndex(), gateKeeper);
- onGateKeeperChanged(target);
- }
-
- });
- }
-
- });
- content.add(new GateKeeperLink("gateKeeperDropdownTrigger") {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Class<? extends GateKeeper> gateKeeperClass) {
- final GateKeeper gateKeeper = ReflectionUtils.instantiateClass(gateKeeperClass);
- if (EditableUtils.isDefaultInstanceValid(gateKeeperClass)) {
- getDepot().getGateKeepers().add(gateKeeper);
- onGateKeeperChanged(target);
- } else {
- new ModalPanel(target) {
-
- @Override
- protected Component newContent(String id) {
- return new GateKeeperEditor(id, gateKeeper) {
-
- @Override
- protected void onCancel(AjaxRequestTarget target) {
- close();
- }
-
- @Override
- protected void onSave(AjaxRequestTarget target, GateKeeper gateKeeper) {
- close();
- getDepot().getGateKeepers().add(gateKeeper);
- onGateKeeperChanged(target);
- }
-
- };
- }
-
- };
- }
- }
-
- @Override
- protected List<Integer> getPosition() {
- return Lists.newArrayList(getDepot().getGateKeepers().size());
- }
-
- });
- content.add(new WebMarkupContainer("gateKeeperPanel").setVisible(false));
- content.add(new WebMarkupContainer("gateKeeperModal").setOutputMarkupPlaceholderTag(true).setVisible(false));
- return content;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(newContent());
-
- add(new ExternalLink("gateKeeperDocLink", GitPlex.getInstance().getDocLink() + "/Working+with+Gate+Keepers"));
- }
-
- void onGateKeeperChanged(AjaxRequestTarget target) {
- GitPlex.getInstance(DepotManager.class).save(getDepot(), null, null);
- replace(newContent());
- target.add(get(CONTAINER_ID));
- }
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Depot depot) {
- setResponsePage(GateKeeperPage.class, GateKeeperPage.paramsOf(depot));
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPanel.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPanel.html
deleted file mode 100644
index 87bdf65c38..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPanel.html
+++ /dev/null
@@ -1,57 +0,0 @@
-<wicket:panel>
- <div wicket:id="container" class="gate-keeper panel ">
- <div class="panel-heading">
- <span wicket:id="title" class="panel-title"></span>
- <span wicket:id="dragHandle" class="fa fa-arrows drag-handle" title="Move this gatekeeper"></span>
- <span wicket:id="edit" class="fa fa-pencil" title="Edit this gatekeeper"></span>
- <span wicket:id="delete" class="fa fa-trash" title="Delete this gatekeeper"></span>
- <span wicket:id="enable" class="fa "></span>
- <span wicket:id="help" class="fa fa-question-circle"></span>
- <div wicket:id="editor"></div>
- </div>
- <div class="panel-body">
- <div wicket:id="content"></div>
- </div>
- </div>
- <wicket:fragment wicket:id="andFrag">
- <div wicket:id="children">
- <div wicket:id="child"></div>
- </div>
- <div wicket:id="childTypeSelectorTrigger" class="well gate-keeper-add">Add gatekeeper <i class="fa fa-plus-circle"></i></div>
- </wicket:fragment>
- <wicket:fragment wicket:id="orFrag">
- <table class="children">
- <tr>
- <td wicket:id="children" class="child">
- <div wicket:id="child"></div>
- </td>
- </tr>
- </table>
- <div wicket:id="childTypeSelectorTrigger" class="well gate-keeper-add">Add gatekeeper <i class="fa fa-plus-circle"></i></div>
- </wicket:fragment>
- <wicket:fragment wicket:id="ifThenFrag">
- <table class="ifthen">
- <tr class="if">
- <td>
- <label>If</label>
- <div wicket:id="ifGate"></div>
- </td>
- </tr>
- <tr class="then">
- <td>
- <label>Then check</label>
- <div wicket:id="thenGate"></div>
- </td>
- </tr>
- </table>
- </wicket:fragment>
- <wicket:fragment wicket:id="notFrag">
- <div class="not">
- <div wicket:id="gateKeeper"></div>
- <div wicket:id="gateKeeperTypeSelectorTrigger" class="well gate-keeper-add">Define gatekeeper <i class="fa fa-plus-circle"></i></div>
- </div>
- </wicket:fragment>
- <wicket:fragment wicket:id="otherFrag">
- <div wicket:id="viewer"></div>
- </wicket:fragment>
-</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPanel.java
deleted file mode 100644
index 694b105e7f..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperPanel.java
+++ /dev/null
@@ -1,457 +0,0 @@
-package com.gitplex.server.web.page.depot.setting.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
-import org.apache.wicket.markup.html.panel.Fragment;
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.Model;
-
-import com.google.common.base.Joiner;
-import com.gitplex.server.gatekeeper.AbstractGateKeeper;
-import com.gitplex.server.gatekeeper.AndGateKeeper;
-import com.gitplex.server.gatekeeper.AndOrGateKeeper;
-import com.gitplex.server.gatekeeper.ConditionalGateKeeper;
-import com.gitplex.server.gatekeeper.DefaultGateKeeper;
-import com.gitplex.server.gatekeeper.GateKeeper;
-import com.gitplex.server.gatekeeper.NotGateKeeper;
-import com.gitplex.server.util.ReflectionUtils;
-import com.gitplex.server.util.editable.EditableUtils;
-import com.gitplex.server.web.behavior.dragdrop.DragBehavior;
-import com.gitplex.server.web.component.modal.ModalLink;
-import com.gitplex.server.web.component.modal.ModalPanel;
-import com.gitplex.server.web.editable.BeanContext;
-import com.gitplex.server.web.util.ajaxlistener.ConfirmListener;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipBehavior;
-
-@SuppressWarnings("serial")
-abstract class GateKeeperPanel extends Panel {
-
- private final GateKeeper gateKeeper;
-
- private final List<Integer> position;
-
- public GateKeeperPanel(String id, GateKeeper gateKeeper, List<Integer> position) {
- super(id);
- this.gateKeeper = gateKeeper;
- this.position = position;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- WebMarkupContainer container = new WebMarkupContainer("container");
- add(container);
-
- if(!gateKeeper.isEnabled())
- container.add(AttributeAppender.append("class", "disabled"));
-
- if (position.size()%2 == 0) {
- container.add(AttributeAppender.append("class", "even panel-danger"));
- } else {
- container.add(AttributeAppender.append("class", "odd panel-success"));
- }
-
- Class<? extends GateKeeper> clazz = gateKeeper.getClass();
- String title = EditableUtils.getName(clazz);
- container.add(new Label("title", title));
- container.add(new WebMarkupContainer("dragHandle").add(new DragBehavior(Joiner.on(":").join(position), title)));
- container.add(new ModalLink("edit") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- setVisible(EditableUtils.hasEditableProperties(clazz));
- }
-
- @Override
- protected Component newContent(String id, ModalPanel modal) {
- return new GateKeeperEditor(id, gateKeeper) {
-
- @Override
- protected void onCancel(AjaxRequestTarget target) {
- modal.close();
- }
-
- @Override
- protected void onSave(AjaxRequestTarget target, GateKeeper gateKeeper) {
- modal.close();
- GateKeeperPanel.this.onChange(target, gateKeeper);
- }
-
- };
- }
-
- });
-
- container.add(new AjaxLink<Void>("delete") {
-
- @Override
- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
- super.updateAjaxAttributes(attributes);
- attributes.getAjaxCallListeners().add(new ConfirmListener("Do you really want to delete this gatekeeper?"));
- }
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- onDelete(target);
- }
-
- });
-
- container.add(new AjaxLink<Void>("enable") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- ((AbstractGateKeeper) gateKeeper).setEnabled(!gateKeeper.isEnabled());
- onChange(target, gateKeeper);
- }
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
- if (gateKeeper.isEnabled()) {
- tag.append("class", "fa-check-square-o", " ");
- } else {
- tag.append("class", "fa-square-o", " ");
- }
- }
-
- }.add(AttributeAppender.append("title", Model.of(gateKeeper.isEnabled()?"Disable this gatekeeper":"Enable this gatekeeper"))));
-
- container.add(new WebMarkupContainer("help").add(new TooltipBehavior(Model.of(EditableUtils.getDescription(gateKeeper.getClass())))));
-
- container.add(new WebMarkupContainer("editor").setOutputMarkupPlaceholderTag(true).setVisible(false));
-
- if (AndOrGateKeeper.class.isAssignableFrom(clazz)) {
- AndOrGateKeeper andOrGateKeeper = (AndOrGateKeeper) gateKeeper;
- Fragment fragment;
- if (andOrGateKeeper instanceof AndGateKeeper)
- fragment = new Fragment("content", "andFrag", GateKeeperPanel.this);
- else
- fragment = new Fragment("content", "orFrag", GateKeeperPanel.this);
-
- fragment.add(new ListView<GateKeeper>("children", andOrGateKeeper.getGateKeepers()) {
-
- @Override
- protected void populateItem(ListItem<GateKeeper> item) {
- List<Integer> newPosition = new ArrayList<>(position);
- newPosition.add(item.getIndex());
- item.add(new GateKeeperPanel("child", item.getModelObject(), newPosition) {
-
- @Override
- protected void onDelete(AjaxRequestTarget target) {
- andOrGateKeeper.getGateKeepers().remove(item.getIndex());
- GateKeeperPanel.this.onChange(target, andOrGateKeeper);
- }
-
- @Override
- protected void onChange(AjaxRequestTarget target, GateKeeper gateKeeper) {
- andOrGateKeeper.getGateKeepers().set(item.getIndex(), gateKeeper);
- GateKeeperPanel.this.onChange(target, andOrGateKeeper);
- }
-
- });
- }
-
- });
- fragment.add(new GateKeeperLink("childTypeSelectorTrigger") {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Class<? extends GateKeeper> gateKeeperClass) {
- final GateKeeper gateKeeper = ReflectionUtils.instantiateClass(gateKeeperClass);
- if (EditableUtils.isDefaultInstanceValid(gateKeeperClass)) {
- andOrGateKeeper.getGateKeepers().add(gateKeeper);
- GateKeeperPanel.this.onChange(target, andOrGateKeeper);
- } else {
- new ModalPanel(target) {
-
- @Override
- protected Component newContent(String id) {
- return new GateKeeperEditor(id, gateKeeper) {
-
- @Override
- protected void onCancel(AjaxRequestTarget target) {
- close();
- }
-
- @Override
- protected void onSave(AjaxRequestTarget target, GateKeeper gateKeeper) {
- close();
- fragment.replace(new WebMarkupContainer("childEditor").setOutputMarkupPlaceholderTag(true).setVisible(true));
- andOrGateKeeper.getGateKeepers().add(gateKeeper);
- GateKeeperPanel.this.onChange(target, andOrGateKeeper);
- }
-
- };
- }
-
- };
- }
- }
-
- @Override
- protected List<Integer> getPosition() {
- List<Integer> newPosition = new ArrayList<>(position);
- newPosition.add(andOrGateKeeper.getGateKeepers().size());
- return newPosition;
- }
-
- });
-
- fragment.add(new WebMarkupContainer("childEditor").setOutputMarkupPlaceholderTag(true).setVisible(false));
- container.add(fragment);
- } else if (clazz == NotGateKeeper.class) {
- final NotGateKeeper notGateKeeper = (NotGateKeeper) gateKeeper;
- final Fragment fragment = new Fragment("content", "notFrag", GateKeeperPanel.this);
-
- if (notGateKeeper.getGateKeeper() instanceof DefaultGateKeeper) {
- fragment.add(new GateKeeperLink("gateKeeperTypeSelectorTrigger") {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Class<? extends GateKeeper> gateKeeperClass) {
- final GateKeeper gateKeeper = ReflectionUtils.instantiateClass(gateKeeperClass);
- if (EditableUtils.isDefaultInstanceValid(gateKeeperClass)) {
- notGateKeeper.setGateKeeper(gateKeeper);
- GateKeeperPanel.this.onChange(target, notGateKeeper);
- } else {
- new ModalPanel(target) {
-
- @Override
- protected Component newContent(String id) {
- return new GateKeeperEditor(id, gateKeeper) {
-
- @Override
- protected void onCancel(AjaxRequestTarget target) {
- close();
- }
-
- @Override
- protected void onSave(AjaxRequestTarget target, GateKeeper gateKeeper) {
- close();
- fragment.replace(new WebMarkupContainer("gateKeeperEditor").setOutputMarkupPlaceholderTag(true).setVisible(true));
- notGateKeeper.setGateKeeper(gateKeeper);
- GateKeeperPanel.this.onChange(target, notGateKeeper);
- }
-
- };
- }
-
- };
- }
- }
-
- @Override
- protected List<Integer> getPosition() {
- List<Integer> newPosition = new ArrayList<>(position);
- newPosition.add(0);
- return newPosition;
- }
-
- });
-
- fragment.add(new WebMarkupContainer("gateKeeper").setVisible(false));
- fragment.add(new WebMarkupContainer("gateKeeperEditor").setOutputMarkupPlaceholderTag(true).setVisible(false));
- } else {
- List<Integer> newPosition = new ArrayList<>(position);
- newPosition.add(0);
- fragment.add(new GateKeeperPanel("gateKeeper", notGateKeeper.getGateKeeper(), newPosition) {
-
- @Override
- protected void onDelete(AjaxRequestTarget target) {
- notGateKeeper.setGateKeeper(new DefaultGateKeeper());
- GateKeeperPanel.this.onChange(target, notGateKeeper);
- }
-
- @Override
- protected void onChange(AjaxRequestTarget target, GateKeeper gateKeeper) {
- notGateKeeper.setGateKeeper(gateKeeper);
- GateKeeperPanel.this.onChange(target, notGateKeeper);
- }
-
- });
- fragment.add(new WebMarkupContainer("gateKeeperTypeSelectorTrigger").setVisible(false));
- fragment.add(new WebMarkupContainer("gateKeeperTypeSelector").setVisible(false));
- fragment.add(new WebMarkupContainer("gateKeeperEditor").setVisible(false));
- }
- container.add(fragment);
- } else if (clazz == ConditionalGateKeeper.class) {
- ConditionalGateKeeper ifThenGateKeeper = (ConditionalGateKeeper) gateKeeper;
- Fragment fragment = new Fragment("content", "ifThenFrag", GateKeeperPanel.this);
-
- if (ifThenGateKeeper.getIfGate() instanceof DefaultGateKeeper) {
- fragment.add(new GateKeeperLink("ifGate") {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Class<? extends GateKeeper> gateKeeperClass) {
- GateKeeper gateKeeper = ReflectionUtils.instantiateClass(gateKeeperClass);
- if (EditableUtils.isDefaultInstanceValid(gateKeeperClass)) {
- ifThenGateKeeper.setIfGate(gateKeeper);
- GateKeeperPanel.this.onChange(target, ifThenGateKeeper);
- } else {
- new ModalPanel(target) {
-
- @Override
- protected Component newContent(String id) {
- return new GateKeeperEditor(id, gateKeeper) {
-
- @Override
- protected void onCancel(AjaxRequestTarget target) {
- close();
- }
-
- @Override
- protected void onSave(AjaxRequestTarget target, GateKeeper gateKeeper) {
- close();
- fragment.replace(new WebMarkupContainer("ifEditor").setOutputMarkupPlaceholderTag(true).setVisible(true));
- ifThenGateKeeper.setIfGate(gateKeeper);
- GateKeeperPanel.this.onChange(target, ifThenGateKeeper);
- }
-
- };
- }
-
- };
- }
- }
-
- @Override
- public IModel<?> getBody() {
- return Model.of("Define gatekeeper <i class='fa fa-plus-circle'></i>");
- }
-
- @Override
- protected List<Integer> getPosition() {
- List<Integer> newPosition = new ArrayList<>(position);
- newPosition.add(0);
- return newPosition;
- }
-
- }.setEscapeModelStrings(false).add(AttributeAppender.append("class", "well gate-keeper-add")));
- } else {
- List<Integer> newPosition = new ArrayList<>(position);
- newPosition.add(0);
- fragment.add(new GateKeeperPanel("ifGate", ifThenGateKeeper.getIfGate(), newPosition) {
-
- @Override
- protected void onDelete(AjaxRequestTarget target) {
- ifThenGateKeeper.setIfGate(new DefaultGateKeeper());
- GateKeeperPanel.this.onChange(target, ifThenGateKeeper);
- }
-
- @Override
- protected void onChange(AjaxRequestTarget target, GateKeeper gateKeeper) {
- ifThenGateKeeper.setIfGate(gateKeeper);
- GateKeeperPanel.this.onChange(target, ifThenGateKeeper);
- }
-
- });
- }
- fragment.add(new WebMarkupContainer("ifEditor").setOutputMarkupPlaceholderTag(true).setVisible(false));
-
- if (ifThenGateKeeper.getThenGate() instanceof DefaultGateKeeper) {
- fragment.add(new GateKeeperLink("thenGate") {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Class<? extends GateKeeper> gateKeeperClass) {
- final GateKeeper gateKeeper = ReflectionUtils.instantiateClass(gateKeeperClass);
- if (EditableUtils.isDefaultInstanceValid(gateKeeperClass)) {
- ifThenGateKeeper.setThenGate(gateKeeper);
- GateKeeperPanel.this.onChange(target, ifThenGateKeeper);
- } else {
- new ModalPanel(target) {
-
- @Override
- protected Component newContent(String id) {
- return new GateKeeperEditor(id, gateKeeper) {
-
- @Override
- protected void onCancel(AjaxRequestTarget target) {
- close();
- }
-
- @Override
- protected void onSave(AjaxRequestTarget target, GateKeeper gateKeeper) {
- close();
- fragment.replace(new WebMarkupContainer("thenEditor").setOutputMarkupPlaceholderTag(true).setVisible(true));
- ifThenGateKeeper.setThenGate(gateKeeper);
- GateKeeperPanel.this.onChange(target, ifThenGateKeeper);
- }
-
- };
- }
-
- };
- }
- }
-
- @Override
- public IModel<?> getBody() {
- return Model.of("Define gatekeeper <i class='fa fa-plus-circle'></i>");
- }
-
- @Override
- protected List<Integer> getPosition() {
- List<Integer> newPosition = new ArrayList<>(position);
- newPosition.add(1);
- return newPosition;
- }
-
- }.setEscapeModelStrings(false).add(AttributeAppender.append("class", "well gate-keeper-add")));
- } else {
- List<Integer> newPosition = new ArrayList<>(position);
- newPosition.add(1);
- fragment.add(new GateKeeperPanel("thenGate", ifThenGateKeeper.getThenGate(), newPosition) {
-
- @Override
- protected void onDelete(AjaxRequestTarget target) {
- ifThenGateKeeper.setThenGate(new DefaultGateKeeper());
- GateKeeperPanel.this.onChange(target, ifThenGateKeeper);
- }
-
- @Override
- protected void onChange(AjaxRequestTarget target, GateKeeper gateKeeper) {
- ifThenGateKeeper.setThenGate(gateKeeper);
- GateKeeperPanel.this.onChange(target, ifThenGateKeeper);
- }
-
- });
- }
- fragment.add(new WebMarkupContainer("thenEditor").setOutputMarkupPlaceholderTag(true).setVisible(false));
-
- container.add(fragment);
- } else {
- Fragment fragment = new Fragment("content", "otherFrag", GateKeeperPanel.this);
- fragment.add(BeanContext.viewBean("viewer", gateKeeper));
- container.add(fragment);
- }
-
- add(new GateKeeperDropBehavior() {
-
- @Override
- protected List<Integer> getPosition() {
- return position;
- }
-
- });
- }
-
- protected abstract void onDelete(AjaxRequestTarget target);
-
- protected abstract void onChange(AjaxRequestTarget target, GateKeeper gateKeeper);
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperSelector.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperSelector.html
deleted file mode 100644
index 4854069c19..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperSelector.html
+++ /dev/null
@@ -1,20 +0,0 @@
-<wicket:panel>
- <div wicket:id="accordion" class="panel-group">
- <div wicket:id="categories" class="panel panel-default">
- <div wicket:id="collapseTrigger" class="panel-heading">
- <div wicket:id="name" class="panel-title"></div>
- </div>
- <div wicket:id="collapsible" class="panel-body">
- <div wicket:id="gateKeepers" class="gate-keeper-item">
- <div wicket:id="gateKeeper">
- <div>
- <span wicket:id="icon" class="fa "></span>
- <span wicket:id="name" class="gate-keeper-name"></span>
- </div>
- <div wicket:id="description" class="gate-keeper-description"></div>
- </div>
- </div>
- </div>
- </div>
- </div>
-</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperSelector.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperSelector.java
deleted file mode 100644
index ecaa1cfae5..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/gatekeeper/GateKeeperSelector.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package com.gitplex.server.web.page.depot.setting.gatekeeper;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
-import org.apache.wicket.markup.html.panel.Panel;
-
-import com.google.common.base.Preconditions;
-import com.gitplex.launcher.loader.ImplementationRegistry;
-import com.gitplex.server.GitPlex;
-import com.gitplex.server.gatekeeper.DefaultGateKeeper;
-import com.gitplex.server.gatekeeper.GateKeeper;
-import com.gitplex.server.gatekeeper.TeamAwareGateKeeper;
-import com.gitplex.server.model.Account;
-import com.gitplex.server.util.editable.EditableUtils;
-import com.gitplex.server.web.behavior.CollapseBehavior;
-import com.gitplex.server.web.component.AccordionPanel;
-import com.gitplex.server.web.page.account.AccountPage;
-
-@SuppressWarnings("serial")
-abstract class GateKeeperSelector extends Panel {
-
- public GateKeeperSelector(String id) {
- super(id);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- final Map<String, List<Class<?>>> gateKeeperClasses = new LinkedHashMap<>();
- gateKeeperClasses.put(GateKeeper.CATEGORY_BASIC, new ArrayList<Class<?>>());
- gateKeeperClasses.put(GateKeeper.CATEGORY_USER, new ArrayList<Class<?>>());
- gateKeeperClasses.put(GateKeeper.CATEGORY_COMPOSITION, new ArrayList<Class<?>>());
-
- Account account = ((AccountPage)getPage()).getAccount();
-
- List<Class<?>> implementations = new ArrayList<>();
-
- for (Class<?> clazz: GitPlex.getInstance(ImplementationRegistry.class).getImplementations(GateKeeper.class)) {
- if (account.isOrganization() || !TeamAwareGateKeeper.class.isAssignableFrom(clazz))
- implementations.add(clazz);
- }
-
- implementations.remove(DefaultGateKeeper.class);
- implementations.sort((o1, o2) -> EditableUtils.getOrder(o1) - EditableUtils.getOrder(o2));
-
- for (Class<?> implementation: implementations) {
- 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.CATEGORY_BASIC);
- categoryClasses.add(implementation);
- }
-
- 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<String>("categories", new ArrayList<String>(gateKeeperClasses.keySet())) {
-
- @Override
- protected void populateItem(ListItem<String> categoryItem) {
- final String category = categoryItem.getModelObject();
-
- List<Class<?>> gateKeepersOfCategory = gateKeeperClasses.get(category);
- Preconditions.checkNotNull(gateKeepersOfCategory);
-
- WebMarkupContainer collapsible = new WebMarkupContainer("collapsible");
- categoryItem.add(collapsible);
- collapsible.add(new ListView<Class<?>>("gateKeepers", gateKeepersOfCategory) {
-
- @Override
- protected void populateItem(ListItem<Class<?>> gateKeeperItem) {
- final Class<?> gateKeeperClass = gateKeeperItem.getModelObject();
- AjaxLink<Void> link = new AjaxLink<Void>("gateKeeper") {
-
- @SuppressWarnings("unchecked")
- @Override
- public void onClick(AjaxRequestTarget target) {
- onSelect(target, (Class<? extends GateKeeper>) gateKeeperClass);
- }
-
- };
- gateKeeperItem.add(link);
- String icon = EditableUtils.getIcon(gateKeeperClass);
- if (icon == null)
- icon = "fa-lock";
- link.add(new WebMarkupContainer("icon").add(AttributeAppender.append("class", icon)));
- link.add(new Label("name", EditableUtils.getName(gateKeeperClass)));
- link.add(new Label("description", EditableUtils.getDescription(gateKeeperClass)).setEscapeModelStrings(false));
- }
-
- });
-
- WebMarkupContainer collapseTrigger = new WebMarkupContainer("collapseTrigger");
- categoryItem.add(collapseTrigger);
- collapseTrigger.add(new Label("name", category)).add(new CollapseBehavior(collapsible));
- }
-
- });
- }
-
- protected abstract void onSelect(AjaxRequestTarget target, Class<? extends GateKeeper> gateKeeperClass);
-}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyEditor.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyEditor.java
deleted file mode 100644
index e1ac0ffd5b..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyEditor.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.gitplex.server.web.page.depot.setting.integrationpolicy;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.panel.Panel;
-
-import com.gitplex.server.model.support.IntegrationPolicy;
-import com.gitplex.server.web.editable.BeanContext;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
-
-@SuppressWarnings("serial")
-abstract class IntegrationPolicyEditor extends Panel {
-
- private final IntegrationPolicy policy;
-
- public IntegrationPolicyEditor(String id, IntegrationPolicy policy) {
- super(id);
-
- this.policy = policy;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- setOutputMarkupId(true);
-
- Form<?> form = new Form<Void>("form");
- form.add(new NotificationPanel("feedback", form));
- form.add(BeanContext.editBean("editor", policy));
- form.add(new AjaxButton("save") {
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
- super.onSubmit(target, form);
- onSave(target, policy);
- }
-
- @Override
- protected void onError(AjaxRequestTarget target, Form<?> form) {
- super.onError(target, form);
- target.add(form);
- }
-
- });
- form.add(new AjaxLink<Void>("cancel") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- onCancel(target);
- }
-
- });
- add(form);
- }
-
- protected abstract void onSave(AjaxRequestTarget target, IntegrationPolicy policy);
-
- protected abstract void onCancel(AjaxRequestTarget target);
-}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPage.html
deleted file mode 100644
index 9f920b0762..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPage.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<wicket:extend>
- <div wicket:id="integrationPolicySetting" class="integration-policy-setting">
- <ul class="list-unstyled policies">
- <li wicket:id="policies" class="policy"><div wicket:id="policy"></div></li>
- </ul>
- <div wicket:id="newPolicy"></div>
- <div class="help-block">
- <ul>
- <li>Integration policies defines applicable strategies when integrate pull requests
- into target branches. For instance besides the ordinary merge strategy, one can use strategy rebase
- strategy to rebase pull request commits on top of target branch, or use squash strategy to squash
- all commits in a pull request into one before merging with target.</li>
- <li>For a given pull request, its branch information will be matched against branch criterias of
- integration policies defined here, and the first matching policy will be used. If no matching
- policy can be found, the pull request will use strategy <em>merge always</em>.</li>
- </ul>
- </div>
- </div>
- <wicket:fragment wicket:id="editNewFrag">
- <div class="policy panel panel-default">
- <div class="panel-heading"><div class="panel-title">Add New Policy</div></div>
- <div class="panel-body">
- <div wicket:id="editor"></div>
- </div>
- </div>
- </wicket:fragment>
- <wicket:fragment wicket:id="addNewLinkFrag">
- <a wicket:id="link" class="add-new">Add Policy <i class="fa fa-plus-circle fa-lg"></i></a>
- </wicket:fragment>
-</wicket:extend>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPanel.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPanel.html
deleted file mode 100644
index 1fb2799f0d..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPanel.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<wicket:panel>
- <div class="policy panel panel-default">
- <div class="panel-heading">
- <span class="drag-handle" title="Drag to reorder policies"><i class="fa fa-arrows"></i></span>
- <a wicket:id="edit" title="Edit this policy"><i class="fa fa-pencil"></i></a>
- <a wicket:id="delete" title="Delete this policy"><i class="fa fa-trash"></i></a>
- </div>
- <div class="panel-body">
- <div wicket:id="policy"></div>
- </div>
- </div>
-</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPanel.java
deleted file mode 100644
index 9655eb0108..0000000000
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPanel.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.gitplex.server.web.page.depot.setting.integrationpolicy;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.markup.html.panel.Panel;
-
-import com.gitplex.server.model.support.IntegrationPolicy;
-import com.gitplex.server.web.editable.BeanContext;
-import com.gitplex.server.web.util.ajaxlistener.ConfirmListener;
-
-@SuppressWarnings("serial")
-abstract class IntegrationPolicyPanel extends Panel {
-
- private final IntegrationPolicy policy;
-
- public IntegrationPolicyPanel(String id, IntegrationPolicy policy) {
- super(id);
-
- this.policy = policy;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new AjaxLink<Void>("edit") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- IntegrationPolicyEditor editor = new IntegrationPolicyEditor("policy", policy) {
-
- @Override
- protected void onSave(AjaxRequestTarget target, IntegrationPolicy policy) {
- IntegrationPolicyPanel.this.onSave(target, policy);
- Component policyViewer = BeanContext.viewBean("policy", policy).setOutputMarkupId(true);
- IntegrationPolicyPanel.this.replace(policyViewer);
- target.add(policyViewer);
- }
-
- @Override
- protected void onCancel(AjaxRequestTarget target) {
- Component policyViewer = BeanContext.viewBean("policy", policy).setOutputMarkupId(true);
- IntegrationPolicyPanel.this.replace(policyViewer);
- target.add(policyViewer);
- }
-
- };
- IntegrationPolicyPanel.this.replace(editor);
- target.add(editor);
- }
-
- });
-
- add(new AjaxLink<Void>("delete") {
-
- @Override
- protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
- super.updateAjaxAttributes(attributes);
- attributes.getAjaxCallListeners().add(new ConfirmListener("Do you really want to delete this policy?"));
- }
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- onDelete(target);
- }
-
- });
-
- add(BeanContext.viewBean("policy", policy).setOutputMarkupId(true));
- }
-
- protected abstract void onDelete(AjaxRequestTarget target);
-
- protected abstract void onSave(AjaxRequestTarget target, IntegrationPolicy policy);
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionEditor.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionEditor.html
new file mode 100644
index 0000000000..686f19ab1c
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionEditor.html
@@ -0,0 +1,10 @@
+<wicket:panel>
+ <form wicket:id="form" class="leave-confirm">
+ <div wicket:id="feedback"></div>
+ <div wicket:id="editor"></div>
+ <div class="actions">
+ <button wicket:id="save" class="btn btn-primary dirty-aware">Save</button> &nbsp;
+ <button wicket:id="cancel" class="btn btn-default">Cancel</button>
+ </div>
+ </form>
+</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionEditor.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionEditor.java
new file mode 100644
index 0000000000..b2132e76ba
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionEditor.java
@@ -0,0 +1,109 @@
+package com.gitplex.server.web.page.depot.setting.tagprotection;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.panel.Panel;
+
+import com.gitplex.server.model.Depot;
+import com.gitplex.server.model.support.TagProtection;
+import com.gitplex.server.model.support.tagcreator.DepotAdministrators;
+import com.gitplex.server.model.support.tagcreator.DepotWriters;
+import com.gitplex.server.model.support.tagcreator.SpecifiedUser;
+import com.gitplex.server.web.editable.BeanContext;
+import com.gitplex.server.web.page.depot.DepotPage;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
+@SuppressWarnings("serial")
+abstract class TagProtectionEditor extends Panel {
+
+ private final TagProtection protection;
+
+ public TagProtectionEditor(String id, TagProtection protection) {
+ super(id);
+
+ this.protection = protection;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ setOutputMarkupId(true);
+
+ TeamlessTagProtection teamlessProtection = new TeamlessTagProtection();
+ teamlessProtection.setNoDeletion(protection.isNoDeletion());
+ teamlessProtection.setNoUpdate(protection.isNoUpdate());
+ teamlessProtection.setTag(protection.getTag());
+ if (protection.getTagCreator() instanceof DepotAdministrators) {
+ teamlessProtection.setTeamlessTagCreator(new TeamlessDepotAdministrators());
+ } else if (protection.getTagCreator() instanceof SpecifiedUser) {
+ SpecifiedUser specifiedUser = (SpecifiedUser) protection.getTagCreator();
+ TeamlessSpecifiedUser teamlessSpecifiedUser = new TeamlessSpecifiedUser();
+ teamlessSpecifiedUser.setUserName(specifiedUser.getUserName());
+ teamlessProtection.setTeamlessTagCreator(teamlessSpecifiedUser);
+ } else {
+ teamlessProtection.setTeamlessTagCreator(new TeamlessDepotWriters());
+ }
+
+ Form<?> form = new Form<Void>("form");
+ form.add(new NotificationPanel("feedback", form));
+
+ Depot depot = ((DepotPage) getPage()).getDepot();
+ if (depot.getAccount().isOrganization())
+ form.add(BeanContext.editBean("editor", protection));
+ else
+ form.add(BeanContext.editBean("editor", teamlessProtection));
+
+ form.add(new AjaxButton("save") {
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ super.onSubmit(target, form);
+
+ Depot depot = ((DepotPage) getPage()).getDepot();
+ if (!depot.getAccount().isOrganization()) {
+ protection.setNoDeletion(teamlessProtection.isNoDeletion());
+ protection.setNoUpdate(teamlessProtection.isNoUpdate());
+ protection.setTag(teamlessProtection.getTag());
+
+ if (teamlessProtection.getTeamlessTagCreator() instanceof TeamlessDepotAdministrators) {
+ protection.setTagCreator(new DepotAdministrators());
+ } else if (teamlessProtection.getTeamlessTagCreator() instanceof TeamlessSpecifiedUser) {
+ TeamlessSpecifiedUser teamlessSpecifiedUser =
+ (TeamlessSpecifiedUser) teamlessProtection.getTeamlessTagCreator();
+ SpecifiedUser specifiedUser = new SpecifiedUser();
+ specifiedUser.setUserName(teamlessSpecifiedUser.getUserName());
+ protection.setTagCreator(specifiedUser);
+ } else {
+ protection.setTagCreator(new DepotWriters());
+ }
+ }
+
+ onSave(target, protection);
+ }
+
+ @Override
+ protected void onError(AjaxRequestTarget target, Form<?> form) {
+ super.onError(target, form);
+ target.add(form);
+ }
+
+ });
+ form.add(new AjaxLink<Void>("cancel") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ onCancel(target);
+ }
+
+ });
+ add(form);
+ }
+
+ protected abstract void onSave(AjaxRequestTarget target, TagProtection protection);
+
+ protected abstract void onCancel(AjaxRequestTarget target);
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPage.html
new file mode 100644
index 0000000000..dff7cda6cf
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPage.html
@@ -0,0 +1,23 @@
+<wicket:extend>
+ <div wicket:id="tagProtectionSetting" class="panel-list">
+ <ul class="list-unstyled protections">
+ <li wicket:id="protections" class="protection"><div wicket:id="protection"></div></li>
+ </ul>
+ <div wicket:id="newProtection"></div>
+ <div class="help-block">
+ <i class="fa fa-info-circle"></i> Specify tag protection settings here. For a given tag, the first matching protection
+ setting will be used
+ </div>
+ </div>
+ <wicket:fragment wicket:id="editNewFrag">
+ <div class="protection panel panel-default">
+ <div class="panel-heading"><div class="panel-title">Edit Protection</div></div>
+ <div class="panel-body">
+ <div wicket:id="editor"></div>
+ </div>
+ </div>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="addNewLinkFrag">
+ <a wicket:id="link" class="add-new">Add Protection<i class="fa fa-plus-circle fa-lg"></i></a>
+ </wicket:fragment>
+</wicket:extend>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPage.java
similarity index 60%
rename from web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPage.java
rename to web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPage.java
index 16b75ffb81..1f497008cc 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/setting/integrationpolicy/IntegrationPolicyPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPage.java
@@ -1,4 +1,4 @@
-package com.gitplex.server.web.page.depot.setting.integrationpolicy;
+package com.gitplex.server.web.page.depot.setting.tagprotection;
import java.util.List;
@@ -15,17 +15,17 @@ import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.DepotManager;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.model.support.IntegrationPolicy;
+import com.gitplex.server.model.support.TagProtection;
import com.gitplex.server.web.behavior.sortable.SortBehavior;
import com.gitplex.server.web.behavior.sortable.SortPosition;
import com.gitplex.server.web.page.depot.setting.DepotSettingPage;
@SuppressWarnings("serial")
-public class IntegrationPolicyPage extends DepotSettingPage {
+public class TagProtectionPage extends DepotSettingPage {
private WebMarkupContainer container;
- public IntegrationPolicyPage(PageParameters params) {
+ public TagProtectionPage(PageParameters params) {
super(params);
}
@@ -33,31 +33,31 @@ public class IntegrationPolicyPage extends DepotSettingPage {
protected void onInitialize() {
super.onInitialize();
- container = new WebMarkupContainer("integrationPolicySetting");
+ container = new WebMarkupContainer("tagProtectionSetting");
container.setOutputMarkupId(true);
add(container);
- container.add(new ListView<IntegrationPolicy>("policies", new AbstractReadOnlyModel<List<IntegrationPolicy>>() {
+ container.add(new ListView<TagProtection>("protections", new AbstractReadOnlyModel<List<TagProtection>>() {
@Override
- public List<IntegrationPolicy> getObject() {
- return getDepot().getIntegrationPolicies();
+ public List<TagProtection> getObject() {
+ return getDepot().getTagProtections();
}
}) {
@Override
- protected void populateItem(final ListItem<IntegrationPolicy> item) {
- item.add(new IntegrationPolicyPanel("policy", item.getModelObject()) {
+ protected void populateItem(final ListItem<TagProtection> item) {
+ item.add(new TagProtectionPanel("protection", item.getModelObject()) {
@Override
protected void onDelete(AjaxRequestTarget target) {
- getDepot().getIntegrationPolicies().remove(item.getIndex());
+ getDepot().getTagProtections().remove(item.getIndex());
GitPlex.getInstance(DepotManager.class).save(getDepot(), null, null);
target.add(container);
}
@Override
- protected void onSave(AjaxRequestTarget target, IntegrationPolicy policy) {
- getDepot().getIntegrationPolicies().set(item.getIndex(), policy);
+ protected void onSave(AjaxRequestTarget target, TagProtection protection) {
+ getDepot().getTagProtections().set(item.getIndex(), protection);
GitPlex.getInstance(DepotManager.class).save(getDepot(), null, null);
}
@@ -70,32 +70,32 @@ public class IntegrationPolicyPage extends DepotSettingPage {
@Override
protected void onSort(AjaxRequestTarget target, SortPosition from, SortPosition to) {
- List<IntegrationPolicy> policies = getDepot().getIntegrationPolicies();
- IntegrationPolicy policy = policies.get(from.getItemIndex());
- policies.set(from.getItemIndex(), policies.set(to.getItemIndex(), policy));
+ List<TagProtection> protections = getDepot().getTagProtections();
+ TagProtection protection = protections.get(from.getItemIndex());
+ protections.set(from.getItemIndex(), protections.set(to.getItemIndex(), protection));
GitPlex.getInstance(DepotManager.class).save(getDepot(), null, null);
target.add(container);
}
- }.handle(".drag-handle").items("li.policy"));
+ }.handle(".drag-handle").items("li.protection"));
container.add(newAddNewFrag());
}
private Component newAddNewFrag() {
- Fragment fragment = new Fragment("newPolicy", "addNewLinkFrag", this);
+ Fragment fragment = new Fragment("newProtection", "addNewLinkFrag", this);
fragment.add(new AjaxLink<Void>("link") {
@Override
public void onClick(AjaxRequestTarget target) {
- Fragment fragment = new Fragment("newPolicy", "editNewFrag", getPage());
+ Fragment fragment = new Fragment("newProtection", "editNewFrag", getPage());
fragment.setOutputMarkupId(true);
- fragment.add(new IntegrationPolicyEditor("editor", new IntegrationPolicy()) {
+ fragment.add(new TagProtectionEditor("editor", new TagProtection()) {
@Override
- protected void onSave(AjaxRequestTarget target, IntegrationPolicy policy) {
- getDepot().getIntegrationPolicies().add(policy);
+ protected void onSave(AjaxRequestTarget target, TagProtection protection) {
+ getDepot().getTagProtections().add(protection);
GitPlex.getInstance(DepotManager.class).save(getDepot(), null, null);
container.replace(newAddNewFrag());
target.add(container);
@@ -120,7 +120,7 @@ public class IntegrationPolicyPage extends DepotSettingPage {
@Override
protected void onSelect(AjaxRequestTarget target, Depot depot) {
- setResponsePage(IntegrationPolicyPage.class, IntegrationPolicyPage.paramsOf(depot));
+ setResponsePage(TagProtectionPage.class, TagProtectionPage.paramsOf(depot));
}
}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPanel.html b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPanel.html
new file mode 100644
index 0000000000..24cbc940de
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPanel.html
@@ -0,0 +1,12 @@
+<wicket:panel>
+ <div class="tag-protection panel panel-default">
+ <div class="panel-heading">
+ <span class="drag-handle" title="Drag to reorder protections"><i class="fa fa-arrows"></i></span>
+ <a wicket:id="edit" title="Edit this protection"><i class="fa fa-pencil"></i></a>
+ <a wicket:id="delete" title="Delete this protection"><i class="fa fa-trash"></i></a>
+ </div>
+ <div class="panel-body">
+ <div wicket:id="protection"></div>
+ </div>
+ </div>
+</wicket:panel>
\ No newline at end of file
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPanel.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPanel.java
new file mode 100644
index 0000000000..4f26a35d17
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TagProtectionPanel.java
@@ -0,0 +1,78 @@
+package com.gitplex.server.web.page.depot.setting.tagprotection;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.panel.Panel;
+
+import com.gitplex.server.model.support.TagProtection;
+import com.gitplex.server.web.editable.BeanContext;
+import com.gitplex.server.web.util.ajaxlistener.ConfirmListener;
+
+@SuppressWarnings("serial")
+abstract class TagProtectionPanel extends Panel {
+
+ private final TagProtection protection;
+
+ public TagProtectionPanel(String id, TagProtection protection) {
+ super(id);
+
+ this.protection = protection;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new AjaxLink<Void>("edit") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ TagProtectionEditor editor = new TagProtectionEditor("protection", protection) {
+
+ @Override
+ protected void onSave(AjaxRequestTarget target, TagProtection protection) {
+ TagProtectionPanel.this.onSave(target, protection);
+ Component protectionViewer = BeanContext.viewBean("protection", protection).setOutputMarkupId(true);
+ TagProtectionPanel.this.replace(protectionViewer);
+ target.add(protectionViewer);
+ }
+
+ @Override
+ protected void onCancel(AjaxRequestTarget target) {
+ Component protectionViewer = BeanContext.viewBean("protection", protection).setOutputMarkupId(true);
+ TagProtectionPanel.this.replace(protectionViewer);
+ target.add(protectionViewer);
+ }
+
+ };
+ TagProtectionPanel.this.replace(editor);
+ target.add(editor);
+ }
+
+ });
+
+ add(new AjaxLink<Void>("delete") {
+
+ @Override
+ protected void updateAjaxAttributes(AjaxRequestAttributes attributes) {
+ super.updateAjaxAttributes(attributes);
+ attributes.getAjaxCallListeners().add(new ConfirmListener("Do you really want to delete this protection?"));
+ }
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ onDelete(target);
+ }
+
+ });
+
+ add(BeanContext.viewBean("protection", protection).setOutputMarkupId(true));
+ }
+
+ protected abstract void onDelete(AjaxRequestTarget target);
+
+ protected abstract void onSave(AjaxRequestTarget target, TagProtection protection);
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessDepotAdministrators.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessDepotAdministrators.java
new file mode 100644
index 0000000000..646a3276a8
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessDepotAdministrators.java
@@ -0,0 +1,11 @@
+package com.gitplex.server.web.page.depot.setting.tagprotection;
+
+import com.gitplex.server.model.support.tagcreator.DepotAdministrators;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable(order=200, name="Repository Administrators")
+public class TeamlessDepotAdministrators extends DepotAdministrators implements TeamlessTagCreator {
+
+ private static final long serialVersionUID = 1L;
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessDepotWriters.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessDepotWriters.java
new file mode 100644
index 0000000000..f3724c4a88
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessDepotWriters.java
@@ -0,0 +1,11 @@
+package com.gitplex.server.web.page.depot.setting.tagprotection;
+
+import com.gitplex.server.model.support.tagcreator.DepotWriters;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable(order=100, name="All Users Able to Write to the Repository")
+public class TeamlessDepotWriters extends DepotWriters implements TeamlessTagCreator {
+
+ private static final long serialVersionUID = 1L;
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessSpecifiedUser.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessSpecifiedUser.java
new file mode 100644
index 0000000000..dfc59808f5
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessSpecifiedUser.java
@@ -0,0 +1,11 @@
+package com.gitplex.server.web.page.depot.setting.tagprotection;
+
+import com.gitplex.server.model.support.tagcreator.SpecifiedUser;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable(order=400, name="Specified User")
+public class TeamlessSpecifiedUser extends SpecifiedUser implements TeamlessTagCreator {
+
+ private static final long serialVersionUID = 1L;
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessTagCreator.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessTagCreator.java
new file mode 100644
index 0000000000..62a900d77f
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessTagCreator.java
@@ -0,0 +1,9 @@
+package com.gitplex.server.web.page.depot.setting.tagprotection;
+
+import com.gitplex.server.model.support.tagcreator.TagCreator;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable
+public interface TeamlessTagCreator extends TagCreator {
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessTagProtection.java b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessTagProtection.java
new file mode 100644
index 0000000000..707d2cc0e9
--- /dev/null
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/setting/tagprotection/TeamlessTagProtection.java
@@ -0,0 +1,31 @@
+package com.gitplex.server.web.page.depot.setting.tagprotection;
+
+import javax.validation.constraints.NotNull;
+
+import com.gitplex.server.model.support.TagProtection;
+import com.gitplex.server.model.support.tagcreator.TagCreator;
+import com.gitplex.server.util.editable.annotation.Editable;
+
+@Editable
+public class TeamlessTagProtection extends TagProtection {
+
+ private static final long serialVersionUID = 1L;
+
+ private TeamlessTagCreator teamlessTagCreator = new TeamlessDepotWriters();
+
+ @Override
+ public TagCreator getTagCreator() {
+ return super.getTagCreator();
+ }
+
+ @Editable(order=400, name="Allowed Creator", description="Specify users allowed to create specified tag")
+ @NotNull
+ public TeamlessTagCreator getTeamlessTagCreator() {
+ return teamlessTagCreator;
+ }
+
+ public void setTeamlessTagCreator(TeamlessTagCreator teamlessTagCreator) {
+ this.teamlessTagCreator = teamlessTagCreator;
+ }
+
+}
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/tags/DepotTagsPage.html b/web/src/main/java/com/gitplex/server/web/page/depot/tags/DepotTagsPage.html
index 6f31cf652e..11087cfef9 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/tags/DepotTagsPage.html
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/tags/DepotTagsPage.html
@@ -28,8 +28,8 @@
</td>
<td class="actions">
<span class="btn-group">
- <a wicket:id="download" class="btn btn-default" title="Download tag archive"><i class="fa fa-download"></i></a>
- <a wicket:id="delete" class="btn btn-default" title="Delete this tag"><i class="fa fa-times fa-lg"></i></a>
+ <a wicket:id="download" class="btn btn-default" title="Download tag archive"><i class="fa fa-download"></i> Download</a>
+ <a wicket:id="delete" class="btn btn-default" title="Delete this tag"><i class="fa fa-trash"></i> Delete</a>
</span>
</td>
</tr>
diff --git a/web/src/main/java/com/gitplex/server/web/page/depot/tags/DepotTagsPage.java b/web/src/main/java/com/gitplex/server/web/page/depot/tags/DepotTagsPage.java
index 3015537860..8130641067 100644
--- a/web/src/main/java/com/gitplex/server/web/page/depot/tags/DepotTagsPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/depot/tags/DepotTagsPage.java
@@ -28,7 +28,6 @@ import org.apache.wicket.model.Model;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
-import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag;
@@ -103,8 +102,7 @@ public class DepotTagsPage extends DepotPage {
protected void onConfigure() {
super.onConfigure();
- ObjectId commit = getDepot().getObjectId(tagRevision);
- setVisible(SecurityUtils.canPushRef(getDepot(), Constants.R_TAGS, ObjectId.zeroId(), commit));
+ setVisible(SecurityUtils.canCreateTag(getDepot(), Constants.R_TAGS));
}
private RevisionPicker newRevisionPicker() {
@@ -324,8 +322,7 @@ public class DepotTagsPage extends DepotPage {
protected void onConfigure() {
super.onConfigure();
- RefInfo ref = item.getModelObject();
- setVisible(SecurityUtils.canPushRef(getDepot(), ref.getRef().getName(), ref.getPeeledObj(), ObjectId.zeroId()));
+ setVisible(SecurityUtils.canDeleteTag(getDepot(), tagName));
}
});
diff --git a/web/src/main/java/com/gitplex/server/web/page/layout/LayoutPage.java b/web/src/main/java/com/gitplex/server/web/page/layout/LayoutPage.java
index dcbdea9a2c..524a1816d8 100644
--- a/web/src/main/java/com/gitplex/server/web/page/layout/LayoutPage.java
+++ b/web/src/main/java/com/gitplex/server/web/page/layout/LayoutPage.java
@@ -138,7 +138,7 @@ public abstract class LayoutPage extends BasePage {
}
if (signedIn) {
- head.add(new AvatarLink("user", user, null));
+ head.add(new AvatarLink("user", user));
head.add(new DropdownLink("userMenuTrigger", new AlignPlacement(50, 100, 50, 0, 8)) {
@Override
diff --git a/web/src/main/java/com/gitplex/server/web/util/AjaxEvent.java b/web/src/main/java/com/gitplex/server/web/util/AjaxPayload.java
similarity index 77%
rename from web/src/main/java/com/gitplex/server/web/util/AjaxEvent.java
rename to web/src/main/java/com/gitplex/server/web/util/AjaxPayload.java
index 44032f2722..26428e265d 100644
--- a/web/src/main/java/com/gitplex/server/web/util/AjaxEvent.java
+++ b/web/src/main/java/com/gitplex/server/web/util/AjaxPayload.java
@@ -2,11 +2,11 @@ package com.gitplex.server.web.util;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
-public class AjaxEvent {
+public class AjaxPayload {
private final IPartialPageRequestHandler partialPageRequestHandler;
- public AjaxEvent(IPartialPageRequestHandler partialPageRequestHandler) {
+ public AjaxPayload(IPartialPageRequestHandler partialPageRequestHandler) {
this.partialPageRequestHandler = partialPageRequestHandler;
}
diff --git a/web/src/main/java/com/gitplex/server/web/util/SuggestionUtils.java b/web/src/main/java/com/gitplex/server/web/util/SuggestionUtils.java
index 84ba9f7a0d..f449789f82 100644
--- a/web/src/main/java/com/gitplex/server/web/util/SuggestionUtils.java
+++ b/web/src/main/java/com/gitplex/server/web/util/SuggestionUtils.java
@@ -8,80 +8,78 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.annotation.Nullable;
-
import com.gitplex.codeassist.InputSuggestion;
import com.gitplex.jsymbol.Range;
import com.gitplex.server.GitPlex;
import com.gitplex.server.git.GitUtils;
import com.gitplex.server.git.RefInfo;
import com.gitplex.server.manager.CommitInfoManager;
+import com.gitplex.server.model.Account;
import com.gitplex.server.model.Depot;
-import com.gitplex.server.persistence.dao.Dao;
-import com.gitplex.server.util.match.PatternApplied;
-import com.gitplex.server.util.match.WildcardUtils;
+import com.gitplex.server.model.Team;
+import com.gitplex.server.security.SecurityUtils;
+import com.gitplex.server.security.privilege.DepotPrivilege;
+import com.gitplex.server.util.stringmatch.PatternApplied;
+import com.gitplex.server.util.stringmatch.WildcardUtils;
import com.google.common.base.Preconditions;
public class SuggestionUtils {
- public static List<InputSuggestion> suggestBranch(Depot depot, String matchWith,
- int count, @Nullable String description, @Nullable String wildcardDescription) {
+ public static List<InputSuggestion> suggestBranch(Depot depot, String matchWith, int count) {
String lowerCaseMatchWith = matchWith.toLowerCase();
int numSuggestions = 0;
List<InputSuggestion> suggestions = new ArrayList<>();
- if (wildcardDescription != null) {
- String wildcard = "*";
- int index = wildcard.indexOf(lowerCaseMatchWith);
- if (index != -1) {
- Range matchRange = new Range(index, index+lowerCaseMatchWith.length());
- suggestions.add(new InputSuggestion(wildcard, wildcardDescription, matchRange));
- }
- }
for (RefInfo ref: depot.getBranches()) {
String branch = GitUtils.ref2branch(ref.getRef().getName());
int index = branch.toLowerCase().indexOf(lowerCaseMatchWith);
if (index != -1 && numSuggestions++<count) {
Range matchRange = new Range(index, index+lowerCaseMatchWith.length());
- suggestions.add(new InputSuggestion(branch, description, matchRange));
+ suggestions.add(new InputSuggestion(branch, null, matchRange));
}
}
return suggestions;
}
- public static List<InputSuggestion> suggestAffinals(Depot depot, String matchWith,
- int count, @Nullable String description, @Nullable String wildcardDescription) {
+ public static List<InputSuggestion> suggestTag(Depot depot, String matchWith, int count) {
String lowerCaseMatchWith = matchWith.toLowerCase();
int numSuggestions = 0;
List<InputSuggestion> suggestions = new ArrayList<>();
- if (wildcardDescription != null) {
- String wildcard = "*/*";
- int index = wildcard.indexOf(lowerCaseMatchWith);
- if (index != -1) {
+ for (RefInfo ref: depot.getTags()) {
+ String tag = GitUtils.ref2tag(ref.getRef().getName());
+ int index = tag.toLowerCase().indexOf(lowerCaseMatchWith);
+ if (index != -1 && numSuggestions++<count) {
Range matchRange = new Range(index, index+lowerCaseMatchWith.length());
- suggestions.add(new InputSuggestion(wildcard, wildcardDescription, matchRange));
+ suggestions.add(new InputSuggestion(tag, null, matchRange));
}
}
- for (Depot affinal: GitPlex.getInstance(Dao.class).findAll(Depot.class)) {
- String FQN = affinal.getFQN();
- int index = FQN.toLowerCase().indexOf(lowerCaseMatchWith);
+ return suggestions;
+ }
+
+ public static List<InputSuggestion> suggestUser(Depot depot, DepotPrivilege privilege, String matchWith, int count) {
+ String lowerCaseMatchWith = matchWith.toLowerCase();
+ int numSuggestions = 0;
+ List<InputSuggestion> suggestions = new ArrayList<>();
+ for (Account user: SecurityUtils.findUsersCan(depot, privilege)) {
+ String name = user.getName();
+ int index = name.toLowerCase().indexOf(lowerCaseMatchWith);
if (index != -1 && numSuggestions++<count) {
Range matchRange = new Range(index, index+lowerCaseMatchWith.length());
- suggestions.add(new InputSuggestion(FQN, description, matchRange));
+ suggestions.add(new InputSuggestion(name, matchRange));
}
}
return suggestions;
}
- public static List<InputSuggestion> suggestTag(Depot depot, String matchWith, int count) {
+ public static List<InputSuggestion> suggestTeam(Depot depot, String matchWith, int count) {
String lowerCaseMatchWith = matchWith.toLowerCase();
int numSuggestions = 0;
List<InputSuggestion> suggestions = new ArrayList<>();
- for (RefInfo ref: depot.getTags()) {
- String tag = GitUtils.ref2tag(ref.getRef().getName());
- int index = tag.toLowerCase().indexOf(lowerCaseMatchWith);
+ for (Team team: depot.getAccount().getDefinedTeams()) {
+ String name = team.getName();
+ int index = name.toLowerCase().indexOf(lowerCaseMatchWith);
if (index != -1 && numSuggestions++<count) {
Range matchRange = new Range(index, index+lowerCaseMatchWith.length());
- suggestions.add(new InputSuggestion(tag, matchRange));
+ suggestions.add(new InputSuggestion(name, matchRange));
}
}
return suggestions;
diff --git a/web/src/main/java/com/gitplex/server/web/util/avatar/AvatarManager.java b/web/src/main/java/com/gitplex/server/web/util/avatar/AvatarManager.java
index de2732fbbd..87bd45424a 100644
--- a/web/src/main/java/com/gitplex/server/web/util/avatar/AvatarManager.java
+++ b/web/src/main/java/com/gitplex/server/web/util/avatar/AvatarManager.java
@@ -17,8 +17,7 @@ public interface AvatarManager {
* @param user
* user to get avatar for
* @return
- * url of avatar image. This url will be relative to context root if gravatar is disabled, or
- * a default avatar is returned when user is null
+ * url of avatar image. This url will be relative to context root if gravatar is disabled
*/
String getAvatarUrl(@Nullable Account user);
diff --git a/web/src/main/java/com/gitplex/server/web/util/avatar/DefaultAvatarManager.java b/web/src/main/java/com/gitplex/server/web/util/avatar/DefaultAvatarManager.java
index ed5ba45039..05510dfe60 100644
--- a/web/src/main/java/com/gitplex/server/web/util/avatar/DefaultAvatarManager.java
+++ b/web/src/main/java/com/gitplex/server/web/util/avatar/DefaultAvatarManager.java
@@ -6,6 +6,7 @@ import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.concurrent.locks.Lock;
+import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -15,6 +16,7 @@ import org.apache.wicket.markup.html.form.upload.FileUpload;
import org.eclipse.jgit.lib.PersonIdent;
import com.gitplex.launcher.bootstrap.Bootstrap;
+import com.gitplex.server.GitPlex;
import com.gitplex.server.manager.ConfigManager;
import com.gitplex.server.model.Account;
import com.gitplex.server.persistence.annotation.Transactional;
@@ -41,19 +43,22 @@ public class DefaultAvatarManager implements AvatarManager {
@Transactional
@Override
- public String getAvatarUrl(Account account) {
- if (account == null)
+ public String getAvatarUrl(@Nullable Account account) {
+ if (account == null) {
+ return AVATARS_BASE_URL + "gitplex.png";
+ } else if (account.getId() == null) {
return AVATARS_BASE_URL + "default.png";
-
- File avatarFile = getUploaded(account);
- if (avatarFile.exists()) {
- return AVATARS_BASE_URL + "uploaded/" + account.getId() + "?version=" + avatarFile.lastModified();
+ } else {
+ File avatarFile = getUploaded(account);
+ if (avatarFile.exists()) {
+ return AVATARS_BASE_URL + "uploaded/" + account.getId() + "?version=" + avatarFile.lastModified();
+ }
+
+ if (configManager.getSystemSetting().isGravatarEnabled() && !account.isOrganization())
+ return Gravatar.getURL(account.getEmail(), GRAVATAR_SIZE);
+ else
+ return generateAvatar(account.getDisplayName(), account.getEmail());
}
-
- if (configManager.getSystemSetting().isGravatarEnabled() && !account.isOrganization())
- return Gravatar.getURL(account.getEmail(), GRAVATAR_SIZE);
- else
- return generateAvatar(account.getDisplayName(), account.getEmail());
}
private String generateAvatar(String primaryName, String secondaryName) {
@@ -85,7 +90,9 @@ public class DefaultAvatarManager implements AvatarManager {
@Override
public String getAvatarUrl(PersonIdent person) {
- if (configManager.getSystemSetting().isGravatarEnabled())
+ if (person.getEmailAddress().length() == 0 && person.getName().equals(GitPlex.NAME))
+ return AVATARS_BASE_URL + "gitplex.png";
+ else if (configManager.getSystemSetting().isGravatarEnabled())
return Gravatar.getURL(person.getEmailAddress(), GRAVATAR_SIZE);
else
return generateAvatar(person.getName(), person.getEmailAddress());
diff --git a/web/src/main/java/com/gitplex/server/web/util/model/ReviewersModel.java b/web/src/main/java/com/gitplex/server/web/util/model/ReviewersModel.java
deleted file mode 100644
index 71dd197e14..0000000000
--- a/web/src/main/java/com/gitplex/server/web/util/model/ReviewersModel.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.gitplex.server.web.util.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.LoadableDetachableModel;
-
-import com.gitplex.server.model.PullRequest;
-import com.gitplex.server.model.PullRequestReviewInvitation;
-
-@SuppressWarnings("serial")
-public class ReviewersModel extends LoadableDetachableModel<List<PullRequestReviewInvitation>>{
-
- private final IModel<PullRequest> requestModel;
-
- public ReviewersModel(IModel<PullRequest> requestModel) {
- this.requestModel = requestModel;
- }
-
- @Override
- protected List<PullRequestReviewInvitation> load() {
- List<PullRequestReviewInvitation> invitations = new ArrayList<>();
- for (PullRequestReviewInvitation invitation: requestModel.getObject().getReviewInvitations()) {
- if (invitation.getStatus() != PullRequestReviewInvitation.Status.EXCLUDED)
- invitations.add(invitation);
- }
- invitations.sort((o1, o2)->{
- if (o1.getId() == null) {
- if (o2.getId() == null)
- return o1.getDate().compareTo(o2.getDate());
- else
- return 1;
- } else {
- if (o2.getId() == null)
- return -1;
- else
- return (int)(o1.getId() - o2.getId());
- }
- });
- return invitations;
- }
-
- @Override
- protected void onDetach() {
- requestModel.detach();
-
- super.onDetach();
- }
-
-}
diff --git a/web/src/main/java/com/gitplex/server/web/websocket/PullRequestChangeBroadcaster.java b/web/src/main/java/com/gitplex/server/web/websocket/PullRequestChangeBroadcaster.java
index a41f6845df..7857ed8d4f 100644
--- a/web/src/main/java/com/gitplex/server/web/websocket/PullRequestChangeBroadcaster.java
+++ b/web/src/main/java/com/gitplex/server/web/websocket/PullRequestChangeBroadcaster.java
@@ -4,10 +4,8 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import com.gitplex.launcher.loader.Listen;
-import com.gitplex.server.event.pullrequest.PullRequestChangeEvent;
+import com.gitplex.server.event.pullrequest.PullRequestEvent;
import com.gitplex.server.web.util.WicketUtils;
-import com.gitplex.server.web.websocket.PageKey;
-import com.gitplex.server.web.websocket.WebSocketManager;
@Singleton
public class PullRequestChangeBroadcaster {
@@ -20,7 +18,7 @@ public class PullRequestChangeBroadcaster {
}
@Listen
- public void on(PullRequestChangeEvent event) {
+ public void on(PullRequestEvent event) {
PullRequestChangedRegion region = new PullRequestChangedRegion(event.getRequest().getId());
PageKey sourcePageKey = WicketUtils.getPageKey();
diff --git a/web/src/main/java/com/gitplex/server/web/websocket/PullRequestChanged.java b/web/src/main/java/com/gitplex/server/web/websocket/PullRequestChanged.java
index 0a97a1792e..93058337ee 100644
--- a/web/src/main/java/com/gitplex/server/web/websocket/PullRequestChanged.java
+++ b/web/src/main/java/com/gitplex/server/web/websocket/PullRequestChanged.java
@@ -2,9 +2,9 @@ package com.gitplex.server.web.websocket;
import org.apache.wicket.core.request.handler.IPartialPageRequestHandler;
-import com.gitplex.server.web.util.AjaxEvent;
+import com.gitplex.server.web.util.AjaxPayload;
-public class PullRequestChanged extends AjaxEvent {
+public class PullRequestChanged extends AjaxPayload {
public PullRequestChanged(IPartialPageRequestHandler partialPageRequestHandler) {
super(partialPageRequestHandler);
diff --git a/web/src/main/java/com/gitplex/server/web/websocket/TaskChangeBroadcaster.java b/web/src/main/java/com/gitplex/server/web/websocket/TaskChangeBroadcaster.java
index 7b01f518f2..890c1f1a0e 100644
--- a/web/src/main/java/com/gitplex/server/web/websocket/TaskChangeBroadcaster.java
+++ b/web/src/main/java/com/gitplex/server/web/websocket/TaskChangeBroadcaster.java
@@ -4,7 +4,7 @@ import javax.inject.Inject;
import javax.inject.Singleton;
import com.gitplex.launcher.loader.Listen;
-import com.gitplex.server.event.TaskChangeEvent;
+import com.gitplex.server.event.TaskChanged;
import com.gitplex.server.web.websocket.WebSocketManager;
@Singleton
@@ -18,7 +18,7 @@ public class TaskChangeBroadcaster {
}
@Listen
- public void on(TaskChangeEvent event) {
+ public void on(TaskChanged event) {
TaskChangedRegion region = new TaskChangedRegion(event.getUserId());
webSocketManager.render(region, null);
}