Skip to content

The Unified and Autonomous Development Platform

Link to exact position of mentioning in email

robin shine3deb7f4546df
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/scrollintoview/jquery.scrollintoview.js b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/scrollintoview/jquery.scrollintoview.js
index 307a6392ad..11dc9c0e04 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/scrollintoview/jquery.scrollintoview.js
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/assets/scrollintoview/jquery.scrollintoview.js
@@ -1,32 +1,33 @@
-/*
- * 2015, Robin Shen
- */
-(function ( $ ) {
-
- var defaultTopMargin = defaultBottomMargin = 8;
-
- $.fn.scrollIntoView = function(selector, topMargin, bottomMargin) {
- if (topMargin == undefined)
- topMargin = defaultTopMargin;
- if (bottomMargin == undefined)
- bottomMargin = defaultBottomMargin;
-
- var $container = jQuery(this);
- var $active = $container.find(selector);
-
- if ($active.length != 0) {
- var containerTop = $container.offset().top;
- var activeTop = $active.offset().top;
- if (activeTop-topMargin<containerTop)
- $container.scrollTop($container.scrollTop()-(containerTop-activeTop+topMargin));
-
- var containerBottom = containerTop + $container.height();
- var activeBottom = activeTop + $active.height();
- if (activeBottom+bottomMargin>containerBottom)
- $container.scrollTop($container.scrollTop()+(activeBottom+bottomMargin-containerBottom));
- }
-
- return this;
- };
-
-}( jQuery ));
+/*
+ * 2015, Robin Shen
+ */
+(function ( $ ) {
+
+ var defaultTopMargin = defaultBottomMargin = 8;
+
+ $.fn.scrollIntoView = function(selector, topMargin, bottomMargin) {
+ if (topMargin == undefined)
+ topMargin = defaultTopMargin;
+ if (bottomMargin == undefined)
+ bottomMargin = defaultBottomMargin;
+
+ var $container = jQuery(this);
+ var $active = $container.find(selector);
+
+ if ($active.length != 0) {
+ var containerTop = $container.offset().top;
+ var containerBottom = containerTop + $container.height();
+ var activeBottom = $active.offset().top + $active.height();
+
+ if (activeBottom+bottomMargin>containerBottom)
+ $container.scrollTop($container.scrollTop()+(activeBottom+bottomMargin-containerBottom));
+
+ var activeTop = $active.offset().top;
+ if (activeTop-topMargin<containerTop)
+ $container.scrollTop($container.scrollTop()-(containerTop-activeTop+topMargin));
+ }
+
+ return this;
+ };
+
+}( jQuery ));
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeComment.java
index 909a9e2f39..173239e916 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeComment.java
@@ -24,6 +24,7 @@ import javax.persistence.Version;
import org.hibernate.annotations.DynamicUpdate;
import com.pmease.commons.hibernate.AbstractEntity;
+import com.pmease.commons.wicket.editable.EditableUtils;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.entity.support.CodeCommentActivity;
import com.pmease.gitplex.core.entity.support.CommentPos;
@@ -216,7 +217,7 @@ public class CodeComment extends AbstractEntity {
public void setLastEvent(CodeCommentEvent event) {
LastEvent lastEvent = new LastEvent();
lastEvent.setDate(event.getDate());
- lastEvent.setType(event.getClass());
+ lastEvent.setType(EditableUtils.getName(event.getClass()));
lastEvent.setUser(event.getUser());
setLastEvent(lastEvent);
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java
index 8926967373..b8251cef47 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequest.java
@@ -46,17 +46,14 @@ import com.pmease.commons.hibernate.UnitOfWork;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.jackson.ExternalView;
import com.pmease.commons.lang.diff.WhitespaceOption;
+import com.pmease.commons.wicket.editable.EditableUtils;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.entity.support.CloseInfo;
import com.pmease.gitplex.core.entity.support.CompareContext;
import com.pmease.gitplex.core.entity.support.DepotAndBranch;
import com.pmease.gitplex.core.entity.support.IntegrationPreview;
import com.pmease.gitplex.core.entity.support.LastEvent;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestChangeEvent;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestCodeCommentReplied;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestCodeCommentResolved;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestCodeCommentUnresolved;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestCodeCommented;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestCodeCommentEvent;
import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;
import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;
import com.pmease.gitplex.core.gatekeeper.checkresult.GateCheckResult;
@@ -1016,19 +1013,21 @@ public class PullRequest extends AbstractEntity {
return merged;
}
- public void setLastEvent(PullRequestChangeEvent event) {
+ public void setLastEvent(PullRequestStatusChange statusChange) {
+ LastEvent lastEvent = new LastEvent();
+ lastEvent.setDate(statusChange.getDate());
+ lastEvent.setType(statusChange.getType().getName());
+ lastEvent.setUser(statusChange.getUser());
+ setLastEvent(lastEvent);
+ }
+
+ public void setLastEvent(PullRequestCodeCommentEvent event) {
LastEvent lastEvent = new LastEvent();
lastEvent.setDate(event.getDate());
- lastEvent.setType(event.getClass());
+ lastEvent.setType(EditableUtils.getName(event.getClass()));
lastEvent.setUser(event.getUser());
setLastEvent(lastEvent);
-
- if (event instanceof PullRequestCodeCommented
- || event instanceof PullRequestCodeCommentReplied
- || event instanceof PullRequestCodeCommentResolved
- || event instanceof PullRequestCodeCommentUnresolved) {
- setLastCodeCommentEventDate(event.getDate());
- }
+ setLastCodeCommentEventDate(event.getDate());
}
public static class ComparingInfo implements Serializable {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequestComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequestComment.java
index 18f8bad0c4..37638f928c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequestComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequestComment.java
@@ -82,4 +82,8 @@ public class PullRequestComment extends AbstractEntity {
return request.getTargetDepot();
}
+ public String getAnchor() {
+ return getClass().getSimpleName() + "-" + getId();
+ }
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequestStatusChange.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequestStatusChange.java
index db2feb78bb..48758dfbd9 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequestStatusChange.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/PullRequestStatusChange.java
@@ -13,7 +13,6 @@ import javax.persistence.Version;
import org.hibernate.annotations.DynamicUpdate;
import com.pmease.commons.hibernate.AbstractEntity;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestStatusChangeEvent;
@Entity
@DynamicUpdate
@@ -21,6 +20,40 @@ public class PullRequestStatusChange extends AbstractEntity {
private static final long serialVersionUID = 1L;
+ 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"),
+ 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"),
+ ;
+
+ private final String name;
+
+ private final String iconClass;
+
+ Type(String name, String iconClass) {
+ this.name = name;
+ this.iconClass = iconClass;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getIconClass() {
+ return iconClass;
+ }
+
+ }
+
@Version
private long version;
@@ -29,7 +62,7 @@ public class PullRequestStatusChange extends AbstractEntity {
private PullRequest request;
@Column(nullable=false)
- private Class<? extends PullRequestStatusChangeEvent> eventType;
+ private Type type;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(nullable=false)
@@ -48,12 +81,12 @@ public class PullRequestStatusChange extends AbstractEntity {
this.request = request;
}
- public Class<? extends PullRequestStatusChangeEvent> getEventType() {
- return eventType;
+ public Type getType() {
+ return type;
}
- public void setEventType(Class<? extends PullRequestStatusChangeEvent> eventType) {
- this.eventType = eventType;
+ public void setType(Type type) {
+ this.type = type;
}
public String getNote() {
@@ -85,8 +118,8 @@ public class PullRequestStatusChange extends AbstractEntity {
return version;
}
- public void setVersion(long version) {
- this.version = version;
+ public String getAnchor() {
+ return getClass().getSimpleName() + "-" + getId();
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/support/CodeCommentActivity.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/support/CodeCommentActivity.java
index 6d71be659d..edf1e3a562 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/support/CodeCommentActivity.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/support/CodeCommentActivity.java
@@ -81,6 +81,10 @@ public abstract class CodeCommentActivity extends AbstractEntity {
return new ComparingInfo(getComment().getCommentPos().getCommit(), getCompareContext());
}
+ public String getAnchor() {
+ return getClass().getSimpleName() + "-" + getId();
+ }
+
public abstract String getNote();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/support/LastEvent.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/support/LastEvent.java
index b8ef61cca1..88e339ca68 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/support/LastEvent.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/support/LastEvent.java
@@ -1,53 +1,53 @@
-package com.pmease.gitplex.core.entity.support;
-
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.persistence.Column;
-import javax.persistence.Embeddable;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-
-import com.pmease.gitplex.core.entity.Account;
-
-@Embeddable
-public class LastEvent implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(name="LAST_EVENT_USER")
- private Account user;
-
- @Column(name="LAST_EVENT_DESC")
- private Class<?> type;
-
- @Column(name="LAST_EVENT_DATE")
- private Date date;
-
- public Class<?> getType() {
- return type;
- }
-
- public void setType(Class<?> type) {
- this.type = type;
- }
-
- public Date getDate() {
- return date;
- }
-
- public void setDate(Date date) {
- this.date = date;
- }
-
- public Account getUser() {
- return user;
- }
-
- public void setUser(Account user) {
- this.user = user;
- }
-
-}
+package com.pmease.gitplex.core.entity.support;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
+import com.pmease.gitplex.core.entity.Account;
+
+@Embeddable
+public class LastEvent implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ @JoinColumn(name="LAST_EVENT_USER")
+ private Account user;
+
+ @Column(name="LAST_EVENT_TYPE")
+ private String type;
+
+ @Column(name="LAST_EVENT_DATE")
+ private Date date;
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public Account getUser() {
+ return user;
+ }
+
+ public void setUser(Account user) {
+ this.user = user;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestApproved.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestApproved.java
deleted file mode 100644
index 06bce5efab..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestApproved.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.PullRequestReview;
-
-@Editable(name="approved", icon="fa fa-thumbs-o-up")
-public class PullRequestApproved extends PullRequestStatusChangeEvent {
-
- private final PullRequestReview review;
-
- public PullRequestApproved(PullRequestReview review, String note) {
- super(review.getUpdate().getRequest(), review.getUser(), review.getDate(), note);
- this.review = review;
- }
-
- public PullRequestReview getReview() {
- return review;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestAssigned.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestAssigned.java
deleted file mode 100644
index aea2e9bcf8..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestAssigned.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import java.util.Date;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequest;
-
-@Editable(name="assigned", icon="fa fa-user")
-public class PullRequestAssigned extends PullRequestStatusChangeEvent {
-
- public PullRequestAssigned(PullRequest request, Account user, String note) {
- super(request, user, new Date(), note);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentEvent.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentEvent.java
new file mode 100644
index 0000000000..4a42297085
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentEvent.java
@@ -0,0 +1,22 @@
+package com.pmease.gitplex.core.event.pullrequest;
+
+import java.util.Date;
+
+import com.pmease.gitplex.core.entity.Account;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.PullRequest;
+
+public class PullRequestCodeCommentEvent extends PullRequestChangeEvent {
+
+ private final CodeComment comment;
+
+ public PullRequestCodeCommentEvent(PullRequest request, Account user, Date date, CodeComment comment) {
+ super(request, user, date);
+ this.comment = comment;
+ }
+
+ public CodeComment getComment() {
+ return comment;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentReplied.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentReplied.java
index 9ce77d32d2..b1c28a94cc 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentReplied.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentReplied.java
@@ -1,27 +1,27 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.CodeCommentReply;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.event.MarkdownAware;
-
-@Editable(name="replied code comment")
-public class PullRequestCodeCommentReplied extends PullRequestChangeEvent implements MarkdownAware {
-
- private final CodeCommentReply reply;
-
- public PullRequestCodeCommentReplied(PullRequest request, CodeCommentReply reply) {
- super(request, reply.getUser(), reply.getDate());
- this.reply = reply;
- }
-
- public CodeCommentReply getReply() {
- return reply;
- }
-
- @Override
- public String getMarkdown() {
- return getReply().getContent();
- }
-
-}
+package com.pmease.gitplex.core.event.pullrequest;
+
+import com.pmease.commons.wicket.editable.annotation.Editable;
+import com.pmease.gitplex.core.entity.CodeCommentReply;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.event.MarkdownAware;
+
+@Editable(name="replied code comment")
+public class PullRequestCodeCommentReplied extends PullRequestCodeCommentEvent implements MarkdownAware {
+
+ private final CodeCommentReply reply;
+
+ public PullRequestCodeCommentReplied(PullRequest request, CodeCommentReply reply) {
+ super(request, reply.getUser(), reply.getDate(), reply.getComment());
+ this.reply = reply;
+ }
+
+ public CodeCommentReply getReply() {
+ return reply;
+ }
+
+ @Override
+ public String getMarkdown() {
+ return getReply().getContent();
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentResolved.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentResolved.java
index 979593db7a..53e079a7e4 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentResolved.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentResolved.java
@@ -1,27 +1,27 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.CodeCommentStatusChange;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.event.MarkdownAware;
-
-@Editable(name="resolved code comment")
-public class PullRequestCodeCommentResolved extends PullRequestChangeEvent implements MarkdownAware {
-
- private final CodeCommentStatusChange statusChange;
-
- public PullRequestCodeCommentResolved(PullRequest request, CodeCommentStatusChange statusChange) {
- super(request, statusChange.getUser(), statusChange.getDate());
- this.statusChange = statusChange;
- }
-
- public CodeCommentStatusChange getStatusChange() {
- return statusChange;
- }
-
- @Override
- public String getMarkdown() {
- return getStatusChange().getNote();
- }
-
-}
+package com.pmease.gitplex.core.event.pullrequest;
+
+import com.pmease.commons.wicket.editable.annotation.Editable;
+import com.pmease.gitplex.core.entity.CodeCommentStatusChange;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.event.MarkdownAware;
+
+@Editable(name="resolved code comment")
+public class PullRequestCodeCommentResolved extends PullRequestCodeCommentEvent implements MarkdownAware {
+
+ private final CodeCommentStatusChange statusChange;
+
+ public PullRequestCodeCommentResolved(PullRequest request, CodeCommentStatusChange statusChange) {
+ super(request, statusChange.getUser(), statusChange.getDate(), statusChange.getComment());
+ this.statusChange = statusChange;
+ }
+
+ public CodeCommentStatusChange getStatusChange() {
+ return statusChange;
+ }
+
+ @Override
+ public String getMarkdown() {
+ return getStatusChange().getNote();
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentUnresolved.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentUnresolved.java
index e8acaa4e9c..4c2c9bb486 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentUnresolved.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommentUnresolved.java
@@ -1,27 +1,27 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.CodeCommentStatusChange;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.event.MarkdownAware;
-
-@Editable(name="Unresolved code comment")
-public class PullRequestCodeCommentUnresolved extends PullRequestChangeEvent implements MarkdownAware {
-
- private final CodeCommentStatusChange statusChange;
-
- public PullRequestCodeCommentUnresolved(PullRequest request, CodeCommentStatusChange statusChange) {
- super(request, statusChange.getUser(), statusChange.getDate());
- this.statusChange = statusChange;
- }
-
- public CodeCommentStatusChange getStatusChange() {
- return statusChange;
- }
-
- @Override
- public String getMarkdown() {
- return getStatusChange().getNote();
- }
-
-}
+package com.pmease.gitplex.core.event.pullrequest;
+
+import com.pmease.commons.wicket.editable.annotation.Editable;
+import com.pmease.gitplex.core.entity.CodeCommentStatusChange;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.event.MarkdownAware;
+
+@Editable(name="Unresolved code comment")
+public class PullRequestCodeCommentUnresolved extends PullRequestCodeCommentEvent implements MarkdownAware {
+
+ private final CodeCommentStatusChange statusChange;
+
+ public PullRequestCodeCommentUnresolved(PullRequest request, CodeCommentStatusChange statusChange) {
+ super(request, statusChange.getUser(), statusChange.getDate(), statusChange.getComment());
+ this.statusChange = statusChange;
+ }
+
+ public CodeCommentStatusChange getStatusChange() {
+ return statusChange;
+ }
+
+ @Override
+ public String getMarkdown() {
+ return getStatusChange().getNote();
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommented.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommented.java
index a2a7e1ea28..2bbbfce741 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommented.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestCodeCommented.java
@@ -1,27 +1,20 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.CodeComment;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.event.MarkdownAware;
-
-@Editable(name="commented code")
-public class PullRequestCodeCommented extends PullRequestChangeEvent implements MarkdownAware {
-
- private final CodeComment comment;
-
- public PullRequestCodeCommented(PullRequest request, CodeComment comment) {
- super(request, comment.getUser(), comment.getDate());
- this.comment = comment;
- }
-
- public CodeComment getComment() {
- return comment;
- }
-
- @Override
- public String getMarkdown() {
- return getComment().getContent();
- }
-
-}
+package com.pmease.gitplex.core.event.pullrequest;
+
+import com.pmease.commons.wicket.editable.annotation.Editable;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.event.MarkdownAware;
+
+@Editable(name="commented code")
+public class PullRequestCodeCommented extends PullRequestCodeCommentEvent implements MarkdownAware {
+
+ public PullRequestCodeCommented(PullRequest request, CodeComment comment) {
+ super(request, comment.getUser(), comment.getDate(), comment);
+ }
+
+ @Override
+ public String getMarkdown() {
+ return getComment().getContent();
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestDisapproved.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestDisapproved.java
deleted file mode 100644
index 2e2883c09f..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestDisapproved.java
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.PullRequestReview;
-
-@Editable(name="disapproved", icon="fa fa-thumbs-o-down")
-public class PullRequestDisapproved extends PullRequestStatusChangeEvent {
-
- private final PullRequestReview review;
-
- public PullRequestDisapproved(PullRequestReview review, String note) {
- super(review.getUpdate().getRequest(), review.getUser(), review.getDate(), note);
- this.review = review;
- }
-
- public PullRequestReview getReview() {
- return review;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestDiscarded.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestDiscarded.java
deleted file mode 100644
index 162396e78e..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestDiscarded.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequest;
-
-@Editable(name="discarded", icon="fa fa-ban")
-public class PullRequestDiscarded extends PullRequestStatusChangeEvent {
-
- public PullRequestDiscarded(PullRequest request, Account user, String note) {
- super(request, user, request.getCloseInfo().getCloseDate(), note);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestIntegrated.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestIntegrated.java
deleted file mode 100644
index ad20631d4e..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestIntegrated.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequest;
-
-@Editable(name="integrated", icon="fa fa-check")
-public class PullRequestIntegrated extends PullRequestStatusChangeEvent {
-
- public PullRequestIntegrated(PullRequest request, Account user, String note) {
- super(request, user, request.getCloseInfo().getCloseDate(), note);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestReopened.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestReopened.java
deleted file mode 100644
index f3db4feb37..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestReopened.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import java.util.Date;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequest;
-
-@Editable(name="reopened", icon="fa fa-repeat")
-public class PullRequestReopened extends PullRequestStatusChangeEvent {
-
- public PullRequestReopened(PullRequest request, Account user, String note) {
- super(request, user, new Date(), note);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestReviewDeleted.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestReviewDeleted.java
deleted file mode 100644
index 6e038d2778..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestReviewDeleted.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import java.util.Date;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequestReview;
-
-@Editable(name="deleted review", icon="fa fa-times")
-public class PullRequestReviewDeleted extends PullRequestStatusChangeEvent {
-
- private final PullRequestReview review;
-
- public PullRequestReviewDeleted(PullRequestReview review, Account user, String note) {
- super(review.getUpdate().getRequest(), user, new Date(), note);
- this.review = review;
- }
-
- public PullRequestReview getReview() {
- return review;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestStatusChangeEvent.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestStatusChangeEvent.java
index b5c18723b0..0fb989e6e9 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestStatusChangeEvent.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestStatusChangeEvent.java
@@ -1,30 +1,24 @@
package com.pmease.gitplex.core.event.pullrequest;
-import java.util.Date;
-
-import javax.annotation.Nullable;
-
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange;
import com.pmease.gitplex.core.event.MarkdownAware;
-public abstract class PullRequestStatusChangeEvent extends PullRequestChangeEvent implements MarkdownAware {
+public class PullRequestStatusChangeEvent extends PullRequestChangeEvent implements MarkdownAware {
- private final String note;
+ private final PullRequestStatusChange statusChange;
- public PullRequestStatusChangeEvent(PullRequest request, Account user, Date date, @Nullable String note) {
- super(request, user, date);
- this.note = note;
+ public PullRequestStatusChangeEvent(PullRequestStatusChange statusChange) {
+ super(statusChange.getRequest(), statusChange.getUser(), statusChange.getDate());
+ this.statusChange = statusChange;
}
- @Nullable
- public String getNote() {
- return note;
+ public PullRequestStatusChange getStatusChange() {
+ return statusChange;
}
@Override
public String getMarkdown() {
- return getNote();
+ return statusChange.getNote();
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestVerificationDeleted.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestVerificationDeleted.java
deleted file mode 100644
index 8f8c3812ef..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestVerificationDeleted.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import java.util.Date;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequestVerification;
-
-@Editable(name="deleted verification", icon="fa fa-times")
-public class PullRequestVerificationDeleted extends PullRequestStatusChangeEvent {
-
- private final PullRequestVerification verification;
-
- public PullRequestVerificationDeleted(PullRequestVerification verification, Account user) {
- super(verification.getRequest(), user, new Date(), "configuration: " + verification.getConfiguration());
- this.verification = verification;
- }
-
- public PullRequestVerification getVerification() {
- return verification;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestVerificationFailed.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestVerificationFailed.java
deleted file mode 100644
index 17d541adcd..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestVerificationFailed.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import java.util.Date;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.PullRequestVerification;
-
-@Editable(name="completed verification (failed)", icon="fa fa-thumbs-o-down")
-public class PullRequestVerificationFailed extends PullRequestStatusChangeEvent {
-
- private final PullRequestVerification verification;
-
- public PullRequestVerificationFailed(PullRequestVerification verification) {
- super(verification.getRequest(), verification.getUser(), new Date(),
- "configuration: " + verification.getConfiguration() + "\n"
- + "message: " + verification.getMessage());
- this.verification = verification;
- }
-
- public PullRequestVerification getVerification() {
- return verification;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestVerificationSucceeded.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestVerificationSucceeded.java
deleted file mode 100644
index 9dabd6d272..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/PullRequestVerificationSucceeded.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import java.util.Date;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.PullRequestVerification;
-
-@Editable(name="completed verification (successful)", icon="fa fa-thumbs-o-up")
-public class PullRequestVerificationSucceeded extends PullRequestStatusChangeEvent {
-
- private final PullRequestVerification verification;
-
- public PullRequestVerificationSucceeded(PullRequestVerification verification) {
- super(verification.getRequest(), verification.getUser(), new Date(),
- "configuration: " + verification.getConfiguration() + "\n"
- + "message: " + verification.getMessage());
- this.verification = verification;
- }
-
- public PullRequestVerification getVerification() {
- return verification;
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/SourceBranchDeleted.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/SourceBranchDeleted.java
deleted file mode 100644
index 5e54020ccc..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/SourceBranchDeleted.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import java.util.Date;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequest;
-
-@Editable(name="deleted source branch", icon="fa fa-times")
-public class SourceBranchDeleted extends PullRequestStatusChangeEvent {
-
- public SourceBranchDeleted(PullRequest request, Account user, String note) {
- super(request, user, new Date(), note);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/SourceBranchRestored.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/SourceBranchRestored.java
deleted file mode 100644
index 23f0646028..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/event/pullrequest/SourceBranchRestored.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.pmease.gitplex.core.event.pullrequest;
-
-import java.util.Date;
-
-import com.pmease.commons.wicket.editable.annotation.Editable;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequest;
-
-@Editable(name="restored source branch", icon="fa fa-repeat")
-public class SourceBranchRestored extends PullRequestStatusChangeEvent {
-
- public SourceBranchRestored(PullRequest request, Account user, String note) {
- super(request, user, new Date(), note);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/UrlManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/UrlManager.java
index 726b3aad88..af645e68f6 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/UrlManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/UrlManager.java
@@ -6,6 +6,9 @@ import com.pmease.gitplex.core.entity.Account;
import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestComment;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange;
+import com.pmease.gitplex.core.entity.support.CodeCommentActivity;
public interface UrlManager {
@@ -15,6 +18,12 @@ public interface UrlManager {
String urlFor(PullRequest request);
+ String urlFor(PullRequestComment comment);
+
+ String urlFor(PullRequestStatusChange statusChange);
+
String urlFor(CodeComment comment, @Nullable PullRequest request);
+ String urlFor(CodeCommentActivity activity, @Nullable PullRequest request);
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAccountManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAccountManager.java
index 74ae8917c6..b9b8d24bda 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAccountManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultAccountManager.java
@@ -24,10 +24,10 @@ import com.pmease.commons.loader.Listen;
import com.pmease.gitplex.core.entity.Account;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange;
import com.pmease.gitplex.core.entity.support.IntegrationPolicy;
import com.pmease.gitplex.core.event.lifecycle.SystemStarting;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestApproved;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestDisapproved;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestStatusChangeEvent;
import com.pmease.gitplex.core.gatekeeper.GateKeeper;
import com.pmease.gitplex.core.manager.AccountManager;
import com.pmease.gitplex.core.manager.DepotManager;
@@ -245,18 +245,13 @@ public class DefaultAccountManager extends AbstractEntityManager<Account> implem
@Transactional
@Listen
- public void on(PullRequestApproved event) {
- Account user = event.getReview().getUser();
- user.setReviewEffort(user.getReviewEffort()+1);
- save(user);
+ 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);
+ }
}
- @Transactional
- @Listen
- public void on(PullRequestDisapproved event) {
- Account user = event.getReview().getUser();
- user.setReviewEffort(user.getReviewEffort()+1);
- save(user);
- }
-
}
\ No newline at end of file
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java
index 9e3c296792..c124c865ed 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentManager.java
@@ -2,7 +2,6 @@ package com.pmease.gitplex.core.manager.impl;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Date;
import java.util.List;
import javax.inject.Inject;
@@ -27,12 +26,11 @@ import com.pmease.gitplex.core.entity.CodeCommentReply;
import com.pmease.gitplex.core.entity.CodeCommentStatusChange;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.support.LastEvent;
+import com.pmease.gitplex.core.event.codecomment.CodeCommentCreated;
import com.pmease.gitplex.core.event.codecomment.CodeCommentEvent;
import com.pmease.gitplex.core.event.codecomment.CodeCommentReplied;
import com.pmease.gitplex.core.event.codecomment.CodeCommentResolved;
import com.pmease.gitplex.core.event.codecomment.CodeCommentUnresolved;
-import com.pmease.gitplex.core.event.codecomment.CodeCommentCreated;
import com.pmease.gitplex.core.event.pullrequest.PullRequestCodeCommentReplied;
import com.pmease.gitplex.core.event.pullrequest.PullRequestCodeCommentResolved;
import com.pmease.gitplex.core.event.pullrequest.PullRequestCodeCommentUnresolved;
@@ -157,11 +155,12 @@ public class DefaultCodeCommentManager extends AbstractEntityManager<CodeComment
new PullRequestCodeCommentReplied(request, reply);
listenerRegistry.post(pullRequestCodeCommentReplied);
request.setLastEvent(pullRequestCodeCommentReplied);
+
pullRequestManager.save(request);
}
}
-
+
@Transactional
@Listen
public void on(CodeCommentResolved event) {
@@ -171,6 +170,7 @@ public class DefaultCodeCommentManager extends AbstractEntityManager<CodeComment
new PullRequestCodeCommentResolved(request, event.getStatusChange());
listenerRegistry.post(pullRequestCodeCommentResolved);
request.setLastEvent(pullRequestCodeCommentResolved);
+
pullRequestManager.save(request);
}
}
@@ -178,20 +178,13 @@ public class DefaultCodeCommentManager extends AbstractEntityManager<CodeComment
@Transactional
@Listen
public void on(CodeCommentUnresolved event) {
- CodeComment comment = event.getComment();
- LastEvent lastEvent = new LastEvent();
- lastEvent.setDate(new Date());
- lastEvent.setType(event.getClass());
- lastEvent.setUser(event.getUser());
- comment.setLastEvent(lastEvent);
- save(comment);
-
for (CodeCommentRelation relation: event.getComment().getRelations()) {
PullRequest request = relation.getRequest();
PullRequestCodeCommentUnresolved pullRequestCodeCommentUnresolved =
new PullRequestCodeCommentUnresolved(request, event.getStatusChange());
listenerRegistry.post(pullRequestCodeCommentUnresolved);
request.setLastEvent(pullRequestCodeCommentUnresolved);
+
pullRequestManager.save(request);
}
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentRelationManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentRelationManager.java
index 2fee494054..b1f1ae512d 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentRelationManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentRelationManager.java
@@ -152,7 +152,9 @@ public class DefaultCodeCommentRelationManager extends AbstractEntityManager<Cod
if (request != null && request.getRequestComparingInfo(comment.getComparingInfo()) != null) {
PullRequestCodeCommented pullRequestCodeCommented = new PullRequestCodeCommented(request, comment);
listenerRegistry.post(pullRequestCodeCommented);
+
request.setLastEvent(pullRequestCodeCommented);
+
pullRequestManager.save(request);
visitInfoManager.visit(comment.getUser(), request);
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultMailManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultMailManager.java
index 95cc14b755..fb013b19a3 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultMailManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultMailManager.java
@@ -27,6 +27,9 @@ import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.core.event.MarkdownAware;
import com.pmease.gitplex.core.event.codecomment.CodeCommentEvent;
+import com.pmease.gitplex.core.event.codecomment.CodeCommentReplied;
+import com.pmease.gitplex.core.event.codecomment.CodeCommentResolved;
+import com.pmease.gitplex.core.event.codecomment.CodeCommentUnresolved;
import com.pmease.gitplex.core.event.pullrequest.PullRequestChangeEvent;
import com.pmease.gitplex.core.event.pullrequest.PullRequestCommented;
import com.pmease.gitplex.core.event.pullrequest.PullRequestOpened;
@@ -159,11 +162,17 @@ public class DefaultMailManager implements MailManager {
|| event instanceof PullRequestStatusChangeEvent) {
String markdown = ((MarkdownAware) event).getMarkdown();
if (markdown != null) {
+ String url;
+ if (event instanceof PullRequestCommented)
+ url = urlManager.urlFor(((PullRequestCommented)event).getComment());
+ else if (event instanceof PullRequestStatusChangeEvent)
+ url = urlManager.urlFor(((PullRequestStatusChangeEvent)event).getStatusChange());
+ else
+ url = urlManager.urlFor(event.getRequest());
for (Account user: new MentionParser().parseMentions(markdownManager.parse(markdown))) {
PullRequest request = event.getRequest();
String subject = String.format("You are mentioned in pull request #%d (%s)",
request.getNumber(), request.getTitle());
- String url = urlManager.urlFor(request);
String body = String.format("%s."
+ "<p style='margin: 16px 0; padding-left: 16px; border-left: 4px solid #CCC;'>%s"
+ "<p style='margin: 16px 0;'>"
@@ -181,9 +190,18 @@ public class DefaultMailManager implements MailManager {
if (event.getMarkdown() != null) {
for (Account user: new MentionParser().parseMentions(markdownManager.parse(event.getMarkdown()))) {
CodeComment comment = event.getComment();
- String subject = String.format("You are mentioned in code comment #%d (%s)",
- comment.getId(), comment.getTitle());
- String url = urlManager.urlFor(comment, event.getRequest());
+ String subject = String.format("You are mentioned in a code comment (%s)",
+ comment.getTitle());
+ String url;
+ if (event instanceof CodeCommentResolved)
+ url = urlManager.urlFor(((CodeCommentResolved)event).getStatusChange(), event.getRequest());
+ else if (event instanceof CodeCommentUnresolved)
+ url = urlManager.urlFor(((CodeCommentUnresolved)event).getStatusChange(), event.getRequest());
+ else if (event instanceof CodeCommentReplied)
+ url = urlManager.urlFor(((CodeCommentReplied)event).getReply(), event.getRequest());
+ else
+ url = urlManager.urlFor(comment, event.getRequest());
+
String body = String.format("%s."
+ "<p style='margin: 16px 0; padding-left: 16px; border-left: 4px solid #CCC;'>%s"
+ "<p style='margin: 16px 0;'>"
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
index d10fb50a15..3498fdd4b3 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
@@ -1,51 +1,58 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import com.pmease.commons.hibernate.Transactional;
-import com.pmease.commons.hibernate.dao.AbstractEntityManager;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.loader.ListenerRegistry;
-import com.pmease.gitplex.core.entity.PullRequestComment;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestCommented;
-import com.pmease.gitplex.core.manager.PullRequestCommentManager;
-import com.pmease.gitplex.core.manager.PullRequestManager;
-
-@Singleton
-public class DefaultPullRequestCommentManager extends AbstractEntityManager<PullRequestComment>
- implements PullRequestCommentManager {
-
- private final ListenerRegistry listenerRegistry;
-
- private final PullRequestManager pullRequestManager;
-
- @Inject
- public DefaultPullRequestCommentManager(Dao dao, PullRequestManager pullRequestManager,
- ListenerRegistry listenerRegistry) {
- super(dao);
-
- this.listenerRegistry = listenerRegistry;
- this.pullRequestManager = pullRequestManager;
- }
-
- @Transactional
- @Override
- public void save(PullRequestComment comment) {
- save(comment, true);
- }
-
- @Transactional
- @Override
- public void save(PullRequestComment comment, boolean notifyListeners) {
- boolean isNew = comment.isNew();
- dao.persist(comment);
- if (notifyListeners && isNew) {
- PullRequestCommented event = new PullRequestCommented(comment);
- listenerRegistry.post(event);
- comment.getRequest().setLastEvent(event);
- pullRequestManager.save(event.getRequest());
- }
- }
-
-}
+package com.pmease.gitplex.core.manager.impl;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import com.pmease.commons.hibernate.Transactional;
+import com.pmease.commons.hibernate.dao.AbstractEntityManager;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.loader.ListenerRegistry;
+import com.pmease.commons.wicket.editable.EditableUtils;
+import com.pmease.gitplex.core.entity.PullRequestComment;
+import com.pmease.gitplex.core.entity.support.LastEvent;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestCommented;
+import com.pmease.gitplex.core.manager.PullRequestCommentManager;
+import com.pmease.gitplex.core.manager.PullRequestManager;
+
+@Singleton
+public class DefaultPullRequestCommentManager extends AbstractEntityManager<PullRequestComment>
+ implements PullRequestCommentManager {
+
+ private final ListenerRegistry listenerRegistry;
+
+ private final PullRequestManager pullRequestManager;
+
+ @Inject
+ public DefaultPullRequestCommentManager(Dao dao, PullRequestManager pullRequestManager,
+ ListenerRegistry listenerRegistry) {
+ super(dao);
+
+ this.listenerRegistry = listenerRegistry;
+ this.pullRequestManager = pullRequestManager;
+ }
+
+ @Transactional
+ @Override
+ public void save(PullRequestComment comment) {
+ save(comment, true);
+ }
+
+ @Transactional
+ @Override
+ public void save(PullRequestComment comment, boolean notifyListeners) {
+ boolean isNew = comment.isNew();
+ dao.persist(comment);
+ if (notifyListeners && isNew) {
+ PullRequestCommented event = new PullRequestCommented(comment);
+ listenerRegistry.post(event);
+
+ LastEvent lastEvent = new LastEvent();
+ lastEvent.setDate(event.getDate());
+ lastEvent.setType(EditableUtils.getName(event.getClass()));
+ lastEvent.setUser(event.getUser());
+ comment.getRequest().setLastEvent(lastEvent);
+ pullRequestManager.save(event.getRequest());
+ }
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
index 8e0102bca6..259a4cc61e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestManager.java
@@ -1,767 +1,781 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofOpen;
-import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofSource;
-import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofSourceDepot;
-import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofSubmitter;
-import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofTarget;
-import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofTargetDepot;
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_ALWAYS;
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_IF_NECESSARY;
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
-import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
-
-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;
-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;
-import org.hibernate.criterion.Restrictions;
-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.pmease.commons.git.GitUtils;
-import com.pmease.commons.hibernate.Sessional;
-import com.pmease.commons.hibernate.Transactional;
-import com.pmease.commons.hibernate.UnitOfWork;
-import com.pmease.commons.hibernate.dao.AbstractEntityManager;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.loader.Listen;
-import com.pmease.commons.loader.ListenerRegistry;
-import com.pmease.commons.markdown.MarkdownManager;
-import com.pmease.commons.util.concurrent.Prioritized;
-import com.pmease.commons.util.match.PatternMatcher;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;
-import com.pmease.gitplex.core.entity.PullRequestReviewInvitation;
-import com.pmease.gitplex.core.entity.PullRequestUpdate;
-import com.pmease.gitplex.core.entity.support.CloseInfo;
-import com.pmease.gitplex.core.entity.support.DepotAndBranch;
-import com.pmease.gitplex.core.entity.support.IntegrationPolicy;
-import com.pmease.gitplex.core.entity.support.IntegrationPreview;
-import com.pmease.gitplex.core.event.RefUpdated;
-import com.pmease.gitplex.core.event.depot.DepotDeleted;
-import com.pmease.gitplex.core.event.pullrequest.IntegrationPreviewCalculated;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestApproved;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestAssigned;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestDisapproved;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestDiscarded;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestIntegrated;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestOpened;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingApproval;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingIntegration;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingUpdate;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestReopened;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestReviewDeleted;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationDeleted;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationFailed;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationSucceeded;
-import com.pmease.gitplex.core.event.pullrequest.SourceBranchDeleted;
-import com.pmease.gitplex.core.event.pullrequest.SourceBranchRestored;
-import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;
-import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;
-import com.pmease.gitplex.core.gatekeeper.checkresult.GateCheckResult;
-import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;
-import com.pmease.gitplex.core.manager.AccountManager;
-import com.pmease.gitplex.core.manager.BatchWorkManager;
-import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.manager.PullRequestNotificationManager;
-import com.pmease.gitplex.core.manager.PullRequestReviewInvitationManager;
-import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
-import com.pmease.gitplex.core.manager.support.BatchWorker;
-import com.pmease.gitplex.core.security.SecurityUtils;
-import com.pmease.gitplex.core.util.ChildAwareMatcher;
-import com.pmease.gitplex.core.util.fullbranchmatch.FullBranchMatchUtils;
-import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;
-
-@Singleton
-public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest> implements PullRequestManager {
-
- private static final Logger logger = LoggerFactory.getLogger(DefaultPullRequestManager.class);
-
- private static final int UI_PREVIEW_PRIORITY = 10;
-
- private static final int BACKEND_PREVIEW_PRIORITY = 50;
-
- private static final PatternMatcher BRANCH_MATCHER = new ChildAwareMatcher();
-
- private final PullRequestUpdateManager pullRequestUpdateManager;
-
- private final AccountManager accountManager;
-
- private final UnitOfWork unitOfWork;
-
- private final ListenerRegistry listenerRegistry;
-
- private final PullRequestReviewInvitationManager reviewInvitationManager;
-
- private final BatchWorkManager batchWorkManager;
-
- private final Map<String, AtomicLong> nextNumbers = new HashMap<>();
-
- @Inject
- public DefaultPullRequestManager(Dao dao, PullRequestUpdateManager pullRequestUpdateManager,
- PullRequestReviewInvitationManager reviewInvitationManager, AccountManager accountManager,
- PullRequestNotificationManager notificationManager, MarkdownManager markdownManager,
- BatchWorkManager batchWorkManager, ListenerRegistry listenerRegistry,
- UnitOfWork unitOfWork) {
- super(dao);
-
- this.pullRequestUpdateManager = pullRequestUpdateManager;
- this.reviewInvitationManager = reviewInvitationManager;
- this.accountManager = accountManager;
- this.batchWorkManager = batchWorkManager;
- this.unitOfWork = unitOfWork;
- this.listenerRegistry = listenerRegistry;
- }
-
- @Transactional
- @Override
- public void delete(PullRequest request) {
- deleteRefs(request);
- dao.remove(request);
- }
-
- @Sessional
- @Override
- public void deleteRefs(PullRequest request) {
- for (PullRequestUpdate update : request.getUpdates())
- update.deleteRefs();
-
- request.deleteRefs();
- }
-
- @Transactional
- @Override
- public void restoreSourceBranch(PullRequest request, String note) {
- Preconditions.checkState(!request.isOpen() && request.getSourceDepot() != null);
- if (request.getSource().getObjectName(false) == null) {
- RevCommit latestCommit = request.getHeadCommit();
- try {
- request.getSourceDepot().git().branchCreate().setName(request.getSourceBranch()).setStartPoint(latestCommit).call();
- } catch (Exception e) {
- Throwables.propagate(e);
- }
- request.getSourceDepot().cacheObjectId(request.getSourceBranch(), latestCommit.copy());
- SourceBranchRestored event = new SourceBranchRestored(request, accountManager.getCurrent(), note);
- listenerRegistry.post(event);
- request.setLastEvent(event);
- save(request);
- }
- }
-
- @Transactional
- @Override
- public void deleteSourceBranch(PullRequest request, String note) {
- Preconditions.checkState(!request.isOpen() && request.getSourceDepot() != null);
-
- if (request.getSource().getObjectName(false) != null) {
- request.getSource().delete();
- SourceBranchDeleted event = new SourceBranchDeleted(request, accountManager.getCurrent(), note);
- listenerRegistry.post(event);
- request.setLastEvent(event);
- save(request);
- }
- }
-
- @Transactional
- @Override
- public void reopen(PullRequest request, String note) {
- Account user = accountManager.getCurrent();
- request.setCloseInfo(null);
- PullRequestReopened event = new PullRequestReopened(request, user, note);
- listenerRegistry.post(event);
- request.setLastEvent(event);
- save(request);
- checkAsync(request);
- }
-
- @Transactional
- @Override
- public void discard(PullRequest request, String note) {
- Account user = accountManager.getCurrent();
-
- CloseInfo closeInfo = new CloseInfo();
- closeInfo.setCloseDate(new Date());
- closeInfo.setClosedBy(user);
- closeInfo.setCloseStatus(CloseInfo.Status.DISCARDED);
- request.setCloseInfo(closeInfo);
-
- PullRequestDiscarded event = new PullRequestDiscarded(request, user, note);
- listenerRegistry.post(event);
- request.setLastEvent(event);
- save(request);
- }
-
- @Transactional
- @Override
- public void integrate(PullRequest request, String note) {
- IntegrationPreview preview = request.getIntegrationPreview();
- if (preview == null)
- throw new IllegalStateException("Integration preview has not been calculated yet.");
-
- String integrated = preview.getIntegrated();
- if (integrated == null)
- throw new IllegalStateException("There are integration conflicts.");
-
- Account user = accountManager.getCurrent();
-
- ObjectId integratedId = ObjectId.fromString(integrated);
- RevCommit integratedCommit = request.getTargetDepot().getRevCommit(integratedId);
-
- 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())) {
- 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.setMessage(request.getCommitMessage());
- newCommit.setTreeId(integratedCommit.getTree());
- newCommit.setParentIds(integratedCommit.getParents());
- integratedId = inserter.insert(newCommit);
- integrated = integratedId.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);
- 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();
- }
- }
-
- });
- }
-
- String targetRef = request.getTargetRef();
- ObjectId targetHeadId = ObjectId.fromString(preview.getTargetHead());
- RefUpdate refUpdate = targetDepot.updateRef(targetRef);
- refUpdate.setRefLogIdent(user.asPerson());
- refUpdate.setRefLogMessage("Pull request #" + request.getNumber(), true);
- refUpdate.setExpectedOldObjectId(targetHeadId);
- refUpdate.setNewObjectId(integratedId);
- GitUtils.updateRef(refUpdate);
-
- Long requestId = request.getId();
- Subject subject = SecurityUtils.getSubject();
- ObjectId newTargetHeadId = integratedId;
- doUnitOfWorkAsyncAfterCommit(new Runnable() {
-
- @Override
- public void run() {
- ThreadContext.bind(subject);
- try {
- PullRequest request = load(requestId);
- request.getTargetDepot().cacheObjectId(request.getTargetRef(), newTargetHeadId);
- listenerRegistry.post(new RefUpdated(request.getTargetDepot(), targetRef,
- targetHeadId, newTargetHeadId));
- } finally {
- ThreadContext.unbindSubject();
- }
- }
-
- });
- }
-
- private long getNextNumber(Depot depot) {
- AtomicLong nextNumber;
- synchronized (nextNumbers) {
- nextNumber = nextNumbers.get(depot.getUUID());
- }
- if (nextNumber == null) {
- long maxNumber;
- Query query = getSession().createQuery("select max(number) from PullRequest where targetDepot=:depot");
- query.setParameter("depot", depot);
- Object result = query.uniqueResult();
- if (result != null) {
- maxNumber = (Long)result;
- } else {
- maxNumber = 0;
- }
-
- /*
- * do not put the whole method in synchronized block to avoid possible deadlocks
- * if there are limited connections.
- */
- synchronized (nextNumbers) {
- nextNumber = nextNumbers.get(depot.getUUID());
- if (nextNumber == null) {
- nextNumber = new AtomicLong(maxNumber+1);
- nextNumbers.put(depot.getUUID(), nextNumber);
- }
- }
- }
- return nextNumber.getAndIncrement();
- }
-
- @Transactional
- @Override
- public void open(PullRequest request) {
- request.setNumber(getNextNumber(request.getTargetDepot()));
- dao.persist(request);
-
- RefUpdate refUpdate = request.getTargetDepot().updateRef(request.getBaseRef());
- refUpdate.setNewObjectId(ObjectId.fromString(request.getBaseCommitHash()));
- GitUtils.updateRef(refUpdate);
-
- for (PullRequestUpdate update: request.getUpdates()) {
- pullRequestUpdateManager.save(update);
- }
-
- for (PullRequestReviewInvitation invitation: request.getReviewInvitations())
- reviewInvitationManager.save(invitation);
-
- checkAsync(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";
- PullRequestAssigned event = new PullRequestAssigned(request, accountManager.getCurrent(), note);
- listenerRegistry.post(event);
- request.setLastEvent(event);
- }
- save(request);
- }
-
- private void closeAsIntegrated(PullRequest request, boolean dueToMerged, String note) {
- Account user = accountManager.getCurrent();
-
- if (dueToMerged)
- request.setLastIntegrationPreview(null);
-
- CloseInfo closeInfo = new CloseInfo();
- closeInfo.setCloseDate(new Date());
- closeInfo.setClosedBy(user);
- closeInfo.setCloseStatus(CloseInfo.Status.INTEGRATED);
- request.setCloseInfo(closeInfo);
-
- if (dueToMerged)
- note = "Source branch is already merged to target branch by some one";
- PullRequestIntegrated event = new PullRequestIntegrated(request, user, note);
- listenerRegistry.post(event);
- request.setLastEvent(event);
- save(request);
- }
-
- private void checkUpdate(PullRequest request, boolean independent) {
- if (!request.getHeadCommitHash().equals(request.getSource().getObjectName())) {
- PullRequestUpdate update = new PullRequestUpdate();
- update.setRequest(request);
- update.setHeadCommitHash(request.getSource().getObjectName());
- ObjectId mergeBase = GitUtils.getMergeBase(
- request.getTargetDepot().getRepository(), request.getTarget().getObjectId(),
- request.getSourceDepot().getRepository(), request.getSource().getObjectId(),
- GitUtils.branch2ref(request.getSourceBranch()));
- update.setMergeCommitHash(mergeBase.name());
- request.addUpdate(update);
- pullRequestUpdateManager.save(update, independent);
- }
- }
-
- @Transactional
- @Override
- public void check(PullRequest request) {
- if (request.isOpen()) {
- if (request.getSourceDepot() == null) {
- discard(request, "Source repository no longer exists");
- } else if (request.getSource().getObjectId(false) == null) {
- discard(request, "Source branch no longer exists");
- } 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);
- } else {
- IntegrationPreview integrationPreview = request.getIntegrationPreview();
- Date timeBeforeCheck = new Date();
- GateCheckResult result = request.checkGates(false);
- if (result instanceof Pending || result instanceof Blocking) {
- for (PullRequestReviewInvitation invitation: request.getReviewInvitations()) {
- if (invitation.getDate().getTime()>=timeBeforeCheck.getTime())
- reviewInvitationManager.save(invitation);
- }
- 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));
- }
- }
- }
- }
- }
-
- @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));
- }
-
- });
- } else {
- batchWorkManager.submit(getIntegrationPreviewer(request), new Prioritized(priority));
- }
- return null;
- } else {
- return preview;
- }
- }
-
- private BatchWorker getIntegrationPreviewer(PullRequest request) {
- Long requestId = request.getId();
- return new BatchWorker("request-" + requestId + "-previewIntegration", 1) {
-
- @Override
- public void doWork(Collection<Prioritized> works) {
- Preconditions.checkState(works.size() == 1);
- unitOfWork.call(new Callable<Void>() {
-
- @Override
- 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 '{}'...",
- 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();
- ObjectId requestHeadId = ObjectId.fromString(requestHead);
- ObjectId targetHeadId = ObjectId.fromString(targetHead);
- if (preview.getIntegrationStrategy() == MERGE_IF_NECESSARY
- && GitUtils.isMergedInto(targetDepot.getRepository(), targetHeadId, requestHeadId)) {
- preview.setIntegrated(requestHead);
- RefUpdate refUpdate = targetDepot.updateRef(integrateRef);
- 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(),
- requestHeadId, targetHeadId, true, user, request.getCommitMessage());
- } else {
- integrated = 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);
- GitUtils.updateRef(refUpdate);
- } else {
- RefUpdate refUpdate = targetDepot.updateRef(integrateRef);
- GitUtils.deleteRef(refUpdate);
- }
- }
- dao.persist(request);
-
- listenerRegistry.post(new IntegrationPreviewCalculated(request));
- logger.info("Integration preview of pull request #{} in repository '{}' is calculated.",
- request.getNumber(), request.getTargetDepot());
- }
- } catch (Exception e) {
- logger.error("Error calculating pull request integration preview", e);
- }
- return null;
- }
-
- });
- }
-
- };
- }
-
- @Transactional
- @Listen
- public void on(DepotDeleted event) {
- for (PullRequest request: event.getDepot().getOutgoingRequests()) {
- if (!request.getTargetDepot().equals(event.getDepot()) && request.isOpen())
- discard(request, "Source repository is deleted.");
- }
-
- Query query = getSession().createQuery("update PullRequest set sourceDepot=null where "
- + "sourceDepot=:depot");
- query.setParameter("depot", event.getDepot());
- query.executeUpdate();
- }
-
- @Transactional
- @Listen
- public void on(RefUpdated event) {
- String branch = GitUtils.ref2branch(event.getRefName());
- if (branch != null) {
- DepotAndBranch depotAndBranch = new DepotAndBranch(event.getDepot(), branch);
- Criterion criterion = Restrictions.and(
- ofOpen(),
- Restrictions.or(ofSource(depotAndBranch), ofTarget(depotAndBranch)));
- for (PullRequest request: findAll(EntityCriteria.of(PullRequest.class).add(criterion))) {
- check(request);
- }
- }
- }
-
- @Sessional
- @Override
- public PullRequest findOpen(DepotAndBranch target, DepotAndBranch source) {
- return find(EntityCriteria.of(PullRequest.class)
- .add(ofTarget(target)).add(ofSource(source)).add(ofOpen()));
- }
-
- @Sessional
- @Override
- public PullRequest findLatest(Depot depot, Account submitter) {
- EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
- criteria.add(ofOpen());
- criteria.add(Restrictions.or(ofSourceDepot(depot), ofTargetDepot(depot)));
- criteria.add(ofSubmitter(submitter));
- criteria.addOrder(Order.desc("id"));
- return find(criteria);
- }
-
- @Sessional
- @Override
- public Collection<PullRequest> findAllOpenTo(DepotAndBranch target, @Nullable Depot sourceDepot) {
- 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);
- }
-
- @Sessional
- @Override
- public Collection<PullRequest> findAllOpen(DepotAndBranch sourceOrTarget) {
- EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
- criteria.add(ofOpen());
- criteria.add(Restrictions.or(ofSource(sourceOrTarget), ofTarget(sourceOrTarget)));
- return findAll(criteria);
- }
-
- @Sessional
- @Override
- public int countOpen(Depot depot) {
- EntityCriteria<PullRequest> criteria = newCriteria();
- criteria.add(PullRequest.CriterionHelper.ofOpen());
- criteria.add(PullRequest.CriterionHelper.ofTargetDepot(depot));
- return count(criteria);
- }
-
- @Sessional
- @Override
- public PullRequest find(Depot target, long number) {
- EntityCriteria<PullRequest> criteria = newCriteria();
- criteria.add(Restrictions.eq("targetDepot", target));
- criteria.add(Restrictions.eq("number", number));
- return find(criteria);
- }
-
- @Sessional
- @Override
- public PullRequest find(String uuid) {
- EntityCriteria<PullRequest> criteria = newCriteria();
- criteria.add(Restrictions.eq("uuid", uuid));
- return find(criteria);
- }
-
- @Listen
- public void on(PullRequestVerificationSucceeded event) {
- checkAsync(event.getRequest());
- }
-
- @Listen
- public void on(PullRequestVerificationFailed event) {
- checkAsync(event.getRequest());
- }
-
- @Listen
- public void on(IntegrationPreviewCalculated event) {
- checkAsync(event.getRequest());
- }
-
- @Transactional
- @Listen
- public void on(PullRequestApproved event) {
- checkAsync(event.getRequest());
- }
-
- @Transactional
- @Listen
- public void on(PullRequestDisapproved event) {
- checkAsync(event.getRequest());
- }
-
- @Transactional
- @Listen
- public void on(PullRequestVerificationDeleted event) {
- checkAsync(event.getRequest());
- }
-
- @Transactional
- @Listen
- public void on(PullRequestReviewDeleted event) {
- checkAsync(event.getRequest());
- }
-
- private Runnable newCheckRunnable(Long requestId, Subject subject) {
- return new Runnable() {
-
- @Override
- public void run() {
- try {
- ThreadContext.bind(subject);
- check(load(requestId));
- } catch (Exception e) {
- logger.error("Error checking pull request", e);
- } finally {
- ThreadContext.unbindSubject();
- }
- }
-
- };
- }
-
- @Sessional
- protected void checkAsync(PullRequest request) {
- Long requestId = request.getId();
- Subject subject = SecurityUtils.getSubject();
- if (dao.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE) {
- doUnitOfWorkAsyncAfterCommit(newCheckRunnable(requestId, subject));
- } else {
- unitOfWork.doAsync(newCheckRunnable(requestId, subject));
- }
- }
-
-}
+package com.pmease.gitplex.core.manager.impl;
+
+import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofOpen;
+import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofSource;
+import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofSourceDepot;
+import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofSubmitter;
+import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofTarget;
+import static com.pmease.gitplex.core.entity.PullRequest.CriterionHelper.ofTargetDepot;
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_ALWAYS;
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_IF_NECESSARY;
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.MERGE_WITH_SQUASH;
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.REBASE_SOURCE_ONTO_TARGET;
+import static com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy.REBASE_TARGET_ONTO_SOURCE;
+
+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;
+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;
+import org.hibernate.criterion.Restrictions;
+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.pmease.commons.git.GitUtils;
+import com.pmease.commons.hibernate.Sessional;
+import com.pmease.commons.hibernate.Transactional;
+import com.pmease.commons.hibernate.UnitOfWork;
+import com.pmease.commons.hibernate.dao.AbstractEntityManager;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.loader.Listen;
+import com.pmease.commons.loader.ListenerRegistry;
+import com.pmease.commons.markdown.MarkdownManager;
+import com.pmease.commons.util.concurrent.Prioritized;
+import com.pmease.commons.util.match.PatternMatcher;
+import com.pmease.gitplex.core.entity.Account;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;
+import com.pmease.gitplex.core.entity.PullRequestReviewInvitation;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange.Type;
+import com.pmease.gitplex.core.entity.PullRequestUpdate;
+import com.pmease.gitplex.core.entity.support.CloseInfo;
+import com.pmease.gitplex.core.entity.support.DepotAndBranch;
+import com.pmease.gitplex.core.entity.support.IntegrationPolicy;
+import com.pmease.gitplex.core.entity.support.IntegrationPreview;
+import com.pmease.gitplex.core.event.RefUpdated;
+import com.pmease.gitplex.core.event.depot.DepotDeleted;
+import com.pmease.gitplex.core.event.pullrequest.IntegrationPreviewCalculated;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestOpened;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingApproval;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingIntegration;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingUpdate;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestStatusChangeEvent;
+import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;
+import com.pmease.gitplex.core.gatekeeper.checkresult.Failed;
+import com.pmease.gitplex.core.gatekeeper.checkresult.GateCheckResult;
+import com.pmease.gitplex.core.gatekeeper.checkresult.Pending;
+import com.pmease.gitplex.core.manager.AccountManager;
+import com.pmease.gitplex.core.manager.BatchWorkManager;
+import com.pmease.gitplex.core.manager.PullRequestManager;
+import com.pmease.gitplex.core.manager.PullRequestNotificationManager;
+import com.pmease.gitplex.core.manager.PullRequestReviewInvitationManager;
+import com.pmease.gitplex.core.manager.PullRequestStatusChangeManager;
+import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
+import com.pmease.gitplex.core.manager.support.BatchWorker;
+import com.pmease.gitplex.core.security.SecurityUtils;
+import com.pmease.gitplex.core.util.ChildAwareMatcher;
+import com.pmease.gitplex.core.util.fullbranchmatch.FullBranchMatchUtils;
+import com.pmease.gitplex.core.util.includeexclude.IncludeExcludeUtils;
+
+@Singleton
+public class DefaultPullRequestManager extends AbstractEntityManager<PullRequest> implements PullRequestManager {
+
+ private static final Logger logger = LoggerFactory.getLogger(DefaultPullRequestManager.class);
+
+ private static final int UI_PREVIEW_PRIORITY = 10;
+
+ private static final int BACKEND_PREVIEW_PRIORITY = 50;
+
+ private static final PatternMatcher BRANCH_MATCHER = new ChildAwareMatcher();
+
+ private final PullRequestUpdateManager pullRequestUpdateManager;
+
+ private final AccountManager accountManager;
+
+ private final UnitOfWork unitOfWork;
+
+ private final ListenerRegistry listenerRegistry;
+
+ private final PullRequestReviewInvitationManager reviewInvitationManager;
+
+ private final BatchWorkManager batchWorkManager;
+
+ private final PullRequestStatusChangeManager pullRequestStatusChangeManager;
+
+ private final Map<String, AtomicLong> nextNumbers = new HashMap<>();
+
+ @Inject
+ public DefaultPullRequestManager(Dao dao, PullRequestUpdateManager pullRequestUpdateManager,
+ PullRequestReviewInvitationManager reviewInvitationManager, AccountManager accountManager,
+ PullRequestNotificationManager notificationManager, MarkdownManager markdownManager,
+ BatchWorkManager batchWorkManager, ListenerRegistry listenerRegistry,
+ UnitOfWork unitOfWork, PullRequestStatusChangeManager pullRequestStatusChangeManager) {
+ super(dao);
+
+ this.pullRequestUpdateManager = pullRequestUpdateManager;
+ this.reviewInvitationManager = reviewInvitationManager;
+ this.accountManager = accountManager;
+ this.batchWorkManager = batchWorkManager;
+ this.unitOfWork = unitOfWork;
+ this.listenerRegistry = listenerRegistry;
+ this.pullRequestStatusChangeManager = pullRequestStatusChangeManager;
+ }
+
+ @Transactional
+ @Override
+ public void delete(PullRequest request) {
+ deleteRefs(request);
+ dao.remove(request);
+ }
+
+ @Sessional
+ @Override
+ public void deleteRefs(PullRequest request) {
+ for (PullRequestUpdate update : request.getUpdates())
+ update.deleteRefs();
+
+ request.deleteRefs();
+ }
+
+ @Transactional
+ @Override
+ public void restoreSourceBranch(PullRequest request, String note) {
+ Preconditions.checkState(!request.isOpen() && request.getSourceDepot() != null);
+ if (request.getSource().getObjectName(false) == null) {
+ RevCommit latestCommit = request.getHeadCommit();
+ try {
+ request.getSourceDepot().git().branchCreate().setName(request.getSourceBranch()).setStartPoint(latestCommit).call();
+ } catch (Exception e) {
+ Throwables.propagate(e);
+ }
+ request.getSourceDepot().cacheObjectId(request.getSourceBranch(), latestCommit.copy());
+
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(new Date());
+ statusChange.setNote(note);
+ statusChange.setRequest(request);
+ statusChange.setType(Type.SOURCE_BRANCH_RESTORED);
+ statusChange.setUser(accountManager.getCurrent());
+ pullRequestStatusChangeManager.save(statusChange);
+
+ request.setLastEvent(statusChange);
+ save(request);
+ }
+ }
+
+ @Transactional
+ @Override
+ public void deleteSourceBranch(PullRequest request, String note) {
+ Preconditions.checkState(!request.isOpen() && request.getSourceDepot() != null);
+
+ if (request.getSource().getObjectName(false) != null) {
+ request.getSource().delete();
+
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(new Date());
+ statusChange.setNote(note);
+ statusChange.setRequest(request);
+ statusChange.setType(Type.SOURCE_BRANCH_DELETED);
+ statusChange.setUser(accountManager.getCurrent());
+ pullRequestStatusChangeManager.save(statusChange);
+
+ request.setLastEvent(statusChange);
+ save(request);
+ }
+ }
+
+ @Transactional
+ @Override
+ public void reopen(PullRequest request, String note) {
+ Account user = accountManager.getCurrent();
+ request.setCloseInfo(null);
+
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(new Date());
+ statusChange.setNote(note);
+ statusChange.setRequest(request);
+ statusChange.setType(Type.REOPENED);
+ statusChange.setUser(user);
+ pullRequestStatusChangeManager.save(statusChange);
+
+ request.setLastEvent(statusChange);
+ save(request);
+ checkAsync(request);
+ }
+
+ @Transactional
+ @Override
+ public void discard(PullRequest request, String note) {
+ Account user = accountManager.getCurrent();
+ Date date = new Date();
+
+ CloseInfo closeInfo = new CloseInfo();
+ closeInfo.setCloseDate(date);
+ closeInfo.setClosedBy(user);
+ closeInfo.setCloseStatus(CloseInfo.Status.DISCARDED);
+ request.setCloseInfo(closeInfo);
+
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(date);
+ statusChange.setNote(note);
+ statusChange.setRequest(request);
+ statusChange.setType(Type.DISCARDED);
+ statusChange.setUser(user);
+ pullRequestStatusChangeManager.save(statusChange);
+
+ request.setLastEvent(statusChange);
+ save(request);
+ }
+
+ @Transactional
+ @Override
+ public void integrate(PullRequest request, String note) {
+ IntegrationPreview preview = request.getIntegrationPreview();
+ if (preview == null)
+ throw new IllegalStateException("Integration preview has not been calculated yet.");
+
+ String integrated = preview.getIntegrated();
+ if (integrated == null)
+ throw new IllegalStateException("There are integration conflicts.");
+
+ Account user = accountManager.getCurrent();
+
+ ObjectId integratedId = ObjectId.fromString(integrated);
+ RevCommit integratedCommit = request.getTargetDepot().getRevCommit(integratedId);
+
+ 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())) {
+ 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.setMessage(request.getCommitMessage());
+ newCommit.setTreeId(integratedCommit.getTree());
+ newCommit.setParentIds(integratedCommit.getParents());
+ integratedId = inserter.insert(newCommit);
+ integrated = integratedId.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);
+ 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();
+ }
+ }
+
+ });
+ }
+
+ String targetRef = request.getTargetRef();
+ ObjectId targetHeadId = ObjectId.fromString(preview.getTargetHead());
+ RefUpdate refUpdate = targetDepot.updateRef(targetRef);
+ refUpdate.setRefLogIdent(user.asPerson());
+ refUpdate.setRefLogMessage("Pull request #" + request.getNumber(), true);
+ refUpdate.setExpectedOldObjectId(targetHeadId);
+ refUpdate.setNewObjectId(integratedId);
+ GitUtils.updateRef(refUpdate);
+
+ Long requestId = request.getId();
+ Subject subject = SecurityUtils.getSubject();
+ ObjectId newTargetHeadId = integratedId;
+ doUnitOfWorkAsyncAfterCommit(new Runnable() {
+
+ @Override
+ public void run() {
+ ThreadContext.bind(subject);
+ try {
+ PullRequest request = load(requestId);
+ request.getTargetDepot().cacheObjectId(request.getTargetRef(), newTargetHeadId);
+ listenerRegistry.post(new RefUpdated(request.getTargetDepot(), targetRef,
+ targetHeadId, newTargetHeadId));
+ } finally {
+ ThreadContext.unbindSubject();
+ }
+ }
+
+ });
+ }
+
+ private long getNextNumber(Depot depot) {
+ AtomicLong nextNumber;
+ synchronized (nextNumbers) {
+ nextNumber = nextNumbers.get(depot.getUUID());
+ }
+ if (nextNumber == null) {
+ long maxNumber;
+ Query query = getSession().createQuery("select max(number) from PullRequest where targetDepot=:depot");
+ query.setParameter("depot", depot);
+ Object result = query.uniqueResult();
+ if (result != null) {
+ maxNumber = (Long)result;
+ } else {
+ maxNumber = 0;
+ }
+
+ /*
+ * do not put the whole method in synchronized block to avoid possible deadlocks
+ * if there are limited connections.
+ */
+ synchronized (nextNumbers) {
+ nextNumber = nextNumbers.get(depot.getUUID());
+ if (nextNumber == null) {
+ nextNumber = new AtomicLong(maxNumber+1);
+ nextNumbers.put(depot.getUUID(), nextNumber);
+ }
+ }
+ }
+ return nextNumber.getAndIncrement();
+ }
+
+ @Transactional
+ @Override
+ public void open(PullRequest request) {
+ request.setNumber(getNextNumber(request.getTargetDepot()));
+ dao.persist(request);
+
+ RefUpdate refUpdate = request.getTargetDepot().updateRef(request.getBaseRef());
+ refUpdate.setNewObjectId(ObjectId.fromString(request.getBaseCommitHash()));
+ GitUtils.updateRef(refUpdate);
+
+ for (PullRequestUpdate update: request.getUpdates()) {
+ pullRequestUpdateManager.save(update, false);
+ }
+
+ for (PullRequestReviewInvitation invitation: request.getReviewInvitations())
+ reviewInvitationManager.save(invitation);
+
+ checkAsync(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();
+ Date date = new Date();
+
+ if (dueToMerged)
+ request.setLastIntegrationPreview(null);
+
+ CloseInfo closeInfo = new CloseInfo();
+ closeInfo.setCloseDate(date);
+ closeInfo.setClosedBy(user);
+ closeInfo.setCloseStatus(CloseInfo.Status.INTEGRATED);
+ request.setCloseInfo(closeInfo);
+
+ if (dueToMerged)
+ note = "Source branch is already merged to target branch by some one";
+
+ PullRequestStatusChange statusChange = new PullRequestStatusChange();
+ statusChange.setDate(date);
+ statusChange.setNote(note);
+ statusChange.setRequest(request);
+ statusChange.setType(Type.INTEGRATED);
+ statusChange.setUser(user);
+ pullRequestStatusChangeManager.save(statusChange);
+ request.setLastEvent(statusChange);
+
+ save(request);
+ }
+
+ private void checkUpdate(PullRequest request, boolean independent) {
+ if (!request.getHeadCommitHash().equals(request.getSource().getObjectName())) {
+ PullRequestUpdate update = new PullRequestUpdate();
+ update.setRequest(request);
+ update.setHeadCommitHash(request.getSource().getObjectName());
+ ObjectId mergeBase = GitUtils.getMergeBase(
+ request.getTargetDepot().getRepository(), request.getTarget().getObjectId(),
+ request.getSourceDepot().getRepository(), request.getSource().getObjectId(),
+ GitUtils.branch2ref(request.getSourceBranch()));
+ update.setMergeCommitHash(mergeBase.name());
+ request.addUpdate(update);
+ pullRequestUpdateManager.save(update, independent);
+ }
+ }
+
+ @Transactional
+ @Override
+ public void check(PullRequest request) {
+ if (request.isOpen()) {
+ if (request.getSourceDepot() == null) {
+ discard(request, "Source repository no longer exists");
+ } else if (request.getSource().getObjectId(false) == null) {
+ discard(request, "Source branch no longer exists");
+ } 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);
+ } else {
+ IntegrationPreview integrationPreview = request.getIntegrationPreview();
+ Date timeBeforeCheck = new Date();
+ GateCheckResult result = request.checkGates(false);
+ if (result instanceof Pending || result instanceof Blocking) {
+ for (PullRequestReviewInvitation invitation: request.getReviewInvitations()) {
+ if (invitation.getDate().getTime()>=timeBeforeCheck.getTime())
+ reviewInvitationManager.save(invitation);
+ }
+ 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));
+ }
+ }
+ }
+ }
+ }
+
+ @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));
+ }
+
+ });
+ } else {
+ batchWorkManager.submit(getIntegrationPreviewer(request), new Prioritized(priority));
+ }
+ return null;
+ } else {
+ return preview;
+ }
+ }
+
+ private BatchWorker getIntegrationPreviewer(PullRequest request) {
+ Long requestId = request.getId();
+ return new BatchWorker("request-" + requestId + "-previewIntegration", 1) {
+
+ @Override
+ public void doWork(Collection<Prioritized> works) {
+ Preconditions.checkState(works.size() == 1);
+ unitOfWork.call(new Callable<Void>() {
+
+ @Override
+ 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 '{}'...",
+ 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();
+ ObjectId requestHeadId = ObjectId.fromString(requestHead);
+ ObjectId targetHeadId = ObjectId.fromString(targetHead);
+ if (preview.getIntegrationStrategy() == MERGE_IF_NECESSARY
+ && GitUtils.isMergedInto(targetDepot.getRepository(), targetHeadId, requestHeadId)) {
+ preview.setIntegrated(requestHead);
+ RefUpdate refUpdate = targetDepot.updateRef(integrateRef);
+ 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(),
+ requestHeadId, targetHeadId, true, user, request.getCommitMessage());
+ } else {
+ integrated = 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);
+ GitUtils.updateRef(refUpdate);
+ } else {
+ RefUpdate refUpdate = targetDepot.updateRef(integrateRef);
+ GitUtils.deleteRef(refUpdate);
+ }
+ }
+ dao.persist(request);
+
+ listenerRegistry.post(new IntegrationPreviewCalculated(request));
+ logger.info("Integration preview of pull request #{} in repository '{}' is calculated.",
+ request.getNumber(), request.getTargetDepot());
+ }
+ } catch (Exception e) {
+ logger.error("Error calculating pull request integration preview", e);
+ }
+ return null;
+ }
+
+ });
+ }
+
+ };
+ }
+
+ @Transactional
+ @Listen
+ public void on(DepotDeleted event) {
+ for (PullRequest request: event.getDepot().getOutgoingRequests()) {
+ if (!request.getTargetDepot().equals(event.getDepot()) && request.isOpen())
+ discard(request, "Source repository is deleted.");
+ }
+
+ Query query = getSession().createQuery("update PullRequest set sourceDepot=null where "
+ + "sourceDepot=:depot");
+ query.setParameter("depot", event.getDepot());
+ query.executeUpdate();
+ }
+
+ @Transactional
+ @Listen
+ public void on(RefUpdated event) {
+ String branch = GitUtils.ref2branch(event.getRefName());
+ if (branch != null) {
+ DepotAndBranch depotAndBranch = new DepotAndBranch(event.getDepot(), branch);
+ Criterion criterion = Restrictions.and(
+ ofOpen(),
+ Restrictions.or(ofSource(depotAndBranch), ofTarget(depotAndBranch)));
+ for (PullRequest request: findAll(EntityCriteria.of(PullRequest.class).add(criterion))) {
+ check(request);
+ }
+ }
+ }
+
+ @Sessional
+ @Override
+ public PullRequest findOpen(DepotAndBranch target, DepotAndBranch source) {
+ return find(EntityCriteria.of(PullRequest.class)
+ .add(ofTarget(target)).add(ofSource(source)).add(ofOpen()));
+ }
+
+ @Sessional
+ @Override
+ public PullRequest findLatest(Depot depot, Account submitter) {
+ EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
+ criteria.add(ofOpen());
+ criteria.add(Restrictions.or(ofSourceDepot(depot), ofTargetDepot(depot)));
+ criteria.add(ofSubmitter(submitter));
+ criteria.addOrder(Order.desc("id"));
+ return find(criteria);
+ }
+
+ @Sessional
+ @Override
+ public Collection<PullRequest> findAllOpenTo(DepotAndBranch target, @Nullable Depot sourceDepot) {
+ 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);
+ }
+
+ @Sessional
+ @Override
+ public Collection<PullRequest> findAllOpen(DepotAndBranch sourceOrTarget) {
+ EntityCriteria<PullRequest> criteria = EntityCriteria.of(PullRequest.class);
+ criteria.add(ofOpen());
+ criteria.add(Restrictions.or(ofSource(sourceOrTarget), ofTarget(sourceOrTarget)));
+ return findAll(criteria);
+ }
+
+ @Sessional
+ @Override
+ public int countOpen(Depot depot) {
+ EntityCriteria<PullRequest> criteria = newCriteria();
+ criteria.add(PullRequest.CriterionHelper.ofOpen());
+ criteria.add(PullRequest.CriterionHelper.ofTargetDepot(depot));
+ return count(criteria);
+ }
+
+ @Sessional
+ @Override
+ public PullRequest find(Depot target, long number) {
+ EntityCriteria<PullRequest> criteria = newCriteria();
+ criteria.add(Restrictions.eq("targetDepot", target));
+ criteria.add(Restrictions.eq("number", number));
+ return find(criteria);
+ }
+
+ @Sessional
+ @Override
+ public PullRequest find(String uuid) {
+ EntityCriteria<PullRequest> criteria = newCriteria();
+ criteria.add(Restrictions.eq("uuid", uuid));
+ return find(criteria);
+ }
+
+ @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());
+ }
+ }
+
+ @Listen
+ public void on(IntegrationPreviewCalculated event) {
+ checkAsync(event.getRequest());
+ }
+
+ private Runnable newCheckRunnable(Long requestId, Subject subject) {
+ return new Runnable() {
+
+ @Override
+ public void run() {
+ try {
+ ThreadContext.bind(subject);
+ check(load(requestId));
+ } catch (Exception e) {
+ logger.error("Error checking pull request", e);
+ } finally {
+ ThreadContext.unbindSubject();
+ }
+ }
+
+ };
+ }
+
+ @Sessional
+ protected void checkAsync(PullRequest request) {
+ Long requestId = request.getId();
+ Subject subject = SecurityUtils.getSubject();
+ if (dao.getSession().getTransaction().getStatus() == TransactionStatus.ACTIVE) {
+ doUnitOfWorkAsyncAfterCommit(newCheckRunnable(requestId, subject));
+ } else {
+ unitOfWork.doAsync(newCheckRunnable(requestId, subject));
+ }
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestNotificationManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestNotificationManager.java
index b19ad82630..1ba557056f 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestNotificationManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestNotificationManager.java
@@ -1,251 +1,232 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import static com.pmease.gitplex.core.entity.PullRequest.Status.PENDING_INTEGRATE;
-import static com.pmease.gitplex.core.entity.PullRequestNotification.Task.INTEGRATE;
-import static com.pmease.gitplex.core.entity.PullRequestNotification.Task.REVIEW;
-import static com.pmease.gitplex.core.entity.PullRequestNotification.Task.UPDATE;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.hibernate.Query;
-import org.hibernate.criterion.Restrictions;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Sets;
-import com.pmease.commons.hibernate.Transactional;
-import com.pmease.commons.hibernate.dao.AbstractEntityManager;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.loader.Listen;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequestReview;
-import com.pmease.gitplex.core.entity.PullRequestReviewInvitation;
-import com.pmease.gitplex.core.entity.PullRequestNotification;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestApproved;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestAssigned;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestDisapproved;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestDiscarded;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestIntegrated;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingApproval;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingIntegration;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingUpdate;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestReviewInvitationChanged;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestUpdated;
-import com.pmease.gitplex.core.manager.MailManager;
-import com.pmease.gitplex.core.manager.PullRequestNotificationManager;
-import com.pmease.gitplex.core.manager.UrlManager;
-
-/**
- * This class manages pull request tasks and send task notifications if necessary.
- * Unlike watch based notifications, task notifications can not be suppressed.
- *
- * @author robin
- *
- */
-@Singleton
-public class DefaultPullRequestNotificationManager extends AbstractEntityManager<PullRequestNotification>
- implements PullRequestNotificationManager {
-
- private final MailManager mailManager;
-
- private final UrlManager urlManager;
-
- @Inject
- public DefaultPullRequestNotificationManager(Dao dao, MailManager mailManager, UrlManager urlManager) {
- super(dao);
-
- this.mailManager = mailManager;
- this.urlManager = urlManager;
- }
-
- @Transactional
- @Listen
- public void on(PullRequestUpdated event) {
- Query query = getSession().createQuery("delete from PullRequestNotification "
- + "where request=:request and task=:task");
- query.setParameter("request", event.getRequest());
- query.setParameter("task", UPDATE);
- query.executeUpdate();
- }
-
- @Transactional
- @Listen
- public void on(PullRequestAssigned event) {
- PullRequest request = event.getRequest();
- Preconditions.checkNotNull(request.getAssignee());
-
- if (request.getStatus() == PENDING_INTEGRATE) {
- Query query = getSession().createQuery("delete from PullRequestNotification "
- + "where request=:request and task=:task and user!=:user");
- query.setParameter("request", request);
- query.setParameter("task", INTEGRATE);
- query.setParameter("user", request.getAssignee());
- query.executeUpdate();
-
- requestIntegration(request);
- }
- }
-
- @Transactional
- @Listen
- public void on(PullRequestIntegrated event) {
- onClosed(event.getRequest());
- }
-
- @Transactional
- @Listen
- public void on(PullRequestDiscarded event) {
- onClosed(event.getRequest());
- }
-
- private void onClosed(PullRequest request) {
- Query query = getSession().createQuery("delete from PullRequestNotification "
- + "where request=:request");
- query.setParameter("request", request);
- query.executeUpdate();
- }
-
- @Transactional
- @Listen
- public void on(PullRequestReviewInvitationChanged event) {
- PullRequestReviewInvitation invitation = event.getInvitation();
- PullRequest request = invitation.getRequest();
- Account user = invitation.getUser();
- if (invitation.getStatus() == PullRequestReviewInvitation.Status.EXCLUDED) {
- Query query = getSession().createQuery("delete from PullRequestNotification "
- + "where request=:request and user=:user and task=:task");
- query.setParameter("request", request);
- query.setParameter("user", user);
- query.setParameter("task", REVIEW);
- query.executeUpdate();
- } else if (invitation.getStatus() == PullRequestReviewInvitation.Status.ADDED_BY_RULE) {
- PullRequestNotification task = new PullRequestNotification();
- task.setRequest(request);
- task.setUser(user);
- task.setTask(REVIEW);
- EntityCriteria<PullRequestNotification> criteria = EntityCriteria.of(PullRequestNotification.class);
- criteria.add(Restrictions.eq("request", request))
- .add(Restrictions.eq("user", user))
- .add(Restrictions.eq("task", task.getTask()));
- if (find(criteria) == null) {
- save(task);
-
- 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>"
- + "Please visit <a href='%s'>%s</a> to do the review.",
- request.getNumber(), request.getTitle(), url, url);
- mailManager.sendMailAsync(Sets.newHashSet(task.getUser()), subject, decorate(user, body));
- }
- } 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()), subject, decorate(user, body));
- }
- }
-
- private String decorate(Account user, String body) {
- return String.format("Dear %s, "
- + "<p style='margin: 16px 0;'>"
- + "%s"
- + "<p style='margin: 16px 0;'>"
- + "-- Sent by GitPlex",
- user.getDisplayName(), body);
- }
-
- @Transactional
- @Listen
- public void on(PullRequestPendingApproval event) {
- Query query = getSession().createQuery("delete from PullRequestNotification "
- + "where request=:request and (task=:update or task=:integrate)");
- query.setParameter("request", event.getRequest());
- query.setParameter("update", UPDATE);
- query.setParameter("integrate", INTEGRATE);
- query.executeUpdate();
- }
-
- private void requestIntegration(PullRequest request) {
- Account user = request.getAssignee();
- PullRequestNotification task = new PullRequestNotification();
- task.setRequest(request);
- task.setUser(user);
- task.setTask(INTEGRATE);
- EntityCriteria<PullRequestNotification> criteria = EntityCriteria.of(PullRequestNotification.class);
- criteria.add(Restrictions.eq("request", task.getRequest()))
- .add(Restrictions.eq("user", user))
- .add(Restrictions.eq("task", task.getTask()));
- 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()), subject, decorate(user, body));
- }
- }
-
- @Transactional
- @Listen
- public void on(PullRequestPendingIntegration event) {
- PullRequest request = event.getRequest();
- if (request.getAssignee() != null)
- requestIntegration(request);
- }
-
- @Transactional
- @Listen
- public void on(PullRequestPendingUpdate event) {
- PullRequest request = event.getRequest();
- PullRequestNotification task = new PullRequestNotification();
- task.setRequest(request);
- task.setUser(request.getSubmitter());
- task.setTask(UPDATE);
- EntityCriteria<PullRequestNotification> criteria = EntityCriteria.of(PullRequestNotification.class);
- criteria.add(Restrictions.eq("request", task.getRequest()))
- .add(Restrictions.eq("user", task.getUser()))
- .add(Restrictions.eq("task", task.getTask()));
- 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()), subject,
- decorate(request.getSubmitter(), body));
- }
- }
-
- @Transactional
- @Listen
- public void on(PullRequestApproved event) {
- onReviewed(event.getReview());
- }
-
- @Transactional
- @Listen
- public void on(PullRequestDisapproved event) {
- onReviewed(event.getReview());
- }
-
- private void onReviewed(PullRequestReview review) {
- Query query = getSession().createQuery("delete from PullRequestNotification "
- + "where request=:request and user=:user and task=:task");
- query.setParameter("request", review.getUpdate().getRequest());
- query.setParameter("user", review.getUser());
- query.setParameter("task", REVIEW);
- query.executeUpdate();
- }
-
+package com.pmease.gitplex.core.manager.impl;
+
+import static com.pmease.gitplex.core.entity.PullRequest.Status.PENDING_INTEGRATE;
+import static com.pmease.gitplex.core.entity.PullRequestNotification.Task.INTEGRATE;
+import static com.pmease.gitplex.core.entity.PullRequestNotification.Task.REVIEW;
+import static com.pmease.gitplex.core.entity.PullRequestNotification.Task.UPDATE;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.hibernate.Query;
+import org.hibernate.criterion.Restrictions;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Sets;
+import com.pmease.commons.hibernate.Transactional;
+import com.pmease.commons.hibernate.dao.AbstractEntityManager;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.loader.Listen;
+import com.pmease.gitplex.core.entity.Account;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestNotification;
+import com.pmease.gitplex.core.entity.PullRequestReviewInvitation;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange.Type;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingApproval;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingIntegration;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestPendingUpdate;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestReviewInvitationChanged;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestStatusChangeEvent;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestUpdated;
+import com.pmease.gitplex.core.manager.MailManager;
+import com.pmease.gitplex.core.manager.PullRequestNotificationManager;
+import com.pmease.gitplex.core.manager.UrlManager;
+
+/**
+ * This class manages pull request tasks and send task notifications if necessary.
+ * Unlike watch based notifications, task notifications can not be suppressed.
+ *
+ * @author robin
+ *
+ */
+@Singleton
+public class DefaultPullRequestNotificationManager extends AbstractEntityManager<PullRequestNotification>
+ implements PullRequestNotificationManager {
+
+ private final MailManager mailManager;
+
+ private final UrlManager urlManager;
+
+ @Inject
+ public DefaultPullRequestNotificationManager(Dao dao, MailManager mailManager, UrlManager urlManager) {
+ super(dao);
+
+ this.mailManager = mailManager;
+ this.urlManager = urlManager;
+ }
+
+ @Transactional
+ @Listen
+ public void on(PullRequestUpdated event) {
+ Query query = getSession().createQuery("delete from PullRequestNotification "
+ + "where request=:request and task=:task");
+ query.setParameter("request", event.getRequest());
+ query.setParameter("task", UPDATE);
+ query.executeUpdate();
+ }
+
+ private void onClosed(PullRequest request) {
+ Query query = getSession().createQuery("delete from PullRequestNotification "
+ + "where request=:request");
+ query.setParameter("request", request);
+ query.executeUpdate();
+ }
+
+ @Transactional
+ @Listen
+ public void on(PullRequestReviewInvitationChanged event) {
+ PullRequestReviewInvitation invitation = event.getInvitation();
+ PullRequest request = invitation.getRequest();
+ Account user = invitation.getUser();
+ if (invitation.getStatus() == PullRequestReviewInvitation.Status.EXCLUDED) {
+ Query query = getSession().createQuery("delete from PullRequestNotification "
+ + "where request=:request and user=:user and task=:task");
+ query.setParameter("request", request);
+ query.setParameter("user", user);
+ query.setParameter("task", REVIEW);
+ query.executeUpdate();
+ } else if (invitation.getStatus() == PullRequestReviewInvitation.Status.ADDED_BY_RULE) {
+ PullRequestNotification task = new PullRequestNotification();
+ task.setRequest(request);
+ task.setUser(user);
+ task.setTask(REVIEW);
+ EntityCriteria<PullRequestNotification> criteria = EntityCriteria.of(PullRequestNotification.class);
+ criteria.add(Restrictions.eq("request", request))
+ .add(Restrictions.eq("user", user))
+ .add(Restrictions.eq("task", task.getTask()));
+ if (find(criteria) == null) {
+ save(task);
+
+ 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>"
+ + "Please visit <a href='%s'>%s</a> to do the review.",
+ request.getNumber(), request.getTitle(), url, url);
+ mailManager.sendMailAsync(Sets.newHashSet(task.getUser()), subject, decorate(user, body));
+ }
+ } 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()), subject, decorate(user, body));
+ }
+ }
+
+ private String decorate(Account user, String body) {
+ return String.format("Dear %s, "
+ + "<p style='margin: 16px 0;'>"
+ + "%s"
+ + "<p style='margin: 16px 0;'>"
+ + "-- Sent by GitPlex",
+ user.getDisplayName(), body);
+ }
+
+ @Transactional
+ @Listen
+ public void on(PullRequestPendingApproval event) {
+ Query query = getSession().createQuery("delete from PullRequestNotification "
+ + "where request=:request and (task=:update or task=:integrate)");
+ query.setParameter("request", event.getRequest());
+ query.setParameter("update", UPDATE);
+ query.setParameter("integrate", INTEGRATE);
+ query.executeUpdate();
+ }
+
+ private void requestIntegration(PullRequest request) {
+ Account user = request.getAssignee();
+ PullRequestNotification task = new PullRequestNotification();
+ task.setRequest(request);
+ task.setUser(user);
+ task.setTask(INTEGRATE);
+ EntityCriteria<PullRequestNotification> criteria = EntityCriteria.of(PullRequestNotification.class);
+ criteria.add(Restrictions.eq("request", task.getRequest()))
+ .add(Restrictions.eq("user", user))
+ .add(Restrictions.eq("task", task.getTask()));
+ 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()), subject, decorate(user, body));
+ }
+ }
+
+ @Transactional
+ @Listen
+ public void on(PullRequestPendingIntegration event) {
+ PullRequest request = event.getRequest();
+ if (request.getAssignee() != null)
+ requestIntegration(request);
+ }
+
+ @Transactional
+ @Listen
+ public void on(PullRequestPendingUpdate event) {
+ PullRequest request = event.getRequest();
+ PullRequestNotification task = new PullRequestNotification();
+ task.setRequest(request);
+ task.setUser(request.getSubmitter());
+ task.setTask(UPDATE);
+ EntityCriteria<PullRequestNotification> criteria = EntityCriteria.of(PullRequestNotification.class);
+ criteria.add(Restrictions.eq("request", task.getRequest()))
+ .add(Restrictions.eq("user", task.getUser()))
+ .add(Restrictions.eq("task", task.getTask()));
+ 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()), subject,
+ decorate(request.getSubmitter(), body));
+ }
+ }
+
+ @Transactional
+ @Listen
+ public void on(PullRequestStatusChangeEvent event) {
+ PullRequestStatusChange statusChange = event.getStatusChange();
+ Type type = statusChange.getType();
+ if (type == Type.APPROVED || type == Type.DISAPPROVED) {
+ onReviewed(statusChange);
+ } else if (type == Type.ASSIGNED) {
+ PullRequest request = event.getRequest();
+ Preconditions.checkNotNull(request.getAssignee());
+
+ if (request.getStatus() == PENDING_INTEGRATE) {
+ Query query = getSession().createQuery("delete from PullRequestNotification "
+ + "where request=:request and task=:task and user!=:user");
+ query.setParameter("request", request);
+ query.setParameter("task", INTEGRATE);
+ query.setParameter("user", request.getAssignee());
+ query.executeUpdate();
+
+ requestIntegration(request);
+ }
+ } else if (type == Type.INTEGRATED || type == Type.DISCARDED) {
+ onClosed(event.getRequest());
+ }
+ }
+
+ private void onReviewed(PullRequestStatusChange statusChange) {
+ Query query = getSession().createQuery("delete from PullRequestNotification "
+ + "where request=:request and user=:user and task=:task");
+ query.setParameter("request", statusChange.getRequest());
+ query.setParameter("user", statusChange.getUser());
+ query.setParameter("task", REVIEW);
+ query.executeUpdate();
+ }
+
}
\ No newline at end of file
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestReviewManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestReviewManager.java
index b1451fec2e..612a15500e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestReviewManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestReviewManager.java
@@ -1,110 +1,124 @@
-package com.pmease.gitplex.core.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.pmease.commons.hibernate.Sessional;
-import com.pmease.commons.hibernate.Transactional;
-import com.pmease.commons.hibernate.dao.AbstractEntityManager;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.loader.ListenerRegistry;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequestReview;
-import com.pmease.gitplex.core.entity.PullRequestUpdate;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestApproved;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestChangeEvent;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestDisapproved;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestReviewDeleted;
-import com.pmease.gitplex.core.manager.AccountManager;
-import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.manager.PullRequestReviewManager;
-
-@Singleton
-public class DefaultPullRequestReviewManager extends AbstractEntityManager<PullRequestReview> implements PullRequestReviewManager {
-
- private final AccountManager accountManager;
-
- private final PullRequestManager pullRequestManager;
-
- private final ListenerRegistry listenerRegistry;
-
- @Inject
- public DefaultPullRequestReviewManager(Dao dao, AccountManager accountManager, PullRequestManager pullRequestManager,
- ListenerRegistry listenerRegistry) {
- super(dao);
-
- this.accountManager = accountManager;
- this.pullRequestManager = pullRequestManager;
- this.listenerRegistry = listenerRegistry;
- }
-
- @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) {
- PullRequestReview review = new PullRequestReview();
- review.setUpdate(request.getLatestUpdate());
- review.setResult(result);
- review.setUser(accountManager.getCurrent());
- review.setDate(new Date());
- save(review);
-
- PullRequestChangeEvent event;
- if (result == PullRequestReview.Result.APPROVE) {
- event = new PullRequestApproved(review, note);
- } else {
- event = new PullRequestDisapproved(review, note);
- }
- listenerRegistry.post(event);
- request.setLastEvent(event);
- pullRequestManager.save(request);
- }
-
- @Transactional
- @Override
- public void delete(PullRequestReview entity) {
- super.delete(entity);
- PullRequestReviewDeleted event = new PullRequestReviewDeleted(entity, accountManager.getCurrent(), null);
- listenerRegistry.post(event);
- event.getRequest().setLastEvent(event);
- pullRequestManager.save(event.getRequest());
- }
-
- @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();
- }
- }
- }
-
-}
+package com.pmease.gitplex.core.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.pmease.commons.hibernate.Sessional;
+import com.pmease.commons.hibernate.Transactional;
+import com.pmease.commons.hibernate.dao.AbstractEntityManager;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.gitplex.core.entity.Account;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestReview;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange.Type;
+import com.pmease.gitplex.core.entity.PullRequestUpdate;
+import com.pmease.gitplex.core.manager.AccountManager;
+import com.pmease.gitplex.core.manager.PullRequestManager;
+import com.pmease.gitplex.core.manager.PullRequestReviewManager;
+import com.pmease.gitplex.core.manager.PullRequestStatusChangeManager;
+
+@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/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestStatusChangeManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestStatusChangeManager.java
index d655b4b78e..db125c038b 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestStatusChangeManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestStatusChangeManager.java
@@ -3,10 +3,9 @@ package com.pmease.gitplex.core.manager.impl;
import javax.inject.Inject;
import javax.inject.Singleton;
-import com.pmease.commons.hibernate.Transactional;
import com.pmease.commons.hibernate.dao.AbstractEntityManager;
import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.loader.Listen;
+import com.pmease.commons.loader.ListenerRegistry;
import com.pmease.gitplex.core.entity.PullRequestStatusChange;
import com.pmease.gitplex.core.event.pullrequest.PullRequestStatusChangeEvent;
import com.pmease.gitplex.core.manager.PullRequestStatusChangeManager;
@@ -15,21 +14,18 @@ import com.pmease.gitplex.core.manager.PullRequestStatusChangeManager;
public class DefaultPullRequestStatusChangeManager extends AbstractEntityManager<PullRequestStatusChange>
implements PullRequestStatusChangeManager {
+ private final ListenerRegistry listenerRegistry;
+
@Inject
- public DefaultPullRequestStatusChangeManager(Dao dao) {
+ public DefaultPullRequestStatusChangeManager(Dao dao, ListenerRegistry listenerRegistry) {
super(dao);
+ this.listenerRegistry = listenerRegistry;
}
- @Transactional
- @Listen
- public void on(PullRequestStatusChangeEvent event) {
- PullRequestStatusChange statusChange = new PullRequestStatusChange();
- statusChange.setRequest(event.getRequest());
- statusChange.setDate(event.getDate());
- statusChange.setEventType(event.getClass());
- statusChange.setUser(event.getUser());
- statusChange.setNote(event.getNote());
- save(statusChange);
+ @Override
+ public void save(PullRequestStatusChange statusChange) {
+ dao.persist(statusChange);
+ listenerRegistry.post(new PullRequestStatusChangeEvent(statusChange));
}
-
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
index 605ae63d83..8d3f278940 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestUpdateManager.java
@@ -1,112 +1,118 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.RefUpdate;
-import org.eclipse.jgit.transport.RefSpec;
-import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Restrictions;
-
-import com.google.common.base.Throwables;
-import com.pmease.commons.git.GitUtils;
-import com.pmease.commons.hibernate.Sessional;
-import com.pmease.commons.hibernate.Transactional;
-import com.pmease.commons.hibernate.dao.AbstractEntityManager;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.loader.ListenerRegistry;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequestUpdate;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestUpdated;
-import com.pmease.gitplex.core.manager.PullRequestCommentManager;
-import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
-
-@Singleton
-public class DefaultPullRequestUpdateManager extends AbstractEntityManager<PullRequestUpdate>
- implements PullRequestUpdateManager {
-
- private final ListenerRegistry listenerRegistry;
-
- private final PullRequestManager pullRequestManager;
-
- @Inject
- public DefaultPullRequestUpdateManager(Dao dao, ListenerRegistry listenerRegistry,
- PullRequestCommentManager commentManager, PullRequestManager pullRequestManager) {
- super(dao);
-
- this.listenerRegistry = listenerRegistry;
- this.pullRequestManager = pullRequestManager;
- }
-
- @Transactional
- @Override
- public void save(PullRequestUpdate update) {
- save(update, true);
- }
-
- @Transactional
- @Override
- public void save(PullRequestUpdate update, boolean independent) {
- PullRequest request = update.getRequest();
-
- dao.persist(update);
-
- ObjectId updateHeadId = ObjectId.fromString(update.getHeadCommitHash());
- if (!request.getTargetDepot().equals(request.getSourceDepot())) {
- try {
- request.getTargetDepot().git().fetch()
- .setRemote(request.getSourceDepot().getDirectory().getAbsolutePath())
- .setRefSpecs(new RefSpec(GitUtils.branch2ref(request.getSourceBranch()) + ":" + update.getHeadRef()))
- .call();
- if (!request.getTargetDepot().getObjectId(update.getHeadRef()).equals(updateHeadId)) {
- RefUpdate refUpdate = request.getTargetDepot().updateRef(update.getHeadRef());
- refUpdate.setNewObjectId(updateHeadId);
- GitUtils.updateRef(refUpdate);
- }
- } catch (Exception e) {
- Throwables.propagate(e);
- }
- } else {
- RefUpdate refUpdate = request.getTargetDepot().updateRef(update.getHeadRef());
- refUpdate.setNewObjectId(updateHeadId);
- GitUtils.updateRef(refUpdate);
- }
-
- if (independent) {
- PullRequestUpdated event = new PullRequestUpdated(update);
- listenerRegistry.post(event);
- request.setLastEvent(event);
- pullRequestManager.save(request);
- }
- }
-
- @Sessional
- @Override
- public PullRequestUpdate find(String uuid) {
- EntityCriteria<PullRequestUpdate> criteria = newCriteria();
- criteria.add(Restrictions.eq("uuid", uuid));
- return find(criteria);
- }
-
- @Sessional
- @Override
- public List<PullRequestUpdate> findAllAfter(Depot depot, String updateUUID) {
- EntityCriteria<PullRequestUpdate> criteria = newCriteria();
- criteria.createCriteria("request").add(Restrictions.eq("targetDepot", depot));
- criteria.addOrder(Order.asc("id"));
- if (updateUUID != null) {
- PullRequestUpdate update = find(updateUUID);
- if (update != null) {
- criteria.add(Restrictions.gt("id", update.getId()));
- }
- }
- return findAll(criteria);
- }
-
-}
+package com.pmease.gitplex.core.manager.impl;
+
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.RefUpdate;
+import org.eclipse.jgit.transport.RefSpec;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
+
+import com.google.common.base.Throwables;
+import com.pmease.commons.git.GitUtils;
+import com.pmease.commons.hibernate.Sessional;
+import com.pmease.commons.hibernate.Transactional;
+import com.pmease.commons.hibernate.dao.AbstractEntityManager;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.loader.ListenerRegistry;
+import com.pmease.commons.wicket.editable.EditableUtils;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestUpdate;
+import com.pmease.gitplex.core.entity.support.LastEvent;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestUpdated;
+import com.pmease.gitplex.core.manager.PullRequestCommentManager;
+import com.pmease.gitplex.core.manager.PullRequestManager;
+import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
+
+@Singleton
+public class DefaultPullRequestUpdateManager extends AbstractEntityManager<PullRequestUpdate>
+ implements PullRequestUpdateManager {
+
+ private final ListenerRegistry listenerRegistry;
+
+ private final PullRequestManager pullRequestManager;
+
+ @Inject
+ public DefaultPullRequestUpdateManager(Dao dao, ListenerRegistry listenerRegistry,
+ PullRequestCommentManager commentManager, PullRequestManager pullRequestManager) {
+ super(dao);
+
+ this.listenerRegistry = listenerRegistry;
+ this.pullRequestManager = pullRequestManager;
+ }
+
+ @Transactional
+ @Override
+ public void save(PullRequestUpdate update) {
+ save(update, true);
+ }
+
+ @Transactional
+ @Override
+ public void save(PullRequestUpdate update, boolean independent) {
+ PullRequest request = update.getRequest();
+
+ dao.persist(update);
+
+ ObjectId updateHeadId = ObjectId.fromString(update.getHeadCommitHash());
+ if (!request.getTargetDepot().equals(request.getSourceDepot())) {
+ try {
+ request.getTargetDepot().git().fetch()
+ .setRemote(request.getSourceDepot().getDirectory().getAbsolutePath())
+ .setRefSpecs(new RefSpec(GitUtils.branch2ref(request.getSourceBranch()) + ":" + update.getHeadRef()))
+ .call();
+ if (!request.getTargetDepot().getObjectId(update.getHeadRef()).equals(updateHeadId)) {
+ RefUpdate refUpdate = request.getTargetDepot().updateRef(update.getHeadRef());
+ refUpdate.setNewObjectId(updateHeadId);
+ GitUtils.updateRef(refUpdate);
+ }
+ } catch (Exception e) {
+ Throwables.propagate(e);
+ }
+ } else {
+ RefUpdate refUpdate = request.getTargetDepot().updateRef(update.getHeadRef());
+ refUpdate.setNewObjectId(updateHeadId);
+ GitUtils.updateRef(refUpdate);
+ }
+
+ if (independent) {
+ PullRequestUpdated event = new PullRequestUpdated(update);
+ listenerRegistry.post(event);
+
+ LastEvent lastEvent = new LastEvent();
+ lastEvent.setDate(event.getDate());
+ lastEvent.setType(EditableUtils.getName(event.getClass()));
+ request.setLastEvent(lastEvent);
+ pullRequestManager.save(request);
+ }
+ }
+
+ @Sessional
+ @Override
+ public PullRequestUpdate find(String uuid) {
+ EntityCriteria<PullRequestUpdate> criteria = newCriteria();
+ criteria.add(Restrictions.eq("uuid", uuid));
+ return find(criteria);
+ }
+
+ @Sessional
+ @Override
+ public List<PullRequestUpdate> findAllAfter(Depot depot, String updateUUID) {
+ EntityCriteria<PullRequestUpdate> criteria = newCriteria();
+ criteria.createCriteria("request").add(Restrictions.eq("targetDepot", depot));
+ criteria.addOrder(Order.asc("id"));
+ if (updateUUID != null) {
+ PullRequestUpdate update = find(updateUUID);
+ if (update != null) {
+ criteria.add(Restrictions.gt("id", update.getId()));
+ }
+ }
+ return findAll(criteria);
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestVerificationManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestVerificationManager.java
index 7d6de41b65..fe42f1ee87 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestVerificationManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestVerificationManager.java
@@ -1,109 +1,131 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import java.util.Collection;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.hibernate.criterion.Restrictions;
-
-import com.pmease.commons.hibernate.Sessional;
-import com.pmease.commons.hibernate.Transactional;
-import com.pmease.commons.hibernate.dao.AbstractEntityManager;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.loader.ListenerRegistry;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequestVerification;
-import com.pmease.gitplex.core.entity.PullRequestVerification.Status;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestChangeEvent;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationDeleted;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationFailed;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationRunning;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationSucceeded;
-import com.pmease.gitplex.core.manager.AccountManager;
-import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.manager.PullRequestVerificationManager;
-
-@Singleton
-public class DefaultPullRequestVerificationManager extends AbstractEntityManager<PullRequestVerification>
- implements PullRequestVerificationManager {
-
- private final AccountManager accountManager;
-
- private final ListenerRegistry listenerRegistry;
-
- private final PullRequestManager pullRequestManager;
-
- @Inject
- public DefaultPullRequestVerificationManager(Dao dao, AccountManager accountManager,
- ListenerRegistry listenerRegistry, PullRequestManager pullRequestManager) {
- super(dao);
- this.accountManager = accountManager;
- this.listenerRegistry = listenerRegistry;
- this.pullRequestManager = pullRequestManager;
- }
-
- @Transactional
- @Override
- public void save(PullRequestVerification entity) {
- super.save(entity);
-
- PullRequestChangeEvent event;
- if (entity.getStatus() == PullRequestVerification.Status.FAILED)
- event = new PullRequestVerificationFailed(entity);
- else if (entity.getStatus() == PullRequestVerification.Status.RUNNING)
- event = new PullRequestVerificationRunning(entity);
- else
- event = new PullRequestVerificationSucceeded(entity);
- if (entity.getStatus() != PullRequestVerification.Status.RUNNING) {
- listenerRegistry.post(event);
- event.getRequest().setLastEvent(event);
- pullRequestManager.save(event.getRequest());
- }
- }
-
- @Transactional
- @Override
- public void delete(PullRequestVerification entity) {
- super.delete(entity);
- PullRequestVerificationDeleted event = new PullRequestVerificationDeleted(entity, accountManager.getCurrent());
- listenerRegistry.post(event);
- event.getRequest().setLastEvent(event);
- pullRequestManager.save(event.getRequest());
- }
-
- @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;
- }
-
-}
+package com.pmease.gitplex.core.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.pmease.commons.hibernate.Sessional;
+import com.pmease.commons.hibernate.Transactional;
+import com.pmease.commons.hibernate.dao.AbstractEntityManager;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.loader.ListenerRegistry;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange.Type;
+import com.pmease.gitplex.core.entity.PullRequestVerification;
+import com.pmease.gitplex.core.entity.PullRequestVerification.Status;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationRunning;
+import com.pmease.gitplex.core.manager.AccountManager;
+import com.pmease.gitplex.core.manager.PullRequestManager;
+import com.pmease.gitplex.core.manager.PullRequestStatusChangeManager;
+import com.pmease.gitplex.core.manager.PullRequestVerificationManager;
+
+@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/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestWatchManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestWatchManager.java
index 5bae22d8b2..90d5710c1e 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestWatchManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestWatchManager.java
@@ -23,20 +23,17 @@ import com.pmease.gitplex.core.entity.Account;
import com.pmease.gitplex.core.entity.BranchWatch;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.core.entity.PullRequestReviewInvitation;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange.Type;
import com.pmease.gitplex.core.entity.PullRequestUpdate;
import com.pmease.gitplex.core.entity.PullRequestWatch;
import com.pmease.gitplex.core.event.MarkdownAware;
import com.pmease.gitplex.core.event.pullrequest.IntegrationPreviewCalculated;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestAssigned;
import com.pmease.gitplex.core.event.pullrequest.PullRequestChangeEvent;
import com.pmease.gitplex.core.event.pullrequest.PullRequestOpened;
import com.pmease.gitplex.core.event.pullrequest.PullRequestReviewInvitationChanged;
+import com.pmease.gitplex.core.event.pullrequest.PullRequestStatusChangeEvent;
import com.pmease.gitplex.core.event.pullrequest.PullRequestUpdated;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationFailed;
import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationRunning;
-import com.pmease.gitplex.core.event.pullrequest.PullRequestVerificationSucceeded;
-import com.pmease.gitplex.core.event.pullrequest.SourceBranchDeleted;
-import com.pmease.gitplex.core.event.pullrequest.SourceBranchRestored;
import com.pmease.gitplex.core.manager.AccountManager;
import com.pmease.gitplex.core.manager.BranchWatchManager;
import com.pmease.gitplex.core.manager.MailManager;
@@ -77,10 +74,20 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
@Transactional
@Listen
public void on(PullRequestChangeEvent event) {
- if (event instanceof IntegrationPreviewCalculated || event instanceof SourceBranchDeleted
- || event instanceof SourceBranchRestored || event instanceof PullRequestVerificationRunning) {
+ if (event instanceof IntegrationPreviewCalculated || event instanceof PullRequestVerificationRunning) {
return;
}
+ String eventType;
+ Type statusChangeType = null;
+ if (event instanceof PullRequestStatusChangeEvent) {
+ statusChangeType = ((PullRequestStatusChangeEvent) event).getStatusChange().getType();
+ eventType = statusChangeType.getName();
+ if (statusChangeType == Type.SOURCE_BRANCH_DELETED || statusChangeType == Type.SOURCE_BRANCH_RESTORED) {
+ return;
+ }
+ } else {
+ eventType = EditableUtils.getName(event.getClass());
+ }
PullRequest request = event.getRequest();
Account user = event.getUser();
@@ -89,9 +96,9 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
* 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 && !(event instanceof PullRequestVerificationSucceeded) && !(event instanceof PullRequestVerificationFailed)) {
+ if (user != null && statusChangeType != Type.VERIFICATION_SUCCEEDED && statusChangeType != Type.VERIFICATION_FAILED) {
watch(request, user,
- "You've set to watch this pull request as you've " + EditableUtils.getName(event.getClass()));
+ "You've set to watch this pull request as you've " + eventType);
}
if (event instanceof PullRequestOpened) {
if (request.getAssignee() != null)
@@ -101,7 +108,7 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
"You are set to watch this pull request as you are watching the target branch.");
}
makeContributorsWatching(request.getLatestUpdate());
- } else if (event instanceof PullRequestAssigned) {
+ } 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;
@@ -129,7 +136,7 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
} else {
Date visitDate = visitInfoManager.getVisitDate(watch.getUser(), request);
if (visitDate == null || visitDate.getTime()<request.getLastEvent().getDate().getTime()) {
- if (request.getLastEvent().getType() != event.getClass()) {
+ if (!request.getLastEvent().getType().equals(eventType)) {
watchUsers.add(watch.getUser());
}
} else {
@@ -143,7 +150,7 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
// them here
watchUsers.removeAll(mentionUsers);
- if ((event instanceof PullRequestOpened || event instanceof PullRequestAssigned)
+ if ((event instanceof PullRequestOpened || statusChangeType == Type.ASSIGNED)
&& request.getAssignee() != null
&& !request.getAssignee().equals(event.getUser())) {
watchUsers.remove(request.getAssignee());
@@ -171,14 +178,14 @@ public class DefaultPullRequestWatchManager extends AbstractEntityManager<PullRe
request.getNumber(), request.getTitle(), url, url);
} else {
subject = String.format("New activity in pull request #%d (%s) - %s",
- request.getNumber(), request.getTitle(), EditableUtils.getName(event.getClass()));
+ request.getNumber(), request.getTitle(), eventType);
body = String.format("Dear Users,"
+ "<p style='margin: 16px 0;'>There is new activity in pull request #%d (%s) - %s "
+ "<p style='margin: 16px 0;'>Visit <a href='%s'>%s</a> for details."
+ "<p style='margin: 16px 0;'>-- Sent by GitPlex"
+ "<p style='margin: 16px 0; font-size: 12px; color: #888;'>"
+ "You receive this email as you are watching the pull request.",
- request.getNumber(), request.getTitle(), EditableUtils.getName(event.getClass()), url, url);
+ request.getNumber(), request.getTitle(), eventType, url, url);
}
mailManager.sendMailAsync(watchUsers, subject, body);
}
diff --git a/gitplex.product/src/test/java/gitplex/product/Test.java b/gitplex.product/src/test/java/gitplex/product/Test.java
index 54ff448956..01392fb01b 100644
--- a/gitplex.product/src/test/java/gitplex/product/Test.java
+++ b/gitplex.product/src/test/java/gitplex/product/Test.java
@@ -1,46 +1,10 @@
package gitplex.product;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-
-import org.apache.commons.io.IOUtils;
-
public class Test {
- private InputStream download(String url) {
- try {
- HttpURLConnection urlConn = (HttpURLConnection) new URL(url).openConnection();
- urlConn.addRequestProperty("Accept-Encoding", "gzip, deflate, sdch");
- return urlConn.getInputStream();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
@org.junit.Test
public void test() {
- InputStream is = null;
- OutputStream bos = null;
- try {
- is = download("http://lark:6610/wicket/resource/org.apache.wicket.Application/a/l/o/n/g/p/a/t/h/bundle-ver-1472770062571.js");
-
- byte[] data = new byte[2048];
- bos = new BufferedOutputStream(new FileOutputStream(new File("w:\\temp\\download.css")), 2048);
- int count;
- while ((count = is.read(data)) > -1)
- bos.write(data, 0, count);
- } catch (IOException e) {
- throw new RuntimeException(e);
- } finally {
- IOUtils.closeQuietly(is);
- IOUtils.closeQuietly(bos);
- }
+ System.out.println(Test.class.getSimpleName());
}
}
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java
index 35e7a3d0a6..5eb46a50e1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/WebModule.java
@@ -115,7 +115,7 @@ public class WebModule extends AbstractPluginModule {
});
- bind(UrlManager.class).to(WebUrlManager.class);
+ bind(UrlManager.class).to(WicketUrlManager.class);
bind(CodeCommentChangeBroadcaster.class);
bind(PullRequestChangeBroadcaster.class);
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebUrlManager.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/WicketUrlManager.java
similarity index 55%
rename from gitplex.web/src/main/java/com/pmease/gitplex/web/WebUrlManager.java
rename to gitplex.web/src/main/java/com/pmease/gitplex/web/WicketUrlManager.java
index 34e7d87a40..935b94fdf1 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/WebUrlManager.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/WicketUrlManager.java
@@ -7,24 +7,22 @@ import com.pmease.gitplex.core.entity.Account;
import com.pmease.gitplex.core.entity.CodeComment;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestComment;
+import com.pmease.gitplex.core.entity.PullRequestStatusChange;
+import com.pmease.gitplex.core.entity.support.CodeCommentActivity;
import com.pmease.gitplex.core.manager.ConfigManager;
import com.pmease.gitplex.core.manager.UrlManager;
@Singleton
-public class WebUrlManager implements UrlManager {
+public class WicketUrlManager implements UrlManager {
private final ConfigManager configManager;
@Inject
- public WebUrlManager(ConfigManager configManager) {
+ public WicketUrlManager(ConfigManager configManager) {
this.configManager = configManager;
}
- @Override
- public String urlFor(PullRequest request) {
- return urlFor(request.getTarget().getDepot()) + "/pulls/" + request.getNumber() + "/overview";
- }
-
@Override
public String urlFor(Account user) {
return configManager.getSystemSetting().getServerUrl() + "/" + user.getName();
@@ -43,4 +41,30 @@ public class WebUrlManager implements UrlManager {
return url;
}
+ @Override
+ public String urlFor(CodeCommentActivity activity, PullRequest request) {
+ String url = urlFor(activity.getComment(), request);
+ if (request != null)
+ return url + "&anchor=" + activity.getAnchor();
+ else
+ return url + "?anchor=" + activity.getAnchor();
+ }
+
+ @Override
+ public String urlFor(PullRequest request) {
+ return urlFor(request.getTarget().getDepot()) + "/pulls/" + request.getNumber() + "/overview";
+ }
+
+ @Override
+ public String urlFor(PullRequestComment comment) {
+ String url = urlFor(comment.getRequest());
+ return url + "#" + comment.getAnchor();
+ }
+
+ @Override
+ public String urlFor(PullRequestStatusChange statusChange) {
+ String url = urlFor(statusChange.getRequest());
+ return url + "#" + statusChange.getAnchor();
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentListPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentListPanel.java
index b9cafba610..b33282b792 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentListPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentListPanel.java
@@ -1,298 +1,297 @@
-package com.pmease.gitplex.web.component.comment;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-
-import javax.annotation.Nullable;
-
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
-import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
-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.data.table.NavigationToolbar;
-import org.apache.wicket.extensions.markup.html.repeater.data.table.NoRecordsToolbar;
-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.Form;
-import org.apache.wicket.markup.html.link.Link;
-import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
-import org.apache.wicket.markup.html.panel.Fragment;
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.data.IDataProvider;
-import org.apache.wicket.model.IModel;
-import org.apache.wicket.model.LoadableDetachableModel;
-import org.apache.wicket.model.Model;
-import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Restrictions;
-
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.wicket.editable.BeanContext;
-import com.pmease.commons.wicket.editable.EditableUtils;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.CodeComment;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.support.CompareContext;
-import com.pmease.gitplex.core.manager.CodeCommentManager;
-import com.pmease.gitplex.core.security.SecurityUtils;
-import com.pmease.gitplex.web.Constants;
-import com.pmease.gitplex.web.component.AccountLink;
-import com.pmease.gitplex.web.page.depot.DepotPage;
-import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
-import com.pmease.gitplex.web.util.DateUtils;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.navigation.BootstrapPagingNavigator;
-
-@SuppressWarnings("serial")
-public abstract class CodeCommentListPanel extends Panel {
-
- private final IModel<CodeCommentFilter> filterOptionModel;
-
- public CodeCommentListPanel(String id, IModel<CodeCommentFilter> filterOptionModel) {
- super(id);
-
- this.filterOptionModel = filterOptionModel;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new Link<Void>("myComments") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(SecurityUtils.getAccount() != null);
- }
-
- @Override
- public void onClick() {
- CodeCommentFilter filterOption = new CodeCommentFilter();
- filterOption.setUserName(SecurityUtils.getAccount().getName());
- filterOptionModel.setObject(filterOption);
- }
-
- });
- add(new Link<Void>("myUnresolvedComments") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(SecurityUtils.getAccount() != null);
- }
-
- @Override
- public void onClick() {
- CodeCommentFilter filterOption = new CodeCommentFilter();
- filterOption.setUserName(SecurityUtils.getAccount().getName());
- filterOption.setUnresolved(true);
- filterOptionModel.setObject(filterOption);
- }
-
- });
- add(new Link<Void>("unresolvedComments") {
-
- @Override
- public void onClick() {
- CodeCommentFilter filterOption = new CodeCommentFilter();
- filterOption.setUnresolved(true);
- filterOptionModel.setObject(filterOption);
- }
-
- });
- add(new Link<Void>("allComments") {
-
- @Override
- public void onClick() {
- filterOptionModel.setObject(new CodeCommentFilter());
- }
-
- });
- Form<?> filterForm = new Form<Void>("filterForm") {
-
- @Override
- protected void onSubmit() {
- super.onSubmit();
- }
-
- };
- filterForm.add(BeanContext.editModel("editor", filterOptionModel));
- add(filterForm);
-
- List<IColumn<CodeComment, Void>> columns = new ArrayList<>();
- columns.add(new AbstractColumn<CodeComment, Void>(Model.of("Code Comment")) {
-
- private void openComment(CodeComment comment) {
- Depot depot = ((DepotPage) getPage()).getDepot();
-
- PullRequest request = getPullRequest();
- if (request != null) {
- setResponsePage(RequestChangesPage.class, RequestChangesPage.paramsOf(request, comment));
- } else {
- CompareContext compareContext = comment.getLastCompareContext();
- if (!compareContext.getCompareCommit().equals(comment.getCommentPos().getCommit())) {
- setResponsePage(RevisionComparePage.class, RevisionComparePage.paramsOf(depot, comment));
- } else {
- setResponsePage(DepotFilePage.class, DepotFilePage.paramsOf(depot, comment));
- }
- }
- }
-
- @Override
- public void populateItem(Item<ICellPopulator<CodeComment>> cellItem,
- String componentId, IModel<CodeComment> rowModel) {
- CodeComment comment = rowModel.getObject();
- Fragment fragment = new Fragment(componentId, "commentFrag", CodeCommentListPanel.this);
- Link<Void> titleLink = new Link<Void>("title") {
-
- @Override
- public void onClick() {
- openComment(rowModel.getObject());
- }
-
- };
- titleLink.add(new Label("label", comment.getTitle()));
- fragment.add(titleLink);
- fragment.add(new WebMarkupContainer("resolved").setVisible(comment.isResolved()));
- fragment.add(new AccountLink("user", comment.getUser()));
-
- Link<Void> fileLink = new Link<Void>("file") {
-
- @Override
- public void onClick() {
- openComment(rowModel.getObject());
- }
-
- };
- fileLink.add(new Label("label", comment.getCommentPos().getPath()));
- fragment.add(fileLink);
-
- fragment.add(new Label("date", DateUtils.formatAge(comment.getDate())));
-
- WebMarkupContainer lastEventContainer = new WebMarkupContainer("lastEvent");
- if (comment.getLastEvent() != null) {
- String description = EditableUtils.getName(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));
- lastEventContainer.add(new Label("date", DateUtils.formatAge(comment.getLastEvent().getDate())));
- } else {
- lastEventContainer.add(new WebMarkupContainer("description"));
- lastEventContainer.add(new WebMarkupContainer("user"));
- lastEventContainer.add(new WebMarkupContainer("date"));
- lastEventContainer.setVisible(false);
- }
- fragment.add(lastEventContainer);
-
- cellItem.add(fragment);
-
- Date lastUpdateDate;
- if (comment.getLastEvent() != null)
- lastUpdateDate = comment.getLastEvent().getDate();
- else
- lastUpdateDate = comment.getDate();
- cellItem.add(AttributeAppender.append("class",
- comment.isVisitedAfter(lastUpdateDate)?"comment":"comment new"));
- }
-
- });
-
- IDataProvider<CodeComment> dataProvider = new IDataProvider<CodeComment>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public Iterator<? extends CodeComment> iterator(long first, long count) {
- DepotPage page = (DepotPage) getPage();
-
- if (getPullRequest() != null) {
- List<CodeComment> comments = new ArrayList<>(getPullRequest().getCodeComments());
- filterOptionModel.getObject().filter(comments);
- return comments.iterator();
- } else {
- EntityCriteria<CodeComment> criteria = EntityCriteria.of(CodeComment.class);
- criteria.add(Restrictions.eq("depot", page.getDepot()));
- filterOptionModel.getObject().fill(criteria);
- criteria.addOrder(Order.desc("id"));
- return GitPlex.getInstance(Dao.class).findRange(criteria, (int)first, (int)count).iterator();
- }
- }
-
- @Override
- public long size() {
- DepotPage page = (DepotPage) getPage();
-
- if (getPullRequest() != null) {
- return getPullRequest().getCodeComments().size();
- } else {
- EntityCriteria<CodeComment> criteria = EntityCriteria.of(CodeComment.class);
- criteria.add(Restrictions.eq("depot", page.getDepot()));
- filterOptionModel.getObject().fill(criteria);
- return GitPlex.getInstance(Dao.class).count(criteria);
- }
- }
-
- @Override
- public IModel<CodeComment> model(CodeComment object) {
- Long commentId = object.getId();
- return new LoadableDetachableModel<CodeComment>() {
-
- @Override
- protected CodeComment load() {
- return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
- }
-
- };
- }
-
- };
- DataTable<CodeComment, Void> dataTable = new DataTable<>("comments", columns,
- dataProvider, getPullRequest()!=null?Integer.MAX_VALUE:Constants.DEFAULT_PAGE_SIZE);
- dataTable.addBottomToolbar(new NoRecordsToolbar(dataTable));
- dataTable.addBottomToolbar(new NavigationToolbar(dataTable) {
-
- @Override
- protected PagingNavigator newPagingNavigator(String navigatorId, DataTable<?, ?> table) {
- return new BootstrapPagingNavigator(navigatorId, dataTable);
- }
-
- });
- add(dataTable);
-
- if (getPullRequest() != null && dataTable.getItemCount() > PullRequest.MAX_CODE_COMMENTS) {
- add(new Label("alert", "Too many code comments, only displaying " + PullRequest.MAX_CODE_COMMENTS));
- } else {
- add(new WebMarkupContainer("alert").setVisible(false));
- }
- }
-
- @Override
- protected void onDetach() {
- filterOptionModel.detach();
- super.onDetach();
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(CssHeaderItem.forReference(new CodeCommentListResourceReference()));
- }
-
- @Nullable
- protected abstract PullRequest getPullRequest();
-
-}
+package com.pmease.gitplex.web.component.comment;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.Nullable;
+
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
+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.data.table.NavigationToolbar;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.NoRecordsToolbar;
+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.Form;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.html.navigation.paging.PagingNavigator;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.data.IDataProvider;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.model.Model;
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
+
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.wicket.editable.BeanContext;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.support.CompareContext;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
+import com.pmease.gitplex.core.security.SecurityUtils;
+import com.pmease.gitplex.web.Constants;
+import com.pmease.gitplex.web.component.AccountLink;
+import com.pmease.gitplex.web.page.depot.DepotPage;
+import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
+import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
+import com.pmease.gitplex.web.util.DateUtils;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.navigation.BootstrapPagingNavigator;
+
+@SuppressWarnings("serial")
+public abstract class CodeCommentListPanel extends Panel {
+
+ private final IModel<CodeCommentFilter> filterOptionModel;
+
+ public CodeCommentListPanel(String id, IModel<CodeCommentFilter> filterOptionModel) {
+ super(id);
+
+ this.filterOptionModel = filterOptionModel;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new Link<Void>("myComments") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(SecurityUtils.getAccount() != null);
+ }
+
+ @Override
+ public void onClick() {
+ CodeCommentFilter filterOption = new CodeCommentFilter();
+ filterOption.setUserName(SecurityUtils.getAccount().getName());
+ filterOptionModel.setObject(filterOption);
+ }
+
+ });
+ add(new Link<Void>("myUnresolvedComments") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(SecurityUtils.getAccount() != null);
+ }
+
+ @Override
+ public void onClick() {
+ CodeCommentFilter filterOption = new CodeCommentFilter();
+ filterOption.setUserName(SecurityUtils.getAccount().getName());
+ filterOption.setUnresolved(true);
+ filterOptionModel.setObject(filterOption);
+ }
+
+ });
+ add(new Link<Void>("unresolvedComments") {
+
+ @Override
+ public void onClick() {
+ CodeCommentFilter filterOption = new CodeCommentFilter();
+ filterOption.setUnresolved(true);
+ filterOptionModel.setObject(filterOption);
+ }
+
+ });
+ add(new Link<Void>("allComments") {
+
+ @Override
+ public void onClick() {
+ filterOptionModel.setObject(new CodeCommentFilter());
+ }
+
+ });
+ Form<?> filterForm = new Form<Void>("filterForm") {
+
+ @Override
+ protected void onSubmit() {
+ super.onSubmit();
+ }
+
+ };
+ filterForm.add(BeanContext.editModel("editor", filterOptionModel));
+ add(filterForm);
+
+ List<IColumn<CodeComment, Void>> columns = new ArrayList<>();
+ columns.add(new AbstractColumn<CodeComment, Void>(Model.of("Code Comment")) {
+
+ private void openComment(CodeComment comment) {
+ Depot depot = ((DepotPage) getPage()).getDepot();
+
+ PullRequest request = getPullRequest();
+ if (request != null) {
+ setResponsePage(RequestChangesPage.class, RequestChangesPage.paramsOf(request, comment, null));
+ } else {
+ CompareContext compareContext = comment.getLastCompareContext();
+ if (!compareContext.getCompareCommit().equals(comment.getCommentPos().getCommit())) {
+ setResponsePage(RevisionComparePage.class, RevisionComparePage.paramsOf(depot, comment, null));
+ } else {
+ setResponsePage(DepotFilePage.class, DepotFilePage.paramsOf(depot, comment, null));
+ }
+ }
+ }
+
+ @Override
+ public void populateItem(Item<ICellPopulator<CodeComment>> cellItem,
+ String componentId, IModel<CodeComment> rowModel) {
+ CodeComment comment = rowModel.getObject();
+ Fragment fragment = new Fragment(componentId, "commentFrag", CodeCommentListPanel.this);
+ Link<Void> titleLink = new Link<Void>("title") {
+
+ @Override
+ public void onClick() {
+ openComment(rowModel.getObject());
+ }
+
+ };
+ titleLink.add(new Label("label", comment.getTitle()));
+ fragment.add(titleLink);
+ fragment.add(new WebMarkupContainer("resolved").setVisible(comment.isResolved()));
+ fragment.add(new AccountLink("user", comment.getUser()));
+
+ Link<Void> fileLink = new Link<Void>("file") {
+
+ @Override
+ public void onClick() {
+ openComment(rowModel.getObject());
+ }
+
+ };
+ fileLink.add(new Label("label", comment.getCommentPos().getPath()));
+ fragment.add(fileLink);
+
+ fragment.add(new Label("date", DateUtils.formatAge(comment.getDate())));
+
+ WebMarkupContainer lastEventContainer = new WebMarkupContainer("lastEvent");
+ 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));
+ lastEventContainer.add(new Label("date", DateUtils.formatAge(comment.getLastEvent().getDate())));
+ } else {
+ lastEventContainer.add(new WebMarkupContainer("description"));
+ lastEventContainer.add(new WebMarkupContainer("user"));
+ lastEventContainer.add(new WebMarkupContainer("date"));
+ lastEventContainer.setVisible(false);
+ }
+ fragment.add(lastEventContainer);
+
+ cellItem.add(fragment);
+
+ Date lastUpdateDate;
+ if (comment.getLastEvent() != null)
+ lastUpdateDate = comment.getLastEvent().getDate();
+ else
+ lastUpdateDate = comment.getDate();
+ cellItem.add(AttributeAppender.append("class",
+ comment.isVisitedAfter(lastUpdateDate)?"comment":"comment new"));
+ }
+
+ });
+
+ IDataProvider<CodeComment> dataProvider = new IDataProvider<CodeComment>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public Iterator<? extends CodeComment> iterator(long first, long count) {
+ DepotPage page = (DepotPage) getPage();
+
+ if (getPullRequest() != null) {
+ List<CodeComment> comments = new ArrayList<>(getPullRequest().getCodeComments());
+ filterOptionModel.getObject().filter(comments);
+ return comments.iterator();
+ } else {
+ EntityCriteria<CodeComment> criteria = EntityCriteria.of(CodeComment.class);
+ criteria.add(Restrictions.eq("depot", page.getDepot()));
+ filterOptionModel.getObject().fill(criteria);
+ criteria.addOrder(Order.desc("id"));
+ return GitPlex.getInstance(Dao.class).findRange(criteria, (int)first, (int)count).iterator();
+ }
+ }
+
+ @Override
+ public long size() {
+ DepotPage page = (DepotPage) getPage();
+
+ if (getPullRequest() != null) {
+ return getPullRequest().getCodeComments().size();
+ } else {
+ EntityCriteria<CodeComment> criteria = EntityCriteria.of(CodeComment.class);
+ criteria.add(Restrictions.eq("depot", page.getDepot()));
+ filterOptionModel.getObject().fill(criteria);
+ return GitPlex.getInstance(Dao.class).count(criteria);
+ }
+ }
+
+ @Override
+ public IModel<CodeComment> model(CodeComment object) {
+ Long commentId = object.getId();
+ return new LoadableDetachableModel<CodeComment>() {
+
+ @Override
+ protected CodeComment load() {
+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ }
+
+ };
+ }
+
+ };
+ DataTable<CodeComment, Void> dataTable = new DataTable<>("comments", columns,
+ dataProvider, getPullRequest()!=null?Integer.MAX_VALUE:Constants.DEFAULT_PAGE_SIZE);
+ dataTable.addBottomToolbar(new NoRecordsToolbar(dataTable));
+ dataTable.addBottomToolbar(new NavigationToolbar(dataTable) {
+
+ @Override
+ protected PagingNavigator newPagingNavigator(String navigatorId, DataTable<?, ?> table) {
+ return new BootstrapPagingNavigator(navigatorId, dataTable);
+ }
+
+ });
+ add(dataTable);
+
+ if (getPullRequest() != null && dataTable.getItemCount() > PullRequest.MAX_CODE_COMMENTS) {
+ add(new Label("alert", "Too many code comments, only displaying " + PullRequest.MAX_CODE_COMMENTS));
+ } else {
+ add(new WebMarkupContainer("alert").setVisible(false));
+ }
+ }
+
+ @Override
+ protected void onDetach() {
+ filterOptionModel.detach();
+ super.onDetach();
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+ response.render(CssHeaderItem.forReference(new CodeCommentListResourceReference()));
+ }
+
+ @Nullable
+ protected abstract PullRequest getPullRequest();
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java
index 39652b54dc..71a5229224 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CodeCommentPanel.java
@@ -307,6 +307,7 @@ public abstract class CodeCommentPanel extends Panel {
ActivityIdentity identity = new ActivityIdentity(activity);
Fragment activityContainer = new Fragment(componentId, "viewFrag", this, Model.of(identity));
activityContainer.setOutputMarkupId(true);
+ activityContainer.setMarkupId(activity.getAnchor());
activityContainer.add(new AvatarLink("userAvatar", activity.getUser()));
activityContainer.add(new AccountLink("userName", activity.getUser()));
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/CompareContextPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/CompareContextPanel.html
new file mode 100644
index 0000000000..27cba32468
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/CompareContextPanel.html
@@ -0,0 +1,15 @@
+<wicket:panel>
+ <div wicket:id="content"></div>
+ <wicket:fragment wicket:id="requestFrag">
+ <ul class="compare-context list-unstyled">
+ <li wicket:id="commits">
+ <a wicket:id="link">
+ <span class="fa fa-ext fa-commit icon"></span>
+ <span wicket:id="hash" class="hash"></span>
+ <span wicket:id="subject" class="subject"></span>
+ <span wicket:id="commented" class="fa fa-commenting" title="Comment is associated with this commit "></span>
+ </a>
+ </li>
+ </ul>
+ </wicket:fragment>
+</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/CompareContextPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/CompareContextPanel.java
new file mode 100644
index 0000000000..f08dcea5ff
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/CompareContextPanel.java
@@ -0,0 +1,162 @@
+package com.pmease.gitplex.web.component.comment.comparecontext;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+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.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 org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.eclipse.jgit.revwalk.RevCommit;
+
+import com.pmease.commons.git.GitUtils;
+import com.pmease.commons.lang.diff.WhitespaceOption;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.support.DepotAndRevision;
+import com.pmease.gitplex.web.component.revisionpicker.RevisionSelector;
+import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
+
+@SuppressWarnings("serial")
+public class CompareContextPanel extends Panel {
+
+ private final IModel<PullRequest> requestModel;
+
+ private final IModel<CodeComment> commentModel;
+
+ private final IModel<String> pathFilterModel;
+
+ private final IModel<WhitespaceOption> whitespaceOptionModel;
+
+ public CompareContextPanel(String id, IModel<PullRequest> requestModel, IModel<CodeComment> commentModel,
+ IModel<String> pathFilterModel, IModel<WhitespaceOption> whitespaceOptionModel) {
+ super(id);
+ this.requestModel = requestModel;
+ this.commentModel = commentModel;
+ this.pathFilterModel = pathFilterModel;
+ this.whitespaceOptionModel = whitespaceOptionModel;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ if (requestModel.getObject() != null) {
+ Fragment fragment = new Fragment("content", "requestFrag", this);
+ add(fragment);
+
+ IModel<List<RevCommit>> commitsModel = new LoadableDetachableModel<List<RevCommit>>() {
+
+ @Override
+ protected List<RevCommit> load() {
+ List<RevCommit> commits = new ArrayList<>();
+ PullRequest request = requestModel.getObject();
+ commits.add(request.getBaseCommit());
+ commits.addAll(request.getCommits());
+ return commits;
+ }
+
+ };
+
+ fragment.add(new ListView<RevCommit>("commits", commitsModel) {
+
+ @Override
+ protected void populateItem(ListItem<RevCommit> item) {
+ RevCommit commit = item.getModelObject();
+ AjaxLink<Void> link = new AjaxLink<Void>("link") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ RequestChangesPage.State state = new RequestChangesPage.State();
+ CodeComment comment = commentModel.getObject();
+ state.commentId = comment.getId();
+ state.mark = comment.getCommentPos();
+ int index = commitsModel.getObject().stream().map(RevCommit::getName).collect(Collectors.toList())
+ .indexOf(comment.getCommentPos().getCommit());
+ int compareIndex = commitsModel.getObject().indexOf(commit);
+ if (index < compareIndex) {
+ state.oldCommit = comment.getCommentPos().getCommit();
+ state.newCommit = commit.name();
+ } else {
+ state.oldCommit = commit.name();
+ state.newCommit = comment.getCommentPos().getCommit();
+ }
+ state.pathFilter = pathFilterModel.getObject();
+ state.whitespaceOption = whitespaceOptionModel.getObject();
+ PageParameters params = RequestChangesPage.paramsOf(requestModel.getObject(), state);
+ setResponsePage(RequestChangesPage.class, params);
+ }
+
+ };
+ link.add(new Label("hash", GitUtils.abbreviateSHA(commit.name())));
+ link.add(new Label("subject", commit.getShortMessage()));
+ if (commit.name().equals(commentModel.getObject().getCommentPos().getCommit())) {
+ link.setEnabled(false);
+ link.add(AttributeAppender.append("class", "commented"));
+ link.add(new WebMarkupContainer("commented"));
+ } else {
+ link.add(new WebMarkupContainer("commented").setVisible(false));
+ }
+ item.add(link);
+ }
+
+ });
+ } else {
+ add(new RevisionSelector("content", new AbstractReadOnlyModel<Depot>() {
+
+ @Override
+ public Depot getObject() {
+ return commentModel.getObject().getDepot();
+ }
+
+ }) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, String revision) {
+ RevisionComparePage.State state = new RevisionComparePage.State();
+ CodeComment comment = commentModel.getObject();
+ state.commentId = comment.getId();
+ state.mark = comment.getCommentPos();
+ state.compareWithMergeBase = false;
+ state.leftSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());
+ state.rightSide = new DepotAndRevision(comment.getDepot(), revision);
+ state.tabPanel = RevisionComparePage.TabPanel.CHANGES;
+ PageParameters params = RevisionComparePage.paramsOf(comment.getDepot(), state);
+ setResponsePage(RevisionComparePage.class, params);
+ }
+
+ });
+ }
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+ response.render(CssHeaderItem.forReference(new CompareContextResourceReference()));
+ }
+
+ @Override
+ protected void onDetach() {
+ commentModel.detach();
+ requestModel.detach();
+ pathFilterModel.detach();
+ whitespaceOptionModel.detach();
+
+ super.onDetach();
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/CompareContextResourceReference.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/CompareContextResourceReference.java
new file mode 100644
index 0000000000..b7730316f7
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/CompareContextResourceReference.java
@@ -0,0 +1,13 @@
+package com.pmease.gitplex.web.component.comment.comparecontext;
+
+import com.pmease.gitplex.web.page.base.BaseDependentCssResourceReference;
+
+public class CompareContextResourceReference extends BaseDependentCssResourceReference {
+
+ private static final long serialVersionUID = 1L;
+
+ public CompareContextResourceReference() {
+ super(CompareContextResourceReference.class, "compare-context.css");
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/compare-context.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/compare-context.css
new file mode 100644
index 0000000000..3813594ae9
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/comparecontext/compare-context.css
@@ -0,0 +1,21 @@
+.compare-context {
+ margin-bottom: 0;
+}
+.compare-context a {
+ text-decoration: none;
+ display: block;
+ color: #333;
+ padding: 4px 8px;
+ white-space: nowrap;
+ font-family: monospace;
+}
+.compare-context a:hover {
+ background: #F2F2F2;
+}
+.compare-context a.commented {
+ background: white;
+ cursor: default;
+}
+.compare-context a .hash, .compare-context .icon {
+ color: #666;
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java
index 5d828c5079..5537f6b521 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/BlobViewContext.java
@@ -29,6 +29,9 @@ public interface BlobViewContext extends Serializable {
@Nullable
TextRange getMark();
+ @Nullable
+ String getAnchor();
+
void onMark(AjaxRequestTarget target, TextRange mark);
String getMarkUrl(TextRange mark);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java
index 0979b2215f..3f379cca9d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/SourceViewPanel.java
@@ -78,7 +78,6 @@ import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.core.entity.support.CommentPos;
import com.pmease.gitplex.core.entity.support.CompareContext;
-import com.pmease.gitplex.core.entity.support.DepotAndRevision;
import com.pmease.gitplex.core.entity.support.TextRange;
import com.pmease.gitplex.core.manager.CodeCommentManager;
import com.pmease.gitplex.core.security.SecurityUtils;
@@ -86,13 +85,12 @@ import com.pmease.gitplex.search.hit.QueryHit;
import com.pmease.gitplex.web.component.comment.CodeCommentPanel;
import com.pmease.gitplex.web.component.comment.CommentInput;
import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
+import com.pmease.gitplex.web.component.comment.comparecontext.CompareContextPanel;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewContext.Mode;
import com.pmease.gitplex.web.component.depotfile.blobview.BlobViewPanel;
-import com.pmease.gitplex.web.component.revisionpicker.RevisionSelector;
import com.pmease.gitplex.web.component.symboltooltip.SymbolTooltipPanel;
import com.pmease.gitplex.web.page.depot.commit.CommitDetailPage;
-import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
import com.pmease.gitplex.web.util.DateUtils;
@@ -312,30 +310,22 @@ public class SourceViewPanel extends BlobViewPanel {
@Override
protected Component newContent(String id) {
- return new RevisionSelector(id, new AbstractReadOnlyModel<Depot>() {
+ CompareContext compareContext = context.getOpenComment().getCompareContext();
+ return new CompareContextPanel(id, new AbstractReadOnlyModel<PullRequest>() {
@Override
- public Depot getObject() {
- return context.getDepot();
+ public PullRequest getObject() {
+ return context.getPullRequest();
}
- }) {
-
+ }, new AbstractReadOnlyModel<CodeComment>() {
+
@Override
- protected void onSelect(AjaxRequestTarget target, String revision) {
- RevisionComparePage.State state = new RevisionComparePage.State();
- CodeComment comment = context.getOpenComment();
- state.commentId = comment.getId();
- state.mark = comment.getCommentPos();
- state.compareWithMergeBase = false;
- state.leftSide = new DepotAndRevision(context.getDepot(), comment.getCommentPos().getCommit());
- state.rightSide = new DepotAndRevision(context.getDepot(), revision);
- state.tabPanel = RevisionComparePage.TabPanel.CHANGES;
- PageParameters params = RevisionComparePage.paramsOf(context.getDepot(), state);
- setResponsePage(RevisionComparePage.class, params);
+ public CodeComment getObject() {
+ return context.getOpenComment();
}
- };
+ }, Model.of(compareContext.getPathFilter()), Model.of(compareContext.getWhitespaceOption()));
}
});
@@ -923,7 +913,7 @@ public class SourceViewPanel extends BlobViewPanel {
explicit("param3"), explicit("param4"));
String viewState = RequestCycle.get().getMetaData(DepotFilePage.VIEW_STATE_KEY);
String script = String.format("gitplex.sourceview.init('%s', '%s', %s, %s, '%s', '%s', "
- + "%s, %s, %s, %s, %s);",
+ + "%s, %s, %s, %s, %s, %s);",
JavaScriptEscape.escapeJavaScript(blob.getText().getContent()),
JavaScriptEscape.escapeJavaScript(context.getBlobIdent().path),
context.getOpenComment()!=null?getJsonOfComment(context.getOpenComment()):"undefined",
@@ -934,7 +924,8 @@ public class SourceViewPanel extends BlobViewPanel {
jsonOfCommentInfos,
callback,
viewState!=null?"JSON.parse('"+viewState+"')":"undefined",
- SecurityUtils.getAccount()!=null);
+ SecurityUtils.getAccount()!=null,
+ context.getAnchor()!=null?"'"+context.getAnchor()+"'":"undefined");
response.render(OnDomReadyHeaderItem.forScript(script));
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
index 92130c0b98..30c49e0e3e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/depotfile/blobview/source/source-view.js
@@ -1,530 +1,538 @@
-gitplex.sourceview = {
- init: function(fileContent, filePath, openComment, mark, symbolTooltipId,
- revision, blameInfos, comments, markCallback, viewState, loggedIn) {
- var cm;
-
- var $sourceView = $(".source-view");
- if (openComment)
- $sourceView.data("openComment", openComment);
- if (mark)
- $sourceView.data("mark", mark);
-
- $sourceView.data("markCallback", markCallback);
-
- var $code = $sourceView.children(".code");
- $sourceView.closest(".content").css("overflow", "visible");
-
- function repositionCommentPopovers() {
- $(".comment-popover:visible").each(function() {
- var $popover = $(this);
- var lineInfo = cm.lineInfo($popover.data("line"));
- if (lineInfo.gutterMarkers) {
- var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
- if (gutter) {
- var $indicator = $(gutter).children("a");
- if ($indicator.offset().top+$indicator.height() < $sourceView.offset().top
- || $indicator.offset().top > $sourceView.offset().top+$sourceView.height()) {
- $popover.css("left", "-10000px");
- } else {
- $popover.css({
- "left": $indicator.offset().left + $indicator.outerWidth() - $sourceView.offset().left,
- "top": $indicator.offset().top + ($indicator.outerHeight() - $popover.outerHeight())/2 - $sourceView.offset().top
- });
- }
- }
- }
- });
- }
-
- $sourceView.on("storeViewState", function(event) {
- event.stopPropagation();
- if (cm) {
- pmease.commons.history.setViewState(pmease.commons.codemirror.getViewState(cm));
- }
- });
-
- $sourceView.on("autofit", function(event, width, height) {
- event.stopPropagation();
- $sourceView.outerWidth(width);
- $sourceView.outerHeight(height);
- $code.outerHeight($sourceView.height());
-
- var $comment = $sourceView.children(".comment");
- var paddingLeft;
- if ($comment.is(":visible")) {
- paddingLeft = $comment.outerWidth();
- $comment.children(".ui-resizable-handle").outerHeight($sourceView.height());
-
- var $commentHead = $comment.find(">.content>.head");
- var $commentBody = $comment.find(">.content>.body");
- $commentBody.outerHeight($sourceView.height() - $commentHead.outerHeight());
- } else {
- paddingLeft = 0;
- }
- $sourceView.css("padding-left", paddingLeft);
-
- var $outline = $sourceView.children(".outline");
- if ($outline.is(":visible")) {
- $sourceView.css("padding-right", $outline.outerWidth());
- $outline.css("left", $code.outerWidth() + paddingLeft);
- $outline.children(".ui-resizable-handle").outerHeight($sourceView.height());
-
- var $outlineHead = $outline.find(">.content>.head");
- var $outlineBody = $outline.find(">.content>.body");
- $outlineBody.outerHeight($sourceView.height() - $outlineHead.outerHeight());
- } else {
- $sourceView.css("padding-right", "0");
- }
-
- /*
- * initialize codemirror here when we know the container width and height
- * as otherwise the annotatescrollbar addon is inaccurate when window
- * initially loads
- */
- var initState = !cm;
- if (!cm) {
- var options = {
- value: fileContent,
- readOnly: pmease.commons.isDevice()?"nocursor":true,
- theme: "eclipse",
- lineNumbers: true,
- lineWrapping: true,
- styleActiveLine: true,
- styleSelectedText: true,
- foldGutter: true,
- matchBrackets: true,
- scrollbarStyle: "simple",
- highlightIdentifiers: {delay: 500},
- gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
- extraKeys: {
- "F11": function(cm) {
- cm.setOption("fullScreen", !cm.getOption("fullScreen"));
- },
- "Esc": function(cm) {
- if (cm.getOption("fullScreen"))
- cm.setOption("fullScreen", false);
- }
- }
- };
-
- cm = CodeMirror($code[0], options);
- pmease.commons.codemirror.setMode(cm, filePath);
-
- // add gutters with a timer to avoid the issue that occasionally
- // gutter becomes much wider than expected
- setTimeout(function() {
- var gutters = cm.getOption("gutters").slice();
- gutters.splice(0, 0, "CodeMirror-comments");
- cm.setOption("gutters", gutters);
- for (var line in comments) {
- if (comments.hasOwnProperty(line)) {
- gitplex.sourceview.addCommentGutter(line, comments[line][1]);
- }
- }
-
- if (blameInfos) {
- gitplex.sourceview.blame(blameInfos);
- }
- gitplex.sourceview.highlightCommentTrigger();
- }, 10);
-
- $code.selectionPopover("init", function() {
- if (cm.hasFocus()) {
- var from = cm.getCursor("from");
- var to = cm.getCursor("to");
- if (from.line != to.line || from.ch != to.ch) {
- markCallback("openSelectionPopover", from.line, from.ch, to.line, to.ch);
- return;
- }
- }
- return "close";
- });
-
- $code.mouseover(function(e) {
- var node = e.target || e.srcElement, $node = $(node);
- if ($node.hasClass("cm-property") || $node.hasClass("cm-variable") || $node.hasClass("cm-variable-2")
- || $node.hasClass("cm-variable-3") || $node.hasClass("cm-def") || $node.hasClass("cm-meta")) {
- document.getElementById(symbolTooltipId).onMouseOverSymbol(revision, node);
- }
- });
- cm.setSize($code.width(), $code.height());
- if (mark)
- pmease.commons.codemirror.mark(cm, mark, true);
- if (initState) // restore cursor and scroll
- pmease.commons.codemirror.initState(cm, viewState);
- cm.on("scroll", function() {
- gitplex.symboltooltip.removeTooltip(document.getElementById(symbolTooltipId));
- gitplex.mouseState.moved = false;
- repositionCommentPopovers(cm);
- });
- } else {
- cm.setSize($code.width(), $code.height());
- if (cm.getOption("fullScreen"))
- cm.setOption("fullScreen", false);
- repositionCommentPopovers(cm);
- }
- });
- },
- initComment: function() {
- var $sourceView = $(".source-view");
- var $code = $sourceView.children(".code");
- var commentWidthCookieKey = "sourceView.comment.width";
- var $comment = $sourceView.children(".comment");
- var commentWidth = Cookies.get(commentWidthCookieKey);
- if (!commentWidth)
- commentWidth = 400;
- $comment.outerWidth(commentWidth);
- var $commentResizeHandle = $comment.children(".ui-resizable-handle");
- $comment.resizable({
- autoHide: false,
- handles: {"e": $commentResizeHandle},
- minWidth: 200,
- resize: function(e, ui) {
- var codeWidth = $code.outerWidth();
- if(codeWidth < 300)
- $(this).resizable({maxWidth: ui.size.width});
- },
- stop: function(e, ui) {
- $(this).resizable({maxWidth: undefined});
- Cookies.set(commentWidthCookieKey, ui.size.width, {expires: Infinity});
- }
- });
- },
- initOutline: function() {
- var $sourceView = $(".source-view");
- var $code = $sourceView.children(".code");
- var outlineWidthCookieKey = "sourceView.outline.width";
- var $outline = $sourceView.children(".outline");
- var outlineWidth = Cookies.get(outlineWidthCookieKey);
- if (!outlineWidth)
- outlineWidth = 350;
- $outline.outerWidth(outlineWidth);
- var $outlineResizeHandle = $outline.children(".ui-resizable-handle");
- $outline.resizable({
- autoHide: false,
- handles: {"w": $outlineResizeHandle},
- minWidth: 100,
- resize: function(e, ui) {
- var codeWidth = $code.outerWidth();
- if(codeWidth < 300)
- $(this).resizable({maxWidth: ui.size.width});
- },
- stop: function(e, ui) {
- $(this).resizable({maxWidth: undefined});
- Cookies.set(outlineWidthCookieKey, ui.size.width, {expires: Infinity});
- }
- });
- },
- showBlameMessage: function(tooltipId, message) {
- var $blameTooltip = $("#" + tooltipId);
- $blameTooltip.empty().text(message);
- $blameTooltip.align({placement: $blameTooltip.data("alignment"), target: {element: $blameTooltip.data("trigger")}});
- },
- restoreMark: function() {
- var $sourceView = $(".source-view");
- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var mark = $sourceView.data("mark");
- if (mark) {
- pmease.commons.codemirror.mark(cm, mark, false);
- } else {
- pmease.commons.codemirror.clearMark(cm);
- }
- },
- addCommentGutter: function(line, comments) {
- $(".comment-popover[data-line='" + line + "']").remove();
-
- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var markCallback = $(".source-view").data("markCallback");
-
- var $gutter = $(document.createElement("div"));
- $gutter.addClass("CodeMirror-comment");
- $gutter.data("comments", comments);
- if (comments.length != 1) {
- /*
- * when there are multiple comments starts with the same line, we should
- * display a comment indicator which will display a comment popover with
- * list of comment triggers upon click, user can then click one of the
- * trigger link to display the actual comment content
- */
- $gutter.append("<a><i class='fa fa-comments'></i></a>");
- var $indicator = $gutter.children("a");
- var content = "";
- for (var i in comments) {
- var comment = comments[i];
- var index = parseInt(i) + 1;
- content += "<a class='comment-trigger' title='Click to show details of this comment'>" + comment.title + "</a>";
- }
- $indicator.popover({
- html: true,
- container: ".source-view",
- placement: "right auto",
- template: "<div data-line='" + line + "' class='popover comment-popover'><div class='arrow'></div><div class='popover-content'></div></div>",
- content: content
- });
- $indicator.on('shown.bs.popover', function () {
- $(".comment-popover[data-line='" + line + "'] a").each(function() {
- $(this).mouseover(function() {
- var comment = comments[$(this).index()];
- pmease.commons.codemirror.mark(cm, comment.mark, false);
- });
- $(this).mouseout(function() {
- gitplex.sourceview.restoreMark();
- });
- $(this).click(function() {
- if ($(".source-view form.dirty").length != 0
- && !confirm("There are unsaved changes, discard and continue?")) {
- return;
- }
- var comment = comments[$(this).index()];
- markCallback("openComment", comment.id);
- });
- });
- gitplex.sourceview.highlightCommentTrigger();
- });
- } else {
- var comment = comments[0];
- $gutter.append("<a class='comment-trigger' title='Click to show comment of marked text'><i class='fa fa-commenting'></i></a>");
- var $indicator = $gutter.children("a");
- $indicator.mouseover(function() {
- pmease.commons.codemirror.mark(cm, comment.mark, false);
- });
- $indicator.mouseout(function() {
- gitplex.sourceview.restoreMark();
- });
- $indicator.click(function() {
- if ($(".source-view form.dirty").length != 0
- && !confirm("There are unsaved changes, discard and continue?")) {
- return;
- }
- markCallback("openComment", comment.id);
- });
- }
- cm.setGutterMarker(parseInt(line), "CodeMirror-comments", $gutter[0]);
- },
- openSelectionPopover: function(mark, markUrl, loggedIn) {
- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var ch = (mark.beginChar + mark.endChar)/2;
- var position = cm.charCoords({line:mark.beginLine, ch:ch});
-
- var $content = $("<div><a class='permanent'><i class='fa fa-link'></i> Permanent link of this selection</a>");
- $content.children("a.permanent").attr("href", markUrl);
- if (loggedIn) {
- $content.append("<a class='comment'><i class='fa fa-comment'></i> Add comment on this selection</a>");
- $content.children("a.comment").click(function() {
- if ($(".source-view").find("form.dirty").length != 0
- && !confirm("There are unsaved changes, discard and continue?")) {
- return;
- }
- var markCallback = $(".source-view").data("markCallback");
- markCallback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);
- });
- } else {
- $content.append("<span class='comment'><i class='fa fa-warning'></i> Log in to comment on selection</span>");
- }
-
- $(".source-view>.code").selectionPopover("open", {
- position: position,
- content: $content
- });
- },
- onCommentAdded: function(comment) {
- var $sourceView = $(".source-view");
- $sourceView.data("openComment", comment);
- $sourceView.data("mark", comment.mark);
-
- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var line = parseInt(comment.mark.beginLine);
- var lineInfo = cm.lineInfo(line);
- var gutter;
- if (lineInfo.gutterMarkers)
- gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
- var comments;
- if (gutter) {
- comments = $(gutter).data("comments");
- } else {
- comments = [];
- }
- comments.push(comment);
- gitplex.sourceview.addCommentGutter(line, comments);
- gitplex.sourceview.highlightCommentTrigger();
- gitplex.sourceview.onLayoutChange();
- },
- onCommentDeleted: function(comment) {
- var $sourceView = $(".source-view");
- $sourceView.removeData("openComment");
-
- var line = parseInt(comment.mark.beginLine);
- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var lineInfo = cm.lineInfo(line);
- var $gutter = $(lineInfo.gutterMarkers["CodeMirror-comments"]);
- var comments = $gutter.data("comments");
- if (comments.length == 1) {
- cm.setGutterMarker(line, "CodeMirror-comments", null);
- } else {
- for (var i in comments) {
- if (comments[i].id == comment.id) {
- comments.splice(i, 1);
- break;
- }
- }
- gitplex.sourceview.addCommentGutter(line, comments);
- }
- gitplex.sourceview.highlightCommentTrigger();
- gitplex.sourceview.onLayoutChange();
-
- // make sure marked text is in view port after changing layout
- var mark = $sourceView.data("mark");
- if (mark)
- gitplex.sourceview.mark(mark, true);
- },
- onLayoutChange: function() {
- $sourceView = $('.source-view');
- $sourceView.trigger('autofit', [$sourceView.outerWidth(), $sourceView.outerHeight()]);
- },
- onAddComment: function(mark) {
- var $sourceView = $(".source-view");
- $sourceView.removeData("openComment");
- $sourceView.data("mark", mark);
- $(".source-view>.code").selectionPopover("close");
-
- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- pmease.commons.codemirror.clearSelection(cm);
- gitplex.sourceview.onLayoutChange();
-
- // mark and scroll after changing layout to make sure scroll
- // works correctly
- pmease.commons.codemirror.mark(cm, mark, true);
-
- gitplex.sourceview.highlightCommentTrigger();
- },
- onOpenComment: function(comment) {
- var $sourceView = $(".source-view");
- $sourceView.data("openComment", comment);
- $sourceView.data("mark", comment.mark);
- gitplex.sourceview.highlightCommentTrigger();
- gitplex.sourceview.onLayoutChange();
-
- // mark and scroll after changing layout to make sure scroll
- // works correctly
- gitplex.sourceview.mark(comment.mark, true);
- },
- onCloseComment: function() {
- var $sourceView = $(".source-view");
- $sourceView.removeData("openComment");
- gitplex.sourceview.highlightCommentTrigger();
- gitplex.sourceview.onLayoutChange();
-
- // make sure marked text is in view port after layout change
- var mark = $sourceView.data("mark");
- if (mark) {
- gitplex.sourceview.mark(mark, true);
- }
- },
- onToggleOutline: function() {
- gitplex.sourceview.onLayoutChange();
- },
- highlightCommentTrigger: function() {
- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- $(".comment-popover a").removeClass("active");
-
- /*
- * we can not simply select all comment triggers via jQuery
- * as comment gutter may be create/destroy dynamically by
- * CodeMirror
- */
- for (var i=0; i<cm.lineCount(); i++) {
- var gutterMarkers = cm.lineInfo(i).gutterMarkers;
- if (gutterMarkers) {
- var gutter = gutterMarkers["CodeMirror-comments"];
- if (gutter) {
- $(gutter).children("a").removeClass("active");
- }
- }
- }
-
- var openComment = $(".source-view").data("openComment");
- if (openComment) {
- var line = parseInt(openComment.mark.beginLine);
- var lineInfo = cm.lineInfo(line);
- if (lineInfo && lineInfo.gutterMarkers) {
- var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
- if (gutter) {
- var comments = $(gutter).data("comments");
- if (comments.length == 1) {
- $(gutter).children("a").addClass("active");
- } else {
- $(".comment-popover[data-line='" + line + "'] a").each(function() {
- var comment = comments[$(this).index()];
- if (comment.id == openComment.id) {
- $(this).addClass("active");
- }
- });
- }
- }
- }
- }
- },
- mark: function(mark, scroll) {
- $(".source-view").data("mark", mark);
- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- pmease.commons.codemirror.mark(cm, mark, scroll);
- },
- blame: function(blameInfos) {
- var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
- var alignment = {targetX: 100, targetY: 100, x: 0, y: 0};
-
- if (blameInfos) {
- var markCallback = $(".source-view").data("markCallback");
- var gutters = cm.getOption("gutters").slice();
- gutters.splice(1, 0, "CodeMirror-annotations");
- cm.setOption("gutters", gutters);
- for (var i in blameInfos) {
- var blameInfo = blameInfos[i];
- for (var j in blameInfo.ranges) {
- var range = blameInfo.ranges[j];
- var $gutter = $(document.createElement("div"));
- $gutter.addClass("CodeMirror-annotation");
- $("<a class='hash'>" + blameInfo.abbreviatedHash + "</a>").appendTo($gutter).attr("href", blameInfo.url);
- var $hashLink = $gutter.children("a.hash");
- $hashLink.data("hash", blameInfo.hash);
- $hashLink.data("line", range.from);
-
- $hashLink.hover(function() {
- var tooltipId = "blame-message-line-" + $(this).data("line");
- markCallback("showBlameMessage", tooltipId, $(this).data("hash"));
- var $tooltip = $("<div class='blame-message'><div class='loading'>Loading...</div></div>");
- $tooltip.attr("id", tooltipId);
- $tooltip.data("trigger", this);
- $tooltip.data("alignment", alignment);
- $(".source-view").append($tooltip);
- return $tooltip;
- }, alignment);
-
- $gutter.append("<span class='date'>" + blameInfo.commitDate + "</span>");
- $gutter.append("<span class='author'>" + blameInfo.authorName + "</span>");
- cm.setGutterMarker(range.from, "CodeMirror-annotations", $gutter[0]);
-
- for (var line = range.from+1; line<range.to; line++) {
- var $gutter = $(document.createElement("div"));
- $gutter.addClass("CodeMirror-annotation");
- $gutter.append("<span class='same-as-above'>...</span>");
- cm.setGutterMarker(line, "CodeMirror-annotations", $gutter[0]);
- }
- }
- }
- } else {
- cm.clearGutter("CodeMirror-annotations");
- var gutters = cm.getOption("gutters").slice();
- gutters.splice(1, 1);
- cm.setOption("gutters", gutters);
- }
- },
- onBlame: function(blameInfos) {
- gitplex.sourceview.blame(blameInfos);
- gitplex.sourceview.onLayoutChange();
- },
- scrollToCommentBottom: function() {
- var $body = $(".source-view>.comment>.content>.body");
- $body.scrollTop($body[0].scrollHeight);
- }
-};
+gitplex.sourceview = {
+ init: function(fileContent, filePath, openComment, mark, symbolTooltipId,
+ revision, blameInfos, comments, markCallback, viewState, loggedIn, anchor) {
+ var cm;
+
+ var $sourceView = $(".source-view");
+ if (openComment)
+ $sourceView.data("openComment", openComment);
+ if (mark)
+ $sourceView.data("mark", mark);
+
+ $sourceView.data("markCallback", markCallback);
+
+ var $code = $sourceView.children(".code");
+ $sourceView.closest(".content").css("overflow", "visible");
+
+ function repositionCommentPopovers() {
+ $(".comment-popover:visible").each(function() {
+ var $popover = $(this);
+ var lineInfo = cm.lineInfo($popover.data("line"));
+ if (lineInfo.gutterMarkers) {
+ var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
+ if (gutter) {
+ var $indicator = $(gutter).children("a");
+ if ($indicator.offset().top+$indicator.height() < $sourceView.offset().top
+ || $indicator.offset().top > $sourceView.offset().top+$sourceView.height()) {
+ $popover.css("left", "-10000px");
+ } else {
+ $popover.css({
+ "left": $indicator.offset().left + $indicator.outerWidth() - $sourceView.offset().left,
+ "top": $indicator.offset().top + ($indicator.outerHeight() - $popover.outerHeight())/2 - $sourceView.offset().top
+ });
+ }
+ }
+ }
+ });
+ }
+
+ $sourceView.on("storeViewState", function(event) {
+ event.stopPropagation();
+ if (cm) {
+ pmease.commons.history.setViewState(pmease.commons.codemirror.getViewState(cm));
+ }
+ });
+
+ $sourceView.on("autofit", function(event, width, height) {
+ event.stopPropagation();
+ $sourceView.outerWidth(width);
+ $sourceView.outerHeight(height);
+ $code.outerHeight($sourceView.height());
+
+ var $comment = $sourceView.children(".comment");
+ var paddingLeft;
+ if ($comment.is(":visible")) {
+ paddingLeft = $comment.outerWidth();
+ $comment.children(".ui-resizable-handle").outerHeight($sourceView.height());
+
+ var $commentHead = $comment.find(">.content>.head");
+ var $commentBody = $comment.find(">.content>.body");
+ $commentBody.outerHeight($sourceView.height() - $commentHead.outerHeight());
+ } else {
+ paddingLeft = 0;
+ }
+ $sourceView.css("padding-left", paddingLeft);
+
+ var $outline = $sourceView.children(".outline");
+ if ($outline.is(":visible")) {
+ $sourceView.css("padding-right", $outline.outerWidth());
+ $outline.css("left", $code.outerWidth() + paddingLeft);
+ $outline.children(".ui-resizable-handle").outerHeight($sourceView.height());
+
+ var $outlineHead = $outline.find(">.content>.head");
+ var $outlineBody = $outline.find(">.content>.body");
+ $outlineBody.outerHeight($sourceView.height() - $outlineHead.outerHeight());
+ } else {
+ $sourceView.css("padding-right", "0");
+ }
+
+ /*
+ * initialize codemirror here when we know the container width and height
+ * as otherwise the annotatescrollbar addon is inaccurate when window
+ * initially loads
+ */
+ var initState = !cm;
+ if (!cm) {
+ var options = {
+ value: fileContent,
+ readOnly: pmease.commons.isDevice()?"nocursor":true,
+ theme: "eclipse",
+ lineNumbers: true,
+ lineWrapping: true,
+ styleActiveLine: true,
+ styleSelectedText: true,
+ foldGutter: true,
+ matchBrackets: true,
+ scrollbarStyle: "simple",
+ highlightIdentifiers: {delay: 500},
+ gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
+ extraKeys: {
+ "F11": function(cm) {
+ cm.setOption("fullScreen", !cm.getOption("fullScreen"));
+ },
+ "Esc": function(cm) {
+ if (cm.getOption("fullScreen"))
+ cm.setOption("fullScreen", false);
+ }
+ }
+ };
+
+ cm = CodeMirror($code[0], options);
+ pmease.commons.codemirror.setMode(cm, filePath);
+
+ // add gutters with a timer to avoid the issue that occasionally
+ // gutter becomes much wider than expected
+ setTimeout(function() {
+ var gutters = cm.getOption("gutters").slice();
+ gutters.splice(0, 0, "CodeMirror-comments");
+ cm.setOption("gutters", gutters);
+ for (var line in comments) {
+ if (comments.hasOwnProperty(line)) {
+ gitplex.sourceview.addCommentGutter(line, comments[line][1]);
+ }
+ }
+
+ if (blameInfos) {
+ gitplex.sourceview.blame(blameInfos);
+ }
+ gitplex.sourceview.highlightCommentTrigger();
+ }, 10);
+
+ $code.selectionPopover("init", function() {
+ if (cm.hasFocus()) {
+ var from = cm.getCursor("from");
+ var to = cm.getCursor("to");
+ if (from.line != to.line || from.ch != to.ch) {
+ markCallback("openSelectionPopover", from.line, from.ch, to.line, to.ch);
+ return;
+ }
+ }
+ return "close";
+ });
+
+ $code.mouseover(function(e) {
+ var node = e.target || e.srcElement, $node = $(node);
+ if ($node.hasClass("cm-property") || $node.hasClass("cm-variable") || $node.hasClass("cm-variable-2")
+ || $node.hasClass("cm-variable-3") || $node.hasClass("cm-def") || $node.hasClass("cm-meta")) {
+ document.getElementById(symbolTooltipId).onMouseOverSymbol(revision, node);
+ }
+ });
+ cm.setSize($code.width(), $code.height());
+ if (mark)
+ pmease.commons.codemirror.mark(cm, mark, true);
+ if (initState) // restore cursor and scroll
+ pmease.commons.codemirror.initState(cm, viewState);
+ cm.on("scroll", function() {
+ gitplex.symboltooltip.removeTooltip(document.getElementById(symbolTooltipId));
+ gitplex.mouseState.moved = false;
+ repositionCommentPopovers(cm);
+ });
+ } else {
+ cm.setSize($code.width(), $code.height());
+ if (cm.getOption("fullScreen"))
+ cm.setOption("fullScreen", false);
+ repositionCommentPopovers(cm);
+ }
+ });
+ if (anchor) {
+ var $anchor = $("#"+anchor);
+ if ($anchor.length != 0) {
+ setTimeout(function() {
+ $anchor.closest(".code-comment").parent().scrollIntoView($anchor);
+ }, 10);
+ }
+ }
+ },
+ initComment: function() {
+ var $sourceView = $(".source-view");
+ var $code = $sourceView.children(".code");
+ var commentWidthCookieKey = "sourceView.comment.width";
+ var $comment = $sourceView.children(".comment");
+ var commentWidth = Cookies.get(commentWidthCookieKey);
+ if (!commentWidth)
+ commentWidth = 400;
+ $comment.outerWidth(commentWidth);
+ var $commentResizeHandle = $comment.children(".ui-resizable-handle");
+ $comment.resizable({
+ autoHide: false,
+ handles: {"e": $commentResizeHandle},
+ minWidth: 200,
+ resize: function(e, ui) {
+ var codeWidth = $code.outerWidth();
+ if(codeWidth < 300)
+ $(this).resizable({maxWidth: ui.size.width});
+ },
+ stop: function(e, ui) {
+ $(this).resizable({maxWidth: undefined});
+ Cookies.set(commentWidthCookieKey, ui.size.width, {expires: Infinity});
+ }
+ });
+ },
+ initOutline: function() {
+ var $sourceView = $(".source-view");
+ var $code = $sourceView.children(".code");
+ var outlineWidthCookieKey = "sourceView.outline.width";
+ var $outline = $sourceView.children(".outline");
+ var outlineWidth = Cookies.get(outlineWidthCookieKey);
+ if (!outlineWidth)
+ outlineWidth = 350;
+ $outline.outerWidth(outlineWidth);
+ var $outlineResizeHandle = $outline.children(".ui-resizable-handle");
+ $outline.resizable({
+ autoHide: false,
+ handles: {"w": $outlineResizeHandle},
+ minWidth: 100,
+ resize: function(e, ui) {
+ var codeWidth = $code.outerWidth();
+ if(codeWidth < 300)
+ $(this).resizable({maxWidth: ui.size.width});
+ },
+ stop: function(e, ui) {
+ $(this).resizable({maxWidth: undefined});
+ Cookies.set(outlineWidthCookieKey, ui.size.width, {expires: Infinity});
+ }
+ });
+ },
+ showBlameMessage: function(tooltipId, message) {
+ var $blameTooltip = $("#" + tooltipId);
+ $blameTooltip.empty().text(message);
+ $blameTooltip.align({placement: $blameTooltip.data("alignment"), target: {element: $blameTooltip.data("trigger")}});
+ },
+ restoreMark: function() {
+ var $sourceView = $(".source-view");
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ var mark = $sourceView.data("mark");
+ if (mark) {
+ pmease.commons.codemirror.mark(cm, mark, false);
+ } else {
+ pmease.commons.codemirror.clearMark(cm);
+ }
+ },
+ addCommentGutter: function(line, comments) {
+ $(".comment-popover[data-line='" + line + "']").remove();
+
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ var markCallback = $(".source-view").data("markCallback");
+
+ var $gutter = $(document.createElement("div"));
+ $gutter.addClass("CodeMirror-comment");
+ $gutter.data("comments", comments);
+ if (comments.length != 1) {
+ /*
+ * when there are multiple comments starts with the same line, we should
+ * display a comment indicator which will display a comment popover with
+ * list of comment triggers upon click, user can then click one of the
+ * trigger link to display the actual comment content
+ */
+ $gutter.append("<a><i class='fa fa-comments'></i></a>");
+ var $indicator = $gutter.children("a");
+ var content = "";
+ for (var i in comments) {
+ var comment = comments[i];
+ var index = parseInt(i) + 1;
+ content += "<a class='comment-trigger' title='Click to show details of this comment'>" + comment.title + "</a>";
+ }
+ $indicator.popover({
+ html: true,
+ container: ".source-view",
+ placement: "right auto",
+ template: "<div data-line='" + line + "' class='popover comment-popover'><div class='arrow'></div><div class='popover-content'></div></div>",
+ content: content
+ });
+ $indicator.on('shown.bs.popover', function () {
+ $(".comment-popover[data-line='" + line + "'] a").each(function() {
+ $(this).mouseover(function() {
+ var comment = comments[$(this).index()];
+ pmease.commons.codemirror.mark(cm, comment.mark, false);
+ });
+ $(this).mouseout(function() {
+ gitplex.sourceview.restoreMark();
+ });
+ $(this).click(function() {
+ if ($(".source-view form.dirty").length != 0
+ && !confirm("There are unsaved changes, discard and continue?")) {
+ return;
+ }
+ var comment = comments[$(this).index()];
+ markCallback("openComment", comment.id);
+ });
+ });
+ gitplex.sourceview.highlightCommentTrigger();
+ });
+ } else {
+ var comment = comments[0];
+ $gutter.append("<a class='comment-trigger' title='Click to show comment of marked text'><i class='fa fa-commenting'></i></a>");
+ var $indicator = $gutter.children("a");
+ $indicator.mouseover(function() {
+ pmease.commons.codemirror.mark(cm, comment.mark, false);
+ });
+ $indicator.mouseout(function() {
+ gitplex.sourceview.restoreMark();
+ });
+ $indicator.click(function() {
+ if ($(".source-view form.dirty").length != 0
+ && !confirm("There are unsaved changes, discard and continue?")) {
+ return;
+ }
+ markCallback("openComment", comment.id);
+ });
+ }
+ cm.setGutterMarker(parseInt(line), "CodeMirror-comments", $gutter[0]);
+ },
+ openSelectionPopover: function(mark, markUrl, loggedIn) {
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ var ch = (mark.beginChar + mark.endChar)/2;
+ var position = cm.charCoords({line:mark.beginLine, ch:ch});
+
+ var $content = $("<div><a class='permanent'><i class='fa fa-link'></i> Permanent link of this selection</a>");
+ $content.children("a.permanent").attr("href", markUrl);
+ if (loggedIn) {
+ $content.append("<a class='comment'><i class='fa fa-comment'></i> Add comment on this selection</a>");
+ $content.children("a.comment").click(function() {
+ if ($(".source-view").find("form.dirty").length != 0
+ && !confirm("There are unsaved changes, discard and continue?")) {
+ return;
+ }
+ var markCallback = $(".source-view").data("markCallback");
+ markCallback("addComment", mark.beginLine, mark.beginChar, mark.endLine, mark.endChar);
+ });
+ } else {
+ $content.append("<span class='comment'><i class='fa fa-warning'></i> Log in to comment on selection</span>");
+ }
+
+ $(".source-view>.code").selectionPopover("open", {
+ position: position,
+ content: $content
+ });
+ },
+ onCommentAdded: function(comment) {
+ var $sourceView = $(".source-view");
+ $sourceView.data("openComment", comment);
+ $sourceView.data("mark", comment.mark);
+
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ var line = parseInt(comment.mark.beginLine);
+ var lineInfo = cm.lineInfo(line);
+ var gutter;
+ if (lineInfo.gutterMarkers)
+ gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
+ var comments;
+ if (gutter) {
+ comments = $(gutter).data("comments");
+ } else {
+ comments = [];
+ }
+ comments.push(comment);
+ gitplex.sourceview.addCommentGutter(line, comments);
+ gitplex.sourceview.highlightCommentTrigger();
+ gitplex.sourceview.onLayoutChange();
+ },
+ onCommentDeleted: function(comment) {
+ var $sourceView = $(".source-view");
+ $sourceView.removeData("openComment");
+
+ var line = parseInt(comment.mark.beginLine);
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ var lineInfo = cm.lineInfo(line);
+ var $gutter = $(lineInfo.gutterMarkers["CodeMirror-comments"]);
+ var comments = $gutter.data("comments");
+ if (comments.length == 1) {
+ cm.setGutterMarker(line, "CodeMirror-comments", null);
+ } else {
+ for (var i in comments) {
+ if (comments[i].id == comment.id) {
+ comments.splice(i, 1);
+ break;
+ }
+ }
+ gitplex.sourceview.addCommentGutter(line, comments);
+ }
+ gitplex.sourceview.highlightCommentTrigger();
+ gitplex.sourceview.onLayoutChange();
+
+ // make sure marked text is in view port after changing layout
+ var mark = $sourceView.data("mark");
+ if (mark)
+ gitplex.sourceview.mark(mark, true);
+ },
+ onLayoutChange: function() {
+ $sourceView = $('.source-view');
+ $sourceView.trigger('autofit', [$sourceView.outerWidth(), $sourceView.outerHeight()]);
+ },
+ onAddComment: function(mark) {
+ var $sourceView = $(".source-view");
+ $sourceView.removeData("openComment");
+ $sourceView.data("mark", mark);
+ $(".source-view>.code").selectionPopover("close");
+
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ pmease.commons.codemirror.clearSelection(cm);
+ gitplex.sourceview.onLayoutChange();
+
+ // mark and scroll after changing layout to make sure scroll
+ // works correctly
+ pmease.commons.codemirror.mark(cm, mark, true);
+
+ gitplex.sourceview.highlightCommentTrigger();
+ },
+ onOpenComment: function(comment) {
+ var $sourceView = $(".source-view");
+ $sourceView.data("openComment", comment);
+ $sourceView.data("mark", comment.mark);
+ gitplex.sourceview.highlightCommentTrigger();
+ gitplex.sourceview.onLayoutChange();
+
+ // mark and scroll after changing layout to make sure scroll
+ // works correctly
+ gitplex.sourceview.mark(comment.mark, true);
+ },
+ onCloseComment: function() {
+ var $sourceView = $(".source-view");
+ $sourceView.removeData("openComment");
+ gitplex.sourceview.highlightCommentTrigger();
+ gitplex.sourceview.onLayoutChange();
+
+ // make sure marked text is in view port after layout change
+ var mark = $sourceView.data("mark");
+ if (mark) {
+ gitplex.sourceview.mark(mark, true);
+ }
+ },
+ onToggleOutline: function() {
+ gitplex.sourceview.onLayoutChange();
+ },
+ highlightCommentTrigger: function() {
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ $(".comment-popover a").removeClass("active");
+
+ /*
+ * we can not simply select all comment triggers via jQuery
+ * as comment gutter may be create/destroy dynamically by
+ * CodeMirror
+ */
+ for (var i=0; i<cm.lineCount(); i++) {
+ var gutterMarkers = cm.lineInfo(i).gutterMarkers;
+ if (gutterMarkers) {
+ var gutter = gutterMarkers["CodeMirror-comments"];
+ if (gutter) {
+ $(gutter).children("a").removeClass("active");
+ }
+ }
+ }
+
+ var openComment = $(".source-view").data("openComment");
+ if (openComment) {
+ var line = parseInt(openComment.mark.beginLine);
+ var lineInfo = cm.lineInfo(line);
+ if (lineInfo && lineInfo.gutterMarkers) {
+ var gutter = lineInfo.gutterMarkers["CodeMirror-comments"];
+ if (gutter) {
+ var comments = $(gutter).data("comments");
+ if (comments.length == 1) {
+ $(gutter).children("a").addClass("active");
+ } else {
+ $(".comment-popover[data-line='" + line + "'] a").each(function() {
+ var comment = comments[$(this).index()];
+ if (comment.id == openComment.id) {
+ $(this).addClass("active");
+ }
+ });
+ }
+ }
+ }
+ }
+ },
+ mark: function(mark, scroll) {
+ $(".source-view").data("mark", mark);
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ pmease.commons.codemirror.mark(cm, mark, scroll);
+ },
+ blame: function(blameInfos) {
+ var cm = $(".source-view>.code>.CodeMirror")[0].CodeMirror;
+ var alignment = {targetX: 100, targetY: 100, x: 0, y: 0};
+
+ if (blameInfos) {
+ var markCallback = $(".source-view").data("markCallback");
+ var gutters = cm.getOption("gutters").slice();
+ gutters.splice(1, 0, "CodeMirror-annotations");
+ cm.setOption("gutters", gutters);
+ for (var i in blameInfos) {
+ var blameInfo = blameInfos[i];
+ for (var j in blameInfo.ranges) {
+ var range = blameInfo.ranges[j];
+ var $gutter = $(document.createElement("div"));
+ $gutter.addClass("CodeMirror-annotation");
+ $("<a class='hash'>" + blameInfo.abbreviatedHash + "</a>").appendTo($gutter).attr("href", blameInfo.url);
+ var $hashLink = $gutter.children("a.hash");
+ $hashLink.data("hash", blameInfo.hash);
+ $hashLink.data("line", range.from);
+
+ $hashLink.hover(function() {
+ var tooltipId = "blame-message-line-" + $(this).data("line");
+ markCallback("showBlameMessage", tooltipId, $(this).data("hash"));
+ var $tooltip = $("<div class='blame-message'><div class='loading'>Loading...</div></div>");
+ $tooltip.attr("id", tooltipId);
+ $tooltip.data("trigger", this);
+ $tooltip.data("alignment", alignment);
+ $(".source-view").append($tooltip);
+ return $tooltip;
+ }, alignment);
+
+ $gutter.append("<span class='date'>" + blameInfo.commitDate + "</span>");
+ $gutter.append("<span class='author'>" + blameInfo.authorName + "</span>");
+ cm.setGutterMarker(range.from, "CodeMirror-annotations", $gutter[0]);
+
+ for (var line = range.from+1; line<range.to; line++) {
+ var $gutter = $(document.createElement("div"));
+ $gutter.addClass("CodeMirror-annotation");
+ $gutter.append("<span class='same-as-above'>...</span>");
+ cm.setGutterMarker(line, "CodeMirror-annotations", $gutter[0]);
+ }
+ }
+ }
+ } else {
+ cm.clearGutter("CodeMirror-annotations");
+ var gutters = cm.getOption("gutters").slice();
+ gutters.splice(1, 1);
+ cm.setOption("gutters", gutters);
+ }
+ },
+ onBlame: function(blameInfos) {
+ gitplex.sourceview.blame(blameInfos);
+ gitplex.sourceview.onLayoutChange();
+ },
+ scrollToCommentBottom: function() {
+ var $body = $(".source-view>.comment>.content>.body");
+ $body.scrollTop($body[0].scrollHeight);
+ }
+};
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/BlobCommentSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/BlobCommentSupport.java
index b04ab12129..e1b710ebc4 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/BlobCommentSupport.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/BlobCommentSupport.java
@@ -17,6 +17,8 @@ public interface BlobCommentSupport extends Serializable {
@Nullable CommentPos getMark();
+ @Nullable String getAnchor();
+
String getMarkUrl(CommentPos mark);
@Nullable CodeComment getOpenComment();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/CommentSupport.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/CommentSupport.java
index 477469e256..78c2ec28c6 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/CommentSupport.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/CommentSupport.java
@@ -13,6 +13,8 @@ public interface CommentSupport extends Serializable {
@Nullable CommentPos getMark();
+ @Nullable String getAnchor();
+
void onMark(AjaxRequestTarget target, CommentPos mark);
String getMarkUrl(CommentPos mark);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
index 01f34a9818..080b3ea19f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.html
@@ -81,16 +81,4 @@
</div>
</form>
</wicket:fragment>
- <wicket:fragment wicket:id="requestCommitSelectorFrag">
- <ul class="request-commit-selector list-unstyled">
- <li wicket:id="commits">
- <a wicket:id="link">
- <span class="fa fa-ext fa-commit icon"></span>
- <span wicket:id="hash" class="hash"></span>
- <span wicket:id="subject" class="subject"></span>
- <span wicket:id="commented" class="fa fa-commenting" title="This commit holds the comment"></span>
- </a>
- </li>
- </ul>
- </wicket:fragment>
</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
index cefad05400..54e9afbdf6 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/RevisionDiffPanel.java
@@ -14,7 +14,6 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
-import java.util.stream.Collectors;
import javax.annotation.Nullable;
import javax.servlet.http.Cookie;
@@ -48,7 +47,6 @@ import org.apache.wicket.model.Model;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.http.WebRequest;
import org.apache.wicket.request.http.WebResponse;
-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.diff.DiffEntry;
@@ -65,7 +63,6 @@ import com.pmease.commons.antlr.codeassist.InputSuggestion;
import com.pmease.commons.git.Blob;
import com.pmease.commons.git.BlobChange;
import com.pmease.commons.git.BlobIdent;
-import com.pmease.commons.git.GitUtils;
import com.pmease.commons.lang.diff.DiffUtils;
import com.pmease.commons.lang.diff.WhitespaceOption;
import com.pmease.commons.util.Range;
@@ -82,19 +79,16 @@ import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
import com.pmease.gitplex.core.entity.support.CommentPos;
import com.pmease.gitplex.core.entity.support.CompareContext;
-import com.pmease.gitplex.core.entity.support.DepotAndRevision;
import com.pmease.gitplex.core.manager.CodeCommentManager;
import com.pmease.gitplex.core.security.SecurityUtils;
import com.pmease.gitplex.web.Constants;
import com.pmease.gitplex.web.component.comment.CodeCommentPanel;
import com.pmease.gitplex.web.component.comment.CommentInput;
import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
+import com.pmease.gitplex.web.component.comment.comparecontext.CompareContextPanel;
import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;
import com.pmease.gitplex.web.component.diff.blob.SourceAware;
import com.pmease.gitplex.web.component.diff.diffstat.DiffStatBar;
-import com.pmease.gitplex.web.component.revisionpicker.RevisionSelector;
-import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
import com.pmease.gitplex.web.util.SuggestionUtils;
import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
@@ -431,7 +425,10 @@ public class RevisionDiffPanel extends Panel {
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
- response.render(OnDomReadyHeaderItem.forScript("gitplex.revisionDiff.init();"));
+
+ String anchor = getAnchor();
+ String script = String.format("gitplex.revisionDiff.init(%s);", anchor!=null?"'"+anchor+"'":"undefined");
+ response.render(OnDomReadyHeaderItem.forScript(script));
}
};
@@ -713,6 +710,11 @@ public class RevisionDiffPanel extends Panel {
return null;
}
+ @Override
+ public String getAnchor() {
+ return RevisionDiffPanel.this.getAnchor();
+ }
+
@Override
public String getMarkUrl(CommentPos mark) {
return commentSupport.getMarkUrl(mark);
@@ -1016,90 +1018,14 @@ public class RevisionDiffPanel extends Panel {
@Override
protected Component newContent(String id) {
- if (requestModel.getObject() != null) {
- Fragment fragment = new Fragment(id, "requestCommitSelectorFrag", RevisionDiffPanel.this);
- IModel<List<RevCommit>> commitsModel = new LoadableDetachableModel<List<RevCommit>>() {
-
- @Override
- protected List<RevCommit> load() {
- List<RevCommit> commits = new ArrayList<>();
- PullRequest request = requestModel.getObject();
- commits.add(request.getBaseCommit());
- commits.addAll(request.getCommits());
- return commits;
- }
-
- };
- fragment.add(new ListView<RevCommit>("commits", commitsModel) {
-
- @Override
- protected void populateItem(ListItem<RevCommit> item) {
- RevCommit commit = item.getModelObject();
- AjaxLink<Void> link = new AjaxLink<Void>("link") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- RequestChangesPage.State state = new RequestChangesPage.State();
- CodeComment comment = getOpenComment();
- state.commentId = comment.getId();
- state.mark = comment.getCommentPos();
- int index = commitsModel.getObject().stream().map(RevCommit::getName).collect(Collectors.toList())
- .indexOf(comment.getCommentPos().getCommit());
- int compareIndex = commitsModel.getObject().indexOf(commit);
- if (index < compareIndex) {
- state.oldCommit = comment.getCommentPos().getCommit();
- state.newCommit = commit.name();
- } else {
- state.oldCommit = commit.name();
- state.newCommit = comment.getCommentPos().getCommit();
- }
- state.pathFilter = pathFilterModel.getObject();
- state.whitespaceOption = whitespaceOptionModel.getObject();
- PageParameters params = RequestChangesPage.paramsOf(requestModel.getObject(), state);
- setResponsePage(RequestChangesPage.class, params);
- }
-
- };
- link.add(new Label("hash", GitUtils.abbreviateSHA(commit.name())));
- link.add(new Label("subject", commit.getShortMessage()));
- if (commit.name().equals(getOpenComment().getCommentPos().getCommit())) {
- link.setEnabled(false);
- link.add(AttributeAppender.append("class", "commented"));
- link.add(new WebMarkupContainer("commented"));
- } else {
- link.add(new WebMarkupContainer("commented").setVisible(false));
- }
- item.add(link);
- }
-
- });
- return fragment;
- } else {
- return new RevisionSelector(id, new AbstractReadOnlyModel<Depot>() {
+ return new CompareContextPanel(id, requestModel, new AbstractReadOnlyModel<CodeComment>() {
- @Override
- public Depot getObject() {
- return getOpenComment().getDepot();
- }
-
- }) {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, String revision) {
- RevisionComparePage.State state = new RevisionComparePage.State();
- CodeComment comment = getOpenComment();
- state.commentId = comment.getId();
- state.mark = comment.getCommentPos();
- state.compareWithMergeBase = false;
- state.leftSide = new DepotAndRevision(comment.getDepot(), comment.getCommentPos().getCommit());
- state.rightSide = new DepotAndRevision(comment.getDepot(), revision);
- state.tabPanel = RevisionComparePage.TabPanel.CHANGES;
- PageParameters params = RevisionComparePage.paramsOf(comment.getDepot(), state);
- setResponsePage(RevisionComparePage.class, params);
- }
-
- };
- }
+ @Override
+ public CodeComment getObject() {
+ return getOpenComment();
+ }
+
+ }, pathFilterModel, whitespaceOptionModel);
}
});
@@ -1326,6 +1252,15 @@ public class RevisionDiffPanel extends Panel {
return null;
}
+ @Nullable
+ private String getAnchor() {
+ if (commentSupport != null) {
+ return commentSupport.getAnchor();
+ } else {
+ return null;
+ }
+ }
+
@Nullable
private SourceAware getSourceAware(String path) {
return diffsView.visitChildren(new IVisitor<Component, SourceAware>() {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css
index 6462e58c30..306edfc870 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.css
@@ -139,24 +139,3 @@
margin: 12px;
}
-.request-commit-selector {
- margin-bottom: 0;
-}
-.request-commit-selector a {
- text-decoration: none;
- display: block;
- color: #333;
- padding: 4px 8px;
- white-space: nowrap;
- font-family: monospace;
-}
-.request-commit-selector a:hover {
- background: #F2F2F2;
-}
-.request-commit-selector a.commented {
- background: white;
- cursor: default;
-}
-.request-commit-selector a .hash, .request-commit-selector .icon {
- color: #666;
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
index d83574c8b4..74e8600887 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/revision/revision-diff.js
@@ -1,5 +1,5 @@
gitplex.revisionDiff = {
- init: function() {
+ init: function(anchor) {
var cookieName = "revisionDiff.showDiffStats";
var $body = $(".revision-diff>.body");
var $diffStats = $body.children(".diff-stats");
@@ -17,6 +17,18 @@ gitplex.revisionDiff = {
gitplex.revisionDiff.reposition();
});
gitplex.revisionDiff.reposition();
+ if (anchor) {
+ var $anchor = $("#"+anchor);
+ if ($anchor.length != 0) {
+ setTimeout(function() {
+ var detailOffset = $(".revision-diff>.body>.detail").offset().top;
+ if ($(window).scrollTop() <= detailOffset) {
+ $(window).scrollTop(detailOffset);
+ }
+ $anchor.closest(".code-comment").parent().scrollIntoView($anchor);
+ }, 10);
+ }
+ }
},
reposition: function(e) {
if ($(".revision-diff>.body>.detail").length == 0)
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/reviewresult/ReviewResultTooltip.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/reviewresult/ReviewResultTooltip.html
index 1574b3e29c..d3c5b9ca0d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/reviewresult/ReviewResultTooltip.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/reviewresult/ReviewResultTooltip.html
@@ -1,9 +1,9 @@
-<wicket:panel>
- <div class="review-result-tooltip">
- <span wicket:id="description"></span>
- <wicket:enclosure child="delete">
- <span class="middot"></span>
- <a wicket:id="delete">delete</a>
- </wicket:enclosure>
- </div>
+<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/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/reviewresult/ReviewResultTooltip.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/reviewresult/ReviewResultTooltip.java
index bbc1a7ca50..484e66ef69 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/reviewresult/ReviewResultTooltip.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/pullrequest/reviewresult/ReviewResultTooltip.java
@@ -1,61 +1,61 @@
-package com.pmease.gitplex.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.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequestReview;
-import com.pmease.gitplex.core.manager.PullRequestReviewManager;
-import com.pmease.gitplex.core.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>("delete") {
-
- @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);
- }
-
- });
- }
-
-}
+package com.pmease.gitplex.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.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequestReview;
+import com.pmease.gitplex.core.manager.PullRequestReviewManager;
+import com.pmease.gitplex.core.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/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/comments/CodeCommentPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/comments/CodeCommentPage.java
index 5fd7b378cd..fbfcd51013 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/comments/CodeCommentPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/comments/CodeCommentPage.java
@@ -1,47 +1,51 @@
-package com.pmease.gitplex.web.page.depot.comments;
-
-import org.apache.wicket.RestartResponseException;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
-
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.CodeComment;
-import com.pmease.gitplex.core.entity.CodeCommentRelation;
-import com.pmease.gitplex.core.entity.support.CompareContext;
-import com.pmease.gitplex.core.manager.CodeCommentManager;
-import com.pmease.gitplex.web.page.depot.DepotPage;
-import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
-import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
-
-@SuppressWarnings("serial")
-public class CodeCommentPage extends DepotPage {
-
- private static final String PARAM_COMMENT = "comment";
-
- private static final String PARAM_REQUEST = "request";
-
- public CodeCommentPage(PageParameters params) {
- super(params);
-
- Long requestId = params.get(PARAM_REQUEST).toOptionalLong();
- Long commentId = params.get(PARAM_COMMENT).toLong();
- CodeComment comment = GitPlex.getInstance(CodeCommentManager.class).load(commentId);
- for (CodeCommentRelation relation: comment.getRelations()) {
- if (relation.getRequest().getId().equals(requestId)) {
- params = RequestChangesPage.paramsOf(relation.getRequest(), comment);
- throw new RestartResponseException(RequestChangesPage.class, params);
- }
- }
- CompareContext compareContext = comment.getLastCompareContext();
- if (!compareContext.getCompareCommit().equals(comment.getCommentPos().getCommit())) {
- throw new RestartResponseException(
- RevisionComparePage.class,
- RevisionComparePage.paramsOf(getDepot(), comment));
- } else {
- throw new RestartResponseException(
- DepotFilePage.class,
- DepotFilePage.paramsOf(getDepot(), comment));
- }
- }
-
-}
+package com.pmease.gitplex.web.page.depot.comments;
+
+import org.apache.wicket.RestartResponseException;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.CodeCommentRelation;
+import com.pmease.gitplex.core.entity.support.CompareContext;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
+import com.pmease.gitplex.web.page.depot.DepotPage;
+import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
+import com.pmease.gitplex.web.page.depot.file.DepotFilePage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.changes.RequestChangesPage;
+
+@SuppressWarnings("serial")
+public class CodeCommentPage extends DepotPage {
+
+ private static final String PARAM_COMMENT = "comment";
+
+ private static final String PARAM_REQUEST = "request";
+
+ private static final String PARAM_ANCHOR = "anchor";
+
+ public CodeCommentPage(PageParameters params) {
+ super(params);
+
+ Long requestId = params.get(PARAM_REQUEST).toOptionalLong();
+ Long commentId = params.get(PARAM_COMMENT).toLong();
+ String anchor = params.get(PARAM_ANCHOR).toString();
+
+ CodeComment comment = GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ for (CodeCommentRelation relation: comment.getRelations()) {
+ if (relation.getRequest().getId().equals(requestId)) {
+ params = RequestChangesPage.paramsOf(relation.getRequest(), comment, anchor);
+ throw new RestartResponseException(RequestChangesPage.class, params);
+ }
+ }
+ CompareContext compareContext = comment.getLastCompareContext();
+ if (!compareContext.getCompareCommit().equals(comment.getCommentPos().getCommit())) {
+ throw new RestartResponseException(
+ RevisionComparePage.class,
+ RevisionComparePage.paramsOf(getDepot(), comment, anchor));
+ } else {
+ throw new RestartResponseException(
+ DepotFilePage.class,
+ DepotFilePage.paramsOf(getDepot(), comment, anchor));
+ }
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java
index 89e6ab3270..8a0d68e84d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/commit/CommitDetailPage.java
@@ -526,4 +526,9 @@ public class CommitDetailPage extends DepotPage implements CommentSupport {
return objectIdCache;
}
+ @Override
+ public String getAnchor() {
+ return null;
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java
index fd6e046eae..669247636d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/compare/RevisionComparePage.java
@@ -90,6 +90,8 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
private static final String PARAM_MARK = "mark";
+ private static final String PARAM_ANCHOR = "anchor";
+
private static final String PARAM_PATH_FILTER = "path-filter";
private static final String PARAM_BLAME_FILE = "blame-file";
@@ -112,10 +114,11 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
private Tabbable tabbable;
- public static PageParameters paramsOf(Depot depot, CodeComment comment) {
+ public static PageParameters paramsOf(Depot depot, CodeComment comment, @Nullable String anchor) {
RevisionComparePage.State state = new RevisionComparePage.State();
state.commentId = comment.getId();
state.mark = comment.getCommentPos();
+ state.anchor = anchor;
state.compareWithMergeBase = false;
CompareContext compareContext = comment.getLastCompareContext();
if (compareContext.isLeftSide()) {
@@ -146,12 +149,14 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
params.set(PARAM_COMMENT, state.commentId);
if (state.mark != null)
params.set(PARAM_MARK, state.mark.toString());
+ if (state.anchor != null)
+ params.set(PARAM_ANCHOR, state.anchor);
if (state.tabPanel != null)
params.set(PARAM_TAB, state.tabPanel.name());
return params;
}
- public RevisionComparePage(final PageParameters params) {
+ public RevisionComparePage(PageParameters params) {
super(params);
if (getDepot().getDefaultBranch() == null)
@@ -192,6 +197,7 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
state.commentId = params.get(PARAM_COMMENT).toOptionalLong();
state.mark = CommentPos.of(params.get(PARAM_MARK).toString());
+ state.anchor = params.get(PARAM_ANCHOR).toString();
state.tabPanel = TabPanel.of(params.get(PARAM_TAB).toString());
@@ -637,6 +643,9 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
@Nullable
public CommentPos mark;
+ @Nullable
+ public String anchor;
+
public State() {
}
@@ -649,6 +658,7 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
blameFile = state.blameFile;
commentId = state.commentId;
mark = state.mark;
+ anchor = state.anchor;
tabPanel = state.tabPanel;
}
@@ -658,6 +668,11 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
public CommentPos getMark() {
return state.mark;
}
+
+ @Override
+ public String getAnchor() {
+ return state.anchor;
+ }
@Override
public String getMarkUrl(CommentPos mark) {
@@ -729,5 +744,5 @@ public class RevisionComparePage extends DepotPage implements CommentSupport {
regions.add(new CodeCommentChangedRegion(state.commentId));
return regions;
}
-
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
index e9bd694b58..32fa1a45fd 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/file/DepotFilePage.java
@@ -127,6 +127,8 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
private static final String PARAM_MARK = "mark";
+ private static final String PARAM_ANCHOR = "anchor";
+
private static final String REVISION_PICKER_ID = "revisionPicker";
private static final String FILE_NAVIGATOR_ID = "fileNavigator";
@@ -143,6 +145,8 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
private TextRange mark;
+ private String anchor;
+
private Mode mode;
private Long requestId;
@@ -197,6 +201,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
if (modeStr != null)
mode = Mode.valueOf(modeStr.toUpperCase());
mark = TextRange.of(params.get(PARAM_MARK).toString());
+ anchor = params.get(PARAM_ANCHOR).toString();
commentId = params.get(PARAM_COMMENT).toOptionalLong();
@@ -732,6 +737,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
state.blobIdent = new BlobIdent(blobIdent);
state.mark = mark;
state.mode = mode;
+ state.anchor = anchor;
state.commentId = commentId;
state.requestId = requestId;
return state;
@@ -751,6 +757,7 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
blobIdent = new BlobIdent(state.blobIdent);
}
mark = state.mark;
+ anchor = state.anchor;
mode = state.mode;
commentId = state.commentId;
requestId = state.requestId;
@@ -835,13 +842,14 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
response.render(JavaScriptHeaderItem.forReference(new DepotFileResourceReference()));
}
- public static PageParameters paramsOf(Depot depot, CodeComment comment) {
+ public static PageParameters paramsOf(Depot depot, CodeComment comment, @Nullable String anchor) {
DepotFilePage.State state = new DepotFilePage.State();
state.blobIdent.revision = comment.getCommentPos().getCommit();
state.blobIdent.path = comment.getCommentPos().getPath();
state.blobIdent.mode = FileMode.TYPE_FILE;
state.commentId = comment.getId();
state.mark = comment.getCommentPos().getRange();
+ state.anchor = anchor;
return paramsOf(depot, state);
}
@@ -853,6 +861,8 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
params.set(PARAM_PATH, state.blobIdent.path);
if (state.mark != null)
params.set(PARAM_MARK, state.mark.toString());
+ if (state.anchor != null)
+ params.set(PARAM_ANCHOR, state.anchor);
if (state.requestId != null)
params.set(PARAM_REQUEST, state.requestId);
if (state.commentId != null)
@@ -925,6 +935,11 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
return mark;
}
+ @Override
+ public String getAnchor() {
+ return anchor;
+ }
+
@Override
public void onMark(AjaxRequestTarget target, TextRange mark) {
this.mark = mark;
@@ -1088,6 +1103,8 @@ public class DepotFilePage extends DepotPage implements BlobViewContext {
public TextRange mark;
+ public String anchor;
+
public Mode mode;
public transient String query;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
index 80f185720d..49872a7563 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/newrequest/NewRequestPage.java
@@ -1,757 +1,762 @@
-package com.pmease.gitplex.web.page.depot.pullrequest.newrequest;
-
-import static com.pmease.gitplex.core.entity.PullRequest.Status.INTEGRATED;
-import static com.pmease.gitplex.core.entity.PullRequest.Status.PENDING_UPDATE;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-
-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.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.form.Button;
-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;
-import org.eclipse.jgit.revwalk.RevWalk;
-
-import com.google.common.base.Preconditions;
-import com.pmease.commons.git.GitUtils;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.lang.diff.WhitespaceOption;
-import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
-import com.pmease.commons.wicket.component.tabbable.AjaxActionTab;
-import com.pmease.commons.wicket.component.tabbable.Tab;
-import com.pmease.commons.wicket.component.tabbable.Tabbable;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.CodeComment;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;
-import com.pmease.gitplex.core.entity.PullRequest.Status;
-import com.pmease.gitplex.core.entity.PullRequestReviewInvitation;
-import com.pmease.gitplex.core.entity.PullRequestUpdate;
-import com.pmease.gitplex.core.entity.support.CloseInfo;
-import com.pmease.gitplex.core.entity.support.CommentPos;
-import com.pmease.gitplex.core.entity.support.DepotAndBranch;
-import com.pmease.gitplex.core.manager.CodeCommentManager;
-import com.pmease.gitplex.core.manager.PullRequestManager;
-import com.pmease.gitplex.core.security.ObjectPermission;
-import com.pmease.gitplex.web.component.BranchLink;
-import com.pmease.gitplex.web.component.branchpicker.AffinalBranchPicker;
-import com.pmease.gitplex.web.component.comment.CommentInput;
-import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
-import com.pmease.gitplex.web.component.commitlist.CommitListPanel;
-import com.pmease.gitplex.web.component.diff.revision.CommentSupport;
-import com.pmease.gitplex.web.component.diff.revision.RevisionDiffPanel;
-import com.pmease.gitplex.web.component.pullrequest.requestassignee.AssigneeChoice;
-import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerAvatar;
-import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerChoice;
-import com.pmease.gitplex.web.model.ReviewersModel;
-import com.pmease.gitplex.web.page.depot.NoBranchesPage;
-import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
-import com.pmease.gitplex.web.page.depot.pullrequest.PullRequestPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.RequestDetailPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.RequestListPage;
-import com.pmease.gitplex.web.page.security.LoginPage;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
-
-@SuppressWarnings("serial")
-public class NewRequestPage extends PullRequestPage implements CommentSupport {
-
- private static final String TAB_PANEL_ID = "tabPanel";
-
- private DepotAndBranch target;
-
- private DepotAndBranch source;
-
- private IModel<List<RevCommit>> commitsModel;
-
- private IModel<PullRequest> requestModel;
-
- private Long commentId;
-
- private CommentPos mark;
-
- private String pathFilter;
-
- private String blameFile;
-
- private WhitespaceOption whitespaceOption = WhitespaceOption.DEFAULT;
-
- public static PageParameters paramsOf(Depot depot, DepotAndBranch target, DepotAndBranch source) {
- PageParameters params = paramsOf(depot);
- params.set("target", target.toString());
- params.set("source", source.toString());
- return params;
- }
-
- public NewRequestPage(PageParameters params) {
- super(params);
-
- if (getDepot().getDefaultBranch() == null)
- throw new RestartResponseException(NoBranchesPage.class, paramsOf(getDepot()));
-
- Account currentUser = getLoginUser();
- if (currentUser == null)
- throw new RestartResponseAtInterceptPageException(LoginPage.class);
-
- PullRequest prevRequest = null;
- String targetParam = params.get("target").toString();
- String sourceParam = params.get("source").toString();
- if (targetParam != null) {
- target = new DepotAndBranch(targetParam);
- } else {
- prevRequest = GitPlex.getInstance(PullRequestManager.class).findLatest(getDepot(), getLoginUser());
- if (prevRequest != null && prevRequest.getTarget().getObjectId(false) != null) {
- target = prevRequest.getTarget();
- } else if (getDepot().getForkedFrom() != null) {
- target = new DepotAndBranch(getDepot().getForkedFrom(),
- getDepot().getForkedFrom().getDefaultBranch());
- } else {
- target = new DepotAndBranch(getDepot(), getDepot().getDefaultBranch());
- }
- }
-
- if (sourceParam != null) {
- source = new DepotAndBranch(sourceParam);
- } else {
- if (prevRequest == null)
- prevRequest = GitPlex.getInstance(PullRequestManager.class).findLatest(getDepot(), getLoginUser());
- if (prevRequest != null && prevRequest.getSource().getObjectId(false) != null) {
- source = prevRequest.getSource();
- } else if (getDepot().getForkedFrom() != null) {
- source = new DepotAndBranch(getDepot(), getDepot().getDefaultBranch());
- } else {
- source = new DepotAndBranch(getDepot(), getDepot().getDefaultBranch());
- }
- }
-
- PullRequest pullRequest;
- if (prevRequest != null && source.equals(prevRequest.getSource()) && target.equals(prevRequest.getTarget()) && prevRequest.isOpen())
- pullRequest = prevRequest;
- else
- pullRequest = GitPlex.getInstance(PullRequestManager.class).findOpen(target, source);
-
- if (pullRequest == null) {
- pullRequest = new PullRequest();
- pullRequest.setTarget(target);
- pullRequest.setSource(source);
- pullRequest.setSubmitter(currentUser);
-
- PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
- List<IntegrationStrategy> strategies = pullRequestManager.getApplicableIntegrationStrategies(pullRequest);
- Preconditions.checkState(!strategies.isEmpty());
- pullRequest.setIntegrationStrategy(strategies.get(0));
-
- ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());
- if (currentUser.asSubject().isPermitted(writePermission))
- pullRequest.setAssignee(currentUser);
- else
- pullRequest.setAssignee(getDepot().getAccount());
-
- ObjectId baseCommitId = GitUtils.getMergeBase(
- target.getDepot().getRepository(), target.getObjectId(),
- source.getDepot().getRepository(), source.getObjectId(),
- GitUtils.branch2ref(source.getBranch()));
-
- pullRequest.setBaseCommitHash(baseCommitId.name());
- if (pullRequest.getBaseCommitHash().equals(source.getObjectName())) {
- CloseInfo closeInfo = new CloseInfo();
- closeInfo.setCloseDate(new Date());
- closeInfo.setCloseStatus(CloseInfo.Status.INTEGRATED);
- pullRequest.setCloseInfo(closeInfo);
- }
-
- PullRequestUpdate update = new PullRequestUpdate();
- pullRequest.addUpdate(update);
- update.setRequest(pullRequest);
- update.setHeadCommitHash(source.getObjectName());
- update.setMergeCommitHash(pullRequest.getBaseCommitHash());
-
- requestModel = Model.of(pullRequest);
- } else {
- Long requestId = pullRequest.getId();
- requestModel = new LoadableDetachableModel<PullRequest>() {
-
- @Override
- protected PullRequest load() {
- return GitPlex.getInstance(PullRequestManager.class).load(requestId);
- }
-
- };
- requestModel.setObject(pullRequest);
- }
-
- commitsModel = new LoadableDetachableModel<List<RevCommit>>() {
-
- @Override
- protected List<RevCommit> load() {
- PullRequest request = getPullRequest();
- List<RevCommit> commits = new ArrayList<>();
- try (RevWalk revWalk = new RevWalk(source.getDepot().getRepository())) {
- ObjectId headId = ObjectId.fromString(request.getHeadCommitHash());
- revWalk.markStart(revWalk.parseCommit(headId));
- ObjectId baseId = ObjectId.fromString(request.getBaseCommitHash());
- revWalk.markUninteresting(revWalk.parseCommit(baseId));
- revWalk.forEach(c->commits.add(c));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return commits;
- }
-
- };
-
- }
-
- private PullRequest getPullRequest() {
- return requestModel.getObject();
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- setOutputMarkupId(true);
-
- add(new AffinalBranchPicker("target", target.getDepotId(), target.getBranch()) {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Depot depot, String branch) {
- PageParameters params = paramsOf(depot, new DepotAndBranch(depot, branch), source);
- setResponsePage(NewRequestPage.class, params);
- }
-
- });
-
- add(new AffinalBranchPicker("source", source.getDepotId(), source.getBranch()) {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Depot depot, String branch) {
- PageParameters params = paramsOf(getDepot(), NewRequestPage.this.target,
- new DepotAndBranch(depot, branch));
- setResponsePage(NewRequestPage.class, params);
- }
-
- });
-
- add(new Link<Void>("swap") {
-
- @Override
- public void onClick() {
- PageParameters params = paramsOf(getPullRequest().getSourceDepot(),
- getPullRequest().getSource(), getPullRequest().getTarget());
- setResponsePage(NewRequestPage.class, params);
- }
-
- });
-
- Fragment fragment;
- if (getPullRequest().getId() != null) {
- fragment = newOpenedFrag();
- } else if (getPullRequest().getSource().equals(getPullRequest().getTarget())) {
- fragment = newSameBranchFrag();
- } else if (getPullRequest().getStatus() == INTEGRATED) {
- fragment = newIntegratedFrag();
- } else if (getPullRequest().getStatus() == PENDING_UPDATE) {
- fragment = newRejectedFrag();
- } else {
- fragment = newCanSendFrag();
- }
- add(fragment);
-
- List<Tab> tabs = new ArrayList<>();
-
- tabs.add(new AjaxActionTab(Model.of("Commits")) {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Component tabLink) {
- Component panel = newCommitsPanel();
- getPage().replace(panel);
- target.add(panel);
- }
-
- });
-
- tabs.add(new AjaxActionTab(Model.of("Files")) {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Component tabLink) {
- Component panel = newRevDiffPanel();
- getPage().replace(panel);
- target.add(panel);
- }
-
- });
-
- add(new Tabbable("tabs", tabs) {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- setVisible(getPullRequest().getStatus() != INTEGRATED);
- }
-
- });
-
- add(newCommitsPanel());
- }
-
- private Component newCommitsPanel() {
- return new CommitListPanel(TAB_PANEL_ID, depotModel, commitsModel) {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() != INTEGRATED);
- }
-
- }.setOutputMarkupId(true);
- }
-
- private RevisionDiffPanel newRevDiffPanel() {
- PullRequest request = getPullRequest();
-
- IModel<Depot> depotModel = new LoadableDetachableModel<Depot>() {
-
- @Override
- protected Depot load() {
- Depot depot = source.getDepot();
- depot.cacheObjectId(source.getRevision(),
- ObjectId.fromString(getPullRequest().getHeadCommitHash()));
- return depot;
- }
-
- };
-
- IModel<String> blameModel = new IModel<String>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public String getObject() {
- return blameFile;
- }
-
- @Override
- public void setObject(String object) {
- blameFile = object;
- }
-
- };
- IModel<String> pathFilterModel = new IModel<String>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public String getObject() {
- return pathFilter;
- }
-
- @Override
- public void setObject(String object) {
- pathFilter = object;
- }
-
- };
- IModel<WhitespaceOption> whitespaceOptionModel = new IModel<WhitespaceOption>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public WhitespaceOption getObject() {
- return whitespaceOption;
- }
-
- @Override
- public void setObject(WhitespaceOption object) {
- whitespaceOption = object;
- }
-
- };
-
- /*
- * we are passing source revision here instead of head commit hash of latest update
- * as we want to preserve the branch name in case they are useful at some point
- * later. Also it is guaranteed to be resolved to the same commit has as we've cached
- * it above when loading the depot
- */
- RevisionDiffPanel diffPanel = new RevisionDiffPanel(TAB_PANEL_ID, depotModel,
- new Model<PullRequest>(null), request.getBaseCommitHash(),
- source.getRevision(), pathFilterModel, whitespaceOptionModel, blameModel, this) {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() != INTEGRATED);
- }
-
- };
- diffPanel.setOutputMarkupId(true);
- return diffPanel;
- }
-
- private Fragment newOpenedFrag() {
- Fragment fragment = new Fragment("status", "openedFrag", this);
- fragment.add(new Label("no", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- return getPullRequest().getId().toString();
- }
- }));
- fragment.add(new Link<Void>("link") {
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
- add(new Label("label", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- return getPullRequest().getTitle();
- }
- }));
- }
-
- @Override
- public void onClick() {
- PageParameters params = RequestDetailPage.paramsOf(getPullRequest());
- setResponsePage(RequestOverviewPage.class, params);
- }
-
- });
-
- return fragment;
- }
-
- private Fragment newSameBranchFrag() {
- return new Fragment("status", "sameBranchFrag", this);
- }
-
- private Fragment newIntegratedFrag() {
- Fragment fragment = new Fragment("status", "integratedFrag", this);
- fragment.add(new BranchLink("sourceBranch", getPullRequest().getSource()));
- fragment.add(new BranchLink("targetBranch", getPullRequest().getTarget()));
- fragment.add(new Link<Void>("swapBranches") {
-
- @Override
- public void onClick() {
- setResponsePage(
- NewRequestPage.class,
- paramsOf(getDepot(), getPullRequest().getSource(), getPullRequest().getTarget()));
- }
-
- });
- 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);
- final Form<?> form = new Form<Void>("form");
- fragment.add(form);
-
- form.add(new Button("send") {
-
- @Override
- public void onSubmit() {
- super.onSubmit();
-
- Dao dao = GitPlex.getInstance(Dao.class);
- DepotAndBranch target = getPullRequest().getTarget();
- DepotAndBranch source = getPullRequest().getSource();
- if (!target.getObjectName().equals(getPullRequest().getTarget().getObjectName())
- || !source.getObjectName().equals(getPullRequest().getSource().getObjectName())) {
- getSession().warn("Either target branch or source branch has new commits just now, please re-check.");
- setResponsePage(NewRequestPage.class, paramsOf(getDepot(), target, source));
- } else {
- getPullRequest().setSource(source);
- getPullRequest().setTarget(target);
- for (PullRequestReviewInvitation 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());
-
- setResponsePage(RequestOverviewPage.class, RequestOverviewPage.paramsOf(getPullRequest()));
- }
- }
-
- });
-
- WebMarkupContainer titleContainer = new WebMarkupContainer("title");
- form.add(titleContainer);
- final TextField<String> titleInput = new TextField<String>("title", new IModel<String>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public String getObject() {
- if (getPullRequest().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());
- }
- return getPullRequest().getTitle();
- }
-
- @Override
- public void setObject(String object) {
- getPullRequest().setTitle(object);
- }
-
- });
- titleInput.setRequired(true);
- titleContainer.add(titleInput);
-
- titleContainer.add(new NotificationPanel("feedback", titleInput));
-
- titleContainer.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
-
- @Override
- public String getObject() {
- return !titleInput.isValid()?" has-error":"";
- }
-
- }));
-
- form.add(new CommentInput("comment", new IModel<String>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public String getObject() {
- return getPullRequest().getDescription();
- }
-
- @Override
- public void setObject(String object) {
- getPullRequest().setDescription(object);
- }
-
- }) {
-
- @Override
- protected AttachmentSupport getAttachmentSupport() {
- return new DepotAttachmentSupport(getDepot(), getPullRequest().getUUID());
- }
-
- @Override
- protected Depot getDepot() {
- return NewRequestPage.this.getDepot();
- }
-
- });
-
- WebMarkupContainer assigneeContainer = new WebMarkupContainer("assignee");
- form.add(assigneeContainer);
- IModel<Account> assigneeModel = new PropertyModel<>(getPullRequest(), "assignee");
- AssigneeChoice assigneeChoice = new AssigneeChoice("assignee", depotModel, 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":"";
- }
-
- }));
-
- WebMarkupContainer reviewersContainer = new WebMarkupContainer("reviewers") {
-
- @Override
- protected void onBeforeRender() {
- super.onBeforeRender();
- }
-
- };
- 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) {
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Account user) {
- super.onSelect(target, user);
-
- target.add(reviewersContainer);
- }
-
- });
-
- reviewersContainer.add(new WebMarkupContainer("prePopulateHint") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getPullRequest().getStatus() == Status.PENDING_APPROVAL);
- }
-
- });
-
- return fragment;
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
- response.render(CssHeaderItem.forReference(new NewRequestResourceReference()));
- }
-
- @Override
- protected void onDetach() {
- commitsModel.detach();
- requestModel.detach();
-
- super.onDetach();
- }
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Depot depot) {
- setResponsePage(RequestListPage.class, paramsOf(depot));
- }
-
- @Override
- public CommentPos getMark() {
- return mark;
- }
-
- @Override
- public String getMarkUrl(CommentPos mark) {
- RevisionComparePage.State state = new RevisionComparePage.State();
- state.mark = mark;
- state.leftSide = new DepotAndBranch(source.getDepot(), getPullRequest().getBaseCommitHash());
- state.rightSide = new DepotAndBranch(source.getDepot(), getPullRequest().getHeadCommitHash());
- state.pathFilter = pathFilter;
- state.tabPanel = RevisionComparePage.TabPanel.CHANGES;
- state.whitespaceOption = whitespaceOption;
- state.compareWithMergeBase = false;
- return urlFor(RevisionComparePage.class, RevisionComparePage.paramsOf(source.getDepot(), state)).toString();
- }
-
- @Override
- public CodeComment getOpenComment() {
- if (commentId != null)
- return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
- else
- return null;
- }
-
- @Override
- public void onCommentOpened(AjaxRequestTarget target, CodeComment comment) {
- if (comment != null) {
- commentId = comment.getId();
- mark = comment.getCommentPos();
- } else {
- commentId = null;
- }
- }
-
- @Override
- public String getCommentUrl(CodeComment comment) {
- RevisionComparePage.State state = new RevisionComparePage.State();
- mark = comment.getCommentPos();
- state.commentId = comment.getId();
- state.leftSide = new DepotAndBranch(source.getDepot(), getPullRequest().getBaseCommitHash());
- state.rightSide = new DepotAndBranch(source.getDepot(), getPullRequest().getHeadCommitHash());
- state.pathFilter = pathFilter;
- state.tabPanel = RevisionComparePage.TabPanel.CHANGES;
- state.whitespaceOption = whitespaceOption;
- state.compareWithMergeBase = false;
- return urlFor(RevisionComparePage.class, RevisionComparePage.paramsOf(source.getDepot(), state)).toString();
- }
-
- @Override
- public void onMark(AjaxRequestTarget target, CommentPos mark) {
- this.mark = mark;
- }
-
- @Override
- public void onAddComment(AjaxRequestTarget target, CommentPos mark) {
- this.commentId = null;
- this.mark = mark;
- }
-
-}
+package com.pmease.gitplex.web.page.depot.pullrequest.newrequest;
+
+import static com.pmease.gitplex.core.entity.PullRequest.Status.INTEGRATED;
+import static com.pmease.gitplex.core.entity.PullRequest.Status.PENDING_UPDATE;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+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.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.form.Button;
+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;
+import org.eclipse.jgit.revwalk.RevWalk;
+
+import com.google.common.base.Preconditions;
+import com.pmease.commons.git.GitUtils;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.lang.diff.WhitespaceOption;
+import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
+import com.pmease.commons.wicket.component.tabbable.AjaxActionTab;
+import com.pmease.commons.wicket.component.tabbable.Tab;
+import com.pmease.commons.wicket.component.tabbable.Tabbable;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.Account;
+import com.pmease.gitplex.core.entity.CodeComment;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.entity.PullRequest.IntegrationStrategy;
+import com.pmease.gitplex.core.entity.PullRequest.Status;
+import com.pmease.gitplex.core.entity.PullRequestReviewInvitation;
+import com.pmease.gitplex.core.entity.PullRequestUpdate;
+import com.pmease.gitplex.core.entity.support.CloseInfo;
+import com.pmease.gitplex.core.entity.support.CommentPos;
+import com.pmease.gitplex.core.entity.support.DepotAndBranch;
+import com.pmease.gitplex.core.manager.CodeCommentManager;
+import com.pmease.gitplex.core.manager.PullRequestManager;
+import com.pmease.gitplex.core.security.ObjectPermission;
+import com.pmease.gitplex.web.component.BranchLink;
+import com.pmease.gitplex.web.component.branchpicker.AffinalBranchPicker;
+import com.pmease.gitplex.web.component.comment.CommentInput;
+import com.pmease.gitplex.web.component.comment.DepotAttachmentSupport;
+import com.pmease.gitplex.web.component.commitlist.CommitListPanel;
+import com.pmease.gitplex.web.component.diff.revision.CommentSupport;
+import com.pmease.gitplex.web.component.diff.revision.RevisionDiffPanel;
+import com.pmease.gitplex.web.component.pullrequest.requestassignee.AssigneeChoice;
+import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerAvatar;
+import com.pmease.gitplex.web.component.pullrequest.requestreviewer.ReviewerChoice;
+import com.pmease.gitplex.web.model.ReviewersModel;
+import com.pmease.gitplex.web.page.depot.NoBranchesPage;
+import com.pmease.gitplex.web.page.depot.compare.RevisionComparePage;
+import com.pmease.gitplex.web.page.depot.pullrequest.PullRequestPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.RequestDetailPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.RequestListPage;
+import com.pmease.gitplex.web.page.security.LoginPage;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+
+@SuppressWarnings("serial")
+public class NewRequestPage extends PullRequestPage implements CommentSupport {
+
+ private static final String TAB_PANEL_ID = "tabPanel";
+
+ private DepotAndBranch target;
+
+ private DepotAndBranch source;
+
+ private IModel<List<RevCommit>> commitsModel;
+
+ private IModel<PullRequest> requestModel;
+
+ private Long commentId;
+
+ private CommentPos mark;
+
+ private String pathFilter;
+
+ private String blameFile;
+
+ private WhitespaceOption whitespaceOption = WhitespaceOption.DEFAULT;
+
+ public static PageParameters paramsOf(Depot depot, DepotAndBranch target, DepotAndBranch source) {
+ PageParameters params = paramsOf(depot);
+ params.set("target", target.toString());
+ params.set("source", source.toString());
+ return params;
+ }
+
+ public NewRequestPage(PageParameters params) {
+ super(params);
+
+ if (getDepot().getDefaultBranch() == null)
+ throw new RestartResponseException(NoBranchesPage.class, paramsOf(getDepot()));
+
+ Account currentUser = getLoginUser();
+ if (currentUser == null)
+ throw new RestartResponseAtInterceptPageException(LoginPage.class);
+
+ PullRequest prevRequest = null;
+ String targetParam = params.get("target").toString();
+ String sourceParam = params.get("source").toString();
+ if (targetParam != null) {
+ target = new DepotAndBranch(targetParam);
+ } else {
+ prevRequest = GitPlex.getInstance(PullRequestManager.class).findLatest(getDepot(), getLoginUser());
+ if (prevRequest != null && prevRequest.getTarget().getObjectId(false) != null) {
+ target = prevRequest.getTarget();
+ } else if (getDepot().getForkedFrom() != null) {
+ target = new DepotAndBranch(getDepot().getForkedFrom(),
+ getDepot().getForkedFrom().getDefaultBranch());
+ } else {
+ target = new DepotAndBranch(getDepot(), getDepot().getDefaultBranch());
+ }
+ }
+
+ if (sourceParam != null) {
+ source = new DepotAndBranch(sourceParam);
+ } else {
+ if (prevRequest == null)
+ prevRequest = GitPlex.getInstance(PullRequestManager.class).findLatest(getDepot(), getLoginUser());
+ if (prevRequest != null && prevRequest.getSource().getObjectId(false) != null) {
+ source = prevRequest.getSource();
+ } else if (getDepot().getForkedFrom() != null) {
+ source = new DepotAndBranch(getDepot(), getDepot().getDefaultBranch());
+ } else {
+ source = new DepotAndBranch(getDepot(), getDepot().getDefaultBranch());
+ }
+ }
+
+ PullRequest pullRequest;
+ if (prevRequest != null && source.equals(prevRequest.getSource()) && target.equals(prevRequest.getTarget()) && prevRequest.isOpen())
+ pullRequest = prevRequest;
+ else
+ pullRequest = GitPlex.getInstance(PullRequestManager.class).findOpen(target, source);
+
+ if (pullRequest == null) {
+ pullRequest = new PullRequest();
+ pullRequest.setTarget(target);
+ pullRequest.setSource(source);
+ pullRequest.setSubmitter(currentUser);
+
+ PullRequestManager pullRequestManager = GitPlex.getInstance(PullRequestManager.class);
+ List<IntegrationStrategy> strategies = pullRequestManager.getApplicableIntegrationStrategies(pullRequest);
+ Preconditions.checkState(!strategies.isEmpty());
+ pullRequest.setIntegrationStrategy(strategies.get(0));
+
+ ObjectPermission writePermission = ObjectPermission.ofDepotWrite(getDepot());
+ if (currentUser.asSubject().isPermitted(writePermission))
+ pullRequest.setAssignee(currentUser);
+ else
+ pullRequest.setAssignee(getDepot().getAccount());
+
+ ObjectId baseCommitId = GitUtils.getMergeBase(
+ target.getDepot().getRepository(), target.getObjectId(),
+ source.getDepot().getRepository(), source.getObjectId(),
+ GitUtils.branch2ref(source.getBranch()));
+
+ pullRequest.setBaseCommitHash(baseCommitId.name());
+ if (pullRequest.getBaseCommitHash().equals(source.getObjectName())) {
+ CloseInfo closeInfo = new CloseInfo();
+ closeInfo.setCloseDate(new Date());
+ closeInfo.setCloseStatus(CloseInfo.Status.INTEGRATED);
+ pullRequest.setCloseInfo(closeInfo);
+ }
+
+ PullRequestUpdate update = new PullRequestUpdate();
+ pullRequest.addUpdate(update);
+ update.setRequest(pullRequest);
+ update.setHeadCommitHash(source.getObjectName());
+ update.setMergeCommitHash(pullRequest.getBaseCommitHash());
+
+ requestModel = Model.of(pullRequest);
+ } else {
+ Long requestId = pullRequest.getId();
+ requestModel = new LoadableDetachableModel<PullRequest>() {
+
+ @Override
+ protected PullRequest load() {
+ return GitPlex.getInstance(PullRequestManager.class).load(requestId);
+ }
+
+ };
+ requestModel.setObject(pullRequest);
+ }
+
+ commitsModel = new LoadableDetachableModel<List<RevCommit>>() {
+
+ @Override
+ protected List<RevCommit> load() {
+ PullRequest request = getPullRequest();
+ List<RevCommit> commits = new ArrayList<>();
+ try (RevWalk revWalk = new RevWalk(source.getDepot().getRepository())) {
+ ObjectId headId = ObjectId.fromString(request.getHeadCommitHash());
+ revWalk.markStart(revWalk.parseCommit(headId));
+ ObjectId baseId = ObjectId.fromString(request.getBaseCommitHash());
+ revWalk.markUninteresting(revWalk.parseCommit(baseId));
+ revWalk.forEach(c->commits.add(c));
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ return commits;
+ }
+
+ };
+
+ }
+
+ private PullRequest getPullRequest() {
+ return requestModel.getObject();
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ setOutputMarkupId(true);
+
+ add(new AffinalBranchPicker("target", target.getDepotId(), target.getBranch()) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Depot depot, String branch) {
+ PageParameters params = paramsOf(depot, new DepotAndBranch(depot, branch), source);
+ setResponsePage(NewRequestPage.class, params);
+ }
+
+ });
+
+ add(new AffinalBranchPicker("source", source.getDepotId(), source.getBranch()) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Depot depot, String branch) {
+ PageParameters params = paramsOf(getDepot(), NewRequestPage.this.target,
+ new DepotAndBranch(depot, branch));
+ setResponsePage(NewRequestPage.class, params);
+ }
+
+ });
+
+ add(new Link<Void>("swap") {
+
+ @Override
+ public void onClick() {
+ PageParameters params = paramsOf(getPullRequest().getSourceDepot(),
+ getPullRequest().getSource(), getPullRequest().getTarget());
+ setResponsePage(NewRequestPage.class, params);
+ }
+
+ });
+
+ Fragment fragment;
+ if (getPullRequest().getId() != null) {
+ fragment = newOpenedFrag();
+ } else if (getPullRequest().getSource().equals(getPullRequest().getTarget())) {
+ fragment = newSameBranchFrag();
+ } else if (getPullRequest().getStatus() == INTEGRATED) {
+ fragment = newIntegratedFrag();
+ } else if (getPullRequest().getStatus() == PENDING_UPDATE) {
+ fragment = newRejectedFrag();
+ } else {
+ fragment = newCanSendFrag();
+ }
+ add(fragment);
+
+ List<Tab> tabs = new ArrayList<>();
+
+ tabs.add(new AjaxActionTab(Model.of("Commits")) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Component tabLink) {
+ Component panel = newCommitsPanel();
+ getPage().replace(panel);
+ target.add(panel);
+ }
+
+ });
+
+ tabs.add(new AjaxActionTab(Model.of("Files")) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Component tabLink) {
+ Component panel = newRevDiffPanel();
+ getPage().replace(panel);
+ target.add(panel);
+ }
+
+ });
+
+ add(new Tabbable("tabs", tabs) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ setVisible(getPullRequest().getStatus() != INTEGRATED);
+ }
+
+ });
+
+ add(newCommitsPanel());
+ }
+
+ private Component newCommitsPanel() {
+ return new CommitListPanel(TAB_PANEL_ID, depotModel, commitsModel) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getStatus() != INTEGRATED);
+ }
+
+ }.setOutputMarkupId(true);
+ }
+
+ private RevisionDiffPanel newRevDiffPanel() {
+ PullRequest request = getPullRequest();
+
+ IModel<Depot> depotModel = new LoadableDetachableModel<Depot>() {
+
+ @Override
+ protected Depot load() {
+ Depot depot = source.getDepot();
+ depot.cacheObjectId(source.getRevision(),
+ ObjectId.fromString(getPullRequest().getHeadCommitHash()));
+ return depot;
+ }
+
+ };
+
+ IModel<String> blameModel = new IModel<String>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public String getObject() {
+ return blameFile;
+ }
+
+ @Override
+ public void setObject(String object) {
+ blameFile = object;
+ }
+
+ };
+ IModel<String> pathFilterModel = new IModel<String>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public String getObject() {
+ return pathFilter;
+ }
+
+ @Override
+ public void setObject(String object) {
+ pathFilter = object;
+ }
+
+ };
+ IModel<WhitespaceOption> whitespaceOptionModel = new IModel<WhitespaceOption>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public WhitespaceOption getObject() {
+ return whitespaceOption;
+ }
+
+ @Override
+ public void setObject(WhitespaceOption object) {
+ whitespaceOption = object;
+ }
+
+ };
+
+ /*
+ * we are passing source revision here instead of head commit hash of latest update
+ * as we want to preserve the branch name in case they are useful at some point
+ * later. Also it is guaranteed to be resolved to the same commit has as we've cached
+ * it above when loading the depot
+ */
+ RevisionDiffPanel diffPanel = new RevisionDiffPanel(TAB_PANEL_ID, depotModel,
+ new Model<PullRequest>(null), request.getBaseCommitHash(),
+ source.getRevision(), pathFilterModel, whitespaceOptionModel, blameModel, this) {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getStatus() != INTEGRATED);
+ }
+
+ };
+ diffPanel.setOutputMarkupId(true);
+ return diffPanel;
+ }
+
+ private Fragment newOpenedFrag() {
+ Fragment fragment = new Fragment("status", "openedFrag", this);
+ fragment.add(new Label("no", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return getPullRequest().getId().toString();
+ }
+ }));
+ fragment.add(new Link<Void>("link") {
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+ add(new Label("label", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return getPullRequest().getTitle();
+ }
+ }));
+ }
+
+ @Override
+ public void onClick() {
+ PageParameters params = RequestDetailPage.paramsOf(getPullRequest());
+ setResponsePage(RequestOverviewPage.class, params);
+ }
+
+ });
+
+ return fragment;
+ }
+
+ private Fragment newSameBranchFrag() {
+ return new Fragment("status", "sameBranchFrag", this);
+ }
+
+ private Fragment newIntegratedFrag() {
+ Fragment fragment = new Fragment("status", "integratedFrag", this);
+ fragment.add(new BranchLink("sourceBranch", getPullRequest().getSource()));
+ fragment.add(new BranchLink("targetBranch", getPullRequest().getTarget()));
+ fragment.add(new Link<Void>("swapBranches") {
+
+ @Override
+ public void onClick() {
+ setResponsePage(
+ NewRequestPage.class,
+ paramsOf(getDepot(), getPullRequest().getSource(), getPullRequest().getTarget()));
+ }
+
+ });
+ 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);
+ final Form<?> form = new Form<Void>("form");
+ fragment.add(form);
+
+ form.add(new Button("send") {
+
+ @Override
+ public void onSubmit() {
+ super.onSubmit();
+
+ Dao dao = GitPlex.getInstance(Dao.class);
+ DepotAndBranch target = getPullRequest().getTarget();
+ DepotAndBranch source = getPullRequest().getSource();
+ if (!target.getObjectName().equals(getPullRequest().getTarget().getObjectName())
+ || !source.getObjectName().equals(getPullRequest().getSource().getObjectName())) {
+ getSession().warn("Either target branch or source branch has new commits just now, please re-check.");
+ setResponsePage(NewRequestPage.class, paramsOf(getDepot(), target, source));
+ } else {
+ getPullRequest().setSource(source);
+ getPullRequest().setTarget(target);
+ for (PullRequestReviewInvitation 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());
+
+ setResponsePage(RequestOverviewPage.class, RequestOverviewPage.paramsOf(getPullRequest()));
+ }
+ }
+
+ });
+
+ WebMarkupContainer titleContainer = new WebMarkupContainer("title");
+ form.add(titleContainer);
+ final TextField<String> titleInput = new TextField<String>("title", new IModel<String>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public String getObject() {
+ if (getPullRequest().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());
+ }
+ return getPullRequest().getTitle();
+ }
+
+ @Override
+ public void setObject(String object) {
+ getPullRequest().setTitle(object);
+ }
+
+ });
+ titleInput.setRequired(true);
+ titleContainer.add(titleInput);
+
+ titleContainer.add(new NotificationPanel("feedback", titleInput));
+
+ titleContainer.add(AttributeAppender.append("class", new AbstractReadOnlyModel<String>() {
+
+ @Override
+ public String getObject() {
+ return !titleInput.isValid()?" has-error":"";
+ }
+
+ }));
+
+ form.add(new CommentInput("comment", new IModel<String>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public String getObject() {
+ return getPullRequest().getDescription();
+ }
+
+ @Override
+ public void setObject(String object) {
+ getPullRequest().setDescription(object);
+ }
+
+ }) {
+
+ @Override
+ protected AttachmentSupport getAttachmentSupport() {
+ return new DepotAttachmentSupport(getDepot(), getPullRequest().getUUID());
+ }
+
+ @Override
+ protected Depot getDepot() {
+ return NewRequestPage.this.getDepot();
+ }
+
+ });
+
+ WebMarkupContainer assigneeContainer = new WebMarkupContainer("assignee");
+ form.add(assigneeContainer);
+ IModel<Account> assigneeModel = new PropertyModel<>(getPullRequest(), "assignee");
+ AssigneeChoice assigneeChoice = new AssigneeChoice("assignee", depotModel, 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":"";
+ }
+
+ }));
+
+ WebMarkupContainer reviewersContainer = new WebMarkupContainer("reviewers") {
+
+ @Override
+ protected void onBeforeRender() {
+ super.onBeforeRender();
+ }
+
+ };
+ 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) {
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Account user) {
+ super.onSelect(target, user);
+
+ target.add(reviewersContainer);
+ }
+
+ });
+
+ reviewersContainer.add(new WebMarkupContainer("prePopulateHint") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(getPullRequest().getStatus() == Status.PENDING_APPROVAL);
+ }
+
+ });
+
+ return fragment;
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+ response.render(CssHeaderItem.forReference(new NewRequestResourceReference()));
+ }
+
+ @Override
+ protected void onDetach() {
+ commitsModel.detach();
+ requestModel.detach();
+
+ super.onDetach();
+ }
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Depot depot) {
+ setResponsePage(RequestListPage.class, paramsOf(depot));
+ }
+
+ @Override
+ public CommentPos getMark() {
+ return mark;
+ }
+
+ @Override
+ public String getMarkUrl(CommentPos mark) {
+ RevisionComparePage.State state = new RevisionComparePage.State();
+ state.mark = mark;
+ state.leftSide = new DepotAndBranch(source.getDepot(), getPullRequest().getBaseCommitHash());
+ state.rightSide = new DepotAndBranch(source.getDepot(), getPullRequest().getHeadCommitHash());
+ state.pathFilter = pathFilter;
+ state.tabPanel = RevisionComparePage.TabPanel.CHANGES;
+ state.whitespaceOption = whitespaceOption;
+ state.compareWithMergeBase = false;
+ return urlFor(RevisionComparePage.class, RevisionComparePage.paramsOf(source.getDepot(), state)).toString();
+ }
+
+ @Override
+ public CodeComment getOpenComment() {
+ if (commentId != null)
+ return GitPlex.getInstance(CodeCommentManager.class).load(commentId);
+ else
+ return null;
+ }
+
+ @Override
+ public void onCommentOpened(AjaxRequestTarget target, CodeComment comment) {
+ if (comment != null) {
+ commentId = comment.getId();
+ mark = comment.getCommentPos();
+ } else {
+ commentId = null;
+ }
+ }
+
+ @Override
+ public String getCommentUrl(CodeComment comment) {
+ RevisionComparePage.State state = new RevisionComparePage.State();
+ mark = comment.getCommentPos();
+ state.commentId = comment.getId();
+ state.leftSide = new DepotAndBranch(source.getDepot(), getPullRequest().getBaseCommitHash());
+ state.rightSide = new DepotAndBranch(source.getDepot(), getPullRequest().getHeadCommitHash());
+ state.pathFilter = pathFilter;
+ state.tabPanel = RevisionComparePage.TabPanel.CHANGES;
+ state.whitespaceOption = whitespaceOption;
+ state.compareWithMergeBase = false;
+ return urlFor(RevisionComparePage.class, RevisionComparePage.paramsOf(source.getDepot(), state)).toString();
+ }
+
+ @Override
+ public void onMark(AjaxRequestTarget target, CommentPos mark) {
+ this.mark = mark;
+ }
+
+ @Override
+ public void onAddComment(AjaxRequestTarget target, CommentPos mark) {
+ this.commentId = null;
+ this.mark = mark;
+ }
+
+ @Override
+ public String getAnchor() {
+ return null;
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.html
index aa6d0e0064..843874bd05 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.html
@@ -18,7 +18,7 @@
<div class="commits-selector noselect">
<div class="head clearfix">
<div class="title pull-left">Click to select a commit, or shift-click to select range of commits</div>
- <a title="Apply selected commits" class="btn btn-sm btn-default"><i class="fa fa-ext fa-file-diff"></i> Show changes</a>
+ <a title="Apply selected commits" disabled="disabled" class="btn btn-xs btn-default"><i class="fa fa-ext fa-file-diff"></i> Show changes</a>
</div>
<ul class="body list-unstyled autosize">
<li wicket:id="commits">
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.java
index 6f35b23fa2..cacd1bd123 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/RequestChangesPage.java
@@ -72,6 +72,8 @@ public class RequestChangesPage extends RequestDetailPage implements CommentSupp
private static final String PARAM_MARK = "mark";
+ private static final String PARAM_ANCHOR = "anchor";
+
private State state = new State();
private WebMarkupContainer head;
@@ -103,6 +105,7 @@ public class RequestChangesPage extends RequestDetailPage implements CommentSupp
state.whitespaceOption = WhitespaceOption.of(params.get(PARAM_WHITESPACE_OPTION).toString());
state.commentId = params.get(PARAM_COMMENT).toOptionalLong();
state.mark = CommentPos.of(params.get(PARAM_MARK).toString());
+ state.anchor = params.get(PARAM_ANCHOR).toString();
}
private int getCommitIndex(String commitHash) {
@@ -334,7 +337,7 @@ public class RequestChangesPage extends RequestDetailPage implements CommentSupp
return paramsOf(request, state);
}
- public static PageParameters paramsOf(PullRequest request, CodeComment comment) {
+ public static PageParameters paramsOf(PullRequest request, CodeComment comment, @Nullable String anchor) {
PullRequest.ComparingInfo comparingInfo = null;
for (int i=comment.getActivities().size()-1; i>=0; i--) {
CodeCommentActivity activity = comment.getActivities().get(i);
@@ -352,6 +355,7 @@ public class RequestChangesPage extends RequestDetailPage implements CommentSupp
state.newCommit = comparingInfo.getNewCommit();
state.pathFilter = comparingInfo.getPathFilter();
state.whitespaceOption = comparingInfo.getWhitespaceOption();
+ state.anchor = anchor;
return paramsOf(request, state);
}
@@ -372,6 +376,8 @@ public class RequestChangesPage extends RequestDetailPage implements CommentSupp
params.set(PARAM_COMMENT, state.commentId);
if (state.mark != null)
params.set(PARAM_MARK, state.mark.toString());
+ if (state.anchor != null)
+ params.set(PARAM_ANCHOR, state.anchor);
return params;
}
@@ -475,6 +481,11 @@ public class RequestChangesPage extends RequestDetailPage implements CommentSupp
return state.mark;
}
+ @Override
+ public String getAnchor() {
+ return state.anchor;
+ }
+
@Override
public String getMarkUrl(CommentPos mark) {
State markState = new State();
@@ -563,6 +574,9 @@ public class RequestChangesPage extends RequestDetailPage implements CommentSupp
@Nullable
public CommentPos mark;
+ @Nullable
+ public String anchor;
+
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/request-changes.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/request-changes.css
index 85076e7474..8b0118694e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/request-changes.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/request-changes.css
@@ -14,9 +14,6 @@
color: #666;
}
-.commits-selector {
- min-width: 520px;
-}
.commits-selector>.head {
padding: 8px;
border-bottom: 1px solid #DDD;
@@ -25,7 +22,6 @@
}
.commits-selector>.head>a {
margin-left: 8px;
- display: none;
}
.commits-selector ul {
margin-bottom: 0;
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/request-changes.js b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/request-changes.js
index 496f6088f8..cc852161a2 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/request-changes.js
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/changes/request-changes.js
@@ -10,7 +10,7 @@ gitplex.requestChanges = {
function onIndexChanged() {
var $apply = $(".commits-selector>.head a");
if (fromIndexToApply != fromIndex || toIndexToApply != toIndex) {
- $apply.show().off("click").click(function() {
+ $apply.removeAttr("disabled").off("click").click(function() {
var oldCommit;
if (fromIndexToApply == 0)
oldCommit = baseCommit;
@@ -20,7 +20,7 @@ gitplex.requestChanges = {
callback(oldCommit, newCommit);
});
} else {
- $apply.hide();
+ $apply.attr("disabled", "disabled");
}
$commits.removeClass("selected").slice(fromIndexToApply, toIndexToApply+1).addClass("selected");
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/PullRequestActivity.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/PullRequestActivity.java
index 2f460c1cc8..3266475eaf 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/PullRequestActivity.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/PullRequestActivity.java
@@ -3,6 +3,8 @@ package com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview;
import java.io.Serializable;
import java.util.Date;
+import javax.annotation.Nullable;
+
import org.apache.wicket.markup.html.panel.Panel;
public interface PullRequestActivity extends Serializable {
@@ -10,4 +12,7 @@ public interface PullRequestActivity extends Serializable {
Date getDate();
Panel render(String panelId);
+
+ @Nullable
+ String getAnchor();
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java
index c5fac1b147..01246c220f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/RequestOverviewPage.java
@@ -124,8 +124,10 @@ public class RequestOverviewPage extends RequestDetailPage {
}
};
-
row.setOutputMarkupId(true);
+ String anchor = activity.getAnchor();
+ if (anchor != null)
+ row.setMarkupId(anchor);
if (row.get("content") == null)
row.add(activity.render("content"));
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/CommentedActivity.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/CommentedActivity.java
index 64a8b7aa85..89472df384 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/CommentedActivity.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/CommentedActivity.java
@@ -40,4 +40,9 @@ public class CommentedActivity implements PullRequestActivity {
return getComment().getDate();
}
+ @Override
+ public String getAnchor() {
+ return getComment().getAnchor();
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/OpenedActivity.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/OpenedActivity.java
index 3446b6be0f..70a5a7286b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/OpenedActivity.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/OpenedActivity.java
@@ -40,4 +40,9 @@ public class OpenedActivity implements PullRequestActivity {
return getRequest().getSubmitDate();
}
+ @Override
+ public String getAnchor() {
+ return null;
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/ReferencedActivity.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/ReferencedActivity.java
index 7b6ba6b2e9..ceb474c67f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/ReferencedActivity.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/ReferencedActivity.java
@@ -39,4 +39,9 @@ public class ReferencedActivity implements PullRequestActivity {
return getReference().getDate();
}
+ @Override
+ public String getAnchor() {
+ return null;
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangeActivity.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangeActivity.java
index 48bf78f44c..0dbc18a304 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangeActivity.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangeActivity.java
@@ -39,5 +39,10 @@ public class StatusChangeActivity implements PullRequestActivity {
public Date getDate() {
return getStatusChange().getDate();
}
-
+
+ @Override
+ public String getAnchor() {
+ return getStatusChange().getAnchor();
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangePanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangePanel.java
index 46efcd10f5..6144f48c1c 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangePanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/StatusChangePanel.java
@@ -22,7 +22,6 @@ import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;
import com.pmease.commons.wicket.behavior.markdown.AttachmentSupport;
import com.pmease.commons.wicket.component.markdown.MarkdownEditSupport;
import com.pmease.commons.wicket.component.markdown.MarkdownPanel;
-import com.pmease.commons.wicket.editable.EditableUtils;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.entity.Depot;
import com.pmease.gitplex.core.entity.PullRequest;
@@ -178,18 +177,18 @@ class StatusChangePanel extends GenericPanel<PullRequestStatusChange> {
PullRequestStatusChange statusChange = getModelObject();
WebMarkupContainer container = new WebMarkupContainer("statusChange");
- String activityName = EditableUtils.getName(statusChange.getEventType());
+ String activityName = statusChange.getType().getName();
container.add(AttributeAppender.append("class", "activity " + activityName.replace(" ", "-").toLowerCase()));
WebMarkupContainer icon = new WebMarkupContainer("icon");
container.add(icon);
- String iconClass = EditableUtils.getIcon(statusChange.getEventType());
+ String iconClass = statusChange.getType().getIconClass();
if (iconClass != null)
icon.add(AttributeAppender.append("class", iconClass));
container.add(new AvatarLink("userAvatar", statusChange.getUser(), null));
container.add(new AccountLink("userName", statusChange.getUser()));
- container.add(new Label("eventName", EditableUtils.getName(statusChange.getEventType())));
+ 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/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedActivity.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedActivity.java
index 07a6b7d3f1..0381f13be0 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedActivity.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestdetail/overview/activity/UpdatedActivity.java
@@ -40,4 +40,9 @@ public class UpdatedActivity implements PullRequestActivity {
return getUpdate().getDate();
}
+ @Override
+ public String getAnchor() {
+ return null;
+ }
+
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestlist/RequestListPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestlist/RequestListPage.java
index aae0b30123..406f9cd74e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestlist/RequestListPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/depot/pullrequest/requestlist/RequestListPage.java
@@ -1,440 +1,439 @@
-package com.pmease.gitplex.web.page.depot.pullrequest.requestlist;
-
-import java.util.ArrayList;
-import java.util.Date;
-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.behavior.AttributeAppender;
-import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
-import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
-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.data.table.NavigationToolbar;
-import org.apache.wicket.extensions.markup.html.repeater.data.table.NoRecordsToolbar;
-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.Form;
-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.navigation.paging.PagingNavigator;
-import org.apache.wicket.markup.html.panel.Fragment;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.data.IDataProvider;
-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 com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.commons.wicket.component.menu.MenuItem;
-import com.pmease.commons.wicket.component.menu.MenuLink;
-import com.pmease.commons.wicket.editable.BeanContext;
-import com.pmease.commons.wicket.editable.EditableUtils;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.entity.Account;
-import com.pmease.gitplex.core.entity.Depot;
-import com.pmease.gitplex.core.entity.PullRequest;
-import com.pmease.gitplex.core.manager.AccountManager;
-import com.pmease.gitplex.web.Constants;
-import com.pmease.gitplex.web.component.AccountLink;
-import com.pmease.gitplex.web.component.BranchLink;
-import com.pmease.gitplex.web.component.pullrequest.requeststatus.RequestStatusPanel;
-import com.pmease.gitplex.web.page.depot.DepotPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.PullRequestPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.newrequest.NewRequestPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.SearchOption.Status;
-import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.SearchOption.Type;
-import com.pmease.gitplex.web.util.DateUtils;
-
-import de.agilecoders.wicket.core.markup.html.bootstrap.navigation.BootstrapPagingNavigator;
-
-@SuppressWarnings("serial")
-public class RequestListPage extends PullRequestPage {
-
- private static final Map<SortOption, String> sortNames = new LinkedHashMap<>();
-
- static {
- sortNames.put(new SortOption("submitDate", false), "Newest");
- sortNames.put(new SortOption("submitDate", true), "Oldest");
- sortNames.put(new SortOption("lastEventDate", false), "Recently updated");
- sortNames.put(new SortOption("lastEventDate", true), "Least recently updated");
- }
-
- private SearchOption searchOption;
-
- private SortOption sortOption;
-
- public RequestListPage(PageParameters params) {
- super(params);
-
- searchOption = new SearchOption(params);
- sortOption = new SortOption(params);
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new MenuLink("filters") {
-
- @Override
- protected List<MenuItem> getMenuItems() {
- List<MenuItem> menuItems = new ArrayList<>();
-
- Account currentUser = GitPlex.getInstance(AccountManager.class).getCurrent();
- if (currentUser != null) {
- final String userName = currentUser.getName();
- menuItems.add(new MenuItem() {
-
- @Override
- public String getIconClass() {
- return null;
- }
-
- @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
- public String getIconClass() {
- return null;
- }
-
- @Override
- public String getLabel() {
- return "Open requests submitted by me";
- }
-
- @Override
- public AbstractLink newLink(String id) {
- return new Link<Void>(id) {
-
- @Override
- public void onClick() {
- searchOption = new SearchOption();
- searchOption.setStatus(Status.OPEN);
- searchOption.setSubmitterName(userName);
-
- setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
- }
-
- };
- }
-
- });
- }
- menuItems.add(new MenuItem() {
-
- @Override
- public String getIconClass() {
- return null;
- }
-
- @Override
- public String getLabel() {
- return "All open requests";
- }
-
- @Override
- public AbstractLink newLink(String id) {
- return new Link<Void>(id) {
-
- @Override
- public void onClick() {
- searchOption = new SearchOption();
- searchOption.setStatus(Status.OPEN);
-
- setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
- }
-
- };
- }
-
- });
- menuItems.add(new MenuItem() {
-
- @Override
- public String getIconClass() {
- return null;
- }
-
- @Override
- public String getLabel() {
- return "Open requests targeting this repository";
- }
-
- @Override
- public AbstractLink newLink(String id) {
- return new Link<Void>(id) {
-
- @Override
- public void onClick() {
- searchOption = new SearchOption();
- searchOption.setType(Type.TARGETING);
- searchOption.setStatus(Status.OPEN);
-
- setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
- }
-
- };
- }
-
- });
- menuItems.add(new MenuItem() {
-
- @Override
- public String getIconClass() {
- return null;
- }
-
- @Override
- public String getLabel() {
- return "Open requests originating from this repository";
- }
-
- @Override
- public AbstractLink newLink(String id) {
- return new Link<Void>(id) {
-
- @Override
- public void onClick() {
- searchOption = new SearchOption();
- searchOption.setType(Type.ORIGINATING);
- searchOption.setStatus(Status.OPEN);
-
- setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
- }
-
- };
- }
-
- });
- return menuItems;
- }
-
- });
-
- add(new MenuLink("sortBy") {
-
- @Override
- protected List<MenuItem> getMenuItems() {
- List<MenuItem> menuItems = new ArrayList<>();
-
- for (Map.Entry<SortOption, String> entry: sortNames.entrySet()) {
- final SortOption sortOption = entry.getKey();
- final String displayName = entry.getValue();
- menuItems.add(new MenuItem() {
-
- @Override
- public String getLabel() {
- return displayName;
- }
-
- @Override
- public String getIconClass() {
- if (RequestListPage.this.sortOption.equals(sortOption))
- return "fa fa-check";
- else
- return null;
- }
-
- @Override
- public AbstractLink newLink(String id) {
- return new Link<Void>(id) {
-
- @Override
- public void onClick() {
- setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
- }
-
- };
- }
-
- });
- }
-
- return menuItems;
- }
-
- });
-
- add(new Link<Void>("newRequest") {
-
- @Override
- public void onClick() {
- DepotPage page = (DepotPage) getPage();
- setResponsePage(NewRequestPage.class, NewRequestPage.paramsOf(page.getDepot()));
- }
-
- });
-
- Form<?> form = new Form<Void>("filterForm") {
-
- @Override
- protected void onSubmit() {
- super.onSubmit();
-
- setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
- }
-
- };
- form.add(BeanContext.editBean("editor", searchOption));
- add(form);
-
- List<IColumn<PullRequest, Void>> columns = new ArrayList<>();
- columns.add(new AbstractColumn<PullRequest, Void>(Model.of("Pull Request")) {
-
- @Override
- public void populateItem(Item<ICellPopulator<PullRequest>> cellItem,
- String componentId, final IModel<PullRequest> rowModel) {
- PullRequest request = rowModel.getObject();
- Fragment fragment = new Fragment(componentId, "requestFrag", RequestListPage.this);
- fragment.add(new Label("number", "#" + request.getNumber()));
- fragment.add(new BookmarkablePageLink<Void>("title", RequestOverviewPage.class,
- RequestOverviewPage.paramsOf(request)) {
-
- @Override
- public IModel<?> getBody() {
- return Model.of(rowModel.getObject().getTitle());
- }
-
- });
-
- fragment.add(new RequestStatusPanel("status", rowModel, false));
- fragment.add(new AccountLink("submitter", rowModel.getObject().getSubmitter()));
- fragment.add(new BranchLink("target", request.getTarget()));
- if (request.getSource() != null)
- fragment.add(new BranchLink("source", request.getSource()));
- else
- fragment.add(new Label("source").setVisible(false));
-
- fragment.add(new Label("date", DateUtils.formatAge(request.getSubmitDate())));
-
- 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));
- String description = EditableUtils.getName(request.getLastEvent().getType());
- lastEventContainer.add(new Label("description", description));
- lastEventContainer.add(new Label("date", DateUtils.formatAge(request.getLastEvent().getDate())));
- } else {
- lastEventContainer.add(new WebMarkupContainer("user"));
- lastEventContainer.add(new WebMarkupContainer("description"));
- lastEventContainer.add(new WebMarkupContainer("date"));
- lastEventContainer.setVisible(false);
- }
- fragment.add(lastEventContainer);
-
- cellItem.add(fragment);
-
- Date lastActivityDate;
- if (request.getLastEvent() != null)
- lastActivityDate = request.getLastEvent().getDate();
- else
- lastActivityDate = request.getSubmitDate();
- cellItem.add(AttributeAppender.append("class",
- request.isVisitedAfter(lastActivityDate)?"request":"request new"));
- }
-
- });
-
- IDataProvider<PullRequest> dataProvider = new IDataProvider<PullRequest>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public Iterator<? extends PullRequest> iterator(long first, long count) {
- DepotPage page = (DepotPage) getPage();
-
- EntityCriteria<PullRequest> criteria = searchOption.getCriteria(page.getDepot());
- criteria.addOrder(sortOption.getOrder());
- return GitPlex.getInstance(Dao.class).findRange(criteria, (int)first, (int)count).iterator();
- }
-
- @Override
- public long size() {
- DepotPage page = (DepotPage) getPage();
- return GitPlex.getInstance(Dao.class).count(searchOption.getCriteria(page.getDepot()));
- }
-
- @Override
- public IModel<PullRequest> model(PullRequest object) {
- final Long pullRequestId = object.getId();
- return new LoadableDetachableModel<PullRequest>() {
-
- @Override
- protected PullRequest load() {
- return GitPlex.getInstance(Dao.class).load(PullRequest.class, pullRequestId);
- }
-
- };
- }
-
- };
- DataTable<PullRequest, Void> dataTable = new DataTable<>("requests", columns,
- dataProvider, Constants.DEFAULT_PAGE_SIZE);
- dataTable.addBottomToolbar(new NoRecordsToolbar(dataTable));
- dataTable.addBottomToolbar(new NavigationToolbar(dataTable) {
-
- @Override
- protected PagingNavigator newPagingNavigator(String navigatorId, DataTable<?, ?> table) {
- return new BootstrapPagingNavigator(navigatorId, dataTable);
- }
-
- });
- add(dataTable);
- }
-
- @Override
- public void renderHead(IHeaderResponse response) {
- super.renderHead(response);
-
- response.render(CssHeaderItem.forReference(new RequestListResourceReference()));
- }
-
- public static PageParameters paramsOf(Depot depot, SearchOption searchOption, SortOption sortOption) {
- PageParameters params = paramsOf(depot);
- searchOption.fillPageParams(params);
- sortOption.fillPageParams(params);
- return params;
- }
-
- @Override
- protected void onSelect(AjaxRequestTarget target, Depot depot) {
- setResponsePage(RequestListPage.class, paramsOf(depot));
- }
-
-}
+package com.pmease.gitplex.web.page.depot.pullrequest.requestlist;
+
+import java.util.ArrayList;
+import java.util.Date;
+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.behavior.AttributeAppender;
+import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
+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.data.table.NavigationToolbar;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.NoRecordsToolbar;
+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.Form;
+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.navigation.paging.PagingNavigator;
+import org.apache.wicket.markup.html.panel.Fragment;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.data.IDataProvider;
+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 com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.hibernate.dao.EntityCriteria;
+import com.pmease.commons.wicket.component.menu.MenuItem;
+import com.pmease.commons.wicket.component.menu.MenuLink;
+import com.pmease.commons.wicket.editable.BeanContext;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.entity.Account;
+import com.pmease.gitplex.core.entity.Depot;
+import com.pmease.gitplex.core.entity.PullRequest;
+import com.pmease.gitplex.core.manager.AccountManager;
+import com.pmease.gitplex.web.Constants;
+import com.pmease.gitplex.web.component.AccountLink;
+import com.pmease.gitplex.web.component.BranchLink;
+import com.pmease.gitplex.web.component.pullrequest.requeststatus.RequestStatusPanel;
+import com.pmease.gitplex.web.page.depot.DepotPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.PullRequestPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.newrequest.NewRequestPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestdetail.overview.RequestOverviewPage;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.SearchOption.Status;
+import com.pmease.gitplex.web.page.depot.pullrequest.requestlist.SearchOption.Type;
+import com.pmease.gitplex.web.util.DateUtils;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.navigation.BootstrapPagingNavigator;
+
+@SuppressWarnings("serial")
+public class RequestListPage extends PullRequestPage {
+
+ private static final Map<SortOption, String> sortNames = new LinkedHashMap<>();
+
+ static {
+ sortNames.put(new SortOption("submitDate", false), "Newest");
+ sortNames.put(new SortOption("submitDate", true), "Oldest");
+ sortNames.put(new SortOption("lastEventDate", false), "Recently updated");
+ sortNames.put(new SortOption("lastEventDate", true), "Least recently updated");
+ }
+
+ private SearchOption searchOption;
+
+ private SortOption sortOption;
+
+ public RequestListPage(PageParameters params) {
+ super(params);
+
+ searchOption = new SearchOption(params);
+ sortOption = new SortOption(params);
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ add(new MenuLink("filters") {
+
+ @Override
+ protected List<MenuItem> getMenuItems() {
+ List<MenuItem> menuItems = new ArrayList<>();
+
+ Account currentUser = GitPlex.getInstance(AccountManager.class).getCurrent();
+ if (currentUser != null) {
+ final String userName = currentUser.getName();
+ menuItems.add(new MenuItem() {
+
+ @Override
+ public String getIconClass() {
+ return null;
+ }
+
+ @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
+ public String getIconClass() {
+ return null;
+ }
+
+ @Override
+ public String getLabel() {
+ return "Open requests submitted by me";
+ }
+
+ @Override
+ public AbstractLink newLink(String id) {
+ return new Link<Void>(id) {
+
+ @Override
+ public void onClick() {
+ searchOption = new SearchOption();
+ searchOption.setStatus(Status.OPEN);
+ searchOption.setSubmitterName(userName);
+
+ setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
+ }
+
+ };
+ }
+
+ });
+ }
+ menuItems.add(new MenuItem() {
+
+ @Override
+ public String getIconClass() {
+ return null;
+ }
+
+ @Override
+ public String getLabel() {
+ return "All open requests";
+ }
+
+ @Override
+ public AbstractLink newLink(String id) {
+ return new Link<Void>(id) {
+
+ @Override
+ public void onClick() {
+ searchOption = new SearchOption();
+ searchOption.setStatus(Status.OPEN);
+
+ setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
+ }
+
+ };
+ }
+
+ });
+ menuItems.add(new MenuItem() {
+
+ @Override
+ public String getIconClass() {
+ return null;
+ }
+
+ @Override
+ public String getLabel() {
+ return "Open requests targeting this repository";
+ }
+
+ @Override
+ public AbstractLink newLink(String id) {
+ return new Link<Void>(id) {
+
+ @Override
+ public void onClick() {
+ searchOption = new SearchOption();
+ searchOption.setType(Type.TARGETING);
+ searchOption.setStatus(Status.OPEN);
+
+ setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
+ }
+
+ };
+ }
+
+ });
+ menuItems.add(new MenuItem() {
+
+ @Override
+ public String getIconClass() {
+ return null;
+ }
+
+ @Override
+ public String getLabel() {
+ return "Open requests originating from this repository";
+ }
+
+ @Override
+ public AbstractLink newLink(String id) {
+ return new Link<Void>(id) {
+
+ @Override
+ public void onClick() {
+ searchOption = new SearchOption();
+ searchOption.setType(Type.ORIGINATING);
+ searchOption.setStatus(Status.OPEN);
+
+ setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
+ }
+
+ };
+ }
+
+ });
+ return menuItems;
+ }
+
+ });
+
+ add(new MenuLink("sortBy") {
+
+ @Override
+ protected List<MenuItem> getMenuItems() {
+ List<MenuItem> menuItems = new ArrayList<>();
+
+ for (Map.Entry<SortOption, String> entry: sortNames.entrySet()) {
+ final SortOption sortOption = entry.getKey();
+ final String displayName = entry.getValue();
+ menuItems.add(new MenuItem() {
+
+ @Override
+ public String getLabel() {
+ return displayName;
+ }
+
+ @Override
+ public String getIconClass() {
+ if (RequestListPage.this.sortOption.equals(sortOption))
+ return "fa fa-check";
+ else
+ return null;
+ }
+
+ @Override
+ public AbstractLink newLink(String id) {
+ return new Link<Void>(id) {
+
+ @Override
+ public void onClick() {
+ setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
+ }
+
+ };
+ }
+
+ });
+ }
+
+ return menuItems;
+ }
+
+ });
+
+ add(new Link<Void>("newRequest") {
+
+ @Override
+ public void onClick() {
+ DepotPage page = (DepotPage) getPage();
+ setResponsePage(NewRequestPage.class, NewRequestPage.paramsOf(page.getDepot()));
+ }
+
+ });
+
+ Form<?> form = new Form<Void>("filterForm") {
+
+ @Override
+ protected void onSubmit() {
+ super.onSubmit();
+
+ setResponsePage(RequestListPage.class, paramsOf(getDepot(), searchOption, sortOption));
+ }
+
+ };
+ form.add(BeanContext.editBean("editor", searchOption));
+ add(form);
+
+ List<IColumn<PullRequest, Void>> columns = new ArrayList<>();
+ columns.add(new AbstractColumn<PullRequest, Void>(Model.of("Pull Request")) {
+
+ @Override
+ public void populateItem(Item<ICellPopulator<PullRequest>> cellItem,
+ String componentId, final IModel<PullRequest> rowModel) {
+ PullRequest request = rowModel.getObject();
+ Fragment fragment = new Fragment(componentId, "requestFrag", RequestListPage.this);
+ fragment.add(new Label("number", "#" + request.getNumber()));
+ fragment.add(new BookmarkablePageLink<Void>("title", RequestOverviewPage.class,
+ RequestOverviewPage.paramsOf(request)) {
+
+ @Override
+ public IModel<?> getBody() {
+ return Model.of(rowModel.getObject().getTitle());
+ }
+
+ });
+
+ fragment.add(new RequestStatusPanel("status", rowModel, false));
+ fragment.add(new AccountLink("submitter", rowModel.getObject().getSubmitter()));
+ fragment.add(new BranchLink("target", request.getTarget()));
+ if (request.getSource() != null)
+ fragment.add(new BranchLink("source", request.getSource()));
+ else
+ fragment.add(new Label("source").setVisible(false));
+
+ fragment.add(new Label("date", DateUtils.formatAge(request.getSubmitDate())));
+
+ 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));
+ String description = request.getLastEvent().getType();
+ lastEventContainer.add(new Label("description", description));
+ lastEventContainer.add(new Label("date", DateUtils.formatAge(request.getLastEvent().getDate())));
+ } else {
+ lastEventContainer.add(new WebMarkupContainer("user"));
+ lastEventContainer.add(new WebMarkupContainer("description"));
+ lastEventContainer.add(new WebMarkupContainer("date"));
+ lastEventContainer.setVisible(false);
+ }
+ fragment.add(lastEventContainer);
+
+ cellItem.add(fragment);
+
+ Date lastActivityDate;
+ if (request.getLastEvent() != null)
+ lastActivityDate = request.getLastEvent().getDate();
+ else
+ lastActivityDate = request.getSubmitDate();
+ cellItem.add(AttributeAppender.append("class",
+ request.isVisitedAfter(lastActivityDate)?"request":"request new"));
+ }
+
+ });
+
+ IDataProvider<PullRequest> dataProvider = new IDataProvider<PullRequest>() {
+
+ @Override
+ public void detach() {
+ }
+
+ @Override
+ public Iterator<? extends PullRequest> iterator(long first, long count) {
+ DepotPage page = (DepotPage) getPage();
+
+ EntityCriteria<PullRequest> criteria = searchOption.getCriteria(page.getDepot());
+ criteria.addOrder(sortOption.getOrder());
+ return GitPlex.getInstance(Dao.class).findRange(criteria, (int)first, (int)count).iterator();
+ }
+
+ @Override
+ public long size() {
+ DepotPage page = (DepotPage) getPage();
+ return GitPlex.getInstance(Dao.class).count(searchOption.getCriteria(page.getDepot()));
+ }
+
+ @Override
+ public IModel<PullRequest> model(PullRequest object) {
+ final Long pullRequestId = object.getId();
+ return new LoadableDetachableModel<PullRequest>() {
+
+ @Override
+ protected PullRequest load() {
+ return GitPlex.getInstance(Dao.class).load(PullRequest.class, pullRequestId);
+ }
+
+ };
+ }
+
+ };
+ DataTable<PullRequest, Void> dataTable = new DataTable<>("requests", columns,
+ dataProvider, Constants.DEFAULT_PAGE_SIZE);
+ dataTable.addBottomToolbar(new NoRecordsToolbar(dataTable));
+ dataTable.addBottomToolbar(new NavigationToolbar(dataTable) {
+
+ @Override
+ protected PagingNavigator newPagingNavigator(String navigatorId, DataTable<?, ?> table) {
+ return new BootstrapPagingNavigator(navigatorId, dataTable);
+ }
+
+ });
+ add(dataTable);
+ }
+
+ @Override
+ public void renderHead(IHeaderResponse response) {
+ super.renderHead(response);
+
+ response.render(CssHeaderItem.forReference(new RequestListResourceReference()));
+ }
+
+ public static PageParameters paramsOf(Depot depot, SearchOption searchOption, SortOption sortOption) {
+ PageParameters params = paramsOf(depot);
+ searchOption.fillPageParams(params);
+ sortOption.fillPageParams(params);
+ return params;
+ }
+
+ @Override
+ protected void onSelect(AjaxRequestTarget target, Depot depot) {
+ setResponsePage(RequestListPage.class, paramsOf(depot));
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/init/ServerInitPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/init/ServerInitPage.java
index b40295e7bf..83da564b88 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/init/ServerInitPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/init/ServerInitPage.java
@@ -52,7 +52,7 @@ public class ServerInitPage extends BasePage {
WebSession.get().logout();
Account root = GitPlex.getInstance(AccountManager.class).getRoot();
SecurityUtils.getSubject().runAs(root.getPrincipals());
- setResponsePage(WelcomePage.class);
+ throw new RestartResponseException(WelcomePage.class);
}
});
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/layout/LayoutPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/layout/LayoutPage.html
index 1f5a52d6d2..6452d6f2c9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/layout/LayoutPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/layout/LayoutPage.html
@@ -9,7 +9,6 @@
<wicket:enclosure child="login">
<div class="logged-out">
<a wicket:id="login">Log in</a>
- <span class="separator">|</span>
<a wicket:id="register">Sign up</a>
</div>
</wicket:enclosure>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/layout/layout.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/layout/layout.css
index e6e340f37e..1229a35cc3 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/layout/layout.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/layout/layout.css
@@ -67,6 +67,9 @@ html, body {
#main>.head>.account>.logged-out a {
font-size: 16px;
}
+#main>.head>.account>.logged-out>a:FIRST-CHILD {
+ margin-right: 16px;
+}
#main>.head>.account .avatar {
width: 32px;
height: 32px;