The Unified and Autonomous Development Platform
Struggling comment support
robin shinef42a17844a8c
diff --git a/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java b/commons.git/src/main/java/com/pmease/commons/git/BlobChange.javaindex e79a49b00b..472e1ebb92 100644--- a/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java+++ b/commons.git/src/main/java/com/pmease/commons/git/BlobChange.java@@ -23,24 +23,13 @@ public abstract class BlobChange implements Serializable {protected final BlobIdent oldBlobIdent;protected final BlobIdent newBlobIdent;-- /*- * oldRef and newRef can be used to record branch name so that we can- * switch to branch name for file editing while comparing branches- */- protected final String oldRef;-- protected final String newRef;private transient List<DiffBlock<List<CmToken>>> diffBlocks;- public BlobChange(String oldCommitHash, String newCommitHash, DiffEntry diffEntry,- @Nullable String oldRef, @Nullable String newRef) {+ public BlobChange(String oldRev, String newRev, DiffEntry diffEntry) {type = diffEntry.getChangeType();- oldBlobIdent = GitUtils.getOldBlobIdent(diffEntry, oldCommitHash);- newBlobIdent = GitUtils.getNewBlobIdent(diffEntry, newCommitHash);- this.oldRef = oldRef;- this.newRef = newRef;+ oldBlobIdent = GitUtils.getOldBlobIdent(diffEntry, oldRev);+ newBlobIdent = GitUtils.getNewBlobIdent(diffEntry, newRev);}public ChangeType getType() {@@ -111,14 +100,6 @@ public abstract class BlobChange implements Serializable {return diffBlocks;}- public String getOldRef() {- return oldRef;- }-- public String getNewRef() {- return newRef;- }-public int getAdditions() {int additions = 0;for (DiffBlock<List<CmToken>> diff: getDiffBlocks()) {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.javaindex 9e8f200b49..597eef3be1 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/blob/text/TextDiffPanel.java@@ -110,6 +110,8 @@ public class TextDiffPanel extends Panel {};+ private final boolean commentable;+private AbstractDefaultAjaxBehavior addCommentBehavior;private RepeatingView newCommentForms;@@ -125,6 +127,17 @@ public class TextDiffPanel extends Panel {this.requestModel = requestModel;this.change = change;this.diffMode = diffMode;++ PullRequest request = requestModel.getObject();+ if (request != null) {+ List<String> commentables = request.getCommentables();+ int oldCommitIndex = commentables.indexOf(change.getOldBlobIdent().revision);+ int newCommitIndex = commentables.indexOf(change.getNewBlobIdent().revision);+ commentable = oldCommitIndex != -1 && newCommitIndex != -1 && oldCommitIndex < newCommitIndex;+ } else {+ commentable = false;+ }+}@Override@@ -135,30 +148,13 @@ public class TextDiffPanel extends Panel {add(new BlobDiffTitle("title", change));Repository repo = repoModel.getObject();- String revision;- String path;- /*- * below logic tries to use branch ref instead of commit hash in order to- * make file editable online- */- if (change.getNewBlobIdent().path != null) {- path = change.getNewBlobIdent().path;- revision = change.getNewRef();- if (revision == null)- revision = change.getNewBlobIdent().revision;- } else {- path = change.getOldBlobIdent().path;- revision = change.getOldRef();- if (revision == null)- revision = change.getOldBlobIdent().revision;- }PageParameters params;PullRequest request = requestModel.getObject();if (request != null)- params = RepoFilePage.paramsOf(request, revision, path);+ params = RepoFilePage.paramsOf(request, change.getBlobIdent());else- params = RepoFilePage.paramsOf(repo, revision, path);+ params = RepoFilePage.paramsOf(repo, change.getBlobIdent());add(new BookmarkablePageLink<Void>("viewFile", RepoFilePage.class, params));@@ -440,7 +436,7 @@ public class TextDiffPanel extends Panel {}private void appendAddComment(StringBuilder builder, int oldLineNo, int newLineNo) {- if (requestModel.getObject() != null) {+ if (commentable) {builder.append("<span class='add-comment'>");String script = String.format("document.getElementById('%s').addComment(%d, %d);",getMarkupId(), oldLineNo, newLineNo);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.javaindex c06878b68f..99cd09e252 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@@ -39,8 +39,8 @@ import com.pmease.commons.lang.diff.DiffUtils;import com.pmease.commons.wicket.ajaxlistener.ConfirmLeaveListener;import com.pmease.commons.wicket.ajaxlistener.IndicateLoadingListener;import com.pmease.gitplex.core.GitPlex;-import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Comment;+import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.web.Constants;import com.pmease.gitplex.web.component.diff.blob.BlobDiffPanel;@@ -83,7 +83,7 @@ public abstract class RevisionDiffPanel extends Panel {List<BlobChange> diffableChanges = new ArrayList<>();for (DiffEntry entry: diffEntries) {if (diffableChanges.size() < Constants.MAX_DIFF_FILES) {- diffableChanges.add(new BlobChange(oldCommitHash, newCommitHash, entry, oldRev, newRev) {+ diffableChanges.add(new BlobChange(oldRev, newRev, entry) {@Overridepublic Blob getBlob(BlobIdent blobIdent) {@@ -94,7 +94,7 @@ public abstract class RevisionDiffPanel extends Panel {public LineProcessor getLineProcessor() {return lineProcessor;}-+});} else {break;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/HistoryState.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/HistoryState.javaindex 06a7d4eab0..c4ef144967 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/HistoryState.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/HistoryState.java@@ -13,7 +13,7 @@ class HistoryState implements Serializable {public Long commentId;- public BlobIdent file = new BlobIdent();+ public BlobIdent blobIdent = new BlobIdent();public TokenPosition tokenPos;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.javaindex d11a5e7771..2183dd9f44 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/file/RepoFilePage.java@@ -87,6 +87,8 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {private static final String PARAM_REVISION = "revision";+ private static final String PARAM_COMMIT = "commit";+private static final String PARAM_PATH = "path";private static final String PARAM_BLAME = "blame";@@ -183,6 +185,9 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {blobIdent.mode = FileMode.TREE.getBits();}+ String commitHash = params.get(PARAM_COMMIT).toString();+ if (commitHash != null)+ getRepository().cacheObjectId(blobIdent.revision, ObjectId.fromString(commitHash));blame = params.get(PARAM_BLAME).toBoolean(false);commentId = params.get(PARAM_COMMENT).toOptionalLong();requestId = params.get(PARAM_REQUEST).toOptionalLong();@@ -561,14 +566,14 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {}private void pushState(AjaxRequestTarget target) {- PageParameters params = paramsOf(getRepository(), blobIdent.revision, blobIdent.path,+ PageParameters params = paramsOf(getRepository(), blobIdent.revision, null, blobIdent.path,blame, commentId, requestId);CharSequence url = RequestCycle.get().urlFor(RepoFilePage.class, params);HistoryState state = new HistoryState();state.blame = blame;state.commentId = commentId;state.requestId = requestId;- state.file = blobIdent;+ state.blobIdent = blobIdent;state.tokenPos = tokenPos;pushState(target, url.toString(), state);}@@ -586,19 +591,47 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {new CssResourceReference(RepoFilePage.class, "repo-file.css")));}+ public static PageParameters paramsOf(PullRequest request, BlobIdent blobIdent) {+ return paramsOf(request, blobIdent.revision, blobIdent.path);+ }++ public static PageParameters paramsOf(PullRequest request, String commitHash, @Nullable String path) {+ if (request.getSourceRepo() != null && commitHash.equals(request.getSource().getHead(false))) {+ return paramsOf(request.getSourceRepo(), request.getSourceBranch(), commitHash,+ path, false, null, request.getId());+ } else {+ return paramsOf(request.getTargetRepo(), commitHash, null, path, false, null, request.getId());+ }+ }++ public static PageParameters paramsOf(Comment comment) {+ String revision = comment.getBlobIdent().revision;+ PullRequest request = comment.getRequest();+ if (request.getSourceRepo() != null && revision.equals(request.getSource().getHead(false))) {+ return paramsOf(request.getSourceRepo(), request.getSourceBranch(), revision,+ comment.getBlobIdent().path, false, comment.getId(), null);+ } else {+ return paramsOf(comment.getRepository(), comment.getBlobIdent().revision, null,+ comment.getBlobIdent().path, false, comment.getId(), null);+ }+ }+public static PageParameters paramsOf(Repository repository, BlobIdent blobIdent) {return paramsOf(repository, blobIdent.revision, blobIdent.path);}public static PageParameters paramsOf(Repository repository, @Nullable String revision, @Nullable String path) {- return paramsOf(repository, revision, path, false, null, null);+ return paramsOf(repository, revision, null, path, false, null, null);}public static PageParameters paramsOf(Repository repository, @Nullable String revision,- @Nullable String path, boolean blame, @Nullable Long commentId, @Nullable Long requestId) {+ @Nullable String commitHash, @Nullable String path, boolean blame,+ @Nullable Long commentId, @Nullable Long requestId) {PageParameters params = paramsOf(repository);if (revision != null)params.set(PARAM_REVISION, revision);+ if (commitHash != null)+ params.set(PARAM_COMMIT, commitHash);if (path != null)params.set(PARAM_PATH, path);if (blame)@@ -610,15 +643,6 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {return params;}- public static PageParameters paramsOf(PullRequest request, String revision, @Nullable String path) {- return paramsOf(request.getTargetRepo(), revision, path, false, null, request.getId());- }-- public static PageParameters paramsOf(Comment comment) {- return paramsOf(comment.getRepository(), comment.getBlobIdent().revision,- comment.getBlobIdent().path, false, comment.getId(), null);- }-private void renderSearchResult(AjaxRequestTarget target, List<QueryHit> hits) {Component searchResult = newSearchResult(hits);@@ -676,7 +700,7 @@ public class RepoFilePage extends RepositoryPage implements BlobViewContext {super.onPopState(target, data);HistoryState state = (HistoryState) data;- blobIdent = state.file;+ blobIdent = state.blobIdent;blame = state.blame;commentId = state.commentId;requestId = state.requestId;diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/UpdateChangesLink.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/UpdateChangesLink.javaindex 0e614fe66f..976a8c5950 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/UpdateChangesLink.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/UpdateChangesLink.java@@ -1,5 +1,7 @@package com.pmease.gitplex.web.page.repository.pullrequest.requestdetail;+import static com.pmease.gitplex.web.page.repository.pullrequest.requestdetail.compare.RequestComparePage.REV_UPDATE_PREFIX;+import org.apache.wicket.markup.html.link.BookmarkablePageLink;import org.apache.wicket.model.IModel;import org.apache.wicket.model.Model;@@ -9,10 +11,6 @@ import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.PullRequestUpdate;import com.pmease.gitplex.web.page.repository.pullrequest.requestdetail.compare.RequestComparePage;-import static com.pmease.gitplex.web.page.repository.pullrequest.requestdetail.compare.RequestComparePage.*;--import java.util.List;-@SuppressWarnings("serial")public class UpdateChangesLink extends BookmarkablePageLink<Void> {@@ -24,12 +22,8 @@ public class UpdateChangesLink extends BookmarkablePageLink<Void> {private static PageParameters paramsOf(PullRequestUpdate update) {PullRequest request = update.getRequest();- List<PullRequestUpdate> updates = request.getSortedUpdates();int index = request.getSortedUpdates().indexOf(update);- if (index == updates.size()-1)- return RequestComparePage.paramsOf(request, REV_LAST_UPDATE_PREFIX+2, REV_LAST_UPDATE_PREFIX+1);- else- return RequestComparePage.paramsOf(request, REV_UPDATE_PREFIX+index, REV_UPDATE_PREFIX+(index+1));+ return RequestComparePage.paramsOf(request, REV_UPDATE_PREFIX+index, REV_UPDATE_PREFIX+(index+1));}public IModel<?> getBody() {diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.javaindex f196a0db38..38121db0e4 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/compare/RequestComparePage.java@@ -193,14 +193,12 @@ public class RequestComparePage extends RequestDetailPage {private String getRevision(String commitHash) {PullRequest request = getPullRequest();- if (request.getLatestUpdate().getHeadCommitHash().equals(commitHash)) {- return REV_LAST_UPDATE_PREFIX+1;- } else if (request.getBaseCommitHash().equals(commitHash)) {+ if (request.getBaseCommitHash().equals(commitHash)) {return REV_BASE;} else {List<PullRequestUpdate> updates = request.getSortedUpdates();for (int i=0; i<updates.size(); i++) {- if (updates.get(i).getHeadCommit().equals(commitHash))+ if (updates.get(i).getHeadCommitHash().equals(commitHash))return REV_UPDATE_PREFIX + (i+1);}if (commitHash.equals(request.getTarget().getHead(false))) {@@ -380,7 +378,7 @@ public class RequestComparePage extends RequestDetailPage {if (request.isOpen()) {final IntegrationPreview preview = request.getIntegrationPreview();if (preview != null && preview.getIntegrated() != null) {- items.add(new ComparisonChoiceItem("Target branch and Integration preview") {+ items.add(new ComparisonChoiceItem("Changes of integration preview") {@Overrideprotected void onSelect(AjaxRequestTarget target) {@@ -401,37 +399,25 @@ public class RequestComparePage extends RequestDetailPage {for (int i=0; i<updates.size(); i++) {final int updateNo = i+1;- if (updateNo == updates.size()) {- items.add(new ComparisonChoiceItem("Changes of latest update") {+ String label;+ if (updateNo == updates.size())+ label = "Changes of latest update";+ else+ label = "Changes of update " + updateNo;+ items.add(new ComparisonChoiceItem(label) {- @Override- protected void onSelect(AjaxRequestTarget target) {- hide(target);-- state.commentId = null;- state.oldRev = REV_LAST_UPDATE_PREFIX + "2";- state.newRev = REV_LAST_UPDATE_PREFIX + "1";- initFromState(state);- onStateChange(target);- }-- });- } else {- items.add(new ComparisonChoiceItem("Changes of update " + updateNo) {-- @Override- protected void onSelect(AjaxRequestTarget target) {- hide(target);-- state.commentId = null;- state.oldRev = REV_LAST_UPDATE_PREFIX + (updateNo-1);- state.newRev = REV_LAST_UPDATE_PREFIX + updateNo;- initFromState(state);- onStateChange(target);- }-- });- }+ @Override+ protected void onSelect(AjaxRequestTarget target) {+ hide(target);++ state.commentId = null;+ state.oldRev = REV_UPDATE_PREFIX + (updateNo-1);+ state.newRev = REV_UPDATE_PREFIX + updateNo;+ initFromState(state);+ onStateChange(target);+ }++ });}return items;@@ -768,36 +754,8 @@ public class RequestComparePage extends RequestDetailPage {}private void newCompareResult(@Nullable AjaxRequestTarget target) {- IModel<PullRequest> requestModel = new LoadableDetachableModel<PullRequest>() {-- @Override- protected PullRequest load() {- PullRequest request = getPullRequest();- List<String> commentables = request.getCommentables();- int oldCommitIndex = commentables.indexOf(oldCommitHash);- int newCommitIndex = commentables.indexOf(newCommitHash);- if (oldCommitIndex == -1 || newCommitIndex == -1 || oldCommitIndex > newCommitIndex) {- // indicate that comment support is not available in text diff panel- return null;- } else {- return request;- }- }-- };-- // use branch ref if possible to make file editable online- String oldRev = oldCommitHash;- String newRev = newCommitHash;- PullRequest request = getPullRequest();- if (request.isOpen()) {- if (oldRev.equals(request.getSource().getHead()))- oldRev = request.getSourceBranch();- if (newRev.equals(request.getSource().getHead()))- newRev = request.getSourceBranch();- }compareResult = new RevisionDiffPanel("compareResult", repoModel, requestModel,- commentModel, oldRev, newRev, path, comparePath,+ commentModel, oldCommitHash, newCommitHash, path, comparePath,diffOption.getLineProcessor(), diffOption.getDiffMode()) {@Overridediff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/UpdateActivityPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/UpdateActivityPanel.javaindex b9ac22fbc7..d1e42a42d6 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/UpdateActivityPanel.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/overview/UpdateActivityPanel.java@@ -16,6 +16,7 @@ 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.request.mapper.parameter.PageParameters;import com.pmease.commons.git.Commit;import com.pmease.gitplex.core.model.PullRequest;@@ -180,8 +181,9 @@ class UpdateActivityPanel extends Panel {item.add(AttributeAppender.append("title", "This commit has been rebased"));}- item.add(new BookmarkablePageLink<Void>("codeLink", RepoFilePage.class,- RepoFilePage.paramsOf(updateModel.getObject().getRequest(), commit.getHash(), null)));+ PageParameters params = RepoFilePage.paramsOf(+ updateModel.getObject().getRequest(), commit.getHash(), null);+ item.add(new BookmarkablePageLink<Void>("codeLink", RepoFilePage.class, params));}});diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/updates/RequestUpdatesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/updates/RequestUpdatesPage.javaindex 4b19c4450b..07ef5af113 100644--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/updates/RequestUpdatesPage.java+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/requestdetail/updates/RequestUpdatesPage.java@@ -31,9 +31,9 @@ import com.pmease.gitplex.core.GitPlex;import com.pmease.gitplex.core.manager.ReviewManager;import com.pmease.gitplex.core.model.PullRequest;import com.pmease.gitplex.core.model.PullRequestUpdate;-import com.pmease.gitplex.core.model.Verification;import com.pmease.gitplex.core.model.Repository;import com.pmease.gitplex.core.model.Review;+import com.pmease.gitplex.core.model.Verification;import com.pmease.gitplex.core.permission.ObjectPermission;import com.pmease.gitplex.web.Constants;import com.pmease.gitplex.web.component.avatar.AvatarMode;@@ -201,14 +201,8 @@ public class RequestUpdatesPage extends RequestDetailPage {commitItem.add(new CommitHashPanel("hash", Model.of(commit.getHash())));- PullRequest request = getPullRequest();- String revision = commit.getHash();- if (request.isOpen() && request.getSourceRepo() != null- && revision.equals(request.getSource().getHead(false))) {- revision = request.getSourceBranch();- }commitItem.add(new BookmarkablePageLink<Void>("codeLink", RepoFilePage.class,- RepoFilePage.paramsOf(getPullRequest(), revision, null)));+ RepoFilePage.paramsOf(getPullRequest(), commit.getHash(), null)));commitItem.add(new VerificationStatusPanel("verification", requestModel, Model.of(commit.getHash())) {