The Unified and Autonomous Development Platform
Click code comment from code comment list to show in appropriate context
robin shinea6f044f7e830
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.javaindex e198e5c78c..6321818bf7 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@@ -1,5 +1,6 @@package com.pmease.gitplex.core.entity;+import java.io.Serializable;import java.util.ArrayList;import java.util.Collection;import java.util.Comparator;@@ -248,4 +249,32 @@ public class CodeComment extends AbstractEntity {}return sortedReplies;}++ public ComparingInfo getComparingInfo() {+ return new ComparingInfo(commit, compareContext);+ }++ public static class ComparingInfo implements Serializable {++ private static final long serialVersionUID = 1L;++ private final String commit;++ private final CompareContext compareContext;++ public ComparingInfo(String commit, CompareContext compareContext) {+ this.commit = commit;+ this.compareContext = compareContext;+ }++ public String getCommit() {+ return commit;+ }++ public CompareContext getCompareContext() {+ return compareContext;+ }++ }+}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.javaindex ce2738e156..bd5e3aa6d0 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/entity/CodeCommentReply.java@@ -16,6 +16,7 @@ import org.hibernate.annotations.DynamicUpdate;import com.pmease.commons.hibernate.AbstractEntity;import com.pmease.gitplex.core.GitPlex;+import com.pmease.gitplex.core.entity.CodeComment.ComparingInfo;import com.pmease.gitplex.core.entity.component.CompareContext;import com.pmease.gitplex.core.manager.VisitInfoManager;import com.pmease.gitplex.core.security.SecurityUtils;@@ -110,4 +111,8 @@ public class CodeCommentReply extends AbstractEntity {}}+ public ComparingInfo getComparingInfo() {+ return new ComparingInfo(comment.getCommit(), compareContext);+ }+}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.javaindex f6bfd31e4d..5b13018b39 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@@ -1,5 +1,6 @@package com.pmease.gitplex.core.entity;+import java.io.Serializable;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;@@ -10,6 +11,7 @@ import java.util.List;import java.util.Map;import java.util.Set;import java.util.UUID;+import java.util.stream.Collectors;import javax.annotation.Nullable;import javax.persistence.CascadeType;@@ -34,14 +36,17 @@ import org.hibernate.criterion.Restrictions;import com.fasterxml.jackson.annotation.JsonView;import com.google.common.base.Preconditions;+import com.pmease.commons.git.BriefCommit;import com.pmease.commons.git.Commit;import com.pmease.commons.git.Git;import com.pmease.commons.git.GitUtils;import com.pmease.commons.hibernate.AbstractEntity;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.jackson.ExternalView;+import com.pmease.commons.lang.diff.WhitespaceOption;import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.entity.component.CloseInfo;+import com.pmease.gitplex.core.entity.component.CompareContext;import com.pmease.gitplex.core.entity.component.DepotAndBranch;import com.pmease.gitplex.core.entity.component.IntegrationPreview;import com.pmease.gitplex.core.gatekeeper.checkresult.Blocking;@@ -947,4 +952,80 @@ public class PullRequest extends AbstractEntity {return codeComments;}+ @Nullable+ public ComparingInfo getRequestComparingInfo(CodeComment.ComparingInfo commentComparingInfo) {+ List<String> commits = new ArrayList<>();+ commits.add(getBaseCommitHash());+ for (PullRequestUpdate update: getSortedUpdates()) {+ commits.addAll(update.getCommits().stream().map(BriefCommit::getHash).collect(Collectors.toList()));+ }+ String commit = commentComparingInfo.getCommit();+ CompareContext compareContext = commentComparingInfo.getCompareContext();+ if (commit.equals(compareContext.getCompareCommit())) {+ int index = commits.indexOf(commit);+ if (index == 0) {+ return null;+ } else {+ return new ComparingInfo(commits.get(index-1), commit,+ compareContext.getWhitespaceOption(), compareContext.getPathFilter());+ }+ } else {+ int commitIndex = commits.indexOf(commit);+ int compareCommitIndex = commits.indexOf(compareContext.getCompareCommit());+ if (commitIndex == -1 || compareCommitIndex == -1) {+ return null;+ } else if (compareContext.isLeftSide()) {+ if (compareCommitIndex < commitIndex) {+ return new ComparingInfo(compareContext.getCompareCommit(), commit,+ compareContext.getWhitespaceOption(), compareContext.getPathFilter());+ } else {+ return null;+ }+ } else {+ if (commitIndex < compareCommitIndex) {+ return new ComparingInfo(commit, compareContext.getCompareCommit(),+ compareContext.getWhitespaceOption(), compareContext.getPathFilter());+ } else {+ return null;+ }+ }+ }+ }++ public static class ComparingInfo implements Serializable {++ private static final long serialVersionUID = 1L;++ private final String oldCommit;++ private final String newCommit;++ private final String pathFilter;++ private final WhitespaceOption whitespaceOption;++ public ComparingInfo(String oldCommit, String newCommit, WhitespaceOption whitespaceOption, @Nullable String pathFilter) {+ this.oldCommit = oldCommit;+ this.newCommit = newCommit;+ this.whitespaceOption = whitespaceOption;+ this.pathFilter = pathFilter;+ }++ public String getOldCommit() {+ return oldCommit;+ }++ public String getNewCommit() {+ return newCommit;+ }++ public String getPathFilter() {+ return pathFilter;+ }++ public WhitespaceOption getWhitespaceOption() {+ return whitespaceOption;+ }++ }}diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentInfoManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentInfoManager.javaindex a5b585d3d1..860c3bfbd6 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentInfoManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CodeCommentInfoManager.java@@ -6,6 +6,7 @@ import java.util.Map;import org.eclipse.jgit.lib.ObjectId;import com.pmease.gitplex.core.entity.Depot;+import com.pmease.gitplex.core.entity.component.CompareContext;public interface CodeCommentInfoManager {@@ -15,9 +16,9 @@ public interface CodeCommentInfoManager {* Get comments over specified depot and commit** @return- * map of comment uuid to compare commit hash+ * map of comment uuid to compare context*/- Map<String, String> getComments(Depot depot, ObjectId commit);+ Map<String, CompareContext> getComments(Depot depot, ObjectId commit);List<String> getCommentedFiles(Depot depot);diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentInfoManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentInfoManager.javaindex 5703f6b24a..1641dd8d30 100644--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentInfoManager.java+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCodeCommentInfoManager.java@@ -32,6 +32,7 @@ import com.pmease.commons.util.concurrent.PrioritizedRunnable;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.component.CompareContext;import com.pmease.gitplex.core.listener.CodeCommentListener;import com.pmease.gitplex.core.listener.DepotListener;import com.pmease.gitplex.core.listener.LifecycleListener;@@ -219,15 +220,12 @@ public class DefaultCodeCommentInfoManager implements CodeCommentInfoManager, DeObjectId.fromString(comment.getCommit()).copyRawTo(keyBytes, 0);ByteIterable commitKey = new ArrayByteIterable(keyBytes);byte[] valueBytes = getBytes(store.get(txn, commitKey));- Map<String, String> comments;+ Map<String, CompareContext> comments;if (valueBytes != null)- comments = (Map<String, String>) SerializationUtils.deserialize(valueBytes);+ comments = (Map<String, CompareContext>) SerializationUtils.deserialize(valueBytes);elsecomments = new HashMap<>();- if (comment.getCompareContext() != null)- comments.put(comment.getUUID(), comment.getCompareContext().getCompareCommit());- else- comments.put(comment.getUUID(), null);+ comments.put(comment.getUUID(), comment.getCompareContext());store.put(txn, commitKey, new ArrayByteIterable(SerializationUtils.serialize((Serializable) comments)));if (comment.getPath() != null) {@@ -269,21 +267,21 @@ public class DefaultCodeCommentInfoManager implements CodeCommentInfoManager, De}@Override- public Map<String, String> getComments(Depot depot, ObjectId commit) {+ public Map<String, CompareContext> getComments(Depot depot, ObjectId commit) {Environment env = getEnv(depot);Store store = getStore(env, DEFAULT_STORE);- return env.computeInReadonlyTransaction(new TransactionalComputable<Map<String, String>>() {+ return env.computeInReadonlyTransaction(new TransactionalComputable<Map<String, CompareContext>>() {@SuppressWarnings("unchecked")@Override- public Map<String, String> compute(Transaction txn) {+ public Map<String, CompareContext> compute(Transaction txn) {byte[] keyBytes = new byte[20];commit.copyRawTo(keyBytes, 0);ByteIterable commitKey = new ArrayByteIterable(keyBytes);byte[] valueBytes = getBytes(store.get(txn, commitKey));if (valueBytes != null) {- return (Map<String, String>) SerializationUtils.deserialize(valueBytes);+ return (Map<String, CompareContext>) SerializationUtils.deserialize(valueBytes);} else {return new HashMap<>();}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.javaindex ef2a43ce01..9c92d97677 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@@ -21,6 +21,7 @@ import com.pmease.gitplex.core.entity.CodeComment;import com.pmease.gitplex.core.entity.CodeCommentRelation;import com.pmease.gitplex.core.entity.PullRequest;import com.pmease.gitplex.core.entity.PullRequestUpdate;+import com.pmease.gitplex.core.entity.component.CompareContext;import com.pmease.gitplex.core.manager.CodeCommentInfoManager;import com.pmease.gitplex.core.manager.CodeCommentManager;import com.pmease.gitplex.core.manager.CodeCommentRelationManager;@@ -66,36 +67,26 @@ public class DefaultCodeCommentRelationManager extends AbstractEntityDao<CodeCom}involvedCommits.add(request.getBaseCommitHash());- Map<String, CommitInfo> commitInfos = new HashMap<>();+ Map<String, CodeComment.ComparingInfo> comparingInfos = new HashMap<>();for (String commit: involvedCommits) {- Map<String, String> commentsOfCommit = codeCommentInfoManager.getComments(+ Map<String, CompareContext> commentsOfCommit = codeCommentInfoManager.getComments(request.getTargetDepot(), ObjectId.fromString(commit));- for (Map.Entry<String, String> entry: commentsOfCommit.entrySet()) {- CommitInfo commitInfo = new CommitInfo();- commitInfo.commit = commit;- commitInfo.compareCommit = entry.getValue();- commitInfos.put(entry.getKey(), commitInfo);+ for (Map.Entry<String, CompareContext> entry: commentsOfCommit.entrySet()) {+ CodeComment.ComparingInfo comparingInfo = new CodeComment.ComparingInfo(commit, entry.getValue());+ comparingInfos.put(entry.getKey(), comparingInfo);}}- commitInfos.keySet().removeAll(relatedComments);+ comparingInfos.keySet().removeAll(relatedComments);- String baseCommit = request.getBaseCommitHash();- for (Map.Entry<String, CommitInfo> entry: commitInfos.entrySet()) {+ for (Map.Entry<String, CodeComment.ComparingInfo> entry: comparingInfos.entrySet()) {String uuid = entry.getKey();- String commit = entry.getValue().commit;- String compareCommit = entry.getValue().compareCommit;+ CodeComment.ComparingInfo comparingInfo = entry.getValue();- /*- * Comment is relevant if both commit and compare commit relates to pull request,- * and also they are not equals to the base commit in the same time- */- if (involvedCommits.contains(commit)- && involvedCommits.contains(compareCommit)- && !(commit.equals(baseCommit) && compareCommit.equals(baseCommit))) {+ if (request.getRequestComparingInfo(comparingInfo) != null) {CodeComment comment = codeCommentManager.find(uuid);if (comment == null) {- codeCommentInfoManager.removeComment(request.getTargetDepot(), ObjectId.fromString(commit), uuid);+ codeCommentInfoManager.removeComment(request.getTargetDepot(), ObjectId.fromString(comparingInfo.getCommit()), uuid);} else if (request.getCodeCommentRelations().size() < PullRequest.MAX_CODE_COMMENTS) {CodeCommentRelation relation = new CodeCommentRelation();relation.setComment(comment);@@ -118,10 +109,4 @@ public class DefaultCodeCommentRelationManager extends AbstractEntityDao<CodeComreturn comments;}- private static class CommitInfo {- String commit;-- String compareCommit;- }-}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.javaindex 83a0a01f2c..a6d2b538af 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@@ -32,6 +32,7 @@ import org.eclipse.jgit.lib.FileMode;import org.hibernate.criterion.Order;import org.hibernate.criterion.Restrictions;+import com.google.common.base.Preconditions;import com.pmease.commons.hibernate.dao.Dao;import com.pmease.commons.hibernate.dao.EntityCriteria;import com.pmease.commons.wicket.editable.BeanContext;@@ -49,6 +50,7 @@ import com.pmease.gitplex.web.component.diff.revision.DiffMark;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;@@ -144,12 +146,29 @@ public abstract class CodeCommentListPanel extends Panel {public void onClick() {Depot depot = ((DepotPage) getPage()).getDepot();+ CodeComment comment = rowModel.getObject();PullRequest request = getPullRequest();+ List<CodeCommentReply> replies = comment.getSortedReplies();if (request != null) {-+ PullRequest.ComparingInfo comparingInfo = null;+ for (int i=replies.size()-1; i>=0; i--) {+ CodeCommentReply reply = replies.get(i);+ comparingInfo = request.getRequestComparingInfo(reply.getComparingInfo());+ if (comparingInfo != null)+ break;+ }+ if (comparingInfo == null) {+ comparingInfo = Preconditions.checkNotNull(request.getRequestComparingInfo(comment.getComparingInfo()));+ }+ RequestChangesPage.State state = new RequestChangesPage.State();+ state.commentId = comment.getId();+ state.mark = new DiffMark(comment);+ state.oldCommit = comparingInfo.getOldCommit();+ state.newCommit = comparingInfo.getNewCommit();+ state.pathFilter = comparingInfo.getPathFilter();+ state.whitespaceOption = comparingInfo.getWhitespaceOption();+ setResponsePage(RequestChangesPage.class, RequestChangesPage.paramsOf(request, state));} else {- CodeComment comment = rowModel.getObject();- List<CodeCommentReply> replies = comment.getSortedReplies();CompareContext compareContext;if (!replies.isEmpty()) {CodeCommentReply lastReply = replies.get(replies.size()-1);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.javaindex 024990bcec..13350ff9c8 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@@ -60,6 +60,7 @@ import com.pmease.commons.git.Blame;import com.pmease.commons.git.Blob;import com.pmease.commons.git.BlobIdent;import com.pmease.commons.git.GitUtils;+import com.pmease.commons.lang.diff.WhitespaceOption;import com.pmease.commons.lang.extractors.ExtractException;import com.pmease.commons.lang.extractors.Extractor;import com.pmease.commons.lang.extractors.Extractors;@@ -887,6 +888,8 @@ public class SourceViewPanel extends BlobViewPanel {private CompareContext getCompareContext() {CompareContext compareContext = new CompareContext();compareContext.setCompareCommit(context.getCommit().name());+ compareContext.setPathFilter(context.getBlobIdent().path);+ compareContext.setWhitespaceOption(WhitespaceOption.DO_NOT_IGNORE);return compareContext;}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.javaindex aca44fef8f..0436b2e50d 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@@ -234,6 +234,7 @@ public class CommitDetailPage extends DepotPage implements MarkSupport {State newState = new State();newState.revision = parent.name();newState.whitespaceOption = state.whitespaceOption;+ newState.pathFilter = state.pathFilter;Link<Void> link = new BookmarkablePageLink<Void>("parent", CommitDetailPage.class,paramsOf(depotModel.getObject(), newState));link.add(new Label("label", GitUtils.abbreviateSHA(parent.name())));@@ -258,6 +259,7 @@ public class CommitDetailPage extends DepotPage implements MarkSupport {State newState = new State();newState.revision = parent.name();newState.whitespaceOption = state.whitespaceOption;+ newState.pathFilter = state.pathFilter;Link<Void> link = new BookmarkablePageLink<Void>("link", CommitDetailPage.class,paramsOf(depotModel.getObject(), newState));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.htmlindex bbeddff51b..aa6d0e0064 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-xs btn-default">Apply</a>+ <a title="Apply selected commits" class="btn btn-sm 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.javaindex e8eb827211..e9c15f74f8 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@@ -164,6 +164,7 @@ public class RequestChangesPage extends RequestDetailPage implements MarkSupportnewRevisionDiff(target);}target.add(head);+ pushState(target);}});@@ -204,6 +205,7 @@ public class RequestChangesPage extends RequestDetailPage implements MarkSupportnewRevisionDiff(target);}target.add(head);+ pushState(target);}});