Skip to content

The Unified and Autonomous Development Platform

Update pull request inline comment context upon new push.

robin shine8f60a885738d
diff --git a/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java b/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java
index 3681ff7ff6..d1d6ae358a 100644
--- a/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java
+++ b/commons.git/src/main/java/com/pmease/commons/git/BlobInfo.java
@@ -2,19 +2,29 @@ package com.pmease.commons.git;
import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import com.google.common.base.Objects;
+@Embeddable
@SuppressWarnings("serial")
public class BlobInfo implements Serializable {
- private final String path;
-
- private final String revision;
+ private String path;
+
+ @Column(nullable=false)
+ private String revision;
- private final int mode;
+ @Column(nullable=false)
+ private int mode;
+
+ public BlobInfo() {
+
+ };
public BlobInfo(String revision, String path, int mode) {
this.revision = revision;
@@ -34,6 +44,18 @@ public class BlobInfo implements Serializable {
return mode;
}
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public void setRevision(String revision) {
+ this.revision = revision;
+ }
+
+ public void setMode(int mode) {
+ this.mode = mode;
+ }
+
@Override
public boolean equals(Object other) {
if (!(other instanceof BlobInfo))
diff --git a/commons.hibernate/pom.xml b/commons.hibernate/pom.xml
index 4d9b80b3b8..b9b3d8df51 100644
--- a/commons.hibernate/pom.xml
+++ b/commons.hibernate/pom.xml
@@ -29,11 +29,6 @@
<artifactId>commons.loader</artifactId>
<version>1.0.31</version>
</dependency>
- <dependency>
- <groupId>org.hibernate.javax.persistence</groupId>
- <artifactId>hibernate-jpa-2.0-api</artifactId>
- <version>1.0.1.Final</version>
- </dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
diff --git a/commons.loader/pom.xml b/commons.loader/pom.xml
index 4533411f27..198baa7ed3 100644
--- a/commons.loader/pom.xml
+++ b/commons.loader/pom.xml
@@ -64,6 +64,11 @@
<artifactId>guice-multibindings</artifactId>
<version>${guiceVersion}</version>
</dependency>
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.0-api</artifactId>
+ <version>1.0.1.Final</version>
+ </dependency>
</dependencies>
<repositories>
<repository>
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContext.java b/commons.util/src/main/java/com/pmease/commons/util/diff/AroundContext.java
similarity index 69%
rename from gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContext.java
rename to commons.util/src/main/java/com/pmease/commons/util/diff/AroundContext.java
index 6135ff7064..d7b8fea960 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContext.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/AroundContext.java
@@ -1,14 +1,12 @@
-package com.pmease.gitplex.core.comment;
+package com.pmease.commons.util.diff;
import java.io.Serializable;
import java.util.List;
-import com.pmease.commons.util.diff.DiffLine;
-
@SuppressWarnings("serial")
-public class InlineContext implements Serializable {
+public class AroundContext implements Serializable {
- private final List<DiffLine> diffs;
+ private List<DiffLine> diffs;
private final int line;
@@ -16,7 +14,7 @@ public class InlineContext implements Serializable {
private final boolean belowOmitted;
- public InlineContext(List<DiffLine> diffs, int line, boolean aboveOmitted, boolean belowOmitted) {
+ public AroundContext(List<DiffLine> diffs, int line, boolean aboveOmitted, boolean belowOmitted) {
this.diffs = diffs;
this.line = line;
this.aboveOmitted = aboveOmitted;
@@ -27,6 +25,10 @@ public class InlineContext implements Serializable {
return diffs;
}
+ public void setDiffs(List<DiffLine> diffs) {
+ this.diffs = diffs;
+ }
+
public int getCommentLine() {
return line;
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java
index 02d2e573ce..e9f3bd09bf 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffLine.java
@@ -39,16 +39,16 @@ public class DiffLine implements Serializable {
private final int newLineNo;
- private final List<Partial> partials;
+ private final List<Token> partials;
public DiffLine(Action action, String line, int oldLineNo, int newLineNo) {
this.action = action;
this.oldLineNo = oldLineNo;
this.newLineNo = newLineNo;
- this.partials = Lists.newArrayList(new Partial(line, false));
+ this.partials = Lists.newArrayList(new Token(line, false));
}
- public DiffLine(Action action, List<Partial> partials, int oldLineNo, int newLineNo) {
+ public DiffLine(Action action, List<Token> partials, int oldLineNo, int newLineNo) {
this.action = action;
this.partials = partials;
this.oldLineNo = oldLineNo;
@@ -61,14 +61,14 @@ public class DiffLine implements Serializable {
/**
* Get list of partials of this diff line. Concatenate all partial contents will
- * form a line, and partials with {@link Partial#isEmphasized()} indicates
+ * form a line, and partials with {@link Token#isEmphasized()} indicates
* whether or not a partial should be emphasized when displayed as they cause
* the line to be considered as a diff line.
*
* @return
* list of partials of this diff line
*/
- public List<Partial> getPartials() {
+ public List<Token> getTokens() {
return partials;
}
@@ -83,7 +83,7 @@ public class DiffLine implements Serializable {
@Override
public String toString() {
StringBuffer buffer = new StringBuffer();
- for (Partial word: partials)
+ for (Token word: partials)
buffer.append(word.toString());
if (action == Action.DELETE)
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java
index 79011652eb..0476541fd4 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/DiffUtils.java
@@ -25,15 +25,15 @@ public class DiffUtils {
* original list of tokens.
* @param revised
* revised list of tokens
- * @param partialSplitter
- * pass a not null partial splitter to split line into partials, in order to
- * identify modified lines in diff result, so that modified partials can be
- * marked via {@link Partial#isEmphasized()}
+ * @param tokenSplitter
+ * pass a not null token splitter to split line into tokens, in order to
+ * identify modified lines in diff result, so that modified tokens can be
+ * marked via {@link Token#isEmphasized()}
* @return
- * list of difference tokens
+ * list of diff lines
*/
public static List<DiffLine> diff(List<String> original, List<String> revised,
- @Nullable PartialSplitter partialSplitter) {
+ @Nullable TokenSplitter tokenSplitter) {
Preconditions.checkArgument(original.size() + revised.size() <= 65535,
"Total size of original and revised list should be less than 65535.");
DiffMatchPatch dmp = new DiffMatchPatch();
@@ -43,61 +43,64 @@ public class DiffUtils {
List<DiffLine> diffLines = charsToTokens(diffs, result.tokenArray);
- if (partialSplitter != null) {
- List<DiffLine> processedDiffLines = new ArrayList<>();
- List<Triple<String, Integer, Integer>> deletions = new ArrayList<>();
- List<Triple<String, Integer, Integer>> additions = new ArrayList<>();
- List<DiffLine> processedDeletions = new ArrayList<>();
- List<DiffLine> processedAdditions = new ArrayList<>();
- for (DiffLine diffLine: diffLines) {
- Preconditions.checkState(diffLine.getPartials().size() == 1);
- if (diffLine.getAction() == DiffLine.Action.DELETE) {
- deletions.add(new Triple<String, Integer, Integer>(
- diffLine.getPartials().get(0).getContent(), diffLine.getOldLineNo(), diffLine.getNewLineNo()));
- } else if (diffLine.getAction() == DiffLine.Action.ADD) {
- additions.add(new Triple<String, Integer, Integer>(
- diffLine.getPartials().get(0).getContent(), diffLine.getOldLineNo(), diffLine.getNewLineNo()));
- } else {
- process(processedDiffLines, deletions, additions, processedDeletions, processedAdditions, partialSplitter);
- processedDiffLines.add(new DiffLine(DiffLine.Action.EQUAL, diffLine.getPartials().get(0).getContent(),
- diffLine.getOldLineNo(), diffLine.getNewLineNo()));
- }
- }
- process(processedDiffLines, deletions, additions, processedDeletions, processedAdditions, partialSplitter);
-
- return processedDiffLines;
- } else {
+ if (tokenSplitter != null)
+ return diffTokens(diffLines, tokenSplitter);
+ else
return diffLines;
+ }
+
+ public static List<DiffLine> diffTokens(List<DiffLine> diffs, TokenSplitter tokenSplitter) {
+ List<DiffLine> processedDiffs = new ArrayList<>();
+ List<Triple<String, Integer, Integer>> deletions = new ArrayList<>();
+ List<Triple<String, Integer, Integer>> additions = new ArrayList<>();
+ List<DiffLine> processedDeletions = new ArrayList<>();
+ List<DiffLine> processedAdditions = new ArrayList<>();
+ for (DiffLine diffLine: diffs) {
+ Preconditions.checkState(diffLine.getTokens().size() == 1);
+ if (diffLine.getAction() == DiffLine.Action.DELETE) {
+ deletions.add(new Triple<String, Integer, Integer>(
+ diffLine.getTokens().get(0).getContent(), diffLine.getOldLineNo(), diffLine.getNewLineNo()));
+ } else if (diffLine.getAction() == DiffLine.Action.ADD) {
+ additions.add(new Triple<String, Integer, Integer>(
+ diffLine.getTokens().get(0).getContent(), diffLine.getOldLineNo(), diffLine.getNewLineNo()));
+ } else {
+ process(processedDiffs, deletions, additions, processedDeletions, processedAdditions, tokenSplitter);
+ processedDiffs.add(new DiffLine(DiffLine.Action.EQUAL, diffLine.getTokens().get(0).getContent(),
+ diffLine.getOldLineNo(), diffLine.getNewLineNo()));
+ }
}
+ process(processedDiffs, deletions, additions, processedDeletions, processedAdditions, tokenSplitter);
+
+ return processedDiffs;
}
- private static List<String> getPartials(String line, PartialSplitter splitter, Map<String, List<String>> partialsCache) {
- List<String> partials = partialsCache.get(line);
- if (partials == null) {
- partials = splitter.split(line);
- partialsCache.put(line, partials);
+ private static List<String> getTokens(String line, TokenSplitter splitter, Map<String, List<String>> tokensCache) {
+ List<String> tokens = tokensCache.get(line);
+ if (tokens == null) {
+ tokens = splitter.split(line);
+ tokensCache.put(line, tokens);
}
- return partials;
+ return tokens;
}
private static void process(List<DiffLine> processedDiffLines, List<Triple<String, Integer, Integer>> deletions,
List<Triple<String, Integer, Integer>> additions, List<DiffLine> processedDeletions,
- List<DiffLine> processedAdditions, PartialSplitter partialSplitter) {
- Map<String, List<String>> partialsCache = new HashMap<String, List<String>>();
+ List<DiffLine> processedAdditions, TokenSplitter tokenSplitter) {
+ Map<String, List<String>> tokensCache = new HashMap<String, List<String>>();
for (Triple<String, Integer, Integer> deletion: deletions) {
boolean matching = false;
for (int i=0; i<additions.size(); i++) {
Triple<String, Integer, Integer> addition = additions.get(i);
- List<DiffLine> diffPartials = diff(getPartials(deletion.getFirst(), partialSplitter, partialsCache),
- getPartials(addition.getFirst(), partialSplitter, partialsCache), null);
+ List<DiffLine> diffTokens = diff(getTokens(deletion.getFirst(), tokenSplitter, tokensCache),
+ getTokens(addition.getFirst(), tokenSplitter, tokensCache), null);
int equals = 0;
int total = 0;
- for (DiffLine diffPartial: diffPartials) {
- if (StringUtils.isNotBlank(diffPartial.getPartials().get(0).getContent())) {
+ for (DiffLine diffToken: diffTokens) {
+ if (StringUtils.isNotBlank(diffToken.getTokens().get(0).getContent())) {
total ++;
- if (diffPartial.getAction() == DiffLine.Action.EQUAL)
+ if (diffToken.getAction() == DiffLine.Action.EQUAL)
equals++;
}
}
@@ -109,22 +112,22 @@ public class DiffUtils {
}
for (int j=0; j<=i; j++)
additions.remove(0);
- List<Partial> addPartials = new ArrayList<>();
- List<Partial> deletePartials = new ArrayList<>();
- for (DiffLine diffPartial: diffPartials) {
- Preconditions.checkState(diffPartial.getPartials().size() == 1);
- if (diffPartial.getAction() == DiffLine.Action.ADD) {
- addPartials.add(new Partial(diffPartial.getPartials().get(0).getContent(), true));
- } else if (diffPartial.getAction() == DiffLine.Action.DELETE) {
- deletePartials.add(new Partial(diffPartial.getPartials().get(0).getContent(), true));
+ List<Token> addTokens = new ArrayList<>();
+ List<Token> deleteTokens = new ArrayList<>();
+ for (DiffLine diffToken: diffTokens) {
+ Preconditions.checkState(diffToken.getTokens().size() == 1);
+ if (diffToken.getAction() == DiffLine.Action.ADD) {
+ addTokens.add(new Token(diffToken.getTokens().get(0).getContent(), true));
+ } else if (diffToken.getAction() == DiffLine.Action.DELETE) {
+ deleteTokens.add(new Token(diffToken.getTokens().get(0).getContent(), true));
} else {
- addPartials.add(new Partial(diffPartial.getPartials().get(0).getContent(), false));
- deletePartials.add(new Partial(diffPartial.getPartials().get(0).getContent(), false));
+ addTokens.add(new Token(diffToken.getTokens().get(0).getContent(), false));
+ deleteTokens.add(new Token(diffToken.getTokens().get(0).getContent(), false));
}
}
- processedAdditions.add(new DiffLine(DiffLine.Action.ADD, addPartials,
+ processedAdditions.add(new DiffLine(DiffLine.Action.ADD, addTokens,
addition.getSecond(), addition.getThird()));
- processedDeletions.add(new DiffLine(DiffLine.Action.DELETE, deletePartials,
+ processedDeletions.add(new DiffLine(DiffLine.Action.DELETE, deleteTokens,
deletion.getSecond(), deletion.getThird()));
matching = true;
break;
@@ -150,10 +153,14 @@ public class DiffUtils {
}
public static Map<Integer, Integer> mapLines(List<String> original, List<String> revised) {
+ return mapLines(diff(original, revised, null));
+ }
+
+ public static Map<Integer, Integer> mapLines(List<DiffLine> diffs) {
Map<Integer, Integer> lineMapping = new HashMap<Integer, Integer>();
int originalLine = 0;
int revisedLine = 0;
- for (DiffLine diff: diff(original, revised, null)) {
+ for (DiffLine diff: diffs) {
if (diff.getAction() == DiffLine.Action.ADD) {
revisedLine++;
} else if (diff.getAction() == DiffLine.Action.DELETE) {
@@ -166,14 +173,40 @@ public class DiffUtils {
}
return lineMapping;
}
+
+ public static AroundContext around(List<DiffLine> diffs, int oldLine, int newLine, int contextSize) {
+ List<DiffLine> contextDiffs = new ArrayList<>();
+ int index = -1;
+ for (int i=0; i<diffs.size(); i++) {
+ DiffLine diff = diffs.get(i);
+ if (diff.getOldLineNo() == oldLine || diff.getNewLineNo() == newLine) {
+ index = i;
+ break;
+ }
+ }
+
+ Preconditions.checkState(index != -1);
+
+ int start = index - contextSize;
+ if (start < 0)
+ start = 0;
+ int end = index + contextSize;
+ if (end > diffs.size() - 1)
+ end = diffs.size() - 1;
+
+ for (int i=start; i<=end; i++)
+ contextDiffs.add(diffs.get(i));
+
+ return new AroundContext(contextDiffs, index-start, start>0, end<diffs.size()-1);
+ }
public static List<DiffHunk> diffAsHunks(List<String> original, List<String> revised,
- PartialSplitter wordSplitter, int contextSize) {
+ TokenSplitter wordSplitter, int contextSize) {
return hunksOf(diff(original, revised, wordSplitter), contextSize);
}
public static List<DiffHunk> diffAsHunks(List<String> original, List<String> revised,
- PartialSplitter wordSplitter, Set<Integer> additionalOldLinesToPreserve,
+ TokenSplitter wordSplitter, Set<Integer> additionalOldLinesToPreserve,
Set<Integer> additionalNewLinesToPreserve, int contextSize) {
return hunksOf(diff(original, revised, wordSplitter), additionalOldLinesToPreserve,
additionalNewLinesToPreserve, contextSize);
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/Partial.java b/commons.util/src/main/java/com/pmease/commons/util/diff/Token.java
similarity index 80%
rename from commons.util/src/main/java/com/pmease/commons/util/diff/Partial.java
rename to commons.util/src/main/java/com/pmease/commons/util/diff/Token.java
index c26141edeb..89510a1bb8 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/diff/Partial.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/Token.java
@@ -3,13 +3,13 @@ package com.pmease.commons.util.diff;
import java.io.Serializable;
@SuppressWarnings("serial")
-public class Partial implements Serializable {
+public class Token implements Serializable {
private final String content;
private final boolean emphasized;
- public Partial(final String content, final boolean emphasized) {
+ public Token(final String content, final boolean emphasized) {
this.content = content;
this.emphasized = emphasized;
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/PartialSplitter.java b/commons.util/src/main/java/com/pmease/commons/util/diff/TokenSplitter.java
similarity index 73%
rename from commons.util/src/main/java/com/pmease/commons/util/diff/PartialSplitter.java
rename to commons.util/src/main/java/com/pmease/commons/util/diff/TokenSplitter.java
index d87eacbd85..495b2e5689 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/diff/PartialSplitter.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/TokenSplitter.java
@@ -2,6 +2,6 @@ package com.pmease.commons.util.diff;
import java.util.List;
-public interface PartialSplitter {
+public interface TokenSplitter {
List<String> split(String line);
}
diff --git a/commons.util/src/main/java/com/pmease/commons/util/diff/WordSplitter.java b/commons.util/src/main/java/com/pmease/commons/util/diff/WordSplitter.java
index 8f5a4c9d7b..d48ec52d13 100644
--- a/commons.util/src/main/java/com/pmease/commons/util/diff/WordSplitter.java
+++ b/commons.util/src/main/java/com/pmease/commons/util/diff/WordSplitter.java
@@ -5,7 +5,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-public class WordSplitter implements PartialSplitter {
+public class WordSplitter implements TokenSplitter {
private static final Pattern pattern = Pattern.compile("\\w+");
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editable/list/concrete/ConcreteListPropertyEditor.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editable/list/concrete/ConcreteListPropertyEditor.java
index 762f216edb..7b34260ba4 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/editable/list/concrete/ConcreteListPropertyEditor.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editable/list/concrete/ConcreteListPropertyEditor.java
@@ -37,9 +37,6 @@ import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PathSegment.Property;
import com.pmease.commons.wicket.editable.PropertyContext;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.commons.wicket.jquery.FunctionWithParams;
-
-import de.agilecoders.wicket.jquery.JQuery;
@SuppressWarnings("serial")
public class ConcreteListPropertyEditor extends PropertyEditor<List<Serializable>> {
@@ -189,13 +186,13 @@ public class ConcreteListPropertyEditor extends PropertyEditor<List<Serializable
lastRow = null;
Component newRow = addRow(rows, newElement());
- JQuery script = $(String.format("<tr id=\"%s\"></tr>", newRow.getMarkupId()));
+ String script = String.format("$('<tr id=\"%s\"></tr>')", newRow.getMarkupId());
if (lastRow != null)
- script.chain(new FunctionWithParams("insertAfter", "'#" + lastRow.getMarkupId() + "'"));
+ script += ".insertAfter('#" + lastRow.getMarkupId() + "');";
else
- script.chain(new FunctionWithParams("appendTo", "'#" + table.getMarkupId() + ">tbody'"));
+ script += ".appendTo('#" + table.getMarkupId() + ">tbody');";
- target.prependJavaScript(script.get());
+ target.prependJavaScript(script);
target.add(newRow);
if (rows.size() == 1)
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/editable/list/polymorphic/PolymorphicListPropertyEditor.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/editable/list/polymorphic/PolymorphicListPropertyEditor.java
index d0c71c9002..c2e93fadf6 100644
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/editable/list/polymorphic/PolymorphicListPropertyEditor.java
+++ b/commons.wicket/src/main/java/com/pmease/commons/wicket/editable/list/polymorphic/PolymorphicListPropertyEditor.java
@@ -38,9 +38,6 @@ import com.pmease.commons.wicket.editable.BeanEditor;
import com.pmease.commons.wicket.editable.ErrorContext;
import com.pmease.commons.wicket.editable.PathSegment;
import com.pmease.commons.wicket.editable.PropertyEditor;
-import com.pmease.commons.wicket.jquery.FunctionWithParams;
-
-import de.agilecoders.wicket.jquery.JQuery;
@SuppressWarnings("serial")
public class PolymorphicListPropertyEditor extends PropertyEditor<List<Serializable>> {
@@ -181,13 +178,13 @@ public class PolymorphicListPropertyEditor extends PropertyEditor<List<Serializa
}
Component newRow = addRow(rows, newElement);
- JQuery script = $(String.format("<tr id=\"%s\"></tr>", newRow.getMarkupId()));
+ String script = String.format("$('<tr id=\"%s\"></tr>')", newRow.getMarkupId());
if (lastRow != null)
- script.chain(new FunctionWithParams("insertAfter", "'#" + lastRow.getMarkupId() + "'"));
+ script += ".insertAfter('#" + lastRow.getMarkupId() + "');";
else
- script.chain(new FunctionWithParams("appendTo", "'#" + table.getMarkupId() + ">tbody'"));
+ script += ".appendTo('#" + table.getMarkupId() + ">tbody');";
- target.prependJavaScript(script.get());
+ target.prependJavaScript(script);
target.add(newRow);
if (rows.size() == 1)
diff --git a/commons.wicket/src/main/java/com/pmease/commons/wicket/jquery/FunctionWithParams.java b/commons.wicket/src/main/java/com/pmease/commons/wicket/jquery/FunctionWithParams.java
deleted file mode 100644
index ca8b23e7b7..0000000000
--- a/commons.wicket/src/main/java/com/pmease/commons/wicket/jquery/FunctionWithParams.java
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.pmease.commons.wicket.jquery;
-
-import de.agilecoders.wicket.jquery.JQuery.AbstractFunction;
-
-@SuppressWarnings("serial")
-public class FunctionWithParams extends AbstractFunction {
-
- public FunctionWithParams(String functionName, String...params) {
- super(functionName);
-
- for (String param: params)
- addParameter(param);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
index 3e7a5c0754..143d0371db 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/ChangeComments.java
@@ -3,18 +3,18 @@ package com.pmease.gitplex.core.comment;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
+import com.google.common.base.Preconditions;
import com.pmease.commons.git.BlobInfo;
import com.pmease.commons.git.BlobText;
import com.pmease.commons.git.RevAwareChange;
-import com.pmease.commons.util.Triple;
import com.pmease.commons.util.diff.DiffUtils;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.manager.PullRequestInlineCommentManager;
import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.PullRequestComment;
+import com.pmease.gitplex.core.model.PullRequestInlineComment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.Repository;
@@ -34,101 +34,43 @@ public class ChangeComments implements Serializable {
Map<String, Map<String, List<InlineComment>>> comments = new HashMap<>();
Map<BlobInfo, List<String>> blobs = new HashMap<>();
- int end = -1;
if (change.getNewPath() != null) {
- end = commits.indexOf(change.getNewRevision());
- if (end != -1 && getContent(blobs, change.getNewBlobInfo(), request.getTarget().getRepository()).isEmpty())
- end = -1;
- }
-
- int begin = -1;
- if (change.getOldPath() != null) {
- begin = commits.indexOf(change.getOldRevision());
- if (begin != -1 && getContent(blobs, change.getOldBlobInfo(), request.getTarget().getRepository()).isEmpty())
- begin = -1;
- }
-
- if (end != -1) {
- for (int i=end-1; i>begin; i--) {
- String commit = commits.get(i);
- Map<String, List<InlineComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, request);
- BlobInfo blobInfo = null;
- List<InlineComment> commentsOnFile = commentsOnCommit.get(change.getNewPath());
- if (commentsOnFile != null) {
- blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());
- } else {
- commentsOnFile = commentsOnCommit.get(change.getOldPath());
- if (commentsOnFile != null)
- blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());
- }
-
- if (blobInfo != null) {
- List<String> fileContent = getContent(blobs, blobInfo, request.getTarget().getRepository());
- if (!fileContent.isEmpty()) {
- List<String> newContent = getContent(blobs, change.getNewBlobInfo(), request.getTarget().getRepository());
- Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, newContent);
- for (InlineComment comment: commentsOnFile) {
- Integer line = lineMap.get(comment.getLine());
- if (line != null)
- addLineComment(newComments, line, comment);
- }
- }
- }
- }
-
- List<InlineComment> commentsOnFile = getCommentsOnCommit(comments, change.getNewRevision(), request).get(change.getNewPath());
- if (commentsOnFile != null) {
- for (InlineComment comment: commentsOnFile)
- addLineComment(newComments, comment.getLine(), comment);
- }
- }
-
- if (begin != -1) {
- Set<CommentKey> appliedComments = new HashSet<>();
- for (List<InlineComment> list: newComments.values()) {
- for (InlineComment comment: list)
- appliedComments.add(new CommentKey(comment.getCommitHash(), comment.getFile(), comment.getLine()));
- }
-
- for (int i=begin+1; i<(end!=-1?end:commits.size()); i++) {
- String commit = commits.get(i);
- Map<String, List<InlineComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, request);
- BlobInfo blobInfo = null;
- List<InlineComment> commentsOnFile = commentsOnCommit.get(change.getOldPath());
- if (commentsOnFile != null) {
- blobInfo = new BlobInfo(commit, change.getOldPath(), change.getOldMode());
- } else {
- commentsOnFile = commentsOnCommit.get(change.getNewPath());
- if (commentsOnFile != null)
- blobInfo = new BlobInfo(commit, change.getNewPath(), change.getNewMode());
- }
-
- if (blobInfo != null) {
- boolean allApplied = true;
- for (InlineComment comment: commentsOnFile) {
- CommentKey key = new CommentKey(comment.getCommitHash(), comment.getFile(), comment.getLine());
- if (!appliedComments.contains(key)) {
- allApplied = false;
- break;
- }
- }
- if (!allApplied) {
+ int end = commits.indexOf(change.getNewRevision());
+ Preconditions.checkState(end != -1);
+ if (!getContent(blobs, change.getNewBlobInfo(), request.getTarget().getRepository()).isEmpty()) {
+ for (int i=commits.size()-1; i>end; i--) {
+ String commit = commits.get(i);
+ Map<String, List<InlineComment>> commentsOnCommit = getCommentsOnCommit(comments, commit, request);
+ List<InlineComment> commentsOnFile = commentsOnCommit.get(change.getNewPath());
+ if (commentsOnFile != null) {
+ Preconditions.checkState(!commentsOnFile.isEmpty());
+ BlobInfo blobInfo = commentsOnFile.get(0).getBlobInfo();
List<String> fileContent = getContent(blobs, blobInfo, request.getTarget().getRepository());
if (!fileContent.isEmpty()) {
- List<String> oldContent = getContent(blobs, change.getOldBlobInfo(), request.getTarget().getRepository());
- Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, oldContent);
+ List<String> newContent = getContent(blobs, change.getNewBlobInfo(), request.getTarget().getRepository());
+ Map<Integer, Integer> lineMap = DiffUtils.mapLines(fileContent, newContent);
for (InlineComment comment: commentsOnFile) {
- CommentKey key = new CommentKey(comment.getCommitHash(), comment.getFile(), comment.getLine());
Integer line = lineMap.get(comment.getLine());
- if (!appliedComments.contains(key) && line != null)
- addLineComment(oldComments, line, comment);
+ if (line != null)
+ addLineComment(newComments, line, comment);
}
}
}
}
+
+ List<InlineComment> commentsOnFile = getCommentsOnCommit(comments, change.getNewRevision(), request).get(change.getNewPath());
+ if (commentsOnFile != null) {
+ for (InlineComment comment: commentsOnFile)
+ addLineComment(newComments, comment.getLine(), comment);
+ }
}
+ }
- if (!change.getOldRevision().equals(change.getNewRevision())) {
+ if (change.getOldPath() != null) {
+ int begin = commits.indexOf(change.getOldRevision());
+ Preconditions.checkState(begin != -1);
+ if (!getContent(blobs, change.getOldBlobInfo(), request.getTarget().getRepository()).isEmpty()
+ && !change.getOldRevision().equals(change.getNewRevision())) {
List<InlineComment> commentsOnFile = getCommentsOnCommit(comments, change.getOldRevision(), request).get(change.getOldPath());
if (commentsOnFile != null) {
for (InlineComment comment: commentsOnFile)
@@ -154,14 +96,15 @@ public class ChangeComments implements Serializable {
if (commentsOnCommit == null) {
commentsOnCommit = new HashMap<>();
- for (PullRequestComment each: request.getComments()) {
- if (each.getInlineInfo() != null && each.getInlineInfo().getCommitHash().equals(commit)) {
- List<InlineComment> commentsOnFile = commentsOnCommit.get(each.getFile());
+ for (PullRequestInlineComment comment: request.getInlineComments()) {
+ GitPlex.getInstance(PullRequestInlineCommentManager.class).update(comment);
+ if (comment.getBlobInfo().getRevision().equals(commit)) {
+ List<InlineComment> commentsOnFile = commentsOnCommit.get(comment.getBlobInfo().getPath());
if (commentsOnFile == null) {
commentsOnFile = new ArrayList<>();
- commentsOnCommit.put(each.getFile(), commentsOnFile);
+ commentsOnCommit.put(comment.getBlobInfo().getPath(), commentsOnFile);
}
- commentsOnFile.add(each);
+ commentsOnFile.add(comment);
}
}
comments.put(commit, commentsOnCommit);
@@ -190,11 +133,4 @@ public class ChangeComments implements Serializable {
return content;
}
- private static class CommentKey extends Triple<String, String, Integer> {
-
- public CommentKey(String commit, String file, int line) {
- super(commit, file, line);
- }
-
- }
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java
index 012d432490..996bfde13c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineComment.java
@@ -1,18 +1,15 @@
package com.pmease.gitplex.core.comment;
+import com.pmease.commons.git.BlobInfo;
+import com.pmease.commons.util.diff.AroundContext;
+
public interface InlineComment extends Comment {
int CONTEXT_SIZE = 10;
- String getCommitHash();
-
- String getOldCommitHash();
-
- String getNewCommitHash();
+ BlobInfo getBlobInfo();
int getLine();
- String getFile();
-
- InlineContext getContext();
+ AroundContext getContext();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java
index da2d01c274..c979309cc0 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineCommentSupport.java
@@ -4,13 +4,17 @@ import java.io.Serializable;
import java.util.List;
import java.util.Map;
+import com.pmease.commons.git.BlobInfo;
+import com.pmease.commons.util.diff.AroundContext;
+
public interface InlineCommentSupport extends Serializable {
Map<Integer, List<InlineComment>> getOldComments();
Map<Integer, List<InlineComment>> getNewComments();
- InlineComment addComment(String commit, String file, int line, String content);
+ InlineComment addComment(BlobInfo commentAt, BlobInfo compareWith,
+ AroundContext commentContext, int line, String content);
InlineComment getConcernedComment();
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContextAware.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContextAware.java
deleted file mode 100644
index 4a788de23d..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/comment/InlineContextAware.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.pmease.gitplex.core.comment;
-
-import javax.annotation.Nullable;
-
-public interface InlineContextAware {
-
- @Nullable
- InlineContext getInlineContext(InlineComment comment);
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.java
deleted file mode 100644
index b3cd5ec8a4..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitCommentManager.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.pmease.gitplex.core.manager;
-
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
-import javax.annotation.Nullable;
-
-import com.google.inject.ImplementedBy;
-import com.pmease.gitplex.core.manager.impl.DefaultCommitCommentManager;
-import com.pmease.gitplex.core.model.CommitComment;
-import com.pmease.gitplex.core.model.Repository;
-
-@ImplementedBy(DefaultCommitCommentManager.class)
-public interface CommitCommentManager {
-
- /**
- * Find comments by commit.
- *
- * @param repository
- * repository to find comment inside
- * @param commit
- * commit to find comment for
- * @return
- * list of comments ordered by id
- */
- List<CommitComment> findByCommit(Repository repository, String commit);
-
- /**
- * Find comments by file.
- *
- * @param repository
- * repository to find comment inside
- * @param commit
- * file to find comment for
- * @return
- * list of comments ordered by id
- */
- List<CommitComment> findByFile(Repository repository, String file);
-
- /**
- * Find comments by commit and file.
- *
- * @param repository
- * repository to find comment inside
- * @param commit
- * commit to find comment for
- * @param file
- * file to find comment for
- * @return
- * list of comments ordered by id
- */
- List<CommitComment> findByCommitAndFile(Repository repository, String commit, String file);
-
- /**
- * Find comments by specified commit date range.
- *
- * @param repository
- * repository to find comment inside
- * @param fromDate
- * from date of associated commit
- * @param toDate
- * to date of associated commit
- * @return
- * list of found comments ordered by id
- */
- List<CommitComment> findByCommitDates(Repository repository, @Nullable Date fromDate, @Nullable Date toDate);
-
- List<CommitComment> findByCommitOrDates(Repository repository, String commit,
- @Nullable Date fromDate, @Nullable Date toDate);
-
- Map<Integer, List<CommitComment>> findLineComments(Repository repository, String commit, String filePath);
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitWatchManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitWatchManager.java
deleted file mode 100644
index f855ad87b4..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/CommitWatchManager.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.pmease.gitplex.core.manager;
-
-import java.util.Collection;
-
-import com.google.inject.ImplementedBy;
-import com.pmease.gitplex.core.manager.impl.DefaultCommitWatchManager;
-import com.pmease.gitplex.core.model.CommitWatch;
-import com.pmease.gitplex.core.model.Repository;
-import com.pmease.gitplex.core.model.User;
-
-@ImplementedBy(DefaultCommitWatchManager.class)
-public interface CommitWatchManager {
-
- Collection<CommitWatch> findBy(User user, Repository repository);
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java
deleted file mode 100644
index de43a271fe..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestCommentManager.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.pmease.gitplex.core.manager;
-
-import java.util.List;
-
-import com.google.inject.ImplementedBy;
-import com.pmease.commons.git.RevAwareChange;
-import com.pmease.gitplex.core.manager.impl.DefaultPullRequestCommentManager;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.PullRequestComment;
-
-@ImplementedBy(DefaultPullRequestCommentManager.class)
-public interface PullRequestCommentManager {
-
- List<PullRequestComment> findByChange(PullRequest request, RevAwareChange change);
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestInlineCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestInlineCommentManager.java
new file mode 100644
index 0000000000..800017a845
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/PullRequestInlineCommentManager.java
@@ -0,0 +1,17 @@
+package com.pmease.gitplex.core.manager;
+
+import com.google.inject.ImplementedBy;
+import com.pmease.gitplex.core.manager.impl.DefaultPullRequestInlineCommentManager;
+import com.pmease.gitplex.core.model.PullRequestInlineComment;
+
+@ImplementedBy(DefaultPullRequestInlineCommentManager.class)
+public interface PullRequestInlineCommentManager {
+
+ /**
+ * Update specified inline comment to make sure it is up to date with latest pull request update
+ *
+ * @param comment
+ * comment to be updated
+ */
+ void update(PullRequestInlineComment comment);
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.java
deleted file mode 100644
index 4aa15da145..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitCommentManager.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.hibernate.criterion.Conjunction;
-import org.hibernate.criterion.Order;
-import org.hibernate.criterion.Restrictions;
-
-import com.pmease.commons.hibernate.Sessional;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.manager.CommitCommentManager;
-import com.pmease.gitplex.core.model.CommentPosition;
-import com.pmease.gitplex.core.model.CommitComment;
-import com.pmease.gitplex.core.model.Repository;
-
-@Singleton
-public class DefaultCommitCommentManager implements CommitCommentManager {
-
- private final Dao dao;
-
- @Inject
- public DefaultCommitCommentManager(Dao dao) {
- this.dao = dao;
- }
-
- @Sessional
- @Override
- public List<CommitComment> findByFile(Repository repository, String file) {
- return dao.query(EntityCriteria.of(CommitComment.class)
- .add(Restrictions.eq("repository", repository))
- .add(Restrictions.eq("position.filePath", file))
- .addOrder(Order.asc("id")), 0, 0);
- }
-
- @Sessional
- @Override
- public List<CommitComment> findByCommit(Repository repository, String commit) {
- return dao.query(EntityCriteria.of(CommitComment.class)
- .add(Restrictions.eq("repository", repository))
- .add(Restrictions.eq("commit", commit))
- .addOrder(Order.asc("id")), 0, 0);
- }
-
- @Override
- public List<CommitComment> findByCommitAndFile(Repository repository, String commit, String filePath) {
- return dao.query(EntityCriteria.of(CommitComment.class)
- .add(Restrictions.eq("repository", repository))
- .add(Restrictions.eq("commit", commit))
- .add(Restrictions.eq("position.filePath", filePath))
- .addOrder(Order.asc("id")), 0, 0);
- }
-
- @Override
- public List<CommitComment> findByCommitDates(Repository repository, Date fromDate, Date toDate) {
- EntityCriteria<CommitComment> criteria = EntityCriteria.of(CommitComment.class);
- criteria.add(Restrictions.eq("repository", repository));
- if (fromDate != null)
- criteria.add(Restrictions.ge("commitDate", fromDate));
- if (toDate != null)
- criteria.add(Restrictions.le("commitDate", toDate));
- criteria.addOrder(Order.asc("id"));
- return dao.query(criteria, 0, 0);
- }
-
- @Override
- public List<CommitComment> findByCommitOrDates(Repository repository,
- String commit, Date fromDate, Date toDate) {
- EntityCriteria<CommitComment> criteria = EntityCriteria.of(CommitComment.class);
- criteria.add(Restrictions.eq("repository", repository));
- Conjunction conjunction = Restrictions.conjunction();
- if (fromDate != null)
- conjunction.add(Restrictions.ge("commitDate", fromDate));
- if (toDate != null)
- conjunction.add(Restrictions.le("commitDate", toDate));
- criteria.add(Restrictions.or(Restrictions.eq("commit", commit), conjunction));
- criteria.addOrder(Order.asc("id"));
- return dao.query(criteria, 0, 0);
- }
-
- @Override
- public Map<Integer, List<CommitComment>> findLineComments(Repository repository,
- String commit, String filePath) {
- Map<Integer, List<CommitComment>> comments = new HashMap<>();
- CommitCommentManager manager = GitPlex.getInstance(CommitCommentManager.class);
- for (CommitComment comment: manager.findByCommitAndFile(repository, commit, filePath)) {
- CommentPosition position = comment.getPosition();
- if (position.getLineNo() != null && position.getFilePath().equals(filePath)) {
- List<CommitComment> lineComments = comments.get(position.getLineNo());
- if (lineComments == null) {
- lineComments = new ArrayList<>();
- comments.put(position.getLineNo(), lineComments);
- }
- lineComments.add(comment);
- }
- }
- return comments;
- }
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitWatchManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitWatchManager.java
deleted file mode 100644
index d2e6af1bcf..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultCommitWatchManager.java
+++ /dev/null
@@ -1,37 +0,0 @@
-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.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.gitplex.core.manager.CommitWatchManager;
-import com.pmease.gitplex.core.model.CommitWatch;
-import com.pmease.gitplex.core.model.Repository;
-import com.pmease.gitplex.core.model.User;
-
-@Singleton
-public class DefaultCommitWatchManager implements CommitWatchManager {
-
- private final Dao dao;
-
- @Inject
- public DefaultCommitWatchManager(Dao dao) {
- this.dao = dao;
- }
-
- @Sessional
- @Override
- public Collection<CommitWatch> findBy(User user, Repository repository) {
- EntityCriteria<CommitWatch> criteria = EntityCriteria.of(CommitWatch.class);
- criteria.add(Restrictions.eq("user", user));
- criteria.createCriteria("branch").add(Restrictions.eq("repository", repository));
- return dao.query(criteria);
- }
-
-}
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
deleted file mode 100644
index cf868a17dd..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestCommentManager.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.pmease.gitplex.core.manager.impl;
-
-import static com.pmease.commons.git.Change.Status.ADDED;
-import static com.pmease.commons.git.Change.Status.DELETED;
-
-import java.util.List;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.hibernate.criterion.Conjunction;
-import org.hibernate.criterion.Restrictions;
-
-import com.google.common.base.Preconditions;
-import com.pmease.commons.git.GitUtils;
-import com.pmease.commons.git.RevAwareChange;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.commons.hibernate.dao.EntityCriteria;
-import com.pmease.gitplex.core.manager.PullRequestCommentManager;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.PullRequestComment;
-
-@Singleton
-public class DefaultPullRequestCommentManager implements PullRequestCommentManager {
-
- private final Dao dao;
-
- @Inject
- public DefaultPullRequestCommentManager(Dao dao) {
- this.dao = dao;
- }
-
- @Override
- public List<PullRequestComment> findByChange(PullRequest request, RevAwareChange change) {
- Preconditions.checkArgument(GitUtils.isHash(change.getOldRevision()));
- Preconditions.checkArgument(GitUtils.isHash(change.getNewRevision()));
- EntityCriteria<PullRequestComment> criteria = EntityCriteria.of(PullRequestComment.class);
- criteria.add(Restrictions.eq("request", request));
-
- Conjunction oldConj = Restrictions.conjunction();
- oldConj.add(Restrictions.eq("inlineInfo.commit", change.getOldRevision()));
- oldConj.add(Restrictions.eq("inlineInfo.file", change.getOldPath()));
-
- Conjunction newConj = Restrictions.conjunction();
- newConj.add(Restrictions.eq("inlineInfo.commit", change.getNewRevision()));
- newConj.add(Restrictions.eq("inlineInfo.file", change.getNewPath()));
-
- if (change.getStatus() == ADDED)
- criteria.add(oldConj);
- else if (change.getStatus() == DELETED)
- criteria.add(newConj);
- else
- criteria.add(Restrictions.or(oldConj, newConj));
-
- return dao.query(criteria);
- }
-
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInlineCommentManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInlineCommentManager.java
new file mode 100644
index 0000000000..6310d45852
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultPullRequestInlineCommentManager.java
@@ -0,0 +1,148 @@
+package com.pmease.gitplex.core.manager.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import com.google.common.base.Preconditions;
+import com.pmease.commons.git.BlobInfo;
+import com.pmease.commons.git.BlobText;
+import com.pmease.commons.git.Change;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.util.diff.AroundContext;
+import com.pmease.commons.util.diff.DiffLine;
+import com.pmease.commons.util.diff.DiffUtils;
+import com.pmease.commons.util.diff.WordSplitter;
+import com.pmease.gitplex.core.comment.InlineComment;
+import com.pmease.gitplex.core.manager.PullRequestInlineCommentManager;
+import com.pmease.gitplex.core.model.PullRequestInlineComment;
+
+@Singleton
+public class DefaultPullRequestInlineCommentManager implements PullRequestInlineCommentManager {
+
+ private final Dao dao;
+
+ @Inject
+ public DefaultPullRequestInlineCommentManager(Dao dao) {
+ this.dao = dao;
+ }
+
+ @Override
+ public void update(PullRequestInlineComment comment) {
+ String latestCommitHash = comment.getRequest().getLatestUpdate().getHeadCommitHash();
+ if (!comment.getNewCommitHash().equals(latestCommitHash)) {
+ List<Change> changes = comment.getRepository().getChanges(comment.getNewCommitHash(), latestCommitHash);
+ String oldCommitHash = comment.getOldCommitHash();
+ if (oldCommitHash.equals(comment.getBlobInfo().getRevision())) {
+ BlobInfo newBlobInfo = null;
+ if (comment.getCompareWith().getPath() != null) {
+ for (Change change: changes) {
+ if (comment.getCompareWith().getPath().equals(change.getOldPath())) {
+ newBlobInfo = new BlobInfo(latestCommitHash, change.getNewPath(), change.getNewMode());
+ break;
+ }
+ }
+ } else {
+ for (Change change: changes) {
+ if (comment.getBlobInfo().getPath().equals(change.getNewPath())) {
+ newBlobInfo = new BlobInfo(latestCommitHash, change.getNewPath(), change.getNewMode());
+ break;
+ }
+ }
+ }
+ if (newBlobInfo != null) {
+ BlobText oldText = comment.getRepository().getBlobText(comment.getBlobInfo());
+ Preconditions.checkNotNull(oldText);
+ List<String> newLines;
+ if (newBlobInfo.getPath() != null) {
+ BlobText newText = comment.getRepository().getBlobText(newBlobInfo);
+ if (newText != null)
+ newLines = newText.getLines();
+ else
+ newLines = null;
+ } else {
+ newLines = new ArrayList<>();
+ }
+ if (newLines != null) {
+ List<DiffLine> diffs = DiffUtils.diff(oldText.getLines(), newLines, null);
+ AroundContext context = DiffUtils.around(
+ diffs, comment.getLine(), -1, InlineComment.CONTEXT_SIZE);
+ context.setDiffs(DiffUtils.diffTokens(context.getDiffs(), new WordSplitter()));
+ comment.setContext(context);
+ } else {
+ comment.setContext(null);
+ }
+ comment.setCompareWith(newBlobInfo);
+ } else {
+ comment.getCompareWith().setRevision(latestCommitHash);
+ }
+ } else {
+ BlobInfo newBlobInfo = null;
+ for (Change change: changes) {
+ if (comment.getBlobInfo().getPath().equals(change.getOldPath())) {
+ newBlobInfo = new BlobInfo(latestCommitHash, change.getNewPath(), change.getNewMode());
+ break;
+ }
+ }
+ if (newBlobInfo != null) {
+ BlobText oldText = comment.getRepository().getBlobText(comment.getBlobInfo());
+ Preconditions.checkNotNull(oldText);
+ List<String> newLines;
+ if (newBlobInfo.getPath() != null) {
+ BlobText newText = comment.getRepository().getBlobText(newBlobInfo);
+ if (newText != null)
+ newLines = newText.getLines();
+ else
+ newLines = null;
+ } else {
+ newLines = new ArrayList<>();
+ }
+ if (newLines != null) {
+ List<DiffLine> diffs = DiffUtils.diff(oldText.getLines(), newLines, null);
+ Integer newLineNo = DiffUtils.mapLines(diffs).get(comment.getLine());
+ if (newLineNo != null) {
+ comment.setBlobInfo(newBlobInfo);
+ comment.setLine(newLineNo);
+
+ List<String> oldLines;
+ if (comment.getCompareWith().getPath() != null) {
+ oldText = comment.getRepository().getBlobText(comment.getCompareWith());
+ if (oldText != null)
+ oldLines = oldText.getLines();
+ else
+ oldLines = null;
+ } else {
+ oldLines = new ArrayList<>();
+ }
+ if (oldLines != null) {
+ diffs = DiffUtils.diff(oldLines, newLines, null);
+ AroundContext context = DiffUtils.around(
+ diffs, -1, newLineNo, InlineComment.CONTEXT_SIZE);
+ context.setDiffs(DiffUtils.diffTokens(context.getDiffs(), new WordSplitter()));
+ comment.setContext(context);
+ } else {
+ comment.setContext(null);
+ }
+ } else {
+ comment.setCompareWith(newBlobInfo);
+
+ AroundContext context = DiffUtils.around(
+ diffs, comment.getLine(), -1, InlineComment.CONTEXT_SIZE);
+ context.setDiffs(DiffUtils.diffTokens(context.getDiffs(), new WordSplitter()));
+ comment.setContext(context);
+ }
+ } else {
+ comment.setCompareWith(newBlobInfo);
+ comment.setContext(null);
+ }
+ } else {
+ comment.getBlobInfo().setRevision(latestCommitHash);
+ }
+ }
+ dao.persist(comment);
+ }
+ }
+
+}
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 8e5d68bdc9..5bdfda2e98 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
@@ -35,6 +35,7 @@ import com.pmease.commons.util.FileUtils;
import com.pmease.gitplex.core.extensionpoint.PullRequestListener;
import com.pmease.gitplex.core.extensionpoint.PullRequestListeners;
import com.pmease.gitplex.core.manager.BranchManager;
+import com.pmease.gitplex.core.manager.PullRequestInlineCommentManager;
import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.manager.PullRequestUpdateManager;
import com.pmease.gitplex.core.manager.StorageManager;
@@ -46,6 +47,7 @@ import com.pmease.gitplex.core.model.PullRequest.CloseStatus;
import com.pmease.gitplex.core.model.PullRequest.IntegrationStrategy;
import com.pmease.gitplex.core.model.PullRequestAudit;
import com.pmease.gitplex.core.model.PullRequestComment;
+import com.pmease.gitplex.core.model.PullRequestInlineComment;
import com.pmease.gitplex.core.model.PullRequestOperation;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.Repository;
@@ -66,6 +68,8 @@ public class DefaultPullRequestManager implements PullRequestManager {
private final UnitOfWork unitOfWork;
+ private final PullRequestInlineCommentManager pullRequestInlineCommentManager;
+
private final PullRequestListeners pullRequestListeners;
private final Set<Long> calculatingRequestIds = new ConcurrentHashSet<>();
@@ -73,13 +77,15 @@ public class DefaultPullRequestManager implements PullRequestManager {
@Inject
public DefaultPullRequestManager(Dao dao, PullRequestUpdateManager pullRequestUpdateManager,
BranchManager branchManager, StorageManager storageManager,
- UnitOfWork unitOfWork, PullRequestListeners pullRequestListeners) {
+ UnitOfWork unitOfWork, PullRequestListeners pullRequestListeners,
+ PullRequestInlineCommentManager pullRequestInlineCommentManager) {
this.dao = dao;
this.pullRequestUpdateManager = pullRequestUpdateManager;
this.branchManager = branchManager;
this.storageManager = storageManager;
this.unitOfWork = unitOfWork;
this.pullRequestListeners = pullRequestListeners;
+ this.pullRequestInlineCommentManager = pullRequestInlineCommentManager;
}
@Sessional
@@ -368,6 +374,17 @@ public class DefaultPullRequestManager implements PullRequestManager {
}
});
+
+ unitOfWork.asyncCall(new Runnable() {
+
+ @Override
+ public void run() {
+ PullRequest request = dao.load(PullRequest.class, requestId);
+ for (PullRequestInlineComment comment: request.getInlineComments())
+ pullRequestInlineCommentManager.update((PullRequestInlineComment) comment);
+ }
+
+ });
}
});
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java
index b2b848bd3e..ce35f6e6dd 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/manager/impl/DefaultStorageManager.java
@@ -51,4 +51,5 @@ public class DefaultStorageManager implements StorageManager {
FileUtils.createDir(dir);
return dir;
}
+
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestComment.java
new file mode 100644
index 0000000000..faf2baa463
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestComment.java
@@ -0,0 +1,103 @@
+package com.pmease.gitplex.core.model;
+
+import java.util.Date;
+
+import javax.annotation.Nullable;
+import javax.persistence.Column;
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.MappedSuperclass;
+
+import com.pmease.commons.hibernate.AbstractEntity;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.comment.Comment;
+
+@SuppressWarnings("serial")
+@MappedSuperclass
+public abstract class AbstractPullRequestComment extends AbstractEntity implements Comment {
+
+ @ManyToOne
+ @JoinColumn(nullable=false)
+ private PullRequest request;
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ private User user;
+
+ @Column(nullable=false)
+ private String content;
+
+ @Column(nullable=false)
+ private Date date = new Date();
+
+ private boolean resolved;
+
+ public PullRequest getRequest() {
+ return request;
+ }
+
+ public void setRequest(PullRequest request) {
+ this.request = request;
+ }
+
+ @Nullable
+ @Override
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(@Nullable User user) {
+ this.user = user;
+ }
+
+ @Override
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ @Override
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ @Override
+ public void saveContent(String content) {
+ setContent(content);
+ GitPlex.getInstance(Dao.class).persist(this);
+ }
+
+ @Override
+ public Repository getRepository() {
+ return request.getTarget().getRepository();
+ }
+
+ @Override
+ public void delete() {
+ GitPlex.getInstance(Dao.class).remove(this);
+ }
+
+ @Override
+ public boolean isResolved() {
+ return resolved;
+ }
+
+ public void setResolved(boolean resolved) {
+ this.resolved = resolved;
+ }
+
+ @Override
+ public void resolve(boolean resolved) {
+ setResolved(resolved);
+ GitPlex.getInstance(Dao.class).persist(this);
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestCommentReply.java
new file mode 100644
index 0000000000..4b36889166
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/AbstractPullRequestCommentReply.java
@@ -0,0 +1,62 @@
+package com.pmease.gitplex.core.model;
+
+import java.util.Date;
+
+import javax.persistence.FetchType;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.MappedSuperclass;
+
+import com.pmease.commons.hibernate.AbstractEntity;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.comment.CommentReply;
+
+@SuppressWarnings("serial")
+@MappedSuperclass
+public abstract class AbstractPullRequestCommentReply extends AbstractEntity implements CommentReply {
+
+ @ManyToOne(fetch=FetchType.LAZY)
+ @JoinColumn(nullable=false)
+ private User user;
+
+ private Date date;
+
+ private String content;
+
+ public User getUser() {
+ return user;
+ }
+
+ public void setUser(User user) {
+ this.user = user;
+ }
+
+ public Date getDate() {
+ return date;
+ }
+
+ public void setDate(Date date) {
+ this.date = date;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ @Override
+ public void saveContent(String content) {
+ setContent(content);
+ GitPlex.getInstance(Dao.class).persist(this);
+ }
+
+ @Override
+ public void delete() {
+ GitPlex.getInstance(Dao.class).remove(this);
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Branch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Branch.java
index 31af280673..3c40ef7308 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Branch.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Branch.java
@@ -44,9 +44,6 @@ public class Branch extends AbstractEntity {
@OneToMany(mappedBy="source")
private Collection<PullRequest> outgoingRequests = new ArrayList<>();
- @OneToMany(mappedBy="branch", cascade=CascadeType.REMOVE)
- private Collection<CommitWatch> commitWatches = new ArrayList<>();
-
@OneToMany(mappedBy="branch", cascade=CascadeType.REMOVE)
private Collection<PullRequestWatch> requestWatches = new ArrayList<>();
@@ -84,14 +81,6 @@ public class Branch extends AbstractEntity {
this.outgoingRequests = outgoingRequests;
}
- public Collection<CommitWatch> getCommitWatches() {
- return commitWatches;
- }
-
- public void setCommitWatches(Collection<CommitWatch> commitWatches) {
- this.commitWatches = commitWatches;
- }
-
public Collection<PullRequestWatch> getRequestWatches() {
return requestWatches;
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPosition.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPosition.java
deleted file mode 100644
index 9a64e48fc2..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommentPosition.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.pmease.gitplex.core.model;
-
-import java.io.Serializable;
-
-import javax.annotation.Nullable;
-import javax.persistence.Embeddable;
-
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-
-import com.google.common.base.Objects;
-
-@SuppressWarnings("serial")
-@Embeddable
-public class CommentPosition implements Serializable {
-
- private String filePath;
-
- private Integer lineNo;
-
- public CommentPosition() {
-
- }
-
- public CommentPosition(String filePath, Integer lineNo) {
- this.filePath = filePath;
- this.lineNo = lineNo;
- }
-
- public String getFilePath() {
- return filePath;
- }
-
- public void setFilePath(String filePath) {
- this.filePath = filePath;
- }
-
- @Nullable
- public Integer getLineNo() {
- return lineNo;
- }
-
- public void setLineNo(Integer lineNo) {
- this.lineNo = lineNo;
- }
-
- @Override
- public boolean equals(Object other) {
- if (!(other instanceof CommentPosition))
- return false;
- if (this == other)
- return true;
- CommentPosition otherPosition = (CommentPosition) other;
- return new EqualsBuilder()
- .append(filePath, otherPosition.getFilePath())
- .append(lineNo, otherPosition.getLineNo())
- .isEquals();
- }
-
- @Override
- public int hashCode() {
- return new HashCodeBuilder(17, 37)
- .append(filePath)
- .append(lineNo)
- .toHashCode();
- }
-
- @Override
- public String toString() {
- return Objects.toStringHelper(CommentPosition.class)
- .add("filePath", filePath)
- .add("lineNo", lineNo)
- .toString();
- }
-}
\ No newline at end of file
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.java
deleted file mode 100644
index 7df85834a4..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitComment.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package com.pmease.gitplex.core.model;
-
-import java.util.Date;
-
-import javax.annotation.Nullable;
-import javax.persistence.Column;
-import javax.persistence.Embedded;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-
-import com.google.common.base.Objects;
-import com.pmease.commons.hibernate.AbstractEntity;
-
-@SuppressWarnings("serial")
-@Entity
-public class CommitComment extends AbstractEntity {
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private Repository repository;
-
- @Column(nullable=false)
- private String commit;
-
- @Column(nullable=false)
- private Date commitDate;
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private User user;
-
- @Column(nullable=false)
- private Date commentDate = new Date();
-
- @Column(nullable=false)
- private String content;
-
- @Embedded
- private CommentPosition position;
-
- public Repository getRepository() {
- return repository;
- }
-
- public void setRepository(Repository repository) {
- this.repository = repository;
- }
-
- public User getUser() {
- return user;
- }
-
- public void setUser(User user) {
- this.user = user;
- }
-
- public String getContent() {
- return content;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- public Date getCommitDate() {
- return commitDate;
- }
-
- public void setCommitDate(Date commitDate) {
- this.commitDate = commitDate;
- }
-
- public Date getCommentDate() {
- return commentDate;
- }
-
- public void setCommentDate(Date commentDate) {
- this.commentDate = commentDate;
- }
-
- public String getCommit() {
- return commit;
- }
-
- public void setCommit(String commit) {
- this.commit = commit;
- }
-
- @Nullable
- public CommentPosition getPosition() {
- return position;
- }
-
- public void setPosition(@Nullable CommentPosition position) {
- this.position = position;
- }
-
- @Override
- public String toString() {
- return Objects.toStringHelper(CommitComment.class)
- .add("commit", commit)
- .add("position", position)
- .add("content", content)
- .toString();
- }
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitWatch.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitWatch.java
deleted file mode 100644
index ad46c79062..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/CommitWatch.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.pmease.gitplex.core.model;
-
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
-import javax.persistence.Table;
-import javax.persistence.UniqueConstraint;
-
-import com.pmease.commons.hibernate.AbstractEntity;
-
-@SuppressWarnings("serial")
-@Entity
-@Table(uniqueConstraints={
- @UniqueConstraint(columnNames={"branch", "user"})
-})
-public class CommitWatch extends AbstractEntity {
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private Branch branch;
-
- public Branch getBranch() {
- return branch;
- }
-
- public void setBranch(Branch branch) {
- this.branch = branch;
- }
-
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private User user;
-
- public User getUser() {
- return user;
- }
-
- public void setUser(User user) {
- this.user = user;
- }
-}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java
deleted file mode 100644
index a2ab57b988..0000000000
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/InlineInfo.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.pmease.gitplex.core.model;
-
-import java.io.Serializable;
-
-import javax.persistence.Embeddable;
-import javax.persistence.Lob;
-
-import com.pmease.gitplex.core.comment.InlineContext;
-
-@SuppressWarnings("serial")
-@Embeddable
-public class InlineInfo implements Serializable {
-
- private String commitHash;
-
- private String file;
-
- private Integer line;
-
- @Lob
- private InlineContext context;
-
- private String oldCommitHash;
-
- private String newCommitHash;
-
- public String getCommitHash() {
- return commitHash;
- }
-
- public void setCommitHash(String commitHash) {
- this.commitHash = commitHash;
- }
-
- public String getFile() {
- return file;
- }
-
- public void setFile(String file) {
- this.file = file;
- }
-
- public Integer getLine() {
- return line;
- }
-
- public void setLine(Integer line) {
- this.line = line;
- }
-
- public InlineContext getContext() {
- return context;
- }
-
- public void setContext(InlineContext context) {
- this.context = context;
- }
-
- public String getOldCommitHash() {
- return oldCommitHash;
- }
-
- public void setOldCommitHash(String oldCommitHash) {
- this.oldCommitHash = oldCommitHash;
- }
-
- public String getNewCommitHash() {
- return newCommitHash;
- }
-
- public void setNewCommitHash(String newCommitHash) {
- this.newCommitHash = newCommitHash;
- }
-
-}
\ No newline at end of file
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
index a3172f88b9..e2a20e20ab 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequest.java
@@ -144,6 +144,9 @@ public class PullRequest extends AbstractEntity {
@OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)
private Collection<PullRequestComment> comments = new ArrayList<>();
+ @OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)
+ private Collection<PullRequestInlineComment> inlineComments = new ArrayList<>();
+
@OneToMany(mappedBy = "request", cascade = CascadeType.REMOVE)
private Collection<PullRequestAudit> audits = new ArrayList<>();
@@ -296,6 +299,12 @@ public class PullRequest extends AbstractEntity {
this.verifications = verifications;
}
+ /**
+ * Get all non-inline comments of the pull request.
+ *
+ * @return
+ * all non-inline comments
+ */
public Collection<PullRequestComment> getComments() {
return comments;
}
@@ -304,6 +313,15 @@ public class PullRequest extends AbstractEntity {
this.comments = comments;
}
+ public Collection<PullRequestInlineComment> getInlineComments() {
+ return inlineComments;
+ }
+
+ public void setInlineComments(
+ Collection<PullRequestInlineComment> inlineComments) {
+ this.inlineComments = inlineComments;
+ }
+
public Collection<PullRequestAudit> getAudits() {
return audits;
}
@@ -587,7 +605,7 @@ public class PullRequest extends AbstractEntity {
return pendingCommits;
}
- public ChangeComments getComments(RevAwareChange change) {
+ public ChangeComments getChangeComments(RevAwareChange change) {
ChangeKey key = new ChangeKey(change.getOldRevision(), change.getNewRevision(), change.getPath());
ChangeComments comments = commentsCache.get(key);
if (comments == null) {
@@ -596,7 +614,15 @@ public class PullRequest extends AbstractEntity {
}
return comments;
}
-
+
+ public List<String> getCommentables() {
+ List<String> commentables = new ArrayList<>();
+ commentables.add(getBaseCommitHash());
+ for (PullRequestUpdate update: getSortedUpdates())
+ commentables.add(update.getHeadCommitHash());
+ return commentables;
+ }
+
/**
* Merged commits represent commits already merged to target branch since base commit.
*
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
index 4e2dfd1326..5f2fcc499c 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestComment.java
@@ -4,94 +4,23 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
-import javax.annotation.Nullable;
import javax.persistence.CascadeType;
-import javax.persistence.Column;
import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
-import javax.persistence.Table;
-import javax.persistence.UniqueConstraint;
import com.google.common.base.Preconditions;
-import com.pmease.commons.hibernate.AbstractEntity;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.CommentReply;
-import com.pmease.gitplex.core.comment.InlineComment;
-import com.pmease.gitplex.core.comment.InlineContext;
import com.pmease.gitplex.core.manager.UserManager;
@SuppressWarnings("serial")
@Entity
-@Table(uniqueConstraints={
- @UniqueConstraint(columnNames={"commitHash", "file", "line"})
-})
-public class PullRequestComment extends AbstractEntity implements InlineComment {
+public class PullRequestComment extends AbstractPullRequestComment {
- @ManyToOne
- @JoinColumn(nullable=false)
- private PullRequest request;
-
- @ManyToOne(fetch=FetchType.LAZY)
- private User user;
-
- @Column(nullable=false)
- private String content;
-
- @Column(nullable=false)
- private Date date = new Date();
-
- private InlineInfo inlineInfo;
-
- private boolean resolved;
-
@OneToMany(mappedBy="comment", cascade=CascadeType.REMOVE)
private Collection<PullRequestCommentReply> replies = new ArrayList<>();
-
- public PullRequest getRequest() {
- return request;
- }
-
- public void setRequest(PullRequest request) {
- this.request = request;
- }
-
- @Nullable
- public User getUser() {
- return user;
- }
-
- public void setUser(@Nullable User user) {
- this.user = user;
- }
-
- public String getContent() {
- return content;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- public Date getDate() {
- return date;
- }
-
- public void setDate(Date date) {
- this.date = date;
- }
-
- public InlineInfo getInlineInfo() {
- return inlineInfo;
- }
-
- public void setInlineInfo(InlineInfo inlineInfo) {
- this.inlineInfo = inlineInfo;
- }
-
+
@Override
public Collection<PullRequestCommentReply> getReplies() {
return replies;
@@ -101,22 +30,6 @@ public class PullRequestComment extends AbstractEntity implements InlineComment
this.replies = replies;
}
- @Override
- public void saveContent(String content) {
- setContent(content);
- GitPlex.getInstance(Dao.class).persist(this);
- }
-
- @Override
- public Repository getRepository() {
- return request.getTarget().getRepository();
- }
-
- @Override
- public void delete() {
- GitPlex.getInstance(Dao.class).remove(this);
- }
-
@Override
public CommentReply addReply(String content) {
User user = GitPlex.getInstance(UserManager.class).getCurrent();
@@ -130,49 +43,4 @@ public class PullRequestComment extends AbstractEntity implements InlineComment
return reply;
}
- @Override
- public int getLine() {
- return Preconditions.checkNotNull(inlineInfo).getLine();
- }
-
- @Override
- public String getCommitHash() {
- return Preconditions.checkNotNull(inlineInfo).getCommitHash();
- }
-
- @Override
- public String getOldCommitHash() {
- return Preconditions.checkNotNull(inlineInfo).getOldCommitHash();
- }
-
- @Override
- public String getNewCommitHash() {
- return Preconditions.checkNotNull(inlineInfo).getNewCommitHash();
- }
-
- @Override
- public String getFile() {
- return Preconditions.checkNotNull(inlineInfo).getFile();
- }
-
- @Override
- public InlineContext getContext() {
- return Preconditions.checkNotNull(inlineInfo).getContext();
- }
-
- @Override
- public boolean isResolved() {
- return resolved;
- }
-
- public void setResolved(boolean resolved) {
- this.resolved = resolved;
- }
-
- @Override
- public void resolve(boolean resolved) {
- setResolved(resolved);
- GitPlex.getInstance(Dao.class).persist(this);
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.java
index d19505888a..3cfd757c55 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestCommentReply.java
@@ -1,33 +1,17 @@
package com.pmease.gitplex.core.model;
-import java.util.Date;
-
import javax.persistence.Entity;
-import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
-import com.pmease.commons.hibernate.AbstractEntity;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.comment.CommentReply;
-
@SuppressWarnings("serial")
@Entity
-public class PullRequestCommentReply extends AbstractEntity implements CommentReply {
+public class PullRequestCommentReply extends AbstractPullRequestCommentReply {
@ManyToOne
@JoinColumn(nullable=false)
private PullRequestComment comment;
- @ManyToOne(fetch=FetchType.LAZY)
- @JoinColumn(nullable=false)
- private User user;
-
- private Date date;
-
- private String content;
-
@Override
public PullRequestComment getComment() {
return comment;
@@ -37,39 +21,4 @@ public class PullRequestCommentReply extends AbstractEntity implements CommentRe
this.comment = comment;
}
- public User getUser() {
- return user;
- }
-
- public void setUser(User user) {
- this.user = user;
- }
-
- public Date getDate() {
- return date;
- }
-
- public void setDate(Date date) {
- this.date = date;
- }
-
- public String getContent() {
- return content;
- }
-
- public void setContent(String content) {
- this.content = content;
- }
-
- @Override
- public void saveContent(String content) {
- setContent(content);
- GitPlex.getInstance(Dao.class).persist(this);
- }
-
- @Override
- public void delete() {
- GitPlex.getInstance(Dao.class).remove(this);
- }
-
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineComment.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineComment.java
new file mode 100644
index 0000000000..4b50dcf40e
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineComment.java
@@ -0,0 +1,146 @@
+package com.pmease.gitplex.core.model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import javax.annotation.Nullable;
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Lob;
+import javax.persistence.OneToMany;
+
+import com.google.common.base.Preconditions;
+import com.pmease.commons.git.BlobInfo;
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.util.Pair;
+import com.pmease.commons.util.diff.AroundContext;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.comment.CommentReply;
+import com.pmease.gitplex.core.comment.InlineComment;
+import com.pmease.gitplex.core.manager.UserManager;
+
+@Entity
+@SuppressWarnings("serial")
+public class PullRequestInlineComment extends AbstractPullRequestComment implements InlineComment {
+
+ @OneToMany(mappedBy="comment", cascade=CascadeType.REMOVE)
+ private Collection<PullRequestInlineCommentReply> replies = new ArrayList<>();
+
+ @Embedded
+ @AttributeOverrides({
+ @AttributeOverride(name="revision", column=@Column(name="G_BLOB_REV", nullable=false)),
+ @AttributeOverride(name="path", column=@Column(name="G_BLOB_PATH", nullable=false)),
+ @AttributeOverride(name="mode", column=@Column(name="G_BLOB_MODE", nullable=false))
+ })
+ private BlobInfo blobInfo;
+
+ @Embedded
+ @AttributeOverrides({
+ @AttributeOverride(name="revision", column=@Column(name="G_COMPARE_REV", nullable=false) ),
+ @AttributeOverride(name="path", column=@Column(name="G_COMPARE_PATH")),
+ @AttributeOverride(name="mode", column=@Column(name="G_COMPARE_MODE", nullable=false))
+ })
+ private BlobInfo compareWith;
+
+ @Column(nullable=false)
+ private int line;
+
+ @Lob
+ private AroundContext context;
+
+ private transient Pair<String, String> oldCommitAndNewCommit;
+
+ @Override
+ public int getLine() {
+ return line;
+ }
+
+ public void setLine(int line) {
+ this.line = line;
+ }
+
+ /**
+ * Inline context to be displayed in pull request activities page.
+ *
+ * @return
+ * null if inline context can not be extracted due to one side
+ * of the diff is a binary file
+ */
+ @Nullable
+ @Override
+ public AroundContext getContext() {
+ return context;
+ }
+
+ public void setContext(@Nullable AroundContext context) {
+ this.context = context;
+ }
+
+ public BlobInfo getCompareWith() {
+ return compareWith;
+ }
+
+ public void setCompareWith(BlobInfo compareWith) {
+ this.compareWith = compareWith;
+ }
+
+ private Pair<String, String> getOldCommitAndNewCommit() {
+ if (oldCommitAndNewCommit == null) {
+ List<String> commitHashes = getRequest().getCommentables();
+ int index = commitHashes.indexOf(getBlobInfo().getRevision());
+ int compareIndex = commitHashes.indexOf(getCompareWith().getRevision());
+ Preconditions.checkState(index != -1 && compareIndex != -1);
+ if (index <= compareIndex)
+ oldCommitAndNewCommit = new Pair<>(getBlobInfo().getRevision(), getCompareWith().getRevision());
+ else
+ oldCommitAndNewCommit = new Pair<>(getCompareWith().getRevision(), getBlobInfo().getRevision());
+ }
+ return oldCommitAndNewCommit;
+ }
+
+ public String getOldCommitHash() {
+ return getOldCommitAndNewCommit().getFirst();
+ }
+
+ public String getNewCommitHash() {
+ return getOldCommitAndNewCommit().getSecond();
+ }
+
+ @Override
+ public BlobInfo getBlobInfo() {
+ return blobInfo;
+ }
+
+ public void setBlobInfo(BlobInfo blobInfo) {
+ this.blobInfo = blobInfo;
+ }
+
+ @Override
+ public Collection<PullRequestInlineCommentReply> getReplies() {
+ return replies;
+ }
+
+ public void setReplies(Collection<PullRequestInlineCommentReply> replies) {
+ this.replies = replies;
+ }
+
+ @Override
+ public CommentReply addReply(String content) {
+ User user = GitPlex.getInstance(UserManager.class).getCurrent();
+ Preconditions.checkNotNull(user);
+ PullRequestInlineCommentReply reply = new PullRequestInlineCommentReply();
+ reply.setUser(user);
+ reply.setDate(new Date());
+ reply.setContent(content);
+ reply.setComment(this);
+ GitPlex.getInstance(Dao.class).persist(reply);
+ return reply;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineCommentReply.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineCommentReply.java
new file mode 100644
index 0000000000..342c824bd6
--- /dev/null
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestInlineCommentReply.java
@@ -0,0 +1,24 @@
+package com.pmease.gitplex.core.model;
+
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+
+@SuppressWarnings("serial")
+@Entity
+public class PullRequestInlineCommentReply extends AbstractPullRequestCommentReply {
+
+ @ManyToOne
+ @JoinColumn(nullable=false)
+ private PullRequestInlineComment comment;
+
+ @Override
+ public PullRequestInlineComment getComment() {
+ return comment;
+ }
+
+ public void setComment(PullRequestInlineComment comment) {
+ this.comment = comment;
+ }
+
+}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestTask.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestTask.java
index fab1757e43..6c43bef830 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestTask.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/PullRequestTask.java
@@ -1,5 +1,6 @@
package com.pmease.gitplex.core.model;
+import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
@@ -26,6 +27,7 @@ public class PullRequestTask extends AbstractEntity {
@JoinColumn(nullable=false)
private User user;
+ @Column(nullable=false)
private TaskType taskType;
public PullRequest getRequest() {
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java
index 16a37ec8b3..cc9bd6f5e8 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/Repository.java
@@ -90,9 +90,6 @@ public class Repository extends AbstractEntity implements UserBelonging {
@OneToMany(mappedBy="repository", cascade=CascadeType.REMOVE)
private Collection<Authorization> authorizations = new ArrayList<>();
- @OneToMany(mappedBy="repository", cascade=CascadeType.REMOVE)
- private Collection<CommitComment> commitComments = new ArrayList<>();
-
@OneToMany(mappedBy="repository", cascade=CascadeType.REMOVE)
private Collection<Branch> branches = new ArrayList<>();
@@ -190,14 +187,6 @@ public class Repository extends AbstractEntity implements UserBelonging {
this.authorizations = authorizations;
}
- public Collection<CommitComment> getCommitComments() {
- return commitComments;
- }
-
- public void setCommitComments(Collection<CommitComment> commitComments) {
- this.commitComments = commitComments;
- }
-
public Repository getForkedFrom() {
return forkedFrom;
}
diff --git a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java
index 2fcb41b0d7..2933539416 100644
--- a/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java
+++ b/gitplex.core/src/main/java/com/pmease/gitplex/core/model/User.java
@@ -43,9 +43,6 @@ public class User extends AbstractUser implements ProtectedObject {
private Date avatarUpdateDate;
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<CommitComment> commitComments = new ArrayList<>();
-
@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
private Collection<Membership> memberships = new ArrayList<>();
@@ -70,9 +67,6 @@ public class User extends AbstractUser implements ProtectedObject {
@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
private Collection<PullRequestCommentReply> requestCommentReplies = new ArrayList<>();
- @OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
- private Collection<CommitWatch> commitWatches = new ArrayList<>();
-
@OneToMany(mappedBy="user", cascade=CascadeType.REMOVE)
private Collection<PullRequestWatch> requestWatches = new ArrayList<>();
@@ -134,14 +128,6 @@ public class User extends AbstractUser implements ProtectedObject {
this.avatarUpdateDate = avatarUpdateDate;
}
- public Collection<CommitComment> getCommitComments() {
- return commitComments;
- }
-
- public void setCommitComments(Collection<CommitComment> commitComments) {
- this.commitComments = commitComments;
- }
-
public Collection<Membership> getMemberships() {
return memberships;
}
@@ -213,14 +199,6 @@ public class User extends AbstractUser implements ProtectedObject {
this.requestCommentReplies = requestCommentReplies;
}
- public Collection<CommitWatch> getCommitWatches() {
- return commitWatches;
- }
-
- public void setCommitWatches(Collection<CommitWatch> commitWatches) {
- this.commitWatches = commitWatches;
- }
-
public Collection<PullRequestWatch> getRequestWatches() {
return requestWatches;
}
diff --git a/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/ChangeCommentsTest.java b/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/ChangeCommentsTest.java
deleted file mode 100644
index 57f50ed6f0..0000000000
--- a/gitplex.core/src/test/java/com/pmease/gitplex/core/comment/ChangeCommentsTest.java
+++ /dev/null
@@ -1,228 +0,0 @@
-package com.pmease.gitplex.core.comment;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-
-import com.pmease.commons.git.AbstractGitTest;
-import com.pmease.commons.git.BlobInfo;
-import com.pmease.commons.git.BlobText;
-import com.pmease.commons.git.Change;
-import com.pmease.commons.git.Commit;
-import com.pmease.commons.git.RevAwareChange;
-import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.InlineInfo;
-import com.pmease.gitplex.core.model.PullRequest;
-import com.pmease.gitplex.core.model.PullRequestComment;
-import com.pmease.gitplex.core.model.PullRequestUpdate;
-import com.pmease.gitplex.core.model.Repository;
-
-public class ChangeCommentsTest extends AbstractGitTest {
-
- @SuppressWarnings("serial")
- @Test
- public void test() {
- final List<String> fileRevs = new ArrayList<>();
- fileRevs.add(""
- + "11\n" //comment1
- + "22\n"
- + "33\n"
- + "44\n"
- + "55\n" //comment3, comment6
- + "66\n"
- + "77\n"
- + "88\n" //comment4
- + "99\n");
- fileRevs.add(""
- + "111\n"
- + "222\n"
- + "33\n"
- + "44\n"
- + "55\n"
- + "66\n"
- + "77\n"
- + "88\n"
- + "99\n");
- fileRevs.add(""
- + "111\n"
- + "222\n"
- + "33\n"
- + "44\n"
- + "55\n"
- + "66\n"
- + "77\n"
- + "888\n"
- + "999\n");
- fileRevs.add(""
- + "111\n"
- + "222\n" //comment2
- + "33\n"
- + "44\n" //comment5
- + "555\n"
- + "66\n"
- + "77\n"
- + "8888\n"
- + "999\n"); //comment8, comment9
-
- addFileAndCommit("file1", fileRevs.get(0), "add file1");
-
- addFileAndCommit("file1", fileRevs.get(1), "modify file1");
-
- addFileAndCommit("file1", fileRevs.get(2), "modify file1");
-
- addFileAndCommit("file1", fileRevs.get(3), "modify file1");
-
- final List<Commit> commits = new ArrayList<>();
- commits.add(git.showRevision("master~3"));
- commits.add(git.showRevision("master~2"));
- commits.add(git.showRevision("master~1"));
- commits.add(git.showRevision("master"));
-
- RevAwareChange change = new RevAwareChange(Change.Status.MODIFIED, "file1", "file1",
- 0, 0, commits.get(0).getHash(), commits.get(3).getHash());
-
-
- PullRequest request = new PullRequest();
- request.setTarget(new Branch());
- request.getTarget().setRepository(new Repository() {
-
- @Override
- public BlobText getBlobText(BlobInfo blobInfo) {
- List<String> commitHashes = new ArrayList<>();
- for (Commit each: commits)
- commitHashes.add(each.getHash());
-
- int index = commitHashes.indexOf(blobInfo.getRevision());
- String content = fileRevs.get(index);
- try {
- return new BlobText(IOUtils.readLines(new ByteArrayInputStream(content.getBytes())));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- });
- Collection<PullRequestComment> comments = new ArrayList<>();
- PullRequestComment comment = new PullRequestComment();
- comment.setId(1L);
- comment.setInlineInfo(new InlineInfo());
- comment.getInlineInfo().setCommitHash(commits.get(0).getHash());
- comment.getInlineInfo().setFile("file1");
- comment.getInlineInfo().setLine(0);
- comment.setContent("comment1");
- comments.add(comment);
-
- comment = new PullRequestComment();
- comment.setId(2L);
- comment.setInlineInfo(new InlineInfo());
- comment.getInlineInfo().setCommitHash(commits.get(1).getHash());
- comment.getInlineInfo().setFile("file1");
- comment.getInlineInfo().setLine(1);
- comment.setContent("comment2");
- comments.add(comment);
-
- comment = new PullRequestComment();
- comment.setId(3L);
- comment.setInlineInfo(new InlineInfo());
- comment.getInlineInfo().setCommitHash(commits.get(1).getHash());
- comment.getInlineInfo().setFile("file1");
- comment.getInlineInfo().setLine(4);
- comment.setContent("comment3");
- comments.add(comment);
-
- comment = new PullRequestComment();
- comment.setId(4L);
- comment.setInlineInfo(new InlineInfo());
- comment.getInlineInfo().setCommitHash(commits.get(1).getHash());
- comment.getInlineInfo().setFile("file1");
- comment.getInlineInfo().setLine(7);
- comment.setContent("comment4");
- comments.add(comment);
-
- comment = new PullRequestComment();
- comment.setId(5L);
- comment.setInlineInfo(new InlineInfo());
- comment.getInlineInfo().setCommitHash(commits.get(2).getHash());
- comment.getInlineInfo().setFile("file1");
- comment.getInlineInfo().setLine(3);
- comment.setContent("comment5");
- comments.add(comment);
-
- comment = new PullRequestComment();
- comment.setId(6L);
- comment.setInlineInfo(new InlineInfo());
- comment.getInlineInfo().setCommitHash(commits.get(2).getHash());
- comment.getInlineInfo().setFile("file1");
- comment.getInlineInfo().setLine(4);
- comment.setContent("comment6");
- comments.add(comment);
-
- comment = new PullRequestComment();
- comment.setId(7L);
- comment.setInlineInfo(new InlineInfo());
- comment.getInlineInfo().setCommitHash(commits.get(2).getHash());
- comment.getInlineInfo().setFile("file1");
- comment.getInlineInfo().setLine(7);
- comment.setContent("comment7");
- comments.add(comment);
-
- comment = new PullRequestComment();
- comment.setId(8L);
- comment.setInlineInfo(new InlineInfo());
- comment.getInlineInfo().setCommitHash(commits.get(2).getHash());
- comment.getInlineInfo().setFile("file1");
- comment.getInlineInfo().setLine(8);
- comment.setContent("comment8");
- comments.add(comment);
-
- comment = new PullRequestComment();
- comment.setId(9L);
- comment.setInlineInfo(new InlineInfo());
- comment.getInlineInfo().setCommitHash(commits.get(3).getHash());
- comment.getInlineInfo().setFile("file1");
- comment.getInlineInfo().setLine(8);
- comment.setContent("comment9");
- comments.add(comment);
-
- request.setComments(comments);
-
- request.setBaseCommitHash(commits.get(0).getHash());
- Collection<PullRequestUpdate> updates = new ArrayList<>();
-
- PullRequestUpdate update = new PullRequestUpdate();
- update.setId(1L);
- update.setHeadCommitHash(commits.get(1).getHash());
- updates.add(update);
-
- update = new PullRequestUpdate();
- update.setId(2L);
- update.setHeadCommitHash(commits.get(2).getHash());
- updates.add(update);
-
- update = new PullRequestUpdate();
- update.setId(3L);
- update.setHeadCommitHash(commits.get(3).getHash());
- updates.add(update);
-
- request.setUpdates(updates);
-
- ChangeComments changeComments = new ChangeComments(request, change);
-
- assertEquals("comment1", changeComments.getOldComments().get(0).get(0).getContent());
- assertEquals("comment2", changeComments.getNewComments().get(1).get(0).getContent());
- assertEquals("comment3", changeComments.getOldComments().get(4).get(0).getContent());
- assertEquals("comment4", changeComments.getOldComments().get(7).get(0).getContent());
- assertEquals("comment5", changeComments.getNewComments().get(3).get(0).getContent());
- assertEquals("comment6", changeComments.getOldComments().get(4).get(1).getContent());
- assertEquals("comment8", changeComments.getNewComments().get(8).get(0).getContent());
- assertEquals("comment9", changeComments.getNewComments().get(8).get(1).getContent());
- }
-
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
index 1fa9943cbd..6f79393c7f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/assets/css/page.css
@@ -908,8 +908,6 @@ ul.status-help li:last-child .description {border-bottom: none;}
.request-detail>.activities .activity>.commits {color: #777; margin-left: -31px;}
.request-detail>.activities .activity>.commits a {color: #555;}
.request-detail>.activities .activity>.commits td {padding-top: 4px; padding-bottom: 4px;}
-.request-detail>.activities .activity>.commits td.detail,
-.request-detail>.activities .activity>.commits td.status {border-top: 1px dotted #CCC;}
.request-detail>.activities .non-update+.update>td tr:first-child td {border-top: none;}
.request-detail>.activities .activity>.commits td.icon {width: 32px; white-space: nowrap; text-align: right;}
.request-detail>.activities .activity>.commits tr.integrated td.icon .fa {color: #35A612;}
@@ -929,6 +927,7 @@ ul.status-help li:last-child .description {border-bottom: none;}
.request-detail>.activities .inline-comment.panel>.panel-heading {padding: 8px;}
.request-detail>.activities .inline-comment.panel>.panel-heading .actions {margin-left: 12px;}
.request-detail>.activities .inline-comment.panel>.panel-heading .actions a {color: #888; margin-right: 4px;}
+.request-detail>.activities .inline-comment.panel {margin-bottom: 4px;}
.request-detail>.activities .activity>.summary .fa {background: white;}
.request-detail>.activities .activity>.update>.fa {margin: 0 8px 0 -15px; font-size: 20px;}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java
index b3b87dfbfc..1366845b0f 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/CommentPanel.java
@@ -30,7 +30,6 @@ import com.pmease.gitplex.core.comment.CommentReply;
import com.pmease.gitplex.core.manager.AuthorizationManager;
import com.pmease.gitplex.web.component.comment.event.CommentCollapsing;
import com.pmease.gitplex.web.component.comment.event.CommentRemoved;
-import com.pmease.gitplex.web.component.comment.event.CommentReplied;
import com.pmease.gitplex.web.component.label.AgeLabel;
import com.pmease.gitplex.web.component.user.AvatarMode;
import com.pmease.gitplex.web.component.user.UserLink;
@@ -252,9 +251,7 @@ public class CommentPanel extends Panel {
CommentPanel.this.replace(row);
target.add(row);
- CommentReply newReply = getComment().addReply(input.getModelObject());
- send(CommentPanel.this, Broadcast.BUBBLE, new CommentReplied(target, newReply));
-
+ getComment().addReply(input.getModelObject());
Component newReplyRow = newReplyRow(repliesView.newChildId(), repliesModel.getObject().size()-1);
repliesView.add(newReplyRow);
String script = String.format("$(\"<tr id='%s' class='reply'></tr>\").insertBefore('#%s');",
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/event/CommentReplied.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/event/CommentReplied.java
deleted file mode 100644
index a95e9fdb07..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/comment/event/CommentReplied.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.pmease.gitplex.web.component.comment.event;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-
-import com.pmease.gitplex.core.comment.CommentReply;
-import com.pmease.gitplex.web.common.wicket.event.AjaxEvent;
-
-public class CommentReplied extends AjaxEvent {
-
- private final CommentReply reply;
-
- public CommentReplied(AjaxRequestTarget target, CommentReply reply) {
- super(target);
-
- this.reply = reply;
- }
-
- public CommentReply getReply() {
- return reply;
- }
-
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java
index 0ddaf4fda9..9e39e4b633 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/BlobDiffPanel.java
@@ -1,29 +1,22 @@
package com.pmease.gitplex.web.component.diff;
import org.apache.tika.mime.MediaType;
-import org.apache.wicket.Component;
import org.apache.wicket.markup.html.panel.Fragment;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
-import org.apache.wicket.util.visit.IVisit;
-import org.apache.wicket.util.visit.IVisitor;
import org.eclipse.jgit.lib.FileMode;
-import com.google.common.base.Preconditions;
import com.pmease.commons.git.BlobText;
import com.pmease.commons.git.RevAwareChange;
import com.pmease.commons.util.MediaTypes;
import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
-import com.pmease.gitplex.core.comment.InlineContext;
-import com.pmease.gitplex.core.comment.InlineContextAware;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.web.extensionpoint.DiffRenderer;
import com.pmease.gitplex.web.extensionpoint.DiffRendererProvider;
@SuppressWarnings("serial")
-public class BlobDiffPanel extends Panel implements InlineContextAware {
+public class BlobDiffPanel extends Panel {
private final IModel<Repository> repoModel;
@@ -121,20 +114,6 @@ public class BlobDiffPanel extends Panel implements InlineContextAware {
}
- @Override
- public InlineContext getInlineContext(final InlineComment comment) {
- InlineContext context = visitChildren(InlineContextAware.class, new IVisitor<Component, InlineContext>() {
-
- @Override
- public void component(Component object, IVisit<InlineContext> visit) {
- InlineContextAware inlineContextAware = (InlineContextAware) object;
- visit.stop(inlineContextAware.getInlineContext(comment));
- }
-
- });
- return Preconditions.checkNotNull(context);
- }
-
protected void onDetach() {
repoModel.detach();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.java
index e37ffba2ee..a1f4cb4592 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/CompareResultPanel.java
@@ -12,25 +12,19 @@ import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
-import org.apache.wicket.util.visit.IVisit;
-import org.apache.wicket.util.visit.IVisitor;
import org.eclipse.jgit.lib.FileMode;
import com.pmease.commons.git.Change;
import com.pmease.commons.git.RevAwareChange;
import com.pmease.commons.git.TreeNode;
import com.pmease.commons.wicket.behavior.StickyBehavior;
-import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
-import com.pmease.gitplex.core.comment.InlineContext;
-import com.pmease.gitplex.core.comment.InlineContextAware;
import com.pmease.gitplex.core.model.Repository;
@SuppressWarnings("serial")
-public abstract class CompareResultPanel extends Panel implements InlineContextAware {
+public abstract class CompareResultPanel extends Panel {
private final IModel<Repository> repoModel;
@@ -55,7 +49,7 @@ public abstract class CompareResultPanel extends Panel implements InlineContextA
List<Change> changes = repoModel.getObject().getChanges(oldCommit, newCommit);
if (file != null) {
for (Change each: repoModel.getObject().getChanges(oldCommit, newCommit)) {
- if (each.getPath().equals(file)) {
+ if (file.equals(each.getOldPath()) || file.equals(each.getNewPath())) {
activeChange = each;
break;
}
@@ -83,8 +77,7 @@ public abstract class CompareResultPanel extends Panel implements InlineContextA
new RevAwareChange(activeChange, oldCommitHash, newCommitHash),
getInlineCommentSupport(activeChange));
} else {
- changeContent = new Label("content", "<div class='error fa fa-alert-o'> File not exist.</div>");
- changeContent.setEscapeModelStrings(false);
+ changeContent = new WebMarkupContainer("content");
}
changeContent.setOutputMarkupId(true);
add(changeContent);
@@ -180,17 +173,4 @@ public abstract class CompareResultPanel extends Panel implements InlineContextA
target.add(changeNav);
}
- @Override
- public InlineContext getInlineContext(final InlineComment comment) {
- return visitChildren(InlineContextAware.class, new IVisitor<Component, InlineContext>() {
-
- @Override
- public void component(Component object, IVisit<InlineContext> visit) {
- InlineContextAware inlineContextAware = (InlineContextAware) object;
- visit.stop(inlineContextAware.getInlineContext(comment));
- }
-
- });
- }
-
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html
index 01f43a7294..675321c2a9 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.html
@@ -47,7 +47,6 @@
<tr wicket:id="comments">
<td class="avatar">
<div wicket:id="avatar"></div>
- <div class="fa fa-flag" title="Concerned comment"></div>
</td>
<td class="comment">
<div wicket:id="comment"></div>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java
index 193ac9c0ae..1bfd990fc7 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/component/diff/TextDiffPanel.java
@@ -43,12 +43,14 @@ import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.util.string.Strings;
import com.google.common.base.Preconditions;
+import com.pmease.commons.git.BlobInfo;
import com.pmease.commons.git.BlobText;
import com.pmease.commons.git.RevAwareChange;
+import com.pmease.commons.util.diff.AroundContext;
import com.pmease.commons.util.diff.DiffHunk;
import com.pmease.commons.util.diff.DiffLine;
import com.pmease.commons.util.diff.DiffUtils;
-import com.pmease.commons.util.diff.Partial;
+import com.pmease.commons.util.diff.Token;
import com.pmease.commons.util.diff.WordSplitter;
import com.pmease.commons.wicket.behavior.ScrollBehavior;
import com.pmease.commons.wicket.behavior.StickyBehavior;
@@ -61,8 +63,6 @@ import com.pmease.commons.wicket.component.markdown.MarkdownInput;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
-import com.pmease.gitplex.core.comment.InlineContext;
-import com.pmease.gitplex.core.comment.InlineContextAware;
import com.pmease.gitplex.core.manager.UserManager;
import com.pmease.gitplex.core.model.Repository;
import com.pmease.gitplex.core.model.User;
@@ -74,7 +74,7 @@ import com.pmease.gitplex.web.component.user.UserLink;
import com.pmease.gitplex.web.model.UserModel;
@SuppressWarnings("serial")
-public class TextDiffPanel extends Panel implements InlineContextAware {
+public class TextDiffPanel extends Panel {
private enum DiffOption {IGNORE_NOTHING, IGNORE_EOL, IGNORE_EOL_SPACES, IGNORE_CHANGE_SPACES};
@@ -543,18 +543,24 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
super.onSubmit(target, form);
DiffLine diff = diffs.get(index);
- String commit;
+ BlobInfo commentAt;
+ BlobInfo compareWith;
int lineNo;
+ AroundContext commentContext;
if (diff.getAction() == DELETE) {
- commit = change.getOldRevision();
+ commentAt = change.getOldBlobInfo();
+ compareWith = change.getNewBlobInfo();
lineNo = diff.getOldLineNo();
+ commentContext = DiffUtils.around(diffs, lineNo, -1, InlineComment.CONTEXT_SIZE);
} else {
- commit = change.getNewRevision();
+ commentAt = change.getNewBlobInfo();
+ compareWith = change.getOldBlobInfo();
lineNo = diff.getNewLineNo();
+ commentContext = DiffUtils.around(diffs, -1, lineNo, InlineComment.CONTEXT_SIZE);
}
- commentSupport.addComment(commit, change.getPath(), lineNo, input.getModelObject());
+ commentSupport.addComment(commentAt, compareWith, commentContext, lineNo, input.getModelObject());
Component commentsRow = newCommentsRow(commentsView.newChildId(), index);
commentsView.add(commentsRow);
@@ -709,7 +715,7 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
builder.append("-");
else
builder.append("&nbsp;");
- for (Partial partial: line.getPartials()) {
+ for (Token partial: line.getTokens()) {
if (partial.isEmphasized())
builder.append("<span class='emphasize'>");
else
@@ -909,57 +915,6 @@ public class TextDiffPanel extends Panel implements InlineContextAware {
return new BlobText();
}
- @Override
- public InlineContext getInlineContext(InlineComment comment) {
- int oldLine = -1;
- if (comment.getCommitHash().equals(change.getOldRevision())) {
- oldLine = comment.getLine();
- } else {
- for (Map.Entry<Integer, List<InlineComment>> entry: commentSupport.getOldComments().entrySet()) {
- if (entry.getValue().contains(comment)) {
- oldLine = entry.getKey();
- break;
- }
- }
- }
-
- int newLine = -1;
- if (comment.getCommitHash().equals(change.getNewRevision())) {
- newLine = comment.getLine();
- } else {
- for (Map.Entry<Integer, List<InlineComment>> entry: commentSupport.getNewComments().entrySet()) {
- if (entry.getValue().contains(comment)
- || comment.getCommitHash().equals(change.getNewRevision()) && comment.getLine() == entry.getKey()) {
- newLine = entry.getKey();
- break;
- }
- }
- }
- List<DiffLine> contextDiffs = new ArrayList<>();
- int index = -1;
- for (int i=0; i<diffs.size(); i++) {
- DiffLine diff = diffs.get(i);
- if (diff.getOldLineNo() == oldLine || diff.getNewLineNo() == newLine) {
- index = i;
- break;
- }
- }
-
- Preconditions.checkState(index != -1);
-
- int start = index - InlineComment.CONTEXT_SIZE;
- if (start < 0)
- start = 0;
- int end = index + InlineComment.CONTEXT_SIZE;
- if (end > diffs.size() - 1)
- end = diffs.size() - 1;
-
- for (int i=start; i<=end; i++)
- contextDiffs.add(diffs.get(i));
-
- return new InlineContext(contextDiffs, index-start, start>0, end<diffs.size()-1);
- }
-
private int locateDiffPos(int lineNo, DiffLine.Action excludeAction) {
int index = 0;
for (int i=0; i<diffs.size(); i++) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html
index e495c50931..53dd9cc14a 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.html
@@ -1,5 +1,6 @@
<wicket:extend>
- <form wicket:id="form">
- <input wicket:id="repository" type="hidden"></input>
- </form>
+ <div class="notice" style="display:none;">Notice</div>
+ <script type="text/javascript">
+ $(".notice").highlight();
+ </script>
</wicket:extend>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
index 0ddcb4f0b7..c2faf6eb4d 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/TestPage.java
@@ -1,19 +1,10 @@
package com.pmease.gitplex.web.page;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.model.IModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
-import com.pmease.commons.hibernate.dao.Dao;
-import com.pmease.gitplex.core.GitPlex;
-import com.pmease.gitplex.core.model.Repository;
-import com.pmease.gitplex.web.component.repository.RepositoryChoice;
-
@SuppressWarnings("serial")
public class TestPage extends BasePage {
- private Long repoId;
-
public TestPage(PageParameters params) {
super(params);
}
@@ -21,30 +12,6 @@ public class TestPage extends BasePage {
@Override
protected void onInitialize() {
super.onInitialize();
-
- Form<?> form = new Form<Void>("form");
- form.add(new RepositoryChoice("repository", new IModel<Repository>() {
-
- @Override
- public void detach() {
- }
-
- @Override
- public Repository getObject() {
- if (repoId != null)
- return GitPlex.getInstance(Dao.class).load(Repository.class, repoId);
- else
- return null;
- }
-
- @Override
- public void setObject(Repository object) {
- repoId = object.getId();
- }
-
- }, null));
-
- add(form);
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/BranchesPage.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/BranchesPage.html
index b4d94807f9..2c96235c82 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/BranchesPage.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/BranchesPage.html
@@ -47,10 +47,8 @@
</td>
<td wicket:id="watch" class="watch">
<div class="btn-group">
- <button wicket:id="unwatchCommits" class="btn btn-default" title="You are watching commits of this branch, click to unwatch"><i class="fa fa-eye-open"></i> <i class="fa fa-commit"></i> </button>
- <button wicket:id="watchCommits" class="btn btn-default" title="You are not watching commits of this branch, click to watch"><i class="fa fa-eye-slash"></i> <i class="fa fa-commit"></i> </button>
- <button wicket:id="unwatchRequests" class="btn btn-default" title="You are watching pull requests of this branch, click to unwatch"><i class="fa fa-eye-open"></i> <i class="fa fa-branch-merge"></i> </button>
- <button wicket:id="watchRequests" class="btn btn-default" title="You are not watching pull requests of this branch, click to watch"><i class="fa fa-eye-slash"></i> <i class="fa fa-branch-merge"></i> </button>
+ <button wicket:id="unwatchRequests" class="btn btn-default" title="You are watching pull requests of this branch, click to unwatch"><i class="fa fa-eye-open"></i></button>
+ <button wicket:id="watchRequests" class="btn btn-default" title="You are not watching pull requests of this branch, click to watch"><i class="fa fa-eye-slash"></i></button>
</div>
</td>
<td class="actions">
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/BranchesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/BranchesPage.java
index 90977e9902..8770030c65 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/BranchesPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/code/branches/BranchesPage.java
@@ -48,12 +48,10 @@ import com.pmease.gitplex.core.gatekeeper.GateKeeper;
import com.pmease.gitplex.core.gatekeeper.checkresult.Approved;
import com.pmease.gitplex.core.gatekeeper.checkresult.CheckResult;
import com.pmease.gitplex.core.manager.BranchManager;
-import com.pmease.gitplex.core.manager.CommitWatchManager;
import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.manager.PullRequestWatchManager;
import com.pmease.gitplex.core.manager.UserManager;
import com.pmease.gitplex.core.model.Branch;
-import com.pmease.gitplex.core.model.CommitWatch;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestWatch;
import com.pmease.gitplex.core.model.User;
@@ -170,20 +168,6 @@ public class BranchesPage extends RepositoryPage {
};
- private final IModel<Map<String, CommitWatch>> commitWatchesModel =
- new LoadableDetachableModel<Map<String, CommitWatch>>() {
-
- @Override
- protected Map<String, CommitWatch> load() {
- Map<String, CommitWatch> commitWatches = new HashMap<>();
- for (CommitWatch watch: GitPlex.getInstance(CommitWatchManager.class).findBy(
- Preconditions.checkNotNull(getCurrentUser()), getRepository()))
- commitWatches.put(watch.getBranch().getName(), watch);
- return commitWatches;
- }
-
- };
-
private final IModel<Map<String, PullRequestWatch>> requestWatchesModel =
new LoadableDetachableModel<Map<String, PullRequestWatch>>() {
@@ -431,27 +415,6 @@ public class BranchesPage extends RepositoryPage {
final WebMarkupContainer watchContainer = new WebMarkupContainer("watch");
item.add(watchContainer.setOutputMarkupId(true));
- watchContainer.add(new AjaxLink<Void>("unwatchCommits") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- String branchName = item.getModelObject().getName();
- CommitWatch watch = commitWatchesModel.getObject().get(branchName);
- if (watch != null) {
- GitPlex.getInstance(Dao.class).remove(watch);
- commitWatchesModel.getObject().remove(branchName);
- }
- target.add(watchContainer);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getCurrentUser() != null
- && commitWatchesModel.getObject().containsKey(item.getModelObject().getName()));
- }
-
- });
watchContainer.add(new AjaxLink<Void>("unwatchRequests") {
@Override
@@ -472,25 +435,6 @@ public class BranchesPage extends RepositoryPage {
&& requestWatchesModel.getObject().containsKey(item.getModelObject().getName()));
}
- });
- watchContainer.add(new AjaxLink<Void>("watchCommits") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- CommitWatch watch = new CommitWatch();
- watch.setBranch(item.getModelObject());
- watch.setUser(getCurrentUser());
- GitPlex.getInstance(Dao.class).persist(watch);
- target.add(watchContainer);
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(getCurrentUser() != null
- && !commitWatchesModel.getObject().containsKey(item.getModelObject().getName()));
- }
-
});
watchContainer.add(new AjaxLink<Void>("watchRequests") {
@@ -580,7 +524,6 @@ public class BranchesPage extends RepositoryPage {
aheadOpenRequestsModel.detach();
behindOpenRequestsModel.detach();
requestWatchesModel.detach();
- commitWatchesModel.detach();
aheadBehindsModel.detach();
aheadBehindWidthModel.detach();
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestActivitiesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestActivitiesPage.java
index 3a63cae106..ba0c3c8f65 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestActivitiesPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestActivitiesPage.java
@@ -31,9 +31,11 @@ import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.commons.wicket.component.markdown.MarkdownInput;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.manager.UserManager;
+import com.pmease.gitplex.core.model.AbstractPullRequestComment;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestAudit;
import com.pmease.gitplex.core.model.PullRequestComment;
+import com.pmease.gitplex.core.model.PullRequestInlineComment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.web.component.comment.event.CommentCollapsing;
import com.pmease.gitplex.web.component.comment.event.CommentRemoved;
@@ -41,8 +43,10 @@ import com.pmease.gitplex.web.component.label.AgeLabel;
import com.pmease.gitplex.web.component.user.AvatarMode;
import com.pmease.gitplex.web.component.user.UserLink;
import com.pmease.gitplex.web.model.UserModel;
+import com.pmease.gitplex.web.page.repository.pullrequest.activity.AbstractCommentPullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.ApprovePullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.CommentPullRequest;
+import com.pmease.gitplex.web.page.repository.pullrequest.activity.InlineCommentPullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.DisapprovePullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.DiscardPullRequest;
import com.pmease.gitplex.web.page.repository.pullrequest.activity.IntegratePullRequest;
@@ -60,9 +64,9 @@ public class RequestActivitiesPage extends RequestDetailPage {
}
private Component newActivityRow(final String id, PullRequestActivity activity) {
- final CommentPullRequest commentActivity;
- if (activity instanceof CommentPullRequest)
- commentActivity = (CommentPullRequest) activity;
+ final AbstractCommentPullRequest commentActivity;
+ if (activity instanceof AbstractCommentPullRequest)
+ commentActivity = (AbstractCommentPullRequest) activity;
else
commentActivity = null;
@@ -87,15 +91,17 @@ public class RequestActivitiesPage extends RequestDetailPage {
};
if (commentActivity != null && commentActivity.isCollapsed()) {
- PullRequestComment comment = commentActivity.getComment();
+ AbstractPullRequestComment comment = commentActivity.getComment();
Fragment fragment = new Fragment("activity", "collapsedCommentFrag", RequestActivitiesPage.this);
fragment.add(new UserLink("user", new UserModel(comment.getUser()), AvatarMode.NAME));
- if (comment.getInlineInfo() != null)
- fragment.add(new Label("activity", "added inline comment on file '" + comment.getFile() + "'"));
- else
+ if (comment instanceof PullRequestInlineComment) {
+ PullRequestInlineComment inlineComment = (PullRequestInlineComment) comment;
+ fragment.add(new Label("activity", "added inline comment on file '" + inlineComment.getBlobInfo().getPath() + "'"));
+ } else {
fragment.add(new Label("activity", "commented"));
+ }
fragment.add(new AgeLabel("age", Model.of(comment.getDate())));
fragment.add(new Label("detail", comment.getContent()));
@@ -121,7 +127,7 @@ public class RequestActivitiesPage extends RequestDetailPage {
if (row.get("activity") == null)
row.add(activity.render("activity"));
- if (activity instanceof OpenPullRequest || activity instanceof CommentPullRequest)
+ if (activity instanceof OpenPullRequest || activity instanceof AbstractCommentPullRequest)
row.add(AttributeAppender.append("class", " discussion non-update"));
else if (activity instanceof UpdatePullRequest)
row.add(AttributeAppender.append("class", " non-discussion update"));
@@ -134,8 +140,8 @@ public class RequestActivitiesPage extends RequestDetailPage {
protected String load() {
String cssClasses = "";
PullRequestActivity activity = (PullRequestActivity) row.getDefaultModelObject();
- if (activity instanceof CommentPullRequest) {
- CommentPullRequest commentActivity = (CommentPullRequest) activity;
+ if (activity instanceof AbstractCommentPullRequest) {
+ AbstractCommentPullRequest commentActivity = (AbstractCommentPullRequest) activity;
if (commentActivity.isCollapsed())
cssClasses += " collapsed";
if (commentActivity.getComment().isResolved())
@@ -161,6 +167,9 @@ public class RequestActivitiesPage extends RequestDetailPage {
for (PullRequestComment comment: request.getComments())
activities.add(new CommentPullRequest(comment));
+ for (PullRequestInlineComment comment: request.getInlineComments())
+ activities.add(new InlineCommentPullRequest(comment));
+
for (PullRequestAudit audit: request.getAudits()) {
if (audit.getOperation() == INTEGRATE) {
activities.add(new IntegratePullRequest(audit.getUser(), audit.getDate()));
@@ -183,7 +192,7 @@ public class RequestActivitiesPage extends RequestDetailPage {
return -1;
else if (o1.getDate().after(o2.getDate()))
return 1;
- else if (o1 instanceof OpenPullRequest || o1 instanceof CommentPullRequest)
+ else if (o1 instanceof OpenPullRequest || o1 instanceof AbstractCommentPullRequest)
return -1;
else
return 1;
@@ -203,7 +212,7 @@ public class RequestActivitiesPage extends RequestDetailPage {
int index = 0;
for (PullRequestActivity activity: activities) {
Component activityRow = newActivityRow(activitiesView.newChildId(), activity);
- if (index == activities.size()-1 || activities.get(index+1) instanceof CommentPullRequest)
+ if (index == activities.size()-1 || activities.get(index+1) instanceof AbstractCommentPullRequest)
activityRow.add(AttributeAppender.append("class", " pre-discussion"));
activitiesView.add(activityRow);
index++;
@@ -288,7 +297,7 @@ public class RequestActivitiesPage extends RequestDetailPage {
for (PullRequestActivity activity: activities) {
if (activity.getDate().after(lastAcvitity.getDate())) {
Component newActivityRow = newActivityRow(activitiesView.newChildId(), activity);
- if (index == activities.size()-1 || activities.get(index+1) instanceof CommentPullRequest)
+ if (index == activities.size()-1 || activities.get(index+1) instanceof AbstractCommentPullRequest)
newActivityRow.add(AttributeAppender.append("class", " pre-discussion"));
activitiesView.add(newActivityRow);
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
index 616af66e1b..1178d6e36e 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestComparePage.java
@@ -3,12 +3,10 @@ package com.pmease.gitplex.web.page.repository.pullrequest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
-import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Set;
import javax.annotation.Nullable;
@@ -28,12 +26,14 @@ import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.google.common.base.Preconditions;
+import com.pmease.commons.git.BlobInfo;
import com.pmease.commons.git.Change;
import com.pmease.commons.git.Commit;
import com.pmease.commons.git.GitUtils;
import com.pmease.commons.git.RevAwareChange;
import com.pmease.commons.hibernate.HibernateUtils;
import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.commons.util.diff.AroundContext;
import com.pmease.commons.wicket.behavior.StickyBehavior;
import com.pmease.commons.wicket.behavior.TooltipBehavior;
import com.pmease.commons.wicket.behavior.dropdown.DropdownBehavior;
@@ -44,17 +44,15 @@ import com.pmease.commons.wicket.behavior.menu.MenuPanel;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.comment.InlineComment;
import com.pmease.gitplex.core.comment.InlineCommentSupport;
-import com.pmease.gitplex.core.comment.InlineContext;
import com.pmease.gitplex.core.manager.PullRequestManager;
import com.pmease.gitplex.core.manager.UserManager;
-import com.pmease.gitplex.core.model.InlineInfo;
import com.pmease.gitplex.core.model.IntegrationPreview;
import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestComment;
+import com.pmease.gitplex.core.model.PullRequestInlineComment;
import com.pmease.gitplex.core.model.PullRequestUpdate;
import com.pmease.gitplex.core.model.User;
import com.pmease.gitplex.web.component.comment.event.CommentRemoved;
-import com.pmease.gitplex.web.component.comment.event.CommentReplied;
import com.pmease.gitplex.web.component.diff.CompareResultPanel;
import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
@@ -67,15 +65,13 @@ public class RequestComparePage extends RequestDetailPage {
private static final String INTEGRATION_PREVIEW = "Integration Preview";
- public static final String LATEST_COMMIT_NAME = "latest";
-
private String file;
private String oldCommitHash;
private String newCommitHash;
- private final IModel<PullRequestComment> concernedCommentModel;
+ private final IModel<PullRequestInlineComment> commentModel;
private final IModel<Map<String, CommitDescription>> commitsModel =
new LoadableDetachableModel<Map<String, CommitDescription>>() {
@@ -85,15 +81,7 @@ public class RequestComparePage extends RequestDetailPage {
LinkedHashMap<String, CommitDescription> choices = new LinkedHashMap<>();
PullRequest request = getPullRequest();
- String concernedCommitHash;
- if (getConcernedComment() != null)
- concernedCommitHash = getConcernedComment().getCommitHash();
- else
- concernedCommitHash = null;
-
String name = "Base of Pull Request";
- if (request.getBaseCommitHash().equals(concernedCommitHash))
- name += " - Concerned";
CommitDescription description = new CommitDescription(name, request.getBaseCommit().getSubject());
choices.put(request.getBaseCommitHash(), description);
@@ -102,8 +90,6 @@ public class RequestComparePage extends RequestDetailPage {
int updateNo = i+1;
name = "Head of Update #" + updateNo;
Commit commit = update.getHeadCommit();
- if (commit.getHash().equals(concernedCommitHash))
- name += " - Concerned";
description = new CommitDescription(name, commit.getSubject());
choices.put(commit.getHash(), description);
}
@@ -131,18 +117,16 @@ public class RequestComparePage extends RequestDetailPage {
private CompareResultPanel compareResult;
- public RequestComparePage(PageParameters params) {
+ public RequestComparePage(final PageParameters params) {
super(params);
- file = params.get("file").toString();
- final Long concernedCommentId = params.get("comment").toOptionalLong();
-
- concernedCommentModel = new LoadableDetachableModel<PullRequestComment>() {
+ commentModel = new LoadableDetachableModel<PullRequestInlineComment>() {
@Override
- protected PullRequestComment load() {
- if (concernedCommentId != null)
- return GitPlex.getInstance(Dao.class).load(PullRequestComment.class, concernedCommentId);
+ protected PullRequestInlineComment load() {
+ Long commentId = params.get("comment").toOptionalLong();
+ if (commentId != null)
+ return GitPlex.getInstance(Dao.class).load(PullRequestInlineComment.class, commentId);
else
return null;
}
@@ -151,35 +135,29 @@ public class RequestComparePage extends RequestDetailPage {
oldCommitHash = params.get("original").toString();
newCommitHash = params.get("revised").toString();
-
- if (oldCommitHash != null) {
- if (oldCommitHash.equals(LATEST_COMMIT_NAME))
- oldCommitHash = getPullRequest().getLatestUpdate().getHeadCommitHash();
- else if (!commitsModel.getObject().containsKey(oldCommitHash))
- throw new IllegalArgumentException("Commit '" + oldCommitHash + "' is not relevant to current pull request.");
- }
-
- if (newCommitHash != null) {
- if (newCommitHash.equals(LATEST_COMMIT_NAME))
- newCommitHash = getPullRequest().getLatestUpdate().getHeadCommitHash();
- else if (!commitsModel.getObject().containsKey(newCommitHash))
- throw new IllegalArgumentException("Commit '" + newCommitHash + "' is not relevant to current pull request.");
- }
+ file = params.get("file").toString();
- PullRequestComment comment = getConcernedComment();
+ PullRequestInlineComment comment = getComment();
if (comment != null) {
- if (file == null)
- file = comment.getInlineInfo().getFile();
- if (oldCommitHash == null)
- oldCommitHash = comment.getInlineInfo().getOldCommitHash();
- if (newCommitHash == null)
- newCommitHash = comment.getInlineInfo().getNewCommitHash();
+ if (oldCommitHash != null || newCommitHash != null || file != null) {
+ throw new IllegalArgumentException("Parameter 'original', 'revised', and 'file' "
+ + "should not be specified if parameter 'comment' is specified.");
+ }
+
+ oldCommitHash = comment.getOldCommitHash();
+ newCommitHash = comment.getNewCommitHash();
+ file = comment.getBlobInfo().getPath();
} else {
if (oldCommitHash == null)
oldCommitHash = getPullRequest().getBaseCommitHash();
if (newCommitHash == null)
newCommitHash = getPullRequest().getLatestUpdate().getHeadCommitHash();
}
+ if (oldCommitHash != null && !commitsModel.getObject().containsKey(oldCommitHash))
+ throw new IllegalArgumentException("Commit '" + oldCommitHash + "' is not relevant to current pull request.");
+
+ if (newCommitHash != null && !commitsModel.getObject().containsKey(newCommitHash))
+ throw new IllegalArgumentException("Commit '" + newCommitHash + "' is not relevant to current pull request.");
}
@Override
@@ -271,38 +249,11 @@ public class RequestComparePage extends RequestDetailPage {
protected List<MenuItem> getMenuItems() {
List<MenuItem> items = new ArrayList<>();
- if (getConcernedComment() != null) {
- items.add(new ComparisonChoiceItem("Base", "Concerned") {
-
- @Override
- protected void onSelect() {
- PageParameters params = paramsOf(getPullRequest(),
- getPullRequest().getBaseCommitHash(), getConcernedComment().getCommitHash(), null,
- getConcernedComment());
- setResponsePage(RequestComparePage.class, params);
- }
-
- });
- items.add(new ComparisonChoiceItem("Concerned", "Latest Update") {
-
- @Override
- protected void onSelect() {
- PageParameters params = paramsOf(getPullRequest(),
- getConcernedComment().getCommitHash(), LATEST_COMMIT_NAME, null,
- getConcernedComment());
- setResponsePage(RequestComparePage.class, params);
- }
-
- });
- }
-
items.add(new ComparisonChoiceItem("Base", "Latest Update") {
@Override
protected void onSelect() {
- PageParameters params = paramsOf(getPullRequest(),
- getPullRequest().getBaseCommitHash(), LATEST_COMMIT_NAME,
- file, getConcernedComment());
+ PageParameters params = paramsOf(getPullRequest(), null, null, file);
setResponsePage(RequestComparePage.class, params);
}
@@ -313,14 +264,12 @@ public class RequestComparePage extends RequestDetailPage {
final IntegrationPreview preview = GitPlex.getInstance(PullRequestManager.class).previewIntegration(request);
if (preview != null && preview.getIntegrated() != null
&& !getRepository().getChanges(preview.getRequestHead(), preview.getIntegrated()).isEmpty()) {
- items.add(new ComparisonChoiceItem("Latest Update", "Integration Preview") {
+ items.add(new ComparisonChoiceItem("Target Branch", "Integration Preview") {
@Override
protected void onSelect() {
PageParameters params = paramsOf(getPullRequest(),
- getPullRequest().getLatestUpdate().getHeadCommitHash(),
- preview.getIntegrated(),
- file, getConcernedComment());
+ getPullRequest().getTarget().getHeadCommitHash(), preview.getIntegrated(), file);
setResponsePage(RequestComparePage.class, params);
}
@@ -343,8 +292,7 @@ public class RequestComparePage extends RequestDetailPage {
@Override
protected void onSelect() {
- PageParameters params = paramsOf(getPullRequest(), baseCommit, headCommit,
- file, getConcernedComment());
+ PageParameters params = paramsOf(getPullRequest(), baseCommit, headCommit, file);
setResponsePage(RequestComparePage.class, params);
}
@@ -381,11 +329,10 @@ public class RequestComparePage extends RequestDetailPage {
@Override
protected InlineCommentSupport getInlineCommentSupport(final Change change) {
- Set<String> commentables = new HashSet<>();
- commentables.add(getPullRequest().getBaseCommitHash());
- for (PullRequestUpdate update: getPullRequest().getUpdates())
- commentables.add(update.getHeadCommitHash());
- if (!commentables.contains(oldCommitHash) || !commentables.contains(newCommitHash)) {
+ List<String> commentables = getPullRequest().getCommentables();
+ int oldCommitIndex = commentables.indexOf(oldCommitHash);
+ int newCommitIndex = commentables.indexOf(newCommitHash);
+ if (oldCommitIndex == -1 || newCommitIndex == -1 || oldCommitIndex > newCommitIndex) {
return null;
} else {
return new InlineCommentSupport() {
@@ -393,41 +340,35 @@ public class RequestComparePage extends RequestDetailPage {
@Override
public Map<Integer, List<InlineComment>> getOldComments() {
RevAwareChange revAwareChange = new RevAwareChange(change, oldCommitHash, newCommitHash);
- return getPullRequest().getComments(revAwareChange).getOldComments();
+ return getPullRequest().getChangeComments(revAwareChange).getOldComments();
}
@Override
public Map<Integer, List<InlineComment>> getNewComments() {
RevAwareChange revAwareChange = new RevAwareChange(change, oldCommitHash, newCommitHash);
- return getPullRequest().getComments(revAwareChange).getNewComments();
+ return getPullRequest().getChangeComments(revAwareChange).getNewComments();
}
@Override
public InlineComment getConcernedComment() {
- return RequestComparePage.this.getConcernedComment();
+ return RequestComparePage.this.getComment();
}
@Override
- public InlineComment addComment(String commit, String file, int line, String content) {
+ public InlineComment addComment(BlobInfo blobInfo, BlobInfo compareWith,
+ AroundContext commentContext, int line, String content) {
User user = GitPlex.getInstance(UserManager.class).getCurrent();
Preconditions.checkNotNull(user);
- PullRequestComment comment = new PullRequestComment();
- getPullRequest().getComments().add(comment);
+ PullRequestInlineComment comment = new PullRequestInlineComment();
+ getPullRequest().getInlineComments().add(comment);
comment.setUser(user);
comment.setDate(new Date());
comment.setContent(content);
comment.setRequest(getPullRequest());
- InlineInfo inlineInfo = new InlineInfo();
- comment.setInlineInfo(inlineInfo);
- inlineInfo.setCommitHash(commit);
- inlineInfo.setOldCommitHash(oldCommitHash);
- inlineInfo.setNewCommitHash(newCommitHash);
- inlineInfo.setFile(file);
- inlineInfo.setLine(line);
- InlineContext context = getInlineContext(comment);
- Preconditions.checkNotNull(context);
- inlineInfo.setContext(context);
- comment.setInlineInfo(inlineInfo);
+ comment.setBlobInfo(blobInfo);
+ comment.setCompareWith(compareWith);
+ comment.setLine(line);
+ comment.setContext(commentContext);
GitPlex.getInstance(Dao.class).persist(comment);
return comment;
}
@@ -447,13 +388,20 @@ public class RequestComparePage extends RequestDetailPage {
@Override
public void onDetach() {
commitsModel.detach();
- concernedCommentModel.detach();
+ commentModel.detach();
super.onDetach();
}
+ public static PageParameters paramsOf(PullRequestInlineComment concernedComment) {
+ PageParameters params = RequestDetailPage.paramsOf(concernedComment.getRequest());
+ params.set("comment", concernedComment.getId());
+
+ return params;
+ }
+
public static PageParameters paramsOf(PullRequest request, @Nullable String oldCommit,
- @Nullable String newCommit, @Nullable String file, @Nullable PullRequestComment concernedComment) {
+ @Nullable String newCommit, @Nullable String file) {
PageParameters params = RequestDetailPage.paramsOf(request);
if (oldCommit != null)
@@ -462,12 +410,10 @@ public class RequestComparePage extends RequestDetailPage {
params.set("revised", newCommit);
if (file != null)
params.set("file", file);
- if (concernedComment != null)
- params.set("comment", concernedComment.getId());
return params;
}
-
+
@Override
public void onEvent(IEvent<?> event) {
super.onEvent(event);
@@ -478,22 +424,11 @@ public class RequestComparePage extends RequestDetailPage {
// compare identifier instead of comment object as comment may have been deleted
// to cause LazyInitializationException
- if (getConcernedComment() != null
- && HibernateUtils.getId(comment).equals(HibernateUtils.getId(getConcernedComment()))) {
- PageParameters params = paramsOf(getPullRequest(), oldCommitHash, newCommitHash,
- comment.getInlineInfo().getFile(), null);
+ if (getComment() != null
+ && HibernateUtils.getId(comment).equals(HibernateUtils.getId(getComment()))) {
+ PageParameters params = paramsOf(getPullRequest(), oldCommitHash, newCommitHash, file);
setResponsePage(RequestComparePage.class, params);
}
- } else if (event.getPayload() instanceof CommentReplied) {
- CommentReplied commentReplied = (CommentReplied) event.getPayload();
- PullRequestComment comment = (PullRequestComment) commentReplied.getReply().getComment();
- comment.getInlineInfo().setOldCommitHash(oldCommitHash);
- comment.getInlineInfo().setNewCommitHash(newCommitHash);
-
- InlineContext context = compareResult.getInlineContext(comment);
- Preconditions.checkNotNull(context);
- comment.getInlineInfo().setContext(context);
- GitPlex.getInstance(Dao.class).persist(comment);
}
}
@@ -556,10 +491,10 @@ public class RequestComparePage extends RequestDetailPage {
Map.Entry<String, CommitDescription> entry = item.getModelObject();
if (forBase) {
setResponsePage(RequestComparePage.class,
- paramsOf(getPullRequest(), entry.getKey(), newCommitHash, file, getConcernedComment()));
+ paramsOf(getPullRequest(), entry.getKey(), newCommitHash, file));
} else {
setResponsePage(RequestComparePage.class,
- paramsOf(getPullRequest(), oldCommitHash, entry.getKey(), file, getConcernedComment()));
+ paramsOf(getPullRequest(), oldCommitHash, entry.getKey(), file));
}
}
@@ -614,7 +549,7 @@ public class RequestComparePage extends RequestDetailPage {
}
}
- private PullRequestComment getConcernedComment() {
- return concernedCommentModel.getObject();
+ private PullRequestInlineComment getComment() {
+ return commentModel.getObject();
}
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java
index 3510bc0923..1b2aff9e12 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestDetailPage.java
@@ -649,8 +649,8 @@ public abstract class RequestDetailPage extends RepositoryPage {
IntegrationPreview preview = manager.previewIntegration(request);
PageParameters params = RequestComparePage.paramsOf(
- request, request.getLatestUpdate().getHeadCommitHash(),
- preview!=null?preview.getIntegrated():null, null, null);
+ request, request.getTarget().getHeadCommitHash(),
+ preview!=null?preview.getIntegrated():null, null);
Link<Void> link = new BookmarkablePageLink<Void>("preview", RequestComparePage.class, params) {
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestUpdatesPage.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestUpdatesPage.java
index caf24a8b1f..4e679c8c64 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestUpdatesPage.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/RequestUpdatesPage.java
@@ -71,7 +71,7 @@ public class RequestUpdatesPage extends RequestDetailPage {
int updateNo = updates.indexOf(update) + 1;
updateItem.add(new Label("updateNo", updateNo));
PageParameters params = RequestComparePage.paramsOf(
- update.getRequest(), update.getBaseCommitHash(), update.getHeadCommitHash(), null, null);
+ update.getRequest(), update.getBaseCommitHash(), update.getHeadCommitHash(), null);
updateItem.add(new AgeLabel("age", Model.of(update.getDate())));
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/AbstractCommentPullRequest.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/AbstractCommentPullRequest.java
new file mode 100644
index 0000000000..601332f2f7
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/AbstractCommentPullRequest.java
@@ -0,0 +1,35 @@
+package com.pmease.gitplex.web.page.repository.pullrequest.activity;
+
+import java.util.Date;
+
+import com.pmease.gitplex.core.model.AbstractPullRequestComment;
+import com.pmease.gitplex.core.model.User;
+
+@SuppressWarnings("serial")
+public abstract class AbstractCommentPullRequest implements PullRequestActivity {
+
+ private Boolean collapsed;
+
+ @Override
+ public Date getDate() {
+ return getComment().getDate();
+ }
+
+ public abstract AbstractPullRequestComment getComment();
+
+ @Override
+ public User getUser() {
+ return getComment().getUser();
+ }
+
+ public boolean isCollapsed() {
+ if (collapsed == null)
+ collapsed = getComment().isResolved();
+ return collapsed;
+ }
+
+ public void setCollapsed(boolean collapsed) {
+ this.collapsed = collapsed;
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentActivityPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentActivityPanel.html
index b5e6f7f67f..96963328b8 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentActivityPanel.html
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentActivityPanel.html
@@ -1,22 +1,6 @@
<wicket:panel>
<div wicket:id="content"></div>
- <wicket:fragment wicket:id="inlineFrag">
- <div class="inline-comment summary">
- <span wicket:id="name" class="user"></span>
- added inline comment
- <span wicket:id="age"></span>
- </div>
- <div class="inline-comment panel panel-default">
- <div class="panel-heading">
- <span wicket:id="file"></span>
- <span class="actions">
- <a wicket:id="compareView" class="fa fa-diff" title="Display comment in compare view"></a>
- </span>
- </div>
- <div wicket:id="comment"></div>
- </div>
- </wicket:fragment>
- <wicket:fragment wicket:id="commentActionsFrag">
+ <wicket:fragment wicket:id="actionsFrag">
<a wicket:id="collapse" class="fa fa-collapse" title="Collapse this comment"></a>
<span wicket:id="changes"></span>
</wicket:fragment>
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentActivityPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentActivityPanel.java
index 0bc48c87f0..dfdfae5170 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentActivityPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentActivityPanel.java
@@ -4,14 +4,10 @@ import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.event.Broadcast;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.link.BookmarkablePageLink;
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.Model;
-import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.pmease.gitplex.core.comment.Comment;
import com.pmease.gitplex.core.comment.CommentReply;
@@ -19,11 +15,6 @@ import com.pmease.gitplex.core.model.PullRequest;
import com.pmease.gitplex.core.model.PullRequestComment;
import com.pmease.gitplex.web.component.comment.CommentPanel;
import com.pmease.gitplex.web.component.comment.event.CommentCollapsing;
-import com.pmease.gitplex.web.component.label.AgeLabel;
-import com.pmease.gitplex.web.component.user.AvatarMode;
-import com.pmease.gitplex.web.component.user.UserLink;
-import com.pmease.gitplex.web.model.UserModel;
-import com.pmease.gitplex.web.page.repository.pullrequest.RequestComparePage;
@SuppressWarnings("serial")
public class CommentActivityPanel extends Panel {
@@ -40,87 +31,70 @@ public class CommentActivityPanel extends Panel {
protected void onInitialize() {
super.onInitialize();
- PullRequestComment comment = commentModel.getObject();
- if (comment.getInlineInfo() != null) {
- Fragment fragment = new Fragment("content", "inlineFrag", this);
- fragment.add(new UserLink("name", new UserModel(comment.getUser()), AvatarMode.NAME));
- fragment.add(new AgeLabel("age", Model.of(comment.getDate())));
-
- fragment.add(new Label("file", comment.getFile()));
-
- PageParameters params = RequestComparePage.paramsOf(comment.getRequest(), comment.getOldCommitHash(),
- comment.getNewCommitHash(), null, comment);
- fragment.add(new BookmarkablePageLink<Void>("compareView", RequestComparePage.class, params));
-
- fragment.add(new InlineCommentPanel("comment", commentModel));
- fragment.setRenderBodyOnly(true);
- add(fragment);
- } else {
- add(new CommentPanel("content", commentModel) {
-
- @Override
- protected Component newAdditionalCommentActions(String id, final IModel<Comment> commentModel) {
- Fragment fragment = new Fragment(id, "commentActionsFrag", CommentActivityPanel.this) {
-
- @Override
- protected void onDetach() {
- commentModel.detach();
- super.onDetach();
- }
-
- };
+ add(new CommentPanel("content", commentModel) {
+
+ @Override
+ protected Component newAdditionalCommentActions(String id, final IModel<Comment> commentModel) {
+ Fragment fragment = new Fragment(id, "actionsFrag", CommentActivityPanel.this) {
+
+ @Override
+ protected void onDetach() {
+ commentModel.detach();
+ super.onDetach();
+ }
- fragment.add(new AjaxLink<Void>("collapse") {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- send(CommentActivityPanel.this, Broadcast.BUBBLE,
- new CommentCollapsing(target, commentModel.getObject()));
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- setVisible(commentModel.getObject().isResolved());
- }
+ };
+
+ fragment.add(new AjaxLink<Void>("collapse") {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ send(CommentActivityPanel.this, Broadcast.BUBBLE,
+ new CommentCollapsing(target, commentModel.getObject()));
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
- });
+ setVisible(commentModel.getObject().isResolved());
+ }
- fragment.add(new SinceChangesPanel("changes", new AbstractReadOnlyModel<PullRequest>() {
+ });
+
+ fragment.add(new SinceChangesPanel("changes", new AbstractReadOnlyModel<PullRequest>() {
- @Override
- public PullRequest getObject() {
- return CommentActivityPanel.this.commentModel.getObject().getRequest();
- }
-
- }, CommentActivityPanel.this.commentModel.getObject().getDate(), "Changes since this comment"));
+ @Override
+ public PullRequest getObject() {
+ return CommentActivityPanel.this.commentModel.getObject().getRequest();
+ }
- return fragment;
- }
+ }, CommentActivityPanel.this.commentModel.getObject().getDate(), "Changes since this comment"));
+
+ return fragment;
+ }
- @Override
- protected Component newAdditionalReplyActions(String id, final IModel<CommentReply> replyModel) {
- return new SinceChangesPanel(id, new AbstractReadOnlyModel<PullRequest>() {
+ @Override
+ protected Component newAdditionalReplyActions(String id, final IModel<CommentReply> replyModel) {
+ return new SinceChangesPanel(id, new AbstractReadOnlyModel<PullRequest>() {
- @Override
- public PullRequest getObject() {
- return commentModel.getObject().getRequest();
- }
-
- }, replyModel.getObject().getDate(), "Changes since this reply") {
+ @Override
+ public PullRequest getObject() {
+ return commentModel.getObject().getRequest();
+ }
+
+ }, replyModel.getObject().getDate(), "Changes since this reply") {
- @Override
- protected void onDetach() {
- replyModel.detach();
- super.onDetach();
- }
-
- };
- }
-
- });
- }
+ @Override
+ protected void onDetach() {
+ replyModel.detach();
+ super.onDetach();
+ }
+
+ };
+ }
+
+ });
}
@Override
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentPullRequest.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentPullRequest.java
index 1493fd3f69..806b9b400b 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentPullRequest.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/CommentPullRequest.java
@@ -1,31 +1,21 @@
package com.pmease.gitplex.web.page.repository.pullrequest.activity;
-import java.util.Date;
-
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.LoadableDetachableModel;
import com.pmease.commons.hibernate.dao.Dao;
import com.pmease.gitplex.core.GitPlex;
import com.pmease.gitplex.core.model.PullRequestComment;
-import com.pmease.gitplex.core.model.User;
@SuppressWarnings("serial")
-public class CommentPullRequest implements PullRequestActivity {
+public class CommentPullRequest extends AbstractCommentPullRequest {
private final Long commentId;
- private Boolean collapsed;
-
public CommentPullRequest(PullRequestComment comment) {
this.commentId = comment.getId();
}
- @Override
- public Date getDate() {
- return getComment().getDate();
- }
-
@Override
public Panel render(String panelId) {
return new CommentActivityPanel(panelId, new LoadableDetachableModel<PullRequestComment>(){
@@ -42,19 +32,4 @@ public class CommentPullRequest implements PullRequestActivity {
return GitPlex.getInstance(Dao.class).load(PullRequestComment.class, commentId);
}
- @Override
- public User getUser() {
- return getComment().getUser();
- }
-
- public boolean isCollapsed() {
- if (collapsed == null)
- collapsed = getComment().isResolved();
- return collapsed;
- }
-
- public void setCollapsed(boolean collapsed) {
- this.collapsed = collapsed;
- }
-
}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.html
new file mode 100644
index 0000000000..3480b9b813
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.html
@@ -0,0 +1,48 @@
+<wicket:panel>
+ <div class="inline-comment summary">
+ <span wicket:id="name" class="user"></span>
+ added inline comment
+ <span wicket:id="age"></span>
+ </div>
+ <div class="inline-comment panel panel-default">
+ <div class="panel-heading">
+ <span wicket:id="file"></span>
+ <span class="actions">
+ <a wicket:id="compareView" class="fa fa-diff" title="Display comment in compare view"></a>
+ </span>
+ </div>
+ <div wicket:id="context"></div>
+ </div>
+ <wicket:fragment wicket:id="withoutContextFrag">
+ <div class="alert alert-warning">Comment context is not available for binary content</div>
+ <div wicket:id="comment"></div>
+ </wicket:fragment>
+ <wicket:fragment wicket:id="withContextFrag">
+ <table class="table-diff">
+ <tr wicket:id="aboveOmitted" class="omit">
+ <td colspan="3"><i class="fa fa-ellipsis"></i></td>
+ </tr>
+ <wicket:container wicket:id="lines">
+ <tr wicket:id="contentRow" class="line diff">
+ <td class="old line-no">
+ <span wicket:id="oldLineNo"></span>
+ </td>
+ <td class="new line-no">
+ <span wicket:id="newLineNo"></span>
+ </td>
+ <td class="text"><wicket:container wicket:id="diffMark"></wicket:container><wicket:container wicket:id="partials"><span wicket:id="partial"></span></wicket:container></td>
+ </tr>
+ <wicket:enclosure child="comment">
+ <tr class="line comments">
+ <td colspan="3">
+ <div wicket:id="comment"></div>
+ </td>
+ </tr>
+ </wicket:enclosure>
+ </wicket:container>
+ <tr wicket:id="belowOmitted" class="omit">
+ <td colspan="3"><i class="fa fa-ellipsis"></i></td>
+ </tr>
+ </table>
+ </wicket:fragment>
+</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.java
new file mode 100644
index 0000000000..b7f263275e
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentActivityPanel.java
@@ -0,0 +1,221 @@
+package com.pmease.gitplex.web.page.repository.pullrequest.activity;
+
+import static com.pmease.commons.util.diff.DiffLine.Action.ADD;
+import static com.pmease.commons.util.diff.DiffLine.Action.DELETE;
+
+import java.util.List;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.behavior.AttributeAppender;
+import org.apache.wicket.event.Broadcast;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+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.Model;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+import com.pmease.commons.util.diff.DiffLine;
+import com.pmease.commons.util.diff.Token;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.comment.Comment;
+import com.pmease.gitplex.core.comment.InlineComment;
+import com.pmease.gitplex.core.manager.PullRequestInlineCommentManager;
+import com.pmease.gitplex.core.model.PullRequestInlineComment;
+import com.pmease.gitplex.web.component.comment.CommentPanel;
+import com.pmease.gitplex.web.component.comment.event.CommentCollapsing;
+import com.pmease.gitplex.web.component.label.AgeLabel;
+import com.pmease.gitplex.web.component.user.AvatarMode;
+import com.pmease.gitplex.web.component.user.UserLink;
+import com.pmease.gitplex.web.model.UserModel;
+import com.pmease.gitplex.web.page.repository.pullrequest.RequestComparePage;
+
+@SuppressWarnings("serial")
+public class InlineCommentActivityPanel extends Panel {
+
+ private final IModel<PullRequestInlineComment> commentModel;
+
+ public InlineCommentActivityPanel(String id, IModel<PullRequestInlineComment> commentModel) {
+ super(id);
+
+ this.commentModel = commentModel;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+
+ PullRequestInlineComment comment = commentModel.getObject();
+ PullRequestInlineComment inlineComment = (PullRequestInlineComment) comment;
+ GitPlex.getInstance(PullRequestInlineCommentManager.class).update(inlineComment);
+ add(new UserLink("name", new UserModel(comment.getUser()), AvatarMode.NAME));
+ add(new AgeLabel("age", Model.of(comment.getDate())));
+
+ add(new Label("file", inlineComment.getBlobInfo().getPath()));
+
+ PageParameters params = RequestComparePage.paramsOf(comment);
+ add(new BookmarkablePageLink<Void>("compareView", RequestComparePage.class, params));
+
+ if (commentModel.getObject().getContext() != null) {
+ Fragment fragment = new Fragment("context", "withContextFrag", this);
+ fragment.add(new WebMarkupContainer("aboveOmitted") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(commentModel.getObject().getContext().isAboveOmitted());
+ }
+
+ });
+ fragment.add(new WebMarkupContainer("belowOmitted") {
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+ setVisible(commentModel.getObject().getContext().isBelowOmitted());
+ }
+
+ });
+ fragment.add(new ListView<DiffLine>("lines", new AbstractReadOnlyModel<List<DiffLine>>() {
+
+ @Override
+ public List<DiffLine> getObject() {
+ return commentModel.getObject().getContext().getDiffs();
+ }
+
+ }) {
+
+ @Override
+ protected void populateItem(final ListItem<DiffLine> item) {
+ DiffLine diffLine = item.getModelObject();
+
+ WebMarkupContainer contentRow = new WebMarkupContainer("contentRow");
+ item.add(contentRow);
+ if (diffLine.getAction() == ADD) {
+ contentRow.add(AttributeAppender.append("class", " new"));
+ contentRow.add(new Label("oldLineNo"));
+ contentRow.add(new Label("newLineNo", diffLine.getNewLineNo() + 1));
+ contentRow.add(new Label("diffMark", "+"));
+ } else if (diffLine.getAction() == DELETE) {
+ contentRow.add(AttributeAppender.append("class", " old"));
+ contentRow.add(new Label("oldLineNo", diffLine.getOldLineNo() + 1));
+ contentRow.add(new Label("newLineNo"));
+ contentRow.add(new Label("diffMark", "-"));
+ } else {
+ contentRow.add(AttributeAppender.append("class", " equal"));
+ contentRow.add(new Label("oldLineNo", diffLine.getOldLineNo()+1));
+ contentRow.add(new Label("newLineNo", diffLine.getNewLineNo()+1));
+ contentRow.add(new Label("diffMark", " "));
+ }
+ contentRow.add(new ListView<Token>("partials", diffLine.getTokens()) {
+
+ @Override
+ protected void populateItem(ListItem<Token> item) {
+ Token partial = item.getModelObject();
+ Label label;
+ if (partial.getContent().equals("\r"))
+ label = new Label("partial", " ");
+ else
+ label = new Label("partial", partial.getContent());
+ if (partial.isEmphasized())
+ label.add(AttributeAppender.append("class", "emphasize"));
+ item.add(label);
+ }
+
+ });
+
+ InlineComment comment = commentModel.getObject();
+ if (item.getIndex() == comment.getContext().getCommentLine()) {
+ item.add(new CommentPanel("comment", commentModel) {
+
+ @Override
+ protected Component newAdditionalCommentActions(String id, IModel<Comment> comment) {
+ return new AjaxLink<Void>(id) {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ send(InlineCommentActivityPanel.this, Broadcast.BUBBLE,
+ new CommentCollapsing(target, commentModel.getObject()));
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ setVisible(commentModel.getObject().isResolved());
+ }
+
+ @Override
+ protected void onComponentTag(ComponentTag tag) {
+ super.onComponentTag(tag);
+ tag.put("class", "fa fa-collapse");
+ tag.put("title", "Collapse this comment");
+ tag.put("style", "cursor:pointer;");
+ }
+
+ };
+
+ }
+
+ });
+ } else {
+ item.add(new WebMarkupContainer("comment").setVisible(false));
+ }
+ }
+
+ });
+ add(fragment);
+ } else {
+ Fragment fragment = new Fragment("context", "withoutContextFrag", this);
+ fragment.add(AttributeAppender.append("class", " panel-body"));
+ fragment.add(new CommentPanel("comment", commentModel) {
+
+ @Override
+ protected Component newAdditionalCommentActions(String id, IModel<Comment> comment) {
+ return new AjaxLink<Void>(id) {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ send(InlineCommentActivityPanel.this, Broadcast.BUBBLE,
+ new CommentCollapsing(target, commentModel.getObject()));
+ }
+
+ @Override
+ protected void onConfigure() {
+ super.onConfigure();
+
+ setVisible(commentModel.getObject().isResolved());
+ }
+
+ @Override
+ protected void onComponentTag(ComponentTag tag) {
+ super.onComponentTag(tag);
+ tag.put("class", "fa fa-collapse");
+ tag.put("title", "Collapse this comment");
+ tag.put("style", "cursor:pointer;");
+ }
+
+ };
+
+ }
+
+ });
+ add(fragment);
+ }
+ }
+
+ @Override
+ protected void onDetach() {
+ commentModel.detach();
+ super.onDetach();
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPanel.html b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPanel.html
deleted file mode 100644
index f989ddc1c2..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPanel.html
+++ /dev/null
@@ -1,28 +0,0 @@
-<wicket:panel>
- <table class="table-diff">
- <tr wicket:id="aboveOmitted" class="omit">
- <td colspan="3"><i class="fa fa-ellipsis"></i></td>
- </tr>
- <wicket:container wicket:id="lines">
- <tr wicket:id="contentRow" class="line diff">
- <td class="old line-no">
- <span wicket:id="oldLineNo"></span>
- </td>
- <td class="new line-no">
- <span wicket:id="newLineNo"></span>
- </td>
- <td class="text"><wicket:container wicket:id="diffMark"></wicket:container><wicket:container wicket:id="partials"><span wicket:id="partial"></span></wicket:container></td>
- </tr>
- <wicket:enclosure child="comment">
- <tr class="line comments">
- <td colspan="3">
- <div wicket:id="comment"></div>
- </td>
- </tr>
- </wicket:enclosure>
- </wicket:container>
- <tr wicket:id="belowOmitted" class="omit">
- <td colspan="3"><i class="fa fa-ellipsis"></i></td>
- </tr>
- </table>
-</wicket:panel>
\ No newline at end of file
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPanel.java
deleted file mode 100644
index 30a3c6d48b..0000000000
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPanel.java
+++ /dev/null
@@ -1,158 +0,0 @@
-package com.pmease.gitplex.web.page.repository.pullrequest.activity;
-
-import static com.pmease.commons.util.diff.DiffLine.Action.ADD;
-import static com.pmease.commons.util.diff.DiffLine.Action.DELETE;
-
-import java.util.List;
-
-import org.apache.wicket.Component;
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.markup.html.AjaxLink;
-import org.apache.wicket.behavior.AttributeAppender;
-import org.apache.wicket.event.Broadcast;
-import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.html.WebMarkupContainer;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.list.ListItem;
-import org.apache.wicket.markup.html.list.ListView;
-import org.apache.wicket.markup.html.panel.Panel;
-import org.apache.wicket.model.AbstractReadOnlyModel;
-import org.apache.wicket.model.IModel;
-
-import com.pmease.commons.util.diff.DiffLine;
-import com.pmease.commons.util.diff.Partial;
-import com.pmease.gitplex.core.comment.Comment;
-import com.pmease.gitplex.core.comment.InlineComment;
-import com.pmease.gitplex.web.component.comment.CommentPanel;
-import com.pmease.gitplex.web.component.comment.event.CommentCollapsing;
-
-@SuppressWarnings("serial")
-public class InlineCommentPanel extends Panel {
-
- private final IModel<? extends InlineComment> commentModel;
-
- public InlineCommentPanel(String id, IModel<? extends InlineComment> commentModel) {
- super(id);
-
- this.commentModel = commentModel;
- }
-
- @Override
- protected void onInitialize() {
- super.onInitialize();
-
- add(new WebMarkupContainer("aboveOmitted") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(commentModel.getObject().getContext().isAboveOmitted());
- }
-
- });
- add(new WebMarkupContainer("belowOmitted") {
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
- setVisible(commentModel.getObject().getContext().isBelowOmitted());
- }
-
- });
- add(new ListView<DiffLine>("lines", new AbstractReadOnlyModel<List<DiffLine>>() {
-
- @Override
- public List<DiffLine> getObject() {
- return commentModel.getObject().getContext().getDiffs();
- }
-
- }) {
-
- @Override
- protected void populateItem(final ListItem<DiffLine> item) {
- DiffLine diffLine = item.getModelObject();
-
- WebMarkupContainer contentRow = new WebMarkupContainer("contentRow");
- item.add(contentRow);
- if (diffLine.getAction() == ADD) {
- contentRow.add(AttributeAppender.append("class", " new"));
- contentRow.add(new Label("oldLineNo"));
- contentRow.add(new Label("newLineNo", diffLine.getNewLineNo() + 1));
- contentRow.add(new Label("diffMark", "+"));
- } else if (diffLine.getAction() == DELETE) {
- contentRow.add(AttributeAppender.append("class", " old"));
- contentRow.add(new Label("oldLineNo", diffLine.getOldLineNo() + 1));
- contentRow.add(new Label("newLineNo"));
- contentRow.add(new Label("diffMark", "-"));
- } else {
- contentRow.add(AttributeAppender.append("class", " equal"));
- contentRow.add(new Label("oldLineNo", diffLine.getOldLineNo()+1));
- contentRow.add(new Label("newLineNo", diffLine.getNewLineNo()+1));
- contentRow.add(new Label("diffMark", " "));
- }
- contentRow.add(new ListView<Partial>("partials", diffLine.getPartials()) {
-
- @Override
- protected void populateItem(ListItem<Partial> item) {
- Partial partial = item.getModelObject();
- Label label;
- if (partial.getContent().equals("\r"))
- label = new Label("partial", " ");
- else
- label = new Label("partial", partial.getContent());
- if (partial.isEmphasized())
- label.add(AttributeAppender.append("class", "emphasize"));
- item.add(label);
- }
-
- });
-
- InlineComment comment = commentModel.getObject();
- if (item.getIndex() == comment.getContext().getCommentLine()) {
- item.add(new CommentPanel("comment", commentModel) {
-
- @Override
- protected Component newAdditionalCommentActions(String id, IModel<Comment> comment) {
- return new AjaxLink<Void>(id) {
-
- @Override
- public void onClick(AjaxRequestTarget target) {
- send(InlineCommentPanel.this, Broadcast.BUBBLE,
- new CommentCollapsing(target, commentModel.getObject()));
- }
-
- @Override
- protected void onConfigure() {
- super.onConfigure();
-
- setVisible(commentModel.getObject().isResolved());
- }
-
- @Override
- protected void onComponentTag(ComponentTag tag) {
- super.onComponentTag(tag);
- tag.put("class", "fa fa-collapse");
- tag.put("title", "Collapse this comment");
- tag.put("style", "cursor:pointer;");
- }
-
- };
-
- }
-
- });
- } else {
- item.add(new WebMarkupContainer("comment").setVisible(false));
- }
- }
-
- });
- }
-
- @Override
- protected void onDetach() {
- commentModel.detach();
- super.onDetach();
- }
-
-}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPullRequest.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPullRequest.java
new file mode 100644
index 0000000000..f71f102e10
--- /dev/null
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/InlineCommentPullRequest.java
@@ -0,0 +1,35 @@
+package com.pmease.gitplex.web.page.repository.pullrequest.activity;
+
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.LoadableDetachableModel;
+
+import com.pmease.commons.hibernate.dao.Dao;
+import com.pmease.gitplex.core.GitPlex;
+import com.pmease.gitplex.core.model.PullRequestInlineComment;
+
+@SuppressWarnings("serial")
+public class InlineCommentPullRequest extends AbstractCommentPullRequest {
+
+ private final Long commentId;
+
+ public InlineCommentPullRequest(PullRequestInlineComment comment) {
+ this.commentId = comment.getId();
+ }
+
+ @Override
+ public Panel render(String panelId) {
+ return new InlineCommentActivityPanel(panelId, new LoadableDetachableModel<PullRequestInlineComment>(){
+
+ @Override
+ protected PullRequestInlineComment load() {
+ return getComment();
+ }
+
+ });
+ }
+
+ public PullRequestInlineComment getComment() {
+ return GitPlex.getInstance(Dao.class).load(PullRequestInlineComment.class, commentId);
+ }
+
+}
diff --git a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/SinceChangesPanel.java b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/SinceChangesPanel.java
index 4a45273179..43815b7d23 100644
--- a/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/SinceChangesPanel.java
+++ b/gitplex.web/src/main/java/com/pmease/gitplex/web/page/repository/pullrequest/activity/SinceChangesPanel.java
@@ -44,13 +44,11 @@ public class SinceChangesPanel extends Panel {
}
}
PageParameters params = RequestComparePage.paramsOf(request, oldCommit,
- request.getLatestUpdate().getHeadCommitHash(), null, null);
+ request.getLatestUpdate().getHeadCommitHash(), null);
Link<Void> link = new BookmarkablePageLink<>("link", RequestComparePage.class, params);
link.add(AttributeAppender.append("title", tooltip));
add(link);
-
- setVisible(!oldCommit.equals(request.getLatestUpdate().getHeadCommitHash()));
}
@Override