Merge "Differentiate RobotComment and HumanComment"

This commit is contained in:
Gal Paikin
2020-06-24 11:44:08 +00:00
committed by Gerrit Code Review
63 changed files with 608 additions and 453 deletions

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.common.data;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -36,7 +37,7 @@ public class CommentDetail {
protected CommentDetail() {} protected CommentDetail() {}
public void include(Change.Id changeId, Comment p) { public void include(Change.Id changeId, HumanComment p) {
PatchSet.Id psId = PatchSet.id(changeId, p.key.patchSetId); PatchSet.Id psId = PatchSet.id(changeId, p.key.patchSetId);
if (p.side == 0) { if (p.side == 0) {
if (idA == null && idB.equals(psId)) { if (idA == null && idB.equals(psId)) {

View File

@@ -39,7 +39,7 @@ import java.util.Optional;
* | * |
* +- {@link PatchSetApproval}: a +/- vote on the change's current state. * +- {@link PatchSetApproval}: a +/- vote on the change's current state.
* | * |
* +- {@link Comment}: comment about a specific line * +- {@link HumanComment}: comment about a specific line
* </pre> * </pre>
* *
* <p> * <p>

View File

@@ -24,15 +24,15 @@ import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
/** /**
* This class represents inline comments in NoteDb. This means it determines the JSON format for * This class is a base class that can be extended by the different types of inline comment
* inline comments in the revision notes that NoteDb uses to persist inline comments. * entities.
* *
* <p>Changing fields in this class changes the storage format of inline comments in NoteDb and may * <p>Changing fields in this class changes the storage format of inline comments in NoteDb and may
* require a corresponding data migration (adding new optional fields is generally okay). * require a corresponding data migration (adding new optional fields is generally okay).
* *
* <p>Consider updating {@link #getApproximateSize()} when adding/changing fields. * <p>Consider updating {@link #getCommentFieldApproximateSize()} when adding/changing fields.
*/ */
public class Comment { public abstract class Comment {
public enum Status { public enum Status {
DRAFT('d'), DRAFT('d'),
@@ -301,11 +301,13 @@ public class Comment {
* Returns the comment's approximate size. This is used to enforce size limits and should * Returns the comment's approximate size. This is used to enforce size limits and should
* therefore include all unbounded fields (e.g. String-s). * therefore include all unbounded fields (e.g. String-s).
*/ */
public int getApproximateSize() { protected int getCommentFieldApproximateSize() {
return nullableLength(message, parentUuid, tag, revId, serverId) return nullableLength(message, parentUuid, tag, revId, serverId)
+ (key != null ? nullableLength(key.filename, key.uuid) : 0); + (key != null ? nullableLength(key.filename, key.uuid) : 0);
} }
public abstract int getApproximateSize();
static int nullableLength(String... strings) { static int nullableLength(String... strings) {
int length = 0; int length = 0;
for (String s : strings) { for (String s : strings) {

View File

@@ -0,0 +1,67 @@
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.entities;
import java.sql.Timestamp;
/**
* This class represents inline human comments in NoteDb. This means it determines the JSON format
* for inline comments in the revision notes that NoteDb uses to persist inline comments.
*
* <p>Changing fields in this class changes the storage format of inline comments in NoteDb and may
* require a corresponding data migration (adding new optional fields is generally okay).
*
* <p>Consider updating {@link #getApproximateSize()} when adding/changing fields.
*/
public class HumanComment extends Comment {
public HumanComment(
Key key,
Account.Id author,
Timestamp writtenOn,
short side,
String message,
String serverId,
boolean unresolved) {
super(key, author, writtenOn, side, message, serverId, unresolved);
}
public HumanComment(HumanComment comment) {
super(comment);
}
@Override
public int getApproximateSize() {
return super.getCommentFieldApproximateSize();
}
@Override
public String toString() {
return toStringHelper().toString();
}
@Override
public boolean equals(Object o) {
if (!(o instanceof HumanComment)) {
return false;
}
return super.equals(o);
}
@Override
public int hashCode() {
return super.hashCode();
}
}

View File

@@ -42,7 +42,8 @@ public final class RobotComment extends Comment {
@Override @Override
public int getApproximateSize() { public int getApproximateSize() {
int approximateSize = super.getApproximateSize() + nullableLength(robotId, robotRunId, url); int approximateSize =
super.getCommentFieldApproximateSize() + nullableLength(robotId, robotRunId, url);
approximateSize += approximateSize +=
properties != null properties != null
? properties.entrySet().stream() ? properties.entrySet().stream()
@@ -66,4 +67,23 @@ public final class RobotComment extends Comment {
.add("fixSuggestions", Objects.toString(fixSuggestions, "")) .add("fixSuggestions", Objects.toString(fixSuggestions, ""))
.toString(); .toString();
} }
@Override
public boolean equals(Object o) {
if (!(o instanceof RobotComment)) {
return false;
}
RobotComment c = (RobotComment) o;
return super.equals(o)
&& Objects.equals(robotId, c.robotId)
&& Objects.equals(robotRunId, c.robotRunId)
&& Objects.equals(url, c.url)
&& Objects.equals(properties, c.properties)
&& Objects.equals(fixSuggestions, c.fixSuggestions);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), robotId, robotRunId, url, properties, fixSuggestions);
}
} }

View File

@@ -18,7 +18,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import com.google.common.collect.PeekingIterator; import com.google.common.collect.PeekingIterator;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -60,7 +60,7 @@ public class HtmlParser {
* @return list of MailComments parsed from the html part of the email * @return list of MailComments parsed from the html part of the email
*/ */
public static List<MailComment> parse( public static List<MailComment> parse(
MailMessage email, Collection<Comment> comments, String changeUrl) { MailMessage email, Collection<HumanComment> comments, String changeUrl) {
// TODO(hiesel) Add support for Gmail Mobile // TODO(hiesel) Add support for Gmail Mobile
// TODO(hiesel) Add tests for other popular email clients // TODO(hiesel) Add tests for other popular email clients
@@ -71,10 +71,10 @@ public class HtmlParser {
// Gerrit as these are generally more reliable then the text captions. // Gerrit as these are generally more reliable then the text captions.
List<MailComment> parsedComments = new ArrayList<>(); List<MailComment> parsedComments = new ArrayList<>();
Document d = Jsoup.parse(email.htmlContent()); Document d = Jsoup.parse(email.htmlContent());
PeekingIterator<Comment> iter = Iterators.peekingIterator(comments.iterator()); PeekingIterator<HumanComment> iter = Iterators.peekingIterator(comments.iterator());
String lastEncounteredFileName = null; String lastEncounteredFileName = null;
Comment lastEncounteredComment = null; HumanComment lastEncounteredComment = null;
for (Element e : d.body().getAllElements()) { for (Element e : d.body().getAllElements()) {
String elementName = e.tagName(); String elementName = e.tagName();
boolean isInBlockQuote = boolean isInBlockQuote =
@@ -91,7 +91,7 @@ public class HtmlParser {
if (!iter.hasNext()) { if (!iter.hasNext()) {
continue; continue;
} }
Comment perspectiveComment = iter.peek(); HumanComment perspectiveComment = iter.peek();
if (href.equals(ParserUtil.filePath(changeUrl, perspectiveComment))) { if (href.equals(ParserUtil.filePath(changeUrl, perspectiveComment))) {
if (lastEncounteredFileName == null if (lastEncounteredFileName == null
|| !lastEncounteredFileName.equals(perspectiveComment.key.filename)) { || !lastEncounteredFileName.equals(perspectiveComment.key.filename)) {

View File

@@ -14,7 +14,7 @@
package com.google.gerrit.mail; package com.google.gerrit.mail;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import java.util.Objects; import java.util.Objects;
/** A comment parsed from inbound email */ /** A comment parsed from inbound email */
@@ -26,7 +26,7 @@ public class MailComment {
} }
CommentType type; CommentType type;
Comment inReplyTo; HumanComment inReplyTo;
String fileName; String fileName;
String message; String message;
boolean isLink; boolean isLink;
@@ -34,7 +34,7 @@ public class MailComment {
public MailComment() {} public MailComment() {}
public MailComment( public MailComment(
String message, String fileName, Comment inReplyTo, CommentType type, boolean isLink) { String message, String fileName, HumanComment inReplyTo, CommentType type, boolean isLink) {
this.message = message; this.message = message;
this.fileName = fileName; this.fileName = fileName;
this.inReplyTo = inReplyTo; this.inReplyTo = inReplyTo;
@@ -46,7 +46,7 @@ public class MailComment {
return type; return type;
} }
public Comment getInReplyTo() { public HumanComment getInReplyTo() {
return inReplyTo; return inReplyTo;
} }

View File

@@ -18,7 +18,7 @@ import com.google.common.base.Splitter;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import com.google.common.collect.PeekingIterator; import com.google.common.collect.PeekingIterator;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -31,15 +31,15 @@ public class TextParser {
* Parses comments from plaintext email. * Parses comments from plaintext email.
* *
* @param email @param email the message as received from the email service * @param email @param email the message as received from the email service
* @param comments list of {@link Comment}s previously persisted on the change that caused the * @param comments list of {@link HumanComment}s previously persisted on the change that caused
* original notification email to be sent out. Ordering must be the same as in the outbound * the original notification email to be sent out. Ordering must be the same as in the
* email * outbound email
* @param changeUrl canonical change url that points to the change on this Gerrit instance. * @param changeUrl canonical change url that points to the change on this Gerrit instance.
* Example: https://go-review.googlesource.com/#/c/91570 * Example: https://go-review.googlesource.com/#/c/91570
* @return list of MailComments parsed from the plaintext part of the email * @return list of MailComments parsed from the plaintext part of the email
*/ */
public static List<MailComment> parse( public static List<MailComment> parse(
MailMessage email, Collection<Comment> comments, String changeUrl) { MailMessage email, Collection<HumanComment> comments, String changeUrl) {
String body = email.textContent(); String body = email.textContent();
// Replace CR-LF by \n // Replace CR-LF by \n
body = body.replace("\r\n", "\n"); body = body.replace("\r\n", "\n");
@@ -62,11 +62,11 @@ public class TextParser {
body = body.replace(doubleQuotePattern, singleQuotePattern); body = body.replace(doubleQuotePattern, singleQuotePattern);
} }
PeekingIterator<Comment> iter = Iterators.peekingIterator(comments.iterator()); PeekingIterator<HumanComment> iter = Iterators.peekingIterator(comments.iterator());
MailComment currentComment = null; MailComment currentComment = null;
String lastEncounteredFileName = null; String lastEncounteredFileName = null;
Comment lastEncounteredComment = null; HumanComment lastEncounteredComment = null;
for (String line : Splitter.on('\n').split(body)) { for (String line : Splitter.on('\n').split(body)) {
if (line.equals(">")) { if (line.equals(">")) {
// Skip empty lines // Skip empty lines
@@ -89,7 +89,7 @@ public class TextParser {
if (!iter.hasNext()) { if (!iter.hasNext()) {
continue; continue;
} }
Comment perspectiveComment = iter.peek(); HumanComment perspectiveComment = iter.peek();
if (line.equals(ParserUtil.filePath(changeUrl, perspectiveComment))) { if (line.equals(ParserUtil.filePath(changeUrl, perspectiveComment))) {
if (lastEncounteredFileName == null if (lastEncounteredFileName == null
|| !lastEncounteredFileName.equals(perspectiveComment.key.filename)) { || !lastEncounteredFileName.equals(perspectiveComment.key.filename)) {

View File

@@ -28,6 +28,7 @@ import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.Patch; import com.google.gerrit.entities.Patch;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.RefNames; import com.google.gerrit.entities.RefNames;
@@ -116,7 +117,7 @@ public class CommentsUtil {
this.serverId = serverId; this.serverId = serverId;
} }
public Comment newComment( public HumanComment newHumanComment(
ChangeContext ctx, ChangeContext ctx,
String path, String path,
PatchSet.Id psId, PatchSet.Id psId,
@@ -132,15 +133,15 @@ public class CommentsUtil {
} else { } else {
// Inherit unresolved value from inReplyTo comment if not specified. // Inherit unresolved value from inReplyTo comment if not specified.
Comment.Key key = new Comment.Key(parentUuid, path, psId.get()); Comment.Key key = new Comment.Key(parentUuid, path, psId.get());
Optional<Comment> parent = getPublished(ctx.getNotes(), key); Optional<HumanComment> parent = getPublishedHumanComment(ctx.getNotes(), key);
if (!parent.isPresent()) { if (!parent.isPresent()) {
throw new UnprocessableEntityException("Invalid parentUuid supplied for comment"); throw new UnprocessableEntityException("Invalid parentUuid supplied for comment");
} }
unresolved = parent.get().unresolved; unresolved = parent.get().unresolved;
} }
} }
Comment c = HumanComment c =
new Comment( new HumanComment(
new Comment.Key(ChangeUtil.messageUuid(), path, psId.get()), new Comment.Key(ChangeUtil.messageUuid(), path, psId.get()),
ctx.getUser().getAccountId(), ctx.getUser().getAccountId(),
ctx.getWhen(), ctx.getWhen(),
@@ -175,19 +176,21 @@ public class CommentsUtil {
return c; return c;
} }
public Optional<Comment> getPublished(ChangeNotes notes, Comment.Key key) { public Optional<HumanComment> getPublishedHumanComment(ChangeNotes notes, Comment.Key key) {
return publishedByChange(notes).stream().filter(c -> key.equals(c.key)).findFirst(); return publishedHumanCommentsByChange(notes).stream()
.filter(c -> key.equals(c.key))
.findFirst();
} }
public Optional<Comment> getDraft(ChangeNotes notes, IdentifiedUser user, Comment.Key key) { public Optional<HumanComment> getDraft(ChangeNotes notes, IdentifiedUser user, Comment.Key key) {
return draftByChangeAuthor(notes, user.getAccountId()).stream() return draftByChangeAuthor(notes, user.getAccountId()).stream()
.filter(c -> key.equals(c.key)) .filter(c -> key.equals(c.key))
.findFirst(); .findFirst();
} }
public List<Comment> publishedByChange(ChangeNotes notes) { public List<HumanComment> publishedHumanCommentsByChange(ChangeNotes notes) {
notes.load(); notes.load();
return sort(Lists.newArrayList(notes.getComments().values())); return sort(Lists.newArrayList(notes.getHumanComments().values()));
} }
public List<RobotComment> robotCommentsByChange(ChangeNotes notes) { public List<RobotComment> robotCommentsByChange(ChangeNotes notes) {
@@ -195,8 +198,8 @@ public class CommentsUtil {
return sort(Lists.newArrayList(notes.getRobotComments().values())); return sort(Lists.newArrayList(notes.getRobotComments().values()));
} }
public List<Comment> draftByChange(ChangeNotes notes) { public List<HumanComment> draftByChange(ChangeNotes notes) {
List<Comment> comments = new ArrayList<>(); List<HumanComment> comments = new ArrayList<>();
for (Ref ref : getDraftRefs(notes.getChangeId())) { for (Ref ref : getDraftRefs(notes.getChangeId())) {
Account.Id account = Account.Id.fromRefSuffix(ref.getName()); Account.Id account = Account.Id.fromRefSuffix(ref.getName());
if (account != null) { if (account != null) {
@@ -206,8 +209,8 @@ public class CommentsUtil {
return sort(comments); return sort(comments);
} }
public List<Comment> byPatchSet(ChangeNotes notes, PatchSet.Id psId) { public List<HumanComment> byPatchSet(ChangeNotes notes, PatchSet.Id psId) {
List<Comment> comments = new ArrayList<>(); List<HumanComment> comments = new ArrayList<>();
comments.addAll(publishedByPatchSet(notes, psId)); comments.addAll(publishedByPatchSet(notes, psId));
for (Ref ref : getDraftRefs(notes.getChangeId())) { for (Ref ref : getDraftRefs(notes.getChangeId())) {
@@ -219,13 +222,13 @@ public class CommentsUtil {
return sort(comments); return sort(comments);
} }
public List<Comment> publishedByChangeFile(ChangeNotes notes, String file) { public List<HumanComment> publishedByChangeFile(ChangeNotes notes, String file) {
return commentsOnFile(notes.load().getComments().values(), file); return commentsOnFile(notes.load().getHumanComments().values(), file);
} }
public List<Comment> publishedByPatchSet(ChangeNotes notes, PatchSet.Id psId) { public List<HumanComment> publishedByPatchSet(ChangeNotes notes, PatchSet.Id psId) {
return removeCommentsOnAncestorOfCommitMessage( return removeCommentsOnAncestorOfCommitMessage(
commentsOnPatchSet(notes.load().getComments().values(), psId)); commentsOnPatchSet(notes.load().getHumanComments().values(), psId));
} }
public List<RobotComment> robotCommentsByPatchSet(ChangeNotes notes, PatchSet.Id psId) { public List<RobotComment> robotCommentsByPatchSet(ChangeNotes notes, PatchSet.Id psId) {
@@ -288,29 +291,31 @@ public class CommentsUtil {
* auto-merge was done. From that time there may still be comments on the auto-merge commit * auto-merge was done. From that time there may still be comments on the auto-merge commit
* message and those we want to filter out. * message and those we want to filter out.
*/ */
private List<Comment> removeCommentsOnAncestorOfCommitMessage(List<Comment> list) { private List<HumanComment> removeCommentsOnAncestorOfCommitMessage(List<HumanComment> list) {
return list.stream() return list.stream()
.filter(c -> c.side != 0 || !Patch.COMMIT_MSG.equals(c.key.filename)) .filter(c -> c.side != 0 || !Patch.COMMIT_MSG.equals(c.key.filename))
.collect(toList()); .collect(toList());
} }
public List<Comment> draftByPatchSetAuthor( public List<HumanComment> draftByPatchSetAuthor(
PatchSet.Id psId, Account.Id author, ChangeNotes notes) { PatchSet.Id psId, Account.Id author, ChangeNotes notes) {
return commentsOnPatchSet(notes.load().getDraftComments(author).values(), psId); return commentsOnPatchSet(notes.load().getDraftComments(author).values(), psId);
} }
public List<Comment> draftByChangeFileAuthor(ChangeNotes notes, String file, Account.Id author) { public List<HumanComment> draftByChangeFileAuthor(
ChangeNotes notes, String file, Account.Id author) {
return commentsOnFile(notes.load().getDraftComments(author).values(), file); return commentsOnFile(notes.load().getDraftComments(author).values(), file);
} }
public List<Comment> draftByChangeAuthor(ChangeNotes notes, Account.Id author) { public List<HumanComment> draftByChangeAuthor(ChangeNotes notes, Account.Id author) {
List<Comment> comments = new ArrayList<>(); List<HumanComment> comments = new ArrayList<>();
comments.addAll(notes.getDraftComments(author).values()); comments.addAll(notes.getDraftComments(author).values());
return sort(comments); return sort(comments);
} }
public void putComments(ChangeUpdate update, Comment.Status status, Iterable<Comment> comments) { public void putHumanComments(
for (Comment c : comments) { ChangeUpdate update, HumanComment.Status status, Iterable<HumanComment> comments) {
for (HumanComment c : comments) {
update.putComment(status, c); update.putComment(status, c);
} }
} }
@@ -321,8 +326,8 @@ public class CommentsUtil {
} }
} }
public void deleteComments(ChangeUpdate update, Iterable<Comment> comments) { public void deleteHumanComments(ChangeUpdate update, Iterable<HumanComment> comments) {
for (Comment c : comments) { for (HumanComment c : comments) {
update.deleteComment(c); update.deleteComment(c);
} }
} }
@@ -332,9 +337,10 @@ public class CommentsUtil {
update.deleteCommentByRewritingHistory(commentKey.uuid, newMessage); update.deleteCommentByRewritingHistory(commentKey.uuid, newMessage);
} }
private static List<Comment> commentsOnFile(Collection<Comment> allComments, String file) { private static List<HumanComment> commentsOnFile(
List<Comment> result = new ArrayList<>(allComments.size()); Collection<HumanComment> allComments, String file) {
for (Comment c : allComments) { List<HumanComment> result = new ArrayList<>(allComments.size());
for (HumanComment c : allComments) {
String currentFilename = c.key.filename; String currentFilename = c.key.filename;
if (currentFilename.equals(file)) { if (currentFilename.equals(file)) {
result.add(c); result.add(c);

View File

@@ -20,8 +20,7 @@ import static java.util.stream.Collectors.toSet;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.flogger.FluentLogger; import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.Comment.Status;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.exceptions.StorageException; import com.google.gerrit.exceptions.StorageException;
import com.google.gerrit.extensions.validators.CommentForValidation; import com.google.gerrit.extensions.validators.CommentForValidation;
@@ -60,7 +59,7 @@ public class PublishCommentUtil {
public void publish( public void publish(
ChangeContext ctx, ChangeContext ctx,
ChangeUpdate changeUpdate, ChangeUpdate changeUpdate,
Collection<Comment> draftComments, Collection<HumanComment> draftComments,
@Nullable String tag) { @Nullable String tag) {
ChangeNotes notes = ctx.getNotes(); ChangeNotes notes = ctx.getNotes();
checkArgument(notes != null); checkArgument(notes != null);
@@ -70,8 +69,8 @@ public class PublishCommentUtil {
Map<PatchSet.Id, PatchSet> patchSets = Map<PatchSet.Id, PatchSet> patchSets =
psUtil.getAsMap(notes, draftComments.stream().map(d -> psId(notes, d)).collect(toSet())); psUtil.getAsMap(notes, draftComments.stream().map(d -> psId(notes, d)).collect(toSet()));
Set<Comment> commentsToPublish = new HashSet<>(); Set<HumanComment> commentsToPublish = new HashSet<>();
for (Comment draftComment : draftComments) { for (HumanComment draftComment : draftComments) {
PatchSet.Id psIdOfDraftComment = psId(notes, draftComment); PatchSet.Id psIdOfDraftComment = psId(notes, draftComment);
PatchSet ps = patchSets.get(psIdOfDraftComment); PatchSet ps = patchSets.get(psIdOfDraftComment);
if (ps == null) { if (ps == null) {
@@ -109,10 +108,10 @@ public class PublishCommentUtil {
} }
commentsToPublish.add(draftComment); commentsToPublish.add(draftComment);
} }
commentsUtil.putComments(changeUpdate, Status.PUBLISHED, commentsToPublish); commentsUtil.putHumanComments(changeUpdate, HumanComment.Status.PUBLISHED, commentsToPublish);
} }
private static PatchSet.Id psId(ChangeNotes notes, Comment c) { private static PatchSet.Id psId(ChangeNotes notes, HumanComment c) {
return PatchSet.id(notes.getChangeId(), c.key.patchSetId); return PatchSet.id(notes.getChangeId(), c.key.patchSetId);
} }

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.server;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
import com.google.gerrit.exceptions.StorageException; import com.google.gerrit.exceptions.StorageException;
@@ -58,7 +58,7 @@ public class PublishCommentsOp implements BatchUpdateOp {
private final PatchSet.Id psId; private final PatchSet.Id psId;
private final PublishCommentUtil publishCommentUtil; private final PublishCommentUtil publishCommentUtil;
private List<Comment> comments = new ArrayList<>(); private List<HumanComment> comments = new ArrayList<>();
private ChangeMessage message; private ChangeMessage message;
private IdentifiedUser user; private IdentifiedUser user;

View File

@@ -20,7 +20,7 @@ import com.google.gerrit.extensions.api.changes.CommentApi;
import com.google.gerrit.extensions.api.changes.DeleteCommentInput; import com.google.gerrit.extensions.api.changes.DeleteCommentInput;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.server.change.CommentResource; import com.google.gerrit.server.change.HumanCommentResource;
import com.google.gerrit.server.restapi.change.DeleteComment; import com.google.gerrit.server.restapi.change.DeleteComment;
import com.google.gerrit.server.restapi.change.GetComment; import com.google.gerrit.server.restapi.change.GetComment;
import com.google.inject.Inject; import com.google.inject.Inject;
@@ -28,16 +28,16 @@ import com.google.inject.assistedinject.Assisted;
class CommentApiImpl implements CommentApi { class CommentApiImpl implements CommentApi {
interface Factory { interface Factory {
CommentApiImpl create(CommentResource c); CommentApiImpl create(HumanCommentResource c);
} }
private final GetComment getComment; private final GetComment getComment;
private final DeleteComment deleteComment; private final DeleteComment deleteComment;
private final CommentResource comment; private final HumanCommentResource comment;
@Inject @Inject
CommentApiImpl( CommentApiImpl(
GetComment getComment, DeleteComment deleteComment, @Assisted CommentResource comment) { GetComment getComment, DeleteComment deleteComment, @Assisted HumanCommentResource comment) {
this.getComment = getComment; this.getComment = getComment;
this.deleteComment = deleteComment; this.deleteComment = deleteComment;
this.comment = comment; this.comment = comment;

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.server.change; package com.google.gerrit.server.change;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.extensions.restapi.RestResource; import com.google.gerrit.extensions.restapi.RestResource;
import com.google.gerrit.extensions.restapi.RestView; import com.google.gerrit.extensions.restapi.RestView;
@@ -27,9 +27,9 @@ public class DraftCommentResource implements RestResource {
new TypeLiteral<RestView<DraftCommentResource>>() {}; new TypeLiteral<RestView<DraftCommentResource>>() {};
private final RevisionResource rev; private final RevisionResource rev;
private final Comment comment; private final HumanComment comment;
public DraftCommentResource(RevisionResource rev, Comment c) { public DraftCommentResource(RevisionResource rev, HumanComment c) {
this.rev = rev; this.rev = rev;
this.comment = c; this.comment = c;
} }
@@ -46,7 +46,7 @@ public class DraftCommentResource implements RestResource {
return rev.getPatchSet(); return rev.getPatchSet();
} }
public Comment getComment() { public HumanComment getComment() {
return comment; return comment;
} }

View File

@@ -65,7 +65,7 @@ public class EmailReviewComments implements Runnable, RequestContext {
PatchSet patchSet, PatchSet patchSet,
IdentifiedUser user, IdentifiedUser user,
ChangeMessage message, ChangeMessage message,
List<Comment> comments, List<? extends Comment> comments,
String patchSetComment, String patchSetComment,
List<LabelVote> labels, List<LabelVote> labels,
RepoView repoView); RepoView repoView);
@@ -82,7 +82,7 @@ public class EmailReviewComments implements Runnable, RequestContext {
private final PatchSet patchSet; private final PatchSet patchSet;
private final IdentifiedUser user; private final IdentifiedUser user;
private final ChangeMessage message; private final ChangeMessage message;
private final List<Comment> comments; private final List<? extends Comment> comments;
private final String patchSetComment; private final String patchSetComment;
private final List<LabelVote> labels; private final List<LabelVote> labels;
private final RepoView repoView; private final RepoView repoView;
@@ -99,7 +99,7 @@ public class EmailReviewComments implements Runnable, RequestContext {
@Assisted PatchSet patchSet, @Assisted PatchSet patchSet,
@Assisted IdentifiedUser user, @Assisted IdentifiedUser user,
@Assisted ChangeMessage message, @Assisted ChangeMessage message,
@Assisted List<Comment> comments, @Assisted List<? extends Comment> comments,
@Nullable @Assisted String patchSetComment, @Nullable @Assisted String patchSetComment,
@Assisted List<LabelVote> labels, @Assisted List<LabelVote> labels,
@Assisted RepoView repoView) { @Assisted RepoView repoView) {

View File

@@ -15,20 +15,20 @@
package com.google.gerrit.server.change; package com.google.gerrit.server.change;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.extensions.restapi.RestResource; import com.google.gerrit.extensions.restapi.RestResource;
import com.google.gerrit.extensions.restapi.RestView; import com.google.gerrit.extensions.restapi.RestView;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
public class CommentResource implements RestResource { public class HumanCommentResource implements RestResource {
public static final TypeLiteral<RestView<CommentResource>> COMMENT_KIND = public static final TypeLiteral<RestView<HumanCommentResource>> COMMENT_KIND =
new TypeLiteral<RestView<CommentResource>>() {}; new TypeLiteral<RestView<HumanCommentResource>>() {};
private final RevisionResource rev; private final RevisionResource rev;
private final Comment comment; private final HumanComment comment;
public CommentResource(RevisionResource rev, Comment c) { public HumanCommentResource(RevisionResource rev, HumanComment c) {
this.rev = rev; this.rev = rev;
this.comment = c; this.comment = c;
} }
@@ -37,7 +37,7 @@ public class CommentResource implements RestResource {
return rev.getPatchSet(); return rev.getPatchSet();
} }
public Comment getComment() { public HumanComment getComment() {
return comment; return comment;
} }

View File

@@ -28,7 +28,7 @@ import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.BranchNameKey; import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
import com.google.gerrit.entities.UserIdentity; import com.google.gerrit.entities.UserIdentity;
@@ -380,8 +380,8 @@ public class EventFactory {
} }
public void addPatchSetComments( public void addPatchSetComments(
PatchSetAttribute patchSetAttribute, Collection<Comment> comments) { PatchSetAttribute patchSetAttribute, Collection<HumanComment> comments) {
for (Comment comment : comments) { for (HumanComment comment : comments) {
if (comment.key.patchSetId == patchSetAttribute.number) { if (comment.key.patchSetId == patchSetAttribute.number) {
if (patchSetAttribute.comments == null) { if (patchSetAttribute.comments == null) {
patchSetAttribute.comments = new ArrayList<>(); patchSetAttribute.comments = new ArrayList<>();
@@ -547,7 +547,7 @@ public class EventFactory {
return a; return a;
} }
public PatchSetCommentAttribute asPatchSetLineAttribute(Comment c) { public PatchSetCommentAttribute asPatchSetLineAttribute(HumanComment c) {
PatchSetCommentAttribute a = new PatchSetCommentAttribute(); PatchSetCommentAttribute a = new PatchSetCommentAttribute();
a.reviewer = asAccountAttribute(c.author.getId()); a.reviewer = asAccountAttribute(c.author.getId());
a.file = c.key.filename; a.file = c.key.filename;

View File

@@ -69,7 +69,7 @@ import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.BooleanProjectConfig; import com.google.gerrit.entities.BooleanProjectConfig;
import com.google.gerrit.entities.BranchNameKey; import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetInfo; import com.google.gerrit.entities.PatchSetInfo;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
@@ -2022,7 +2022,7 @@ class ReceiveCommits {
} }
if (magicBranch != null && magicBranch.shouldPublishComments()) { if (magicBranch != null && magicBranch.shouldPublishComments()) {
List<Comment> drafts = List<HumanComment> drafts =
commentsUtil.draftByChangeAuthor( commentsUtil.draftByChangeAuthor(
notesFactory.createChecked(change), user.getAccountId()); notesFactory.createChecked(change), user.getAccountId());
ImmutableList<CommentForValidation> draftsForValidation = ImmutableList<CommentForValidation> draftsForValidation =

View File

@@ -45,7 +45,7 @@ public class CommentCountValidator implements CommentValidator {
ChangeNotes notes = ChangeNotes notes =
notesFactory.createChecked(Project.nameKey(ctx.getProject()), Change.id(ctx.getChangeId())); notesFactory.createChecked(Project.nameKey(ctx.getProject()), Change.id(ctx.getChangeId()));
int numExistingCommentsAndChangeMessages = int numExistingCommentsAndChangeMessages =
notes.getComments().size() notes.getHumanComments().size()
+ notes.getRobotComments().size() + notes.getRobotComments().size()
+ notes.getChangeMessages().size(); + notes.getChangeMessages().size();
if (!comments.isEmpty() if (!comments.isEmpty()

View File

@@ -51,7 +51,7 @@ public class CommentCumulativeSizeValidator implements CommentValidator {
notesFactory.createChecked(Project.nameKey(ctx.getProject()), Change.id(ctx.getChangeId())); notesFactory.createChecked(Project.nameKey(ctx.getProject()), Change.id(ctx.getChangeId()));
int existingCumulativeSize = int existingCumulativeSize =
Stream.concat( Stream.concat(
notes.getComments().values().stream(), notes.getHumanComments().values().stream(),
notes.getRobotComments().values().stream()) notes.getRobotComments().values().stream())
.mapToInt(Comment::getApproximateSize) .mapToInt(Comment::getApproximateSize)
.sum() .sum()

View File

@@ -24,7 +24,7 @@ import com.google.common.flogger.FluentLogger;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
import com.google.gerrit.exceptions.StorageException; import com.google.gerrit.exceptions.StorageException;
@@ -257,7 +257,7 @@ public class MailProcessor {
// Get all comments; filter and sort them to get the original list of // Get all comments; filter and sort them to get the original list of
// comments from the outbound email. // comments from the outbound email.
// TODO(hiesel) Also filter by original comment author. // TODO(hiesel) Also filter by original comment author.
Collection<Comment> comments = Collection<HumanComment> comments =
cd.publishedComments().stream() cd.publishedComments().stream()
.filter(c -> (c.writtenOn.getTime() / 1000) == (metadata.timestamp.getTime() / 1000)) .filter(c -> (c.writtenOn.getTime() / 1000) == (metadata.timestamp.getTime() / 1000))
.sorted(CommentsUtil.COMMENT_ORDER) .sorted(CommentsUtil.COMMENT_ORDER)
@@ -319,7 +319,7 @@ public class MailProcessor {
private final List<MailComment> parsedComments; private final List<MailComment> parsedComments;
private final String tag; private final String tag;
private ChangeMessage changeMessage; private ChangeMessage changeMessage;
private List<Comment> comments; private List<HumanComment> comments;
private PatchSet patchSet; private PatchSet patchSet;
private ChangeNotes notes; private ChangeNotes notes;
@@ -349,8 +349,10 @@ public class MailProcessor {
comments.add( comments.add(
persistentCommentFromMailComment(ctx, c, targetPatchSetForComment(ctx, c, patchSet))); persistentCommentFromMailComment(ctx, c, targetPatchSetForComment(ctx, c, patchSet)));
} }
commentsUtil.putComments( commentsUtil.putHumanComments(
ctx.getUpdate(ctx.getChange().currentPatchSetId()), Comment.Status.PUBLISHED, comments); ctx.getUpdate(ctx.getChange().currentPatchSetId()),
HumanComment.Status.PUBLISHED,
comments);
return true; return true;
} }
@@ -416,7 +418,7 @@ public class MailProcessor {
return current; return current;
} }
private Comment persistentCommentFromMailComment( private HumanComment persistentCommentFromMailComment(
ChangeContext ctx, MailComment mailComment, PatchSet patchSetForComment) ChangeContext ctx, MailComment mailComment, PatchSet patchSetForComment)
throws UnprocessableEntityException, PatchListNotAvailableException { throws UnprocessableEntityException, PatchListNotAvailableException {
String fileName; String fileName;
@@ -431,8 +433,8 @@ public class MailProcessor {
side = Side.REVISION; side = Side.REVISION;
} }
Comment comment = HumanComment comment =
commentsUtil.newComment( commentsUtil.newHumanComment(
ctx, ctx,
fileName, fileName,
patchSetForComment.id(), patchSetForComment.id(),

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.common.data.FilenameComparator;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.KeyUtil; import com.google.gerrit.entities.KeyUtil;
import com.google.gerrit.entities.Patch; import com.google.gerrit.entities.Patch;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
@@ -114,7 +115,7 @@ public class CommentSender extends ReplyToChangeSender {
} }
} }
private List<Comment> inlineComments = Collections.emptyList(); private List<? extends Comment> inlineComments = Collections.emptyList();
private String patchSetComment; private String patchSetComment;
private List<LabelVote> labels = Collections.emptyList(); private List<LabelVote> labels = Collections.emptyList();
private final CommentsUtil commentsUtil; private final CommentsUtil commentsUtil;
@@ -136,7 +137,7 @@ public class CommentSender extends ReplyToChangeSender {
this.replyToAddress = cfg.getString("sendemail", null, "replyToAddress"); this.replyToAddress = cfg.getString("sendemail", null, "replyToAddress");
} }
public void setComments(List<Comment> comments) { public void setComments(List<? extends Comment> comments) {
inlineComments = comments; inlineComments = comments;
} }
@@ -244,23 +245,21 @@ public class CommentSender extends ReplyToChangeSender {
/** Get the set of accounts whose comments have been replied to in this email. */ /** Get the set of accounts whose comments have been replied to in this email. */
private HashSet<Account.Id> getReplyAccounts() { private HashSet<Account.Id> getReplyAccounts() {
HashSet<Account.Id> replyAccounts = new HashSet<>(); HashSet<Account.Id> replyAccounts = new HashSet<>();
// Track visited parent UUIDs to avoid cycles. // Track visited parent UUIDs to avoid cycles.
HashSet<String> visitedUuids = new HashSet<>(); HashSet<String> visitedUuids = new HashSet<>();
for (Comment comment : inlineComments) { for (Comment comment : inlineComments) {
visitedUuids.add(comment.key.uuid); visitedUuids.add(comment.key.uuid);
// Traverse the parent relation to the top of the comment thread. // Traverse the parent relation to the top of the comment thread.
Comment current = comment; Comment current = comment;
while (current.parentUuid != null && !visitedUuids.contains(current.parentUuid)) { while (current.parentUuid != null && !visitedUuids.contains(current.parentUuid)) {
Optional<Comment> optParent = getParent(current); Optional<HumanComment> optParent = getParent(current);
if (!optParent.isPresent()) { if (!optParent.isPresent()) {
// There is a parent UUID, but it cannot be loaded, break from the comment thread. // There is a parent UUID, but it cannot be loaded, break from the comment thread.
break; break;
} }
Comment parent = optParent.get(); HumanComment parent = optParent.get();
replyAccounts.add(parent.author.getId()); replyAccounts.add(parent.author.getId());
visitedUuids.add(current.parentUuid); visitedUuids.add(current.parentUuid);
current = parent; current = parent;
@@ -307,14 +306,13 @@ public class CommentSender extends ReplyToChangeSender {
* @return an optional comment that will be present if the given comment has a parent, and is * @return an optional comment that will be present if the given comment has a parent, and is
* empty if it does not. * empty if it does not.
*/ */
private Optional<Comment> getParent(Comment child) { private Optional<HumanComment> getParent(Comment child) {
if (child.parentUuid == null) { if (child.parentUuid == null) {
return Optional.empty(); return Optional.empty();
} }
Comment.Key key = new Comment.Key(child.parentUuid, child.key.filename, child.key.patchSetId); Comment.Key key = new Comment.Key(child.parentUuid, child.key.filename, child.key.patchSetId);
try { try {
return commentsUtil.getPublished(changeData.notes(), key); return commentsUtil.getPublishedHumanComment(changeData.notes(), key);
} catch (StorageException e) { } catch (StorageException e) {
logger.atWarning().log("Could not find the parent of this comment: %s", child); logger.atWarning().log("Could not find the parent of this comment: %s", child);
return Optional.empty(); return Optional.empty();
@@ -448,7 +446,7 @@ public class CommentSender extends ReplyToChangeSender {
// If the comment has a quote, don't bother loading the parent message. // If the comment has a quote, don't bother loading the parent message.
if (!hasQuote(blocks)) { if (!hasQuote(blocks)) {
// Set parent comment info. // Set parent comment info.
Optional<Comment> parent = getParent(comment); Optional<HumanComment> parent = getParent(comment);
if (parent.isPresent()) { if (parent.isPresent()) {
commentData.put("parentMessage", getShortenedCommentMessage(parent.get())); commentData.put("parentMessage", getShortenedCommentMessage(parent.get()));
} }

View File

@@ -22,6 +22,7 @@ import com.google.auto.value.AutoValue;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RefNames; import com.google.gerrit.entities.RefNames;
import com.google.gerrit.exceptions.StorageException; import com.google.gerrit.exceptions.StorageException;
@@ -82,13 +83,13 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
FIXED FIXED
} }
private static Key key(Comment c) { private static Key key(HumanComment c) {
return new AutoValue_ChangeDraftUpdate_Key(c.getCommitId(), c.key); return new AutoValue_ChangeDraftUpdate_Key(c.getCommitId(), c.key);
} }
private final AllUsersName draftsProject; private final AllUsersName draftsProject;
private List<Comment> put = new ArrayList<>(); private List<HumanComment> put = new ArrayList<>();
private Map<Key, DeleteReason> delete = new HashMap<>(); private Map<Key, DeleteReason> delete = new HashMap<>();
@AssistedInject @AssistedInject
@@ -119,7 +120,7 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
this.draftsProject = allUsers; this.draftsProject = allUsers;
} }
public void putComment(Comment c) { public void putComment(HumanComment c) {
checkState(!put.contains(c), "comment already added"); checkState(!put.contains(c), "comment already added");
verifyComment(c); verifyComment(c);
put.add(c); put.add(c);
@@ -128,7 +129,7 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
/** /**
* Marks a comment for deletion. Called when the comment is deleted because the user published it. * Marks a comment for deletion. Called when the comment is deleted because the user published it.
*/ */
public void markCommentPublished(Comment c) { public void markCommentPublished(HumanComment c) {
checkState(!delete.containsKey(key(c)), "comment already marked for deletion"); checkState(!delete.containsKey(key(c)), "comment already marked for deletion");
verifyComment(c); verifyComment(c);
delete.put(key(c), DeleteReason.PUBLISHED); delete.put(key(c), DeleteReason.PUBLISHED);
@@ -137,7 +138,7 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
/** /**
* Marks a comment for deletion. Called when the comment is deleted because the user removed it. * Marks a comment for deletion. Called when the comment is deleted because the user removed it.
*/ */
public void deleteComment(Comment c) { public void deleteComment(HumanComment c) {
checkState(!delete.containsKey(key(c)), "comment already marked for deletion"); checkState(!delete.containsKey(key(c)), "comment already marked for deletion");
verifyComment(c); verifyComment(c);
delete.put(key(c), DeleteReason.DELETED); delete.put(key(c), DeleteReason.DELETED);
@@ -191,7 +192,7 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
RevisionNoteMap<ChangeRevisionNote> rnm = getRevisionNoteMap(rw, curr); RevisionNoteMap<ChangeRevisionNote> rnm = getRevisionNoteMap(rw, curr);
RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(rnm); RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(rnm);
for (Comment c : put) { for (HumanComment c : put) {
if (!delete.keySet().contains(key(c))) { if (!delete.keySet().contains(key(c))) {
cache.get(c.getCommitId()).putComment(c); cache.get(c.getCommitId()).putComment(c);
} }
@@ -259,7 +260,7 @@ public class ChangeDraftUpdate extends AbstractChangeUpdate {
// Even though reading from changes might not be enabled, we need to // Even though reading from changes might not be enabled, we need to
// parse any existing revision notes so we can merge them. // parse any existing revision notes so we can merge them.
return RevisionNoteMap.parse( return RevisionNoteMap.parse(
noteUtil.getChangeNoteJson(), rw.getObjectReader(), noteMap, Comment.Status.DRAFT); noteUtil.getChangeNoteJson(), rw.getObjectReader(), noteMap, HumanComment.Status.DRAFT);
} }
@Override @Override

View File

@@ -45,6 +45,7 @@ import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
@@ -435,14 +436,14 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
} }
/** @return inline comments on each revision. */ /** @return inline comments on each revision. */
public ImmutableListMultimap<ObjectId, Comment> getComments() { public ImmutableListMultimap<ObjectId, HumanComment> getHumanComments() {
return state.publishedComments(); return state.publishedComments();
} }
public ImmutableSet<Comment.Key> getCommentKeys() { public ImmutableSet<Comment.Key> getCommentKeys() {
if (commentKeys == null) { if (commentKeys == null) {
ImmutableSet.Builder<Comment.Key> b = ImmutableSet.builder(); ImmutableSet.Builder<Comment.Key> b = ImmutableSet.builder();
for (Comment c : getComments().values()) { for (Comment c : getHumanComments().values()) {
b.add(new Comment.Key(c.key)); b.add(new Comment.Key(c.key));
} }
commentKeys = b.build(); commentKeys = b.build();
@@ -454,11 +455,11 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
return state.updateCount(); return state.updateCount();
} }
public ImmutableListMultimap<ObjectId, Comment> getDraftComments(Account.Id author) { public ImmutableListMultimap<ObjectId, HumanComment> getDraftComments(Account.Id author) {
return getDraftComments(author, null); return getDraftComments(author, null);
} }
public ImmutableListMultimap<ObjectId, Comment> getDraftComments( public ImmutableListMultimap<ObjectId, HumanComment> getDraftComments(
Account.Id author, @Nullable Ref ref) { Account.Id author, @Nullable Ref ref) {
loadDraftComments(author, ref); loadDraftComments(author, ref);
// Filter out any zombie draft comments. These are drafts that are also in // Filter out any zombie draft comments. These are drafts that are also in
@@ -502,7 +503,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
return robotCommentNotes; return robotCommentNotes;
} }
public boolean containsComment(Comment c) { public boolean containsComment(HumanComment c) {
if (containsCommentPublished(c)) { if (containsCommentPublished(c)) {
return true; return true;
} }
@@ -511,7 +512,7 @@ public class ChangeNotes extends AbstractChangeNotes<ChangeNotes> {
} }
public boolean containsCommentPublished(Comment c) { public boolean containsCommentPublished(Comment c) {
for (Comment l : getComments().values()) { for (Comment l : getHumanComments().values()) {
if (c.key.equals(l.key)) { if (c.key.equals(l.key)) {
return true; return true;
} }

View File

@@ -61,7 +61,7 @@ import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.AttentionSetUpdate; import com.google.gerrit.entities.AttentionSetUpdate;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.LabelId; import com.google.gerrit.entities.LabelId;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
@@ -121,7 +121,7 @@ class ChangeNotesParser {
private final List<AssigneeStatusUpdate> assigneeUpdates; private final List<AssigneeStatusUpdate> assigneeUpdates;
private final List<SubmitRecord> submitRecords; private final List<SubmitRecord> submitRecords;
private final ListMultimap<ObjectId, Comment> comments; private final ListMultimap<ObjectId, HumanComment> humanComments;
private final Map<PatchSet.Id, PatchSet.Builder> patchSets; private final Map<PatchSet.Id, PatchSet.Builder> patchSets;
private final Set<PatchSet.Id> deletedPatchSets; private final Set<PatchSet.Id> deletedPatchSets;
private final Map<PatchSet.Id, PatchSetState> patchSetStates; private final Map<PatchSet.Id, PatchSetState> patchSetStates;
@@ -178,7 +178,7 @@ class ChangeNotesParser {
assigneeUpdates = new ArrayList<>(); assigneeUpdates = new ArrayList<>();
submitRecords = Lists.newArrayListWithExpectedSize(1); submitRecords = Lists.newArrayListWithExpectedSize(1);
allChangeMessages = new ArrayList<>(); allChangeMessages = new ArrayList<>();
comments = MultimapBuilder.hashKeys().arrayListValues().build(); humanComments = MultimapBuilder.hashKeys().arrayListValues().build();
patchSets = new HashMap<>(); patchSets = new HashMap<>();
deletedPatchSets = new HashSet<>(); deletedPatchSets = new HashSet<>();
patchSetStates = new HashMap<>(); patchSetStates = new HashMap<>();
@@ -249,7 +249,7 @@ class ChangeNotesParser {
assigneeUpdates, assigneeUpdates,
submitRecords, submitRecords,
buildAllMessages(), buildAllMessages(),
comments, humanComments,
firstNonNull(isPrivate, false), firstNonNull(isPrivate, false),
firstNonNull(workInProgress, false), firstNonNull(workInProgress, false),
firstNonNull(hasReviewStarted, true), firstNonNull(hasReviewStarted, true),
@@ -735,12 +735,12 @@ class ChangeNotesParser {
ChangeNotesCommit tipCommit = walk.parseCommit(tip); ChangeNotesCommit tipCommit = walk.parseCommit(tip);
revisionNoteMap = revisionNoteMap =
RevisionNoteMap.parse( RevisionNoteMap.parse(
changeNoteJson, reader, NoteMap.read(reader, tipCommit), Comment.Status.PUBLISHED); changeNoteJson, reader, NoteMap.read(reader, tipCommit), HumanComment.Status.PUBLISHED);
Map<ObjectId, ChangeRevisionNote> rns = revisionNoteMap.revisionNotes; Map<ObjectId, ChangeRevisionNote> rns = revisionNoteMap.revisionNotes;
for (Map.Entry<ObjectId, ChangeRevisionNote> e : rns.entrySet()) { for (Map.Entry<ObjectId, ChangeRevisionNote> e : rns.entrySet()) {
for (Comment c : e.getValue().getEntities()) { for (HumanComment c : e.getValue().getEntities()) {
comments.put(e.getKey(), c); humanComments.put(e.getKey(), c);
} }
} }
@@ -1055,7 +1055,7 @@ class ChangeNotesParser {
pruneEntitiesForMissingPatchSets(allChangeMessages, ChangeMessage::getPatchSetId, missing); pruneEntitiesForMissingPatchSets(allChangeMessages, ChangeMessage::getPatchSetId, missing);
pruned += pruned +=
pruneEntitiesForMissingPatchSets( pruneEntitiesForMissingPatchSets(
comments.values(), c -> PatchSet.id(id, c.key.patchSetId), missing); humanComments.values(), c -> PatchSet.id(id, c.key.patchSetId), missing);
pruned += pruned +=
pruneEntitiesForMissingPatchSets( pruneEntitiesForMissingPatchSets(
approvals.values(), psa -> psa.key().patchSetId(), missing); approvals.values(), psa -> psa.key().patchSetId(), missing);

View File

@@ -39,7 +39,7 @@ import com.google.gerrit.entities.AttentionSetUpdate;
import com.google.gerrit.entities.BranchNameKey; import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
@@ -123,7 +123,7 @@ public abstract class ChangeNotesState {
List<AssigneeStatusUpdate> assigneeUpdates, List<AssigneeStatusUpdate> assigneeUpdates,
List<SubmitRecord> submitRecords, List<SubmitRecord> submitRecords,
List<ChangeMessage> changeMessages, List<ChangeMessage> changeMessages,
ListMultimap<ObjectId, Comment> publishedComments, ListMultimap<ObjectId, HumanComment> publishedComments,
boolean isPrivate, boolean isPrivate,
boolean workInProgress, boolean workInProgress,
boolean reviewStarted, boolean reviewStarted,
@@ -314,7 +314,7 @@ public abstract class ChangeNotesState {
abstract ImmutableList<ChangeMessage> changeMessages(); abstract ImmutableList<ChangeMessage> changeMessages();
abstract ImmutableListMultimap<ObjectId, Comment> publishedComments(); abstract ImmutableListMultimap<ObjectId, HumanComment> publishedComments();
abstract int updateCount(); abstract int updateCount();
@@ -427,7 +427,7 @@ public abstract class ChangeNotesState {
abstract Builder changeMessages(List<ChangeMessage> changeMessages); abstract Builder changeMessages(List<ChangeMessage> changeMessages);
abstract Builder publishedComments(ListMultimap<ObjectId, Comment> publishedComments); abstract Builder publishedComments(ListMultimap<ObjectId, HumanComment> publishedComments);
abstract Builder updateCount(int updateCount); abstract Builder updateCount(int updateCount);
@@ -634,8 +634,8 @@ public abstract class ChangeNotesState {
.collect(toImmutableList())) .collect(toImmutableList()))
.publishedComments( .publishedComments(
proto.getPublishedCommentList().stream() proto.getPublishedCommentList().stream()
.map(r -> GSON.fromJson(r, Comment.class)) .map(r -> GSON.fromJson(r, HumanComment.class))
.collect(toImmutableListMultimap(Comment::getCommitId, c -> c))) .collect(toImmutableListMultimap(HumanComment::getCommitId, c -> c)))
.updateCount(proto.getUpdateCount()); .updateCount(proto.getUpdateCount());
return b.build(); return b.build();
} }

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.server.notedb;
import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.charset.StandardCharsets.UTF_8;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -29,13 +29,13 @@ import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.util.MutableInteger; import org.eclipse.jgit.util.MutableInteger;
/** Implements the parsing of comment data, handling JSON decoding and push certificates. */ /** Implements the parsing of comment data, handling JSON decoding and push certificates. */
class ChangeRevisionNote extends RevisionNote<Comment> { class ChangeRevisionNote extends RevisionNote<HumanComment> {
private final ChangeNoteJson noteJson; private final ChangeNoteJson noteJson;
private final Comment.Status status; private final HumanComment.Status status;
private String pushCert; private String pushCert;
ChangeRevisionNote( ChangeRevisionNote(
ChangeNoteJson noteJson, ObjectReader reader, ObjectId noteId, Comment.Status status) { ChangeNoteJson noteJson, ObjectReader reader, ObjectId noteId, HumanComment.Status status) {
super(reader, noteId); super(reader, noteId);
this.noteJson = noteJson; this.noteJson = noteJson;
this.status = status; this.status = status;
@@ -47,12 +47,13 @@ class ChangeRevisionNote extends RevisionNote<Comment> {
} }
@Override @Override
protected List<Comment> parse(byte[] raw, int offset) throws IOException, ConfigInvalidException { protected List<HumanComment> parse(byte[] raw, int offset)
throws IOException, ConfigInvalidException {
MutableInteger p = new MutableInteger(); MutableInteger p = new MutableInteger();
p.value = offset; p.value = offset;
RevisionNoteData data = parseJson(noteJson, raw, p.value); HumanCommentsRevisionNoteData data = parseJson(noteJson, raw, p.value);
if (status == Comment.Status.PUBLISHED) { if (status == HumanComment.Status.PUBLISHED) {
pushCert = data.pushCert; pushCert = data.pushCert;
} else { } else {
pushCert = null; pushCert = null;
@@ -60,11 +61,11 @@ class ChangeRevisionNote extends RevisionNote<Comment> {
return data.comments; return data.comments;
} }
private RevisionNoteData parseJson(ChangeNoteJson noteUtil, byte[] raw, int offset) private HumanCommentsRevisionNoteData parseJson(ChangeNoteJson noteUtil, byte[] raw, int offset)
throws IOException { throws IOException {
try (InputStream is = new ByteArrayInputStream(raw, offset, raw.length - offset); try (InputStream is = new ByteArrayInputStream(raw, offset, raw.length - offset);
Reader r = new InputStreamReader(is, UTF_8)) { Reader r = new InputStreamReader(is, UTF_8)) {
return noteUtil.getGson().fromJson(r, RevisionNoteData.class); return noteUtil.getGson().fromJson(r, HumanCommentsRevisionNoteData.class);
} }
} }
} }

View File

@@ -58,6 +58,7 @@ import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.AttentionSetUpdate; import com.google.gerrit.entities.AttentionSetUpdate;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
import com.google.gerrit.entities.RobotComment; import com.google.gerrit.entities.RobotComment;
import com.google.gerrit.entities.SubmissionId; import com.google.gerrit.entities.SubmissionId;
@@ -122,7 +123,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
private final Table<String, Account.Id, Optional<Short>> approvals; private final Table<String, Account.Id, Optional<Short>> approvals;
private final Map<Account.Id, ReviewerStateInternal> reviewers = new LinkedHashMap<>(); private final Map<Account.Id, ReviewerStateInternal> reviewers = new LinkedHashMap<>();
private final Map<Address, ReviewerStateInternal> reviewersByEmail = new LinkedHashMap<>(); private final Map<Address, ReviewerStateInternal> reviewersByEmail = new LinkedHashMap<>();
private final List<Comment> comments = new ArrayList<>(); private final List<HumanComment> comments = new ArrayList<>();
private String commitSubject; private String commitSubject;
private String subject; private String subject;
@@ -289,10 +290,10 @@ public class ChangeUpdate extends AbstractChangeUpdate {
this.psDescription = psDescription; this.psDescription = psDescription;
} }
public void putComment(Comment.Status status, Comment c) { public void putComment(HumanComment.Status status, HumanComment c) {
verifyComment(c); verifyComment(c);
createDraftUpdateIfNull(); createDraftUpdateIfNull();
if (status == Comment.Status.DRAFT) { if (status == HumanComment.Status.DRAFT) {
draftUpdate.putComment(c); draftUpdate.putComment(c);
} else { } else {
comments.add(c); comments.add(c);
@@ -306,7 +307,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
robotCommentUpdate.putComment(c); robotCommentUpdate.putComment(c);
} }
public void deleteComment(Comment c) { public void deleteComment(HumanComment c) {
verifyComment(c); verifyComment(c);
createDraftUpdateIfNull().deleteComment(c); createDraftUpdateIfNull().deleteComment(c);
} }
@@ -475,7 +476,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
RevisionNoteMap<ChangeRevisionNote> rnm = getRevisionNoteMap(rw, curr); RevisionNoteMap<ChangeRevisionNote> rnm = getRevisionNoteMap(rw, curr);
RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(rnm); RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(rnm);
for (Comment c : comments) { for (HumanComment c : comments) {
c.tag = tag; c.tag = tag;
cache.get(c.getCommitId()).putComment(c); cache.get(c.getCommitId()).putComment(c);
} }
@@ -512,7 +513,7 @@ public class ChangeUpdate extends AbstractChangeUpdate {
// Even though reading from changes might not be enabled, we need to // Even though reading from changes might not be enabled, we need to
// parse any existing revision notes so we can merge them. // parse any existing revision notes so we can merge them.
return RevisionNoteMap.parse( return RevisionNoteMap.parse(
noteUtil.getChangeNoteJson(), rw.getObjectReader(), noteMap, Comment.Status.PUBLISHED); noteUtil.getChangeNoteJson(), rw.getObjectReader(), noteMap, HumanComment.Status.PUBLISHED);
} }
private void checkComments( private void checkComments(

View File

@@ -15,14 +15,13 @@
package com.google.gerrit.server.notedb; package com.google.gerrit.server.notedb;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.gerrit.entities.Comment.Status;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap; import static java.util.stream.Collectors.toMap;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.RefNames; import com.google.gerrit.entities.RefNames;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
@@ -94,14 +93,14 @@ public class DeleteCommentRewriter implements NoteDbRewriter {
ObjectReader reader = revWalk.getObjectReader(); ObjectReader reader = revWalk.getObjectReader();
RevCommit newTipCommit = revWalk.next(); // The first commit will not be rewritten. RevCommit newTipCommit = revWalk.next(); // The first commit will not be rewritten.
Map<String, Comment> parentComments = Map<String, HumanComment> parentComments =
getPublishedComments(noteUtil, reader, NoteMap.read(reader, newTipCommit)); getPublishedComments(noteUtil, reader, NoteMap.read(reader, newTipCommit));
boolean rewrite = false; boolean rewrite = false;
RevCommit originalCommit; RevCommit originalCommit;
while ((originalCommit = revWalk.next()) != null) { while ((originalCommit = revWalk.next()) != null) {
NoteMap noteMap = NoteMap.read(reader, originalCommit); NoteMap noteMap = NoteMap.read(reader, originalCommit);
Map<String, Comment> currComments = getPublishedComments(noteUtil, reader, noteMap); Map<String, HumanComment> currComments = getPublishedComments(noteUtil, reader, noteMap);
if (!rewrite && currComments.containsKey(uuid)) { if (!rewrite && currComments.containsKey(uuid)) {
rewrite = true; rewrite = true;
@@ -113,8 +112,8 @@ public class DeleteCommentRewriter implements NoteDbRewriter {
continue; continue;
} }
List<Comment> putInComments = getPutInComments(parentComments, currComments); List<HumanComment> putInComments = getPutInComments(parentComments, currComments);
List<Comment> deletedComments = getDeletedComments(parentComments, currComments); List<HumanComment> deletedComments = getDeletedComments(parentComments, currComments);
newTipCommit = newTipCommit =
revWalk.parseCommit( revWalk.parseCommit(
rewriteCommit( rewriteCommit(
@@ -130,16 +129,16 @@ public class DeleteCommentRewriter implements NoteDbRewriter {
* the previous commits. * the previous commits.
*/ */
@VisibleForTesting @VisibleForTesting
public static Map<String, Comment> getPublishedComments( public static Map<String, HumanComment> getPublishedComments(
ChangeNoteJson changeNoteJson, ObjectReader reader, NoteMap noteMap) ChangeNoteJson changeNoteJson, ObjectReader reader, NoteMap noteMap)
throws IOException, ConfigInvalidException { throws IOException, ConfigInvalidException {
return RevisionNoteMap.parse(changeNoteJson, reader, noteMap, Status.PUBLISHED).revisionNotes return RevisionNoteMap.parse(changeNoteJson, reader, noteMap, HumanComment.Status.PUBLISHED)
.values().stream() .revisionNotes.values().stream()
.flatMap(n -> n.getEntities().stream()) .flatMap(n -> n.getEntities().stream())
.collect(toMap(c -> c.key.uuid, Function.identity())); .collect(toMap(c -> c.key.uuid, Function.identity()));
} }
public static Map<String, Comment> getPublishedComments( public static Map<String, HumanComment> getPublishedComments(
ChangeNoteUtil noteUtil, ObjectReader reader, NoteMap noteMap) ChangeNoteUtil noteUtil, ObjectReader reader, NoteMap noteMap)
throws IOException, ConfigInvalidException { throws IOException, ConfigInvalidException {
return getPublishedComments(noteUtil.getChangeNoteJson(), reader, noteMap); return getPublishedComments(noteUtil.getChangeNoteJson(), reader, noteMap);
@@ -152,11 +151,12 @@ public class DeleteCommentRewriter implements NoteDbRewriter {
* @param curMap the comment map of the current commit. * @param curMap the comment map of the current commit.
* @return The comments put in by the current commit. * @return The comments put in by the current commit.
*/ */
private List<Comment> getPutInComments(Map<String, Comment> parMap, Map<String, Comment> curMap) { private List<HumanComment> getPutInComments(
List<Comment> comments = new ArrayList<>(); Map<String, HumanComment> parMap, Map<String, HumanComment> curMap) {
List<HumanComment> comments = new ArrayList<>();
for (String key : curMap.keySet()) { for (String key : curMap.keySet()) {
if (!parMap.containsKey(key)) { if (!parMap.containsKey(key)) {
Comment comment = curMap.get(key); HumanComment comment = curMap.get(key);
if (key.equals(uuid)) { if (key.equals(uuid)) {
comment.message = newMessage; comment.message = newMessage;
} }
@@ -173,8 +173,8 @@ public class DeleteCommentRewriter implements NoteDbRewriter {
* @param curMap the comment map of the current commit. * @param curMap the comment map of the current commit.
* @return The comments deleted by the current commit. * @return The comments deleted by the current commit.
*/ */
private List<Comment> getDeletedComments( private List<HumanComment> getDeletedComments(
Map<String, Comment> parMap, Map<String, Comment> curMap) { Map<String, HumanComment> parMap, Map<String, HumanComment> curMap) {
return parMap.entrySet().stream() return parMap.entrySet().stream()
.filter(c -> !curMap.containsKey(c.getKey())) .filter(c -> !curMap.containsKey(c.getKey()))
.map(Map.Entry::getValue) .map(Map.Entry::getValue)
@@ -199,22 +199,22 @@ public class DeleteCommentRewriter implements NoteDbRewriter {
RevCommit parentCommit, RevCommit parentCommit,
ObjectInserter inserter, ObjectInserter inserter,
ObjectReader reader, ObjectReader reader,
List<Comment> putInComments, List<HumanComment> putInComments,
List<Comment> deletedComments) List<HumanComment> deletedComments)
throws IOException, ConfigInvalidException { throws IOException, ConfigInvalidException {
RevisionNoteMap<ChangeRevisionNote> revNotesMap = RevisionNoteMap<ChangeRevisionNote> revNotesMap =
RevisionNoteMap.parse( RevisionNoteMap.parse(
noteUtil.getChangeNoteJson(), noteUtil.getChangeNoteJson(),
reader, reader,
NoteMap.read(reader, parentCommit), NoteMap.read(reader, parentCommit),
Status.PUBLISHED); HumanComment.Status.PUBLISHED);
RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(revNotesMap); RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(revNotesMap);
for (Comment c : putInComments) { for (HumanComment c : putInComments) {
cache.get(c.getCommitId()).putComment(c); cache.get(c.getCommitId()).putComment(c);
} }
for (Comment c : deletedComments) { for (HumanComment c : deletedComments) {
cache.get(c.getCommitId()).deleteComment(c.key); cache.get(c.getCommitId()).deleteComment(c.key);
} }

View File

@@ -26,7 +26,7 @@ import com.google.common.flogger.FluentLogger;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject; import com.google.inject.assistedinject.AssistedInject;
@@ -50,7 +50,7 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
private final Account.Id author; private final Account.Id author;
private final Ref ref; private final Ref ref;
private ImmutableListMultimap<ObjectId, Comment> comments; private ImmutableListMultimap<ObjectId, HumanComment> comments;
private RevisionNoteMap<ChangeRevisionNote> revisionNoteMap; private RevisionNoteMap<ChangeRevisionNote> revisionNoteMap;
@AssistedInject @AssistedInject
@@ -80,12 +80,12 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
return author; return author;
} }
public ImmutableListMultimap<ObjectId, Comment> getComments() { public ImmutableListMultimap<ObjectId, HumanComment> getComments() {
return comments; return comments;
} }
public boolean containsComment(Comment c) { public boolean containsComment(HumanComment c) {
for (Comment existing : comments.values()) { for (HumanComment existing : comments.values()) {
if (c.key.equals(existing.key)) { if (c.key.equals(existing.key)) {
return true; return true;
} }
@@ -120,10 +120,13 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
ObjectReader reader = handle.walk().getObjectReader(); ObjectReader reader = handle.walk().getObjectReader();
revisionNoteMap = revisionNoteMap =
RevisionNoteMap.parse( RevisionNoteMap.parse(
args.changeNoteJson, reader, NoteMap.read(reader, tipCommit), Comment.Status.DRAFT); args.changeNoteJson,
ListMultimap<ObjectId, Comment> cs = MultimapBuilder.hashKeys().arrayListValues().build(); reader,
NoteMap.read(reader, tipCommit),
HumanComment.Status.DRAFT);
ListMultimap<ObjectId, HumanComment> cs = MultimapBuilder.hashKeys().arrayListValues().build();
for (ChangeRevisionNote rn : revisionNoteMap.revisionNotes.values()) { for (ChangeRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
for (Comment c : rn.getEntities()) { for (HumanComment c : rn.getEntities()) {
cs.put(c.getCommitId(), c); cs.put(c.getCommitId(), c);
} }
} }

View File

@@ -0,0 +1,28 @@
// Copyright (C) 2020 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.notedb;
import com.google.gerrit.entities.HumanComment;
import java.util.List;
/**
* Holds the raw data of a RevisionNote.
*
* <p>It is intended for deserialization from JSON only. It is used for human comments only.
*/
class HumanCommentsRevisionNoteData {
String pushCert;
List<HumanComment> comments;
}

View File

@@ -20,7 +20,8 @@ import java.util.List;
/** /**
* Holds the raw data of a RevisionNote. * Holds the raw data of a RevisionNote.
* *
* <p>It is intended for (de)serialization to JSON only. * <p>It is intended for serialization to JSON only. It is used for human comments and robot
* comments.
*/ */
class RevisionNoteData { class RevisionNoteData {
String pushCert; String pushCert;

View File

@@ -16,6 +16,7 @@ package com.google.gerrit.server.notedb;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import java.io.IOException; import java.io.IOException;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
@@ -41,7 +42,7 @@ class RevisionNoteMap<T extends RevisionNote<? extends Comment>> {
} }
static RevisionNoteMap<ChangeRevisionNote> parse( static RevisionNoteMap<ChangeRevisionNote> parse(
ChangeNoteJson noteJson, ObjectReader reader, NoteMap noteMap, Comment.Status status) ChangeNoteJson noteJson, ObjectReader reader, NoteMap noteMap, HumanComment.Status status)
throws ConfigInvalidException, IOException { throws ConfigInvalidException, IOException {
ImmutableMap.Builder<ObjectId, ChangeRevisionNote> result = ImmutableMap.builder(); ImmutableMap.Builder<ObjectId, ChangeRevisionNote> result = ImmutableMap.builder();
for (Note note : noteMap) { for (Note note : noteMap) {

View File

@@ -26,7 +26,11 @@ import java.util.List;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectReader; import org.eclipse.jgit.lib.ObjectReader;
/** Like {@link RevisionNote} but for robot comments. */ /**
* Holds the raw data of a RevisionNote.
*
* <p>It is intended for deserialization from JSON only. It is used for robot comments only.
*/
public class RobotCommentsRevisionNote extends RevisionNote<RobotComment> { public class RobotCommentsRevisionNote extends RevisionNote<RobotComment> {
private final ChangeNoteJson noteUtil; private final ChangeNoteJson noteUtil;

View File

@@ -24,7 +24,7 @@ import com.google.gerrit.common.data.CommentDetail;
import com.google.gerrit.common.data.PatchScript; import com.google.gerrit.common.data.PatchScript;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.Patch.ChangeType; import com.google.gerrit.entities.Patch.ChangeType;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
@@ -381,13 +381,13 @@ public class PatchScriptFactory implements Callable<PatchScript> {
} }
private void loadPublished(String file) { private void loadPublished(String file) {
for (Comment c : commentsUtil.publishedByChangeFile(notes, file)) { for (HumanComment c : commentsUtil.publishedByChangeFile(notes, file)) {
comments.include(notes.getChangeId(), c); comments.include(notes.getChangeId(), c);
} }
} }
private void loadDrafts(Account.Id me, String file) { private void loadDrafts(Account.Id me, String file) {
for (Comment c : commentsUtil.draftByChangeFileAuthor(notes, file, me)) { for (HumanComment c : commentsUtil.draftByChangeFileAuthor(notes, file, me)) {
comments.include(notes.getChangeId(), c); comments.include(notes.getChangeId(), c);
} }
} }

View File

@@ -41,6 +41,7 @@ import com.google.gerrit.entities.AttentionSetUpdate;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
@@ -277,7 +278,7 @@ public class ChangeData {
private List<PatchSetApproval> currentApprovals; private List<PatchSetApproval> currentApprovals;
private List<String> currentFiles; private List<String> currentFiles;
private Optional<DiffSummary> diffSummary; private Optional<DiffSummary> diffSummary;
private Collection<Comment> publishedComments; private Collection<HumanComment> publishedComments;
private Collection<RobotComment> robotComments; private Collection<RobotComment> robotComments;
private CurrentUser visibleTo; private CurrentUser visibleTo;
private List<ChangeMessage> messages; private List<ChangeMessage> messages;
@@ -760,12 +761,12 @@ public class ChangeData {
return reviewerUpdates; return reviewerUpdates;
} }
public Collection<Comment> publishedComments() { public Collection<HumanComment> publishedComments() {
if (publishedComments == null) { if (publishedComments == null) {
if (!lazyLoad) { if (!lazyLoad) {
return Collections.emptyList(); return Collections.emptyList();
} }
publishedComments = commentsUtil.publishedByChange(notes()); publishedComments = commentsUtil.publishedHumanCommentsByChange(notes());
} }
return publishedComments; return publishedComments;
} }

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.server.query.change;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.server.index.change.ChangeField; import com.google.gerrit.server.index.change.ChangeField;
import java.util.Objects; import java.util.Objects;
@@ -39,7 +39,7 @@ public class CommentByPredicate extends ChangeIndexPredicate {
return true; return true;
} }
} }
for (Comment c : cd.publishedComments()) { for (HumanComment c : cd.publishedComments()) {
if (Objects.equals(c.author.getId(), id)) { if (Objects.equals(c.author.getId(), id)) {
return true; return true;
} }

View File

@@ -22,7 +22,7 @@ import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput; import com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput;
@@ -48,7 +48,7 @@ import com.google.gerrit.server.query.change.ChangeQueryBuilder;
import com.google.gerrit.server.query.change.HasDraftByPredicate; import com.google.gerrit.server.query.change.HasDraftByPredicate;
import com.google.gerrit.server.query.change.InternalChangeQuery; import com.google.gerrit.server.query.change.InternalChangeQuery;
import com.google.gerrit.server.restapi.change.CommentJson; import com.google.gerrit.server.restapi.change.CommentJson;
import com.google.gerrit.server.restapi.change.CommentJson.CommentFormatter; import com.google.gerrit.server.restapi.change.CommentJson.HumanCommentFormatter;
import com.google.gerrit.server.update.BatchUpdate; import com.google.gerrit.server.update.BatchUpdate;
import com.google.gerrit.server.update.BatchUpdate.Factory; import com.google.gerrit.server.update.BatchUpdate.Factory;
import com.google.gerrit.server.update.BatchUpdateListener; import com.google.gerrit.server.update.BatchUpdateListener;
@@ -123,7 +123,8 @@ public class DeleteDraftComments
throw new AuthException("Cannot delete drafts of other user"); throw new AuthException("Cannot delete drafts of other user");
} }
CommentFormatter commentFormatter = commentJsonProvider.get().newCommentFormatter(); HumanCommentFormatter humanCommentFormatter =
commentJsonProvider.get().newHumanCommentFormatter();
Account.Id accountId = rsrc.getUser().getAccountId(); Account.Id accountId = rsrc.getUser().getAccountId();
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Map<Project.NameKey, BatchUpdate> updates = new LinkedHashMap<>(); Map<Project.NameKey, BatchUpdate> updates = new LinkedHashMap<>();
@@ -137,7 +138,7 @@ public class DeleteDraftComments
BatchUpdate update = BatchUpdate update =
updates.computeIfAbsent( updates.computeIfAbsent(
cd.project(), p -> batchUpdateFactory.create(p, rsrc.getUser(), now)); cd.project(), p -> batchUpdateFactory.create(p, rsrc.getUser(), now));
Op op = new Op(commentFormatter, accountId); Op op = new Op(humanCommentFormatter, accountId);
update.addOp(cd.getId(), op); update.addOp(cd.getId(), op);
ops.add(op); ops.add(op);
} }
@@ -165,12 +166,12 @@ public class DeleteDraftComments
} }
private class Op implements BatchUpdateOp { private class Op implements BatchUpdateOp {
private final CommentFormatter commentFormatter; private final HumanCommentFormatter humanCommentFormatter;
private final Account.Id accountId; private final Account.Id accountId;
private DeletedDraftCommentInfo result; private DeletedDraftCommentInfo result;
Op(CommentFormatter commentFormatter, Account.Id accountId) { Op(HumanCommentFormatter humanCommentFormatter, Account.Id accountId) {
this.commentFormatter = commentFormatter; this.humanCommentFormatter = humanCommentFormatter;
this.accountId = accountId; this.accountId = accountId;
} }
@@ -179,12 +180,12 @@ public class DeleteDraftComments
throws PatchListNotAvailableException, PermissionBackendException { throws PatchListNotAvailableException, PermissionBackendException {
ImmutableList.Builder<CommentInfo> comments = ImmutableList.builder(); ImmutableList.Builder<CommentInfo> comments = ImmutableList.builder();
boolean dirty = false; boolean dirty = false;
for (Comment c : commentsUtil.draftByChangeAuthor(ctx.getNotes(), accountId)) { for (HumanComment c : commentsUtil.draftByChangeAuthor(ctx.getNotes(), accountId)) {
dirty = true; dirty = true;
PatchSet.Id psId = PatchSet.id(ctx.getChange().getId(), c.key.patchSetId); PatchSet.Id psId = PatchSet.id(ctx.getChange().getId(), c.key.patchSetId);
setCommentCommitId(c, patchListCache, ctx.getChange(), psUtil.get(ctx.getNotes(), psId)); setCommentCommitId(c, patchListCache, ctx.getChange(), psUtil.get(ctx.getNotes(), psId));
commentsUtil.deleteComments(ctx.getUpdate(psId), Collections.singleton(c)); commentsUtil.deleteHumanComments(ctx.getUpdate(psId), Collections.singleton(c));
comments.add(commentFormatter.format(c)); comments.add(humanCommentFormatter.format(c));
} }
if (dirty) { if (dirty) {
result = new DeletedDraftCommentInfo(); result = new DeletedDraftCommentInfo();

View File

@@ -25,6 +25,7 @@ import com.google.gerrit.common.Nullable;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.FixReplacement; import com.google.gerrit.entities.FixReplacement;
import com.google.gerrit.entities.FixSuggestion; import com.google.gerrit.entities.FixSuggestion;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.RobotComment; import com.google.gerrit.entities.RobotComment;
import com.google.gerrit.extensions.client.Comment.Range; import com.google.gerrit.extensions.client.Comment.Range;
import com.google.gerrit.extensions.client.Side; import com.google.gerrit.extensions.client.Side;
@@ -63,8 +64,8 @@ public class CommentJson {
return this; return this;
} }
public CommentFormatter newCommentFormatter() { public HumanCommentFormatter newHumanCommentFormatter() {
return new CommentFormatter(); return new HumanCommentFormatter();
} }
public RobotCommentFormatter newRobotCommentFormatter() { public RobotCommentFormatter newRobotCommentFormatter() {
@@ -161,15 +162,15 @@ public class CommentJson {
} }
} }
public class CommentFormatter extends BaseCommentFormatter<Comment, CommentInfo> { public class HumanCommentFormatter extends BaseCommentFormatter<HumanComment, CommentInfo> {
@Override @Override
protected CommentInfo toInfo(Comment c, AccountLoader loader) { protected CommentInfo toInfo(HumanComment c, AccountLoader loader) {
CommentInfo ci = new CommentInfo(); CommentInfo ci = new CommentInfo();
fillCommentInfo(c, ci, loader); fillCommentInfo(c, ci, loader);
return ci; return ci;
} }
private CommentFormatter() {} private HumanCommentFormatter() {}
} }
class RobotCommentFormatter extends BaseCommentFormatter<RobotComment, RobotCommentInfo> { class RobotCommentFormatter extends BaseCommentFormatter<RobotComment, RobotCommentInfo> {

View File

@@ -14,28 +14,28 @@
package com.google.gerrit.server.restapi.change; package com.google.gerrit.server.restapi.change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.ChildCollection; import com.google.gerrit.extensions.restapi.ChildCollection;
import com.google.gerrit.extensions.restapi.IdString; import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException; import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestView; import com.google.gerrit.extensions.restapi.RestView;
import com.google.gerrit.server.CommentsUtil; import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.change.CommentResource; import com.google.gerrit.server.change.HumanCommentResource;
import com.google.gerrit.server.change.RevisionResource; import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.notedb.ChangeNotes; import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@Singleton @Singleton
public class Comments implements ChildCollection<RevisionResource, CommentResource> { public class Comments implements ChildCollection<RevisionResource, HumanCommentResource> {
private final DynamicMap<RestView<CommentResource>> views; private final DynamicMap<RestView<HumanCommentResource>> views;
private final ListRevisionComments list; private final ListRevisionComments list;
private final CommentsUtil commentsUtil; private final CommentsUtil commentsUtil;
@Inject @Inject
Comments( Comments(
DynamicMap<RestView<CommentResource>> views, DynamicMap<RestView<HumanCommentResource>> views,
ListRevisionComments list, ListRevisionComments list,
CommentsUtil commentsUtil) { CommentsUtil commentsUtil) {
this.views = views; this.views = views;
@@ -44,7 +44,7 @@ public class Comments implements ChildCollection<RevisionResource, CommentResour
} }
@Override @Override
public DynamicMap<RestView<CommentResource>> views() { public DynamicMap<RestView<HumanCommentResource>> views() {
return views; return views;
} }
@@ -54,13 +54,14 @@ public class Comments implements ChildCollection<RevisionResource, CommentResour
} }
@Override @Override
public CommentResource parse(RevisionResource rev, IdString id) throws ResourceNotFoundException { public HumanCommentResource parse(RevisionResource rev, IdString id)
throws ResourceNotFoundException {
String uuid = id.get(); String uuid = id.get();
ChangeNotes notes = rev.getNotes(); ChangeNotes notes = rev.getNotes();
for (Comment c : commentsUtil.publishedByPatchSet(notes, rev.getPatchSet().id())) { for (HumanComment c : commentsUtil.publishedByPatchSet(notes, rev.getPatchSet().id())) {
if (uuid.equals(c.key.uuid)) { if (uuid.equals(c.key.uuid)) {
return new CommentResource(rev, c); return new HumanCommentResource(rev, c);
} }
} }
throw new ResourceNotFoundException(id); throw new ResourceNotFoundException(id);

View File

@@ -18,7 +18,7 @@ import static com.google.gerrit.entities.Patch.PATCHSET_LEVEL;
import static com.google.gerrit.server.CommentsUtil.setCommentCommitId; import static com.google.gerrit.server.CommentsUtil.setCommentCommitId;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.extensions.api.changes.DraftInput; import com.google.gerrit.extensions.api.changes.DraftInput;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
@@ -89,7 +89,7 @@ public class CreateDraftComment implements RestModifyView<RevisionResource, Draf
bu.addOp(rsrc.getChange().getId(), op); bu.addOp(rsrc.getChange().getId(), op);
bu.execute(); bu.execute();
return Response.created( return Response.created(
commentJson.get().setFillAccounts(false).newCommentFormatter().format(op.comment)); commentJson.get().setFillAccounts(false).newHumanCommentFormatter().format(op.comment));
} }
} }
@@ -97,7 +97,7 @@ public class CreateDraftComment implements RestModifyView<RevisionResource, Draf
private final PatchSet.Id psId; private final PatchSet.Id psId;
private final DraftInput in; private final DraftInput in;
private Comment comment; private HumanComment comment;
private Op(PatchSet.Id psId, DraftInput in) { private Op(PatchSet.Id psId, DraftInput in) {
this.psId = psId; this.psId = psId;
@@ -115,15 +115,15 @@ public class CreateDraftComment implements RestModifyView<RevisionResource, Draf
String parentUuid = Url.decode(in.inReplyTo); String parentUuid = Url.decode(in.inReplyTo);
comment = comment =
commentsUtil.newComment( commentsUtil.newHumanComment(
ctx, in.path, ps.id(), in.side(), in.message.trim(), in.unresolved, parentUuid); ctx, in.path, ps.id(), in.side(), in.message.trim(), in.unresolved, parentUuid);
comment.setLineNbrAndRange(in.line, in.range); comment.setLineNbrAndRange(in.line, in.range);
comment.tag = in.tag; comment.tag = in.tag;
setCommentCommitId(comment, patchListCache, ctx.getChange(), ps); setCommentCommitId(comment, patchListCache, ctx.getChange(), ps);
commentsUtil.putComments( commentsUtil.putHumanComments(
ctx.getUpdate(psId), Comment.Status.DRAFT, Collections.singleton(comment)); ctx.getUpdate(psId), HumanComment.Status.DRAFT, Collections.singleton(comment));
return true; return true;
} }
} }

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.server.restapi.change; package com.google.gerrit.server.restapi.change;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.extensions.api.changes.DeleteCommentInput; import com.google.gerrit.extensions.api.changes.DeleteCommentInput;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
@@ -26,7 +26,7 @@ import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.server.CommentsUtil; import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.change.CommentResource; import com.google.gerrit.server.change.HumanCommentResource;
import com.google.gerrit.server.notedb.ChangeNotes; import com.google.gerrit.server.notedb.ChangeNotes;
import com.google.gerrit.server.permissions.GlobalPermission; import com.google.gerrit.server.permissions.GlobalPermission;
import com.google.gerrit.server.permissions.PermissionBackend; import com.google.gerrit.server.permissions.PermissionBackend;
@@ -45,7 +45,7 @@ import java.util.Optional;
import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.ConfigInvalidException;
@Singleton @Singleton
public class DeleteComment implements RestModifyView<CommentResource, DeleteCommentInput> { public class DeleteComment implements RestModifyView<HumanCommentResource, DeleteCommentInput> {
private final Provider<CurrentUser> userProvider; private final Provider<CurrentUser> userProvider;
private final PermissionBackend permissionBackend; private final PermissionBackend permissionBackend;
@@ -71,7 +71,7 @@ public class DeleteComment implements RestModifyView<CommentResource, DeleteComm
} }
@Override @Override
public Response<CommentInfo> apply(CommentResource rsrc, DeleteCommentInput input) public Response<CommentInfo> apply(HumanCommentResource rsrc, DeleteCommentInput input)
throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException, throws RestApiException, IOException, ConfigInvalidException, PermissionBackendException,
UpdateException { UpdateException {
CurrentUser user = userProvider.get(); CurrentUser user = userProvider.get();
@@ -90,15 +90,15 @@ public class DeleteComment implements RestModifyView<CommentResource, DeleteComm
ChangeNotes updatedNotes = ChangeNotes updatedNotes =
notesFactory.createChecked(rsrc.getRevisionResource().getChange().getId()); notesFactory.createChecked(rsrc.getRevisionResource().getChange().getId());
List<Comment> changeComments = commentsUtil.publishedByChange(updatedNotes); List<HumanComment> changeComments = commentsUtil.publishedHumanCommentsByChange(updatedNotes);
Optional<Comment> updatedComment = Optional<HumanComment> updatedComment =
changeComments.stream().filter(c -> c.key.equals(rsrc.getComment().key)).findFirst(); changeComments.stream().filter(c -> c.key.equals(rsrc.getComment().key)).findFirst();
if (!updatedComment.isPresent()) { if (!updatedComment.isPresent()) {
// This should not happen as this endpoint should not remove the whole comment. // This should not happen as this endpoint should not remove the whole comment.
throw new ResourceNotFoundException("comment not found: " + rsrc.getComment().key); throw new ResourceNotFoundException("comment not found: " + rsrc.getComment().key);
} }
return Response.ok(commentJson.get().newCommentFormatter().format(updatedComment.get())); return Response.ok(commentJson.get().newHumanCommentFormatter().format(updatedComment.get()));
} }
private static String getCommentNewMessage(String name, String reason) { private static String getCommentNewMessage(String name, String reason) {
@@ -110,10 +110,10 @@ public class DeleteComment implements RestModifyView<CommentResource, DeleteComm
} }
private class DeleteCommentOp implements BatchUpdateOp { private class DeleteCommentOp implements BatchUpdateOp {
private final CommentResource rsrc; private final HumanCommentResource rsrc;
private final String newMessage; private final String newMessage;
DeleteCommentOp(CommentResource rsrc, String newMessage) { DeleteCommentOp(HumanCommentResource rsrc, String newMessage) {
this.rsrc = rsrc; this.rsrc = rsrc;
this.newMessage = newMessage; this.newMessage = newMessage;
} }

View File

@@ -17,6 +17,7 @@ package com.google.gerrit.server.restapi.change;
import static com.google.gerrit.server.CommentsUtil.setCommentCommitId; import static com.google.gerrit.server.CommentsUtil.setCommentCommitId;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.common.Input; import com.google.gerrit.extensions.common.Input;
@@ -80,7 +81,7 @@ public class DeleteDraftComment implements RestModifyView<DraftCommentResource,
@Override @Override
public boolean updateChange(ChangeContext ctx) public boolean updateChange(ChangeContext ctx)
throws ResourceNotFoundException, PatchListNotAvailableException { throws ResourceNotFoundException, PatchListNotAvailableException {
Optional<Comment> maybeComment = Optional<HumanComment> maybeComment =
commentsUtil.getDraft(ctx.getNotes(), ctx.getIdentifiedUser(), key); commentsUtil.getDraft(ctx.getNotes(), ctx.getIdentifiedUser(), key);
if (!maybeComment.isPresent()) { if (!maybeComment.isPresent()) {
return false; // Nothing to do. return false; // Nothing to do.
@@ -90,9 +91,9 @@ public class DeleteDraftComment implements RestModifyView<DraftCommentResource,
if (ps == null) { if (ps == null) {
throw new ResourceNotFoundException("patch set not found: " + psId); throw new ResourceNotFoundException("patch set not found: " + psId);
} }
Comment c = maybeComment.get(); HumanComment c = maybeComment.get();
setCommentCommitId(c, patchListCache, ctx.getChange(), ps); setCommentCommitId(c, patchListCache, ctx.getChange(), ps);
commentsUtil.deleteComments(ctx.getUpdate(psId), Collections.singleton(c)); commentsUtil.deleteHumanComments(ctx.getUpdate(psId), Collections.singleton(c));
return true; return true;
} }
} }

View File

@@ -14,7 +14,7 @@
package com.google.gerrit.server.restapi.change; package com.google.gerrit.server.restapi.change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.extensions.registration.DynamicMap; import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.ChildCollection; import com.google.gerrit.extensions.restapi.ChildCollection;
@@ -64,7 +64,7 @@ public class DraftComments implements ChildCollection<RevisionResource, DraftCom
throws ResourceNotFoundException, AuthException { throws ResourceNotFoundException, AuthException {
checkIdentifiedUser(); checkIdentifiedUser();
String uuid = id.get(); String uuid = id.get();
for (Comment c : for (HumanComment c :
commentsUtil.draftByPatchSetAuthor( commentsUtil.draftByPatchSetAuthor(
rev.getPatchSet().id(), rev.getAccountId(), rev.getNotes())) { rev.getPatchSet().id(), rev.getAccountId(), rev.getNotes())) {
if (uuid.equals(c.key.uuid)) { if (uuid.equals(c.key.uuid)) {

View File

@@ -17,14 +17,14 @@ package com.google.gerrit.server.restapi.change;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.server.change.CommentResource; import com.google.gerrit.server.change.HumanCommentResource;
import com.google.gerrit.server.permissions.PermissionBackendException; import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@Singleton @Singleton
public class GetComment implements RestReadView<CommentResource> { public class GetComment implements RestReadView<HumanCommentResource> {
private final Provider<CommentJson> commentJson; private final Provider<CommentJson> commentJson;
@@ -34,7 +34,7 @@ public class GetComment implements RestReadView<CommentResource> {
} }
@Override @Override
public Response<CommentInfo> apply(CommentResource rsrc) throws PermissionBackendException { public Response<CommentInfo> apply(HumanCommentResource rsrc) throws PermissionBackendException {
return Response.ok(commentJson.get().newCommentFormatter().format(rsrc.getComment())); return Response.ok(commentJson.get().newHumanCommentFormatter().format(rsrc.getComment()));
} }
} }

View File

@@ -35,6 +35,6 @@ public class GetDraftComment implements RestReadView<DraftCommentResource> {
@Override @Override
public Response<CommentInfo> apply(DraftCommentResource rsrc) throws PermissionBackendException { public Response<CommentInfo> apply(DraftCommentResource rsrc) throws PermissionBackendException {
return Response.ok(commentJson.get().newCommentFormatter().format(rsrc.getComment())); return Response.ok(commentJson.get().newHumanCommentFormatter().format(rsrc.getComment()));
} }
} }

View File

@@ -18,7 +18,7 @@ import static java.util.stream.Collectors.toList;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.Response;
@@ -28,7 +28,6 @@ import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.change.ChangeResource; import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.permissions.PermissionBackendException; import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.query.change.ChangeData; import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.restapi.change.CommentJson.CommentFormatter;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -64,12 +63,12 @@ public class ListChangeComments implements RestReadView<ChangeResource> {
return getAsList(listComments(rsrc), rsrc); return getAsList(listComments(rsrc), rsrc);
} }
private Iterable<Comment> listComments(ChangeResource rsrc) { private Iterable<HumanComment> listComments(ChangeResource rsrc) {
ChangeData cd = changeDataFactory.create(rsrc.getNotes()); ChangeData cd = changeDataFactory.create(rsrc.getNotes());
return commentsUtil.publishedByChange(cd.notes()); return commentsUtil.publishedHumanCommentsByChange(cd.notes());
} }
private ImmutableList<CommentInfo> getAsList(Iterable<Comment> comments, ChangeResource rsrc) private ImmutableList<CommentInfo> getAsList(Iterable<HumanComment> comments, ChangeResource rsrc)
throws PermissionBackendException { throws PermissionBackendException {
ImmutableList<CommentInfo> commentInfos = getCommentFormatter().formatAsList(comments); ImmutableList<CommentInfo> commentInfos = getCommentFormatter().formatAsList(comments);
List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes()); List<ChangeMessage> changeMessages = changeMessagesUtil.byChange(rsrc.getNotes());
@@ -77,8 +76,8 @@ public class ListChangeComments implements RestReadView<ChangeResource> {
return commentInfos; return commentInfos;
} }
private Map<String, List<CommentInfo>> getAsMap(Iterable<Comment> comments, ChangeResource rsrc) private Map<String, List<CommentInfo>> getAsMap(
throws PermissionBackendException { Iterable<HumanComment> comments, ChangeResource rsrc) throws PermissionBackendException {
Map<String, List<CommentInfo>> commentInfosMap = getCommentFormatter().format(comments); Map<String, List<CommentInfo>> commentInfosMap = getCommentFormatter().format(comments);
List<CommentInfo> commentInfos = List<CommentInfo> commentInfos =
commentInfosMap.values().stream().flatMap(List::stream).collect(toList()); commentInfosMap.values().stream().flatMap(List::stream).collect(toList());
@@ -87,7 +86,7 @@ public class ListChangeComments implements RestReadView<ChangeResource> {
return commentInfosMap; return commentInfosMap;
} }
private CommentFormatter getCommentFormatter() { private CommentJson.HumanCommentFormatter getCommentFormatter() {
return commentJson.get().setFillAccounts(true).setFillPatchSet(true).newCommentFormatter(); return commentJson.get().setFillAccounts(true).setFillPatchSet(true).newHumanCommentFormatter();
} }
} }

View File

@@ -14,7 +14,7 @@
package com.google.gerrit.server.restapi.change; package com.google.gerrit.server.restapi.change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.AuthException; import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.Response;
@@ -23,7 +23,7 @@ import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.change.ChangeResource; import com.google.gerrit.server.change.ChangeResource;
import com.google.gerrit.server.permissions.PermissionBackendException; import com.google.gerrit.server.permissions.PermissionBackendException;
import com.google.gerrit.server.query.change.ChangeData; import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.restapi.change.CommentJson.CommentFormatter; import com.google.gerrit.server.restapi.change.CommentJson.HumanCommentFormatter;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@@ -46,7 +46,7 @@ public class ListChangeDrafts implements RestReadView<ChangeResource> {
this.commentsUtil = commentsUtil; this.commentsUtil = commentsUtil;
} }
private Iterable<Comment> listComments(ChangeResource rsrc) { private Iterable<HumanComment> listComments(ChangeResource rsrc) {
ChangeData cd = changeDataFactory.create(rsrc.getNotes()); ChangeData cd = changeDataFactory.create(rsrc.getNotes());
return commentsUtil.draftByChangeAuthor(cd.notes(), rsrc.getUser().getAccountId()); return commentsUtil.draftByChangeAuthor(cd.notes(), rsrc.getUser().getAccountId());
} }
@@ -68,7 +68,11 @@ public class ListChangeDrafts implements RestReadView<ChangeResource> {
return getCommentFormatter().formatAsList(listComments(rsrc)); return getCommentFormatter().formatAsList(listComments(rsrc));
} }
private CommentFormatter getCommentFormatter() { private HumanCommentFormatter getCommentFormatter() {
return commentJson.get().setFillAccounts(false).setFillPatchSet(true).newCommentFormatter(); return commentJson
.get()
.setFillAccounts(false)
.setFillPatchSet(true)
.newHumanCommentFormatter();
} }
} }

View File

@@ -14,7 +14,7 @@
package com.google.gerrit.server.restapi.change; package com.google.gerrit.server.restapi.change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.server.CommentsUtil; import com.google.gerrit.server.CommentsUtil;
import com.google.gerrit.server.change.RevisionResource; import com.google.gerrit.server.change.RevisionResource;
import com.google.gerrit.server.notedb.ChangeNotes; import com.google.gerrit.server.notedb.ChangeNotes;
@@ -35,7 +35,7 @@ public class ListRevisionComments extends ListRevisionDrafts {
} }
@Override @Override
protected Iterable<Comment> listComments(RevisionResource rsrc) { protected Iterable<HumanComment> listComments(RevisionResource rsrc) {
ChangeNotes notes = rsrc.getNotes(); ChangeNotes notes = rsrc.getNotes();
return commentsUtil.publishedByPatchSet(notes, rsrc.getPatchSet().id()); return commentsUtil.publishedByPatchSet(notes, rsrc.getPatchSet().id());
} }

View File

@@ -15,7 +15,7 @@
package com.google.gerrit.server.restapi.change; package com.google.gerrit.server.restapi.change;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
import com.google.gerrit.extensions.restapi.Response; import com.google.gerrit.extensions.restapi.Response;
import com.google.gerrit.extensions.restapi.RestReadView; import com.google.gerrit.extensions.restapi.RestReadView;
@@ -39,7 +39,7 @@ public class ListRevisionDrafts implements RestReadView<RevisionResource> {
this.commentsUtil = commentsUtil; this.commentsUtil = commentsUtil;
} }
protected Iterable<Comment> listComments(RevisionResource rsrc) { protected Iterable<HumanComment> listComments(RevisionResource rsrc) {
return commentsUtil.draftByPatchSetAuthor( return commentsUtil.draftByPatchSetAuthor(
rsrc.getPatchSet().id(), rsrc.getAccountId(), rsrc.getNotes()); rsrc.getPatchSet().id(), rsrc.getAccountId(), rsrc.getNotes());
} }
@@ -55,7 +55,7 @@ public class ListRevisionDrafts implements RestReadView<RevisionResource> {
commentJson commentJson
.get() .get()
.setFillAccounts(includeAuthorInfo()) .setFillAccounts(includeAuthorInfo())
.newCommentFormatter() .newHumanCommentFormatter()
.format(listComments(rsrc))); .format(listComments(rsrc)));
} }
@@ -64,7 +64,7 @@ public class ListRevisionDrafts implements RestReadView<RevisionResource> {
return commentJson return commentJson
.get() .get()
.setFillAccounts(includeAuthorInfo()) .setFillAccounts(includeAuthorInfo())
.newCommentFormatter() .newHumanCommentFormatter()
.formatAsList(listComments(rsrc)); .formatAsList(listComments(rsrc));
} }
} }

View File

@@ -18,10 +18,10 @@ import static com.google.gerrit.server.change.AttentionSetEntryResource.ATTENTIO
import static com.google.gerrit.server.change.ChangeEditResource.CHANGE_EDIT_KIND; import static com.google.gerrit.server.change.ChangeEditResource.CHANGE_EDIT_KIND;
import static com.google.gerrit.server.change.ChangeMessageResource.CHANGE_MESSAGE_KIND; import static com.google.gerrit.server.change.ChangeMessageResource.CHANGE_MESSAGE_KIND;
import static com.google.gerrit.server.change.ChangeResource.CHANGE_KIND; import static com.google.gerrit.server.change.ChangeResource.CHANGE_KIND;
import static com.google.gerrit.server.change.CommentResource.COMMENT_KIND;
import static com.google.gerrit.server.change.DraftCommentResource.DRAFT_COMMENT_KIND; import static com.google.gerrit.server.change.DraftCommentResource.DRAFT_COMMENT_KIND;
import static com.google.gerrit.server.change.FileResource.FILE_KIND; import static com.google.gerrit.server.change.FileResource.FILE_KIND;
import static com.google.gerrit.server.change.FixResource.FIX_KIND; import static com.google.gerrit.server.change.FixResource.FIX_KIND;
import static com.google.gerrit.server.change.HumanCommentResource.COMMENT_KIND;
import static com.google.gerrit.server.change.ReviewerResource.REVIEWER_KIND; import static com.google.gerrit.server.change.ReviewerResource.REVIEWER_KIND;
import static com.google.gerrit.server.change.RevisionResource.REVISION_KIND; import static com.google.gerrit.server.change.RevisionResource.REVISION_KIND;
import static com.google.gerrit.server.change.RobotCommentResource.ROBOT_COMMENT_KIND; import static com.google.gerrit.server.change.RobotCommentResource.ROBOT_COMMENT_KIND;

View File

@@ -49,6 +49,7 @@ import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.FixReplacement; import com.google.gerrit.entities.FixReplacement;
import com.google.gerrit.entities.FixSuggestion; import com.google.gerrit.entities.FixSuggestion;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.Patch; import com.google.gerrit.entities.Patch;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
@@ -811,8 +812,8 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
} }
/** /**
* Used to compare existing {@link Comment}-s with {@link CommentInput} comments by copying only * Used to compare existing {@link HumanComment}-s with {@link CommentInput} comments by copying
* the fields to compare. * only the fields to compare.
*/ */
@AutoValue @AutoValue
abstract static class CommentSetEntry { abstract static class CommentSetEntry {
@@ -942,7 +943,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
// HashMap instead of Collections.emptyMap() avoids warning about remove() on immutable // HashMap instead of Collections.emptyMap() avoids warning about remove() on immutable
// object. // object.
Map<String, Comment> drafts = new HashMap<>(); Map<String, HumanComment> drafts = new HashMap<>();
// If there are inputComments we need the deduplication loop below, so we have to read (and // If there are inputComments we need the deduplication loop below, so we have to read (and
// publish) drafts here. // publish) drafts here.
if (!inputComments.isEmpty() || in.drafts != DraftHandling.KEEP) { if (!inputComments.isEmpty() || in.drafts != DraftHandling.KEEP) {
@@ -954,7 +955,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
} }
// This will be populated with Comment-s created from inputComments. // This will be populated with Comment-s created from inputComments.
List<Comment> toPublish = new ArrayList<>(); List<HumanComment> toPublish = new ArrayList<>();
Set<CommentSetEntry> existingComments = Set<CommentSetEntry> existingComments =
in.omitDuplicateComments ? readExistingComments(ctx) : Collections.emptySet(); in.omitDuplicateComments ? readExistingComments(ctx) : Collections.emptySet();
@@ -965,11 +966,11 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
for (Map.Entry<String, List<CommentInput>> entry : inputComments.entrySet()) { for (Map.Entry<String, List<CommentInput>> entry : inputComments.entrySet()) {
String path = entry.getKey(); String path = entry.getKey();
for (CommentInput inputComment : entry.getValue()) { for (CommentInput inputComment : entry.getValue()) {
Comment comment = drafts.remove(Url.decode(inputComment.id)); HumanComment comment = drafts.remove(Url.decode(inputComment.id));
if (comment == null) { if (comment == null) {
String parent = Url.decode(inputComment.inReplyTo); String parent = Url.decode(inputComment.inReplyTo);
comment = comment =
commentsUtil.newComment( commentsUtil.newHumanComment(
ctx, ctx,
path, path,
psId, psId,
@@ -1014,7 +1015,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
break; break;
} }
ChangeUpdate changeUpdate = ctx.getUpdate(psId); ChangeUpdate changeUpdate = ctx.getUpdate(psId);
commentsUtil.putComments(changeUpdate, Comment.Status.PUBLISHED, toPublish); commentsUtil.putHumanComments(changeUpdate, HumanComment.Status.PUBLISHED, toPublish);
comments.addAll(toPublish); comments.addAll(toPublish);
return !toPublish.isEmpty(); return !toPublish.isEmpty();
} }
@@ -1134,7 +1135,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
} }
private Set<CommentSetEntry> readExistingComments(ChangeContext ctx) { private Set<CommentSetEntry> readExistingComments(ChangeContext ctx) {
return commentsUtil.publishedByChange(ctx.getNotes()).stream() return commentsUtil.publishedHumanCommentsByChange(ctx.getNotes()).stream()
.map(CommentSetEntry::create) .map(CommentSetEntry::create)
.collect(toSet()); .collect(toSet());
} }
@@ -1145,7 +1146,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
.collect(toSet()); .collect(toSet());
} }
private Map<String, Comment> changeDrafts(ChangeContext ctx) { private Map<String, HumanComment> changeDrafts(ChangeContext ctx) {
return commentsUtil.draftByChangeAuthor(ctx.getNotes(), user.getAccountId()).stream() return commentsUtil.draftByChangeAuthor(ctx.getNotes(), user.getAccountId()).stream()
.collect( .collect(
Collectors.toMap( Collectors.toMap(
@@ -1156,7 +1157,7 @@ public class PostReview implements RestModifyView<RevisionResource, ReviewInput>
})); }));
} }
private Map<String, Comment> patchSetDrafts(ChangeContext ctx) { private Map<String, HumanComment> patchSetDrafts(ChangeContext ctx) {
return commentsUtil.draftByPatchSetAuthor(psId, user.getAccountId(), ctx.getNotes()).stream() return commentsUtil.draftByPatchSetAuthor(psId, user.getAccountId(), ctx.getNotes()).stream()
.collect(Collectors.toMap(c -> c.key.uuid, c -> c)); .collect(Collectors.toMap(c -> c.key.uuid, c -> c));
} }

View File

@@ -18,6 +18,7 @@ import static com.google.gerrit.entities.Patch.PATCHSET_LEVEL;
import static com.google.gerrit.server.CommentsUtil.setCommentCommitId; import static com.google.gerrit.server.CommentsUtil.setCommentCommitId;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.extensions.api.changes.DraftInput; import com.google.gerrit.extensions.api.changes.DraftInput;
import com.google.gerrit.extensions.common.CommentInfo; import com.google.gerrit.extensions.common.CommentInfo;
@@ -93,7 +94,7 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
bu.addOp(rsrc.getChange().getId(), op); bu.addOp(rsrc.getChange().getId(), op);
bu.execute(); bu.execute();
return Response.ok( return Response.ok(
commentJson.get().setFillAccounts(false).newCommentFormatter().format(op.comment)); commentJson.get().setFillAccounts(false).newHumanCommentFormatter().format(op.comment));
} }
} }
@@ -101,7 +102,7 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
private final Comment.Key key; private final Comment.Key key;
private final DraftInput in; private final DraftInput in;
private Comment comment; private HumanComment comment;
private Op(Comment.Key key, DraftInput in) { private Op(Comment.Key key, DraftInput in) {
this.key = key; this.key = key;
@@ -111,15 +112,15 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
@Override @Override
public boolean updateChange(ChangeContext ctx) public boolean updateChange(ChangeContext ctx)
throws ResourceNotFoundException, PatchListNotAvailableException { throws ResourceNotFoundException, PatchListNotAvailableException {
Optional<Comment> maybeComment = Optional<HumanComment> maybeComment =
commentsUtil.getDraft(ctx.getNotes(), ctx.getIdentifiedUser(), key); commentsUtil.getDraft(ctx.getNotes(), ctx.getIdentifiedUser(), key);
if (!maybeComment.isPresent()) { if (!maybeComment.isPresent()) {
// Disappeared out from under us. Can't easily fall back to insert, // Disappeared out from under us. Can't easily fall back to insert,
// because the input might be missing required fields. Just give up. // because the input might be missing required fields. Just give up.
throw new ResourceNotFoundException("comment not found: " + key); throw new ResourceNotFoundException("comment not found: " + key);
} }
Comment origComment = maybeComment.get(); HumanComment origComment = maybeComment.get();
comment = new Comment(origComment); comment = new HumanComment(origComment);
// Copy constructor preserved old real author; replace with current real // Copy constructor preserved old real author; replace with current real
// user. // user.
ctx.getUser().updateRealAccountId(comment::setRealAuthor); ctx.getUser().updateRealAccountId(comment::setRealAuthor);
@@ -135,17 +136,19 @@ public class PutDraftComment implements RestModifyView<DraftCommentResource, Dra
// Updating the path alters the primary key, which isn't possible. // Updating the path alters the primary key, which isn't possible.
// Delete then recreate the comment instead of an update. // Delete then recreate the comment instead of an update.
commentsUtil.deleteComments(update, Collections.singleton(origComment)); commentsUtil.deleteHumanComments(update, Collections.singleton(origComment));
comment.key.filename = in.path; comment.key.filename = in.path;
} }
setCommentCommitId(comment, patchListCache, ctx.getChange(), ps); setCommentCommitId(comment, patchListCache, ctx.getChange(), ps);
commentsUtil.putComments( commentsUtil.putHumanComments(
update, Comment.Status.DRAFT, Collections.singleton(update(comment, in, ctx.getWhen()))); update,
HumanComment.Status.DRAFT,
Collections.singleton(update(comment, in, ctx.getWhen())));
return true; return true;
} }
} }
private static Comment update(Comment e, DraftInput in, Timestamp when) { private static HumanComment update(HumanComment e, DraftInput in, Timestamp when) {
if (in.side != null) { if (in.side != null) {
e.side = in.side(); e.side = in.side();
} }

View File

@@ -41,7 +41,7 @@ import com.google.gerrit.common.data.LabelType;
import com.google.gerrit.common.data.Permission; import com.google.gerrit.common.data.Permission;
import com.google.gerrit.entities.AccountGroup; import com.google.gerrit.entities.AccountGroup;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.Patch; import com.google.gerrit.entities.Patch;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
import com.google.gerrit.entities.RobotComment; import com.google.gerrit.entities.RobotComment;
@@ -225,7 +225,8 @@ public class ImpersonationIT extends AbstractDaemonTest {
assertThat(psa.realAccountId()).isEqualTo(admin.id()); assertThat(psa.realAccountId()).isEqualTo(admin.id());
ChangeData cd = r.getChange(); ChangeData cd = r.getChange();
Comment c = Iterables.getOnlyElement(commentsUtil.publishedByChange(cd.notes())); HumanComment c =
Iterables.getOnlyElement(commentsUtil.publishedHumanCommentsByChange(cd.notes()));
assertThat(c.message).isEqualTo(ci.message); assertThat(c.message).isEqualTo(ci.message);
assertThat(c.author.getId()).isEqualTo(user.id()); assertThat(c.author.getId()).isEqualTo(user.id());
assertThat(c.getRealAuthor().getId()).isEqualTo(admin.id()); assertThat(c.getRealAuthor().getId()).isEqualTo(admin.id());

View File

@@ -34,6 +34,7 @@ import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.acceptance.testsuite.project.ProjectOperations; import com.google.gerrit.acceptance.testsuite.project.ProjectOperations;
import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations; import com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.Patch; import com.google.gerrit.entities.Patch;
import com.google.gerrit.entities.RefNames; import com.google.gerrit.entities.RefNames;
import com.google.gerrit.extensions.api.changes.DeleteCommentInput; import com.google.gerrit.extensions.api.changes.DeleteCommentInput;
@@ -1425,16 +1426,16 @@ public class CommentsIT extends AbstractDaemonTest {
RevCommit commitBefore = beforeDelete.get(i); RevCommit commitBefore = beforeDelete.get(i);
RevCommit commitAfter = afterDelete.get(i); RevCommit commitAfter = afterDelete.get(i);
Map<String, com.google.gerrit.entities.Comment> commentMapBefore = Map<String, HumanComment> commentMapBefore =
DeleteCommentRewriter.getPublishedComments( DeleteCommentRewriter.getPublishedComments(
noteUtil, reader, NoteMap.read(reader, commitBefore)); noteUtil, reader, NoteMap.read(reader, commitBefore));
Map<String, com.google.gerrit.entities.Comment> commentMapAfter = Map<String, HumanComment> commentMapAfter =
DeleteCommentRewriter.getPublishedComments( DeleteCommentRewriter.getPublishedComments(
noteUtil, reader, NoteMap.read(reader, commitAfter)); noteUtil, reader, NoteMap.read(reader, commitAfter));
if (commentMapBefore.containsKey(targetCommentUuid)) { if (commentMapBefore.containsKey(targetCommentUuid)) {
assertThat(commentMapAfter).containsKey(targetCommentUuid); assertThat(commentMapAfter).containsKey(targetCommentUuid);
com.google.gerrit.entities.Comment comment = commentMapAfter.get(targetCommentUuid); HumanComment comment = commentMapAfter.get(targetCommentUuid);
assertThat(comment.message).isEqualTo(expectedMessage); assertThat(comment.message).isEqualTo(expectedMessage);
comment.message = commentMapBefore.get(targetCommentUuid).message; comment.message = commentMapBefore.get(targetCommentUuid).message;
commentMapAfter.put(targetCommentUuid, comment); commentMapAfter.put(targetCommentUuid, comment);

View File

@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@@ -37,7 +38,7 @@ public class AbstractParserTest {
} }
protected static void assertInlineComment( protected static void assertInlineComment(
String message, MailComment comment, Comment inReplyTo) { String message, MailComment comment, HumanComment inReplyTo) {
assertThat(comment.fileName).isNull(); assertThat(comment.fileName).isNull();
assertThat(comment.message).isEqualTo(message); assertThat(comment.message).isEqualTo(message);
assertThat(comment.inReplyTo.key).isEqualTo(inReplyTo.key); assertThat(comment.inReplyTo.key).isEqualTo(inReplyTo.key);
@@ -51,9 +52,9 @@ public class AbstractParserTest {
assertThat(comment.type).isEqualTo(MailComment.CommentType.FILE_COMMENT); assertThat(comment.type).isEqualTo(MailComment.CommentType.FILE_COMMENT);
} }
protected static Comment newComment(String uuid, String file, String message, int line) { protected static HumanComment newComment(String uuid, String file, String message, int line) {
Comment c = HumanComment c =
new Comment( new HumanComment(
new Comment.Key(uuid, file, 1), new Comment.Key(uuid, file, 1),
Account.id(0), Account.id(0),
new Timestamp(0L), new Timestamp(0L),
@@ -65,9 +66,10 @@ public class AbstractParserTest {
return c; return c;
} }
protected static Comment newRangeComment(String uuid, String file, String message, int line) { protected static HumanComment newRangeComment(
Comment c = String uuid, String file, String message, int line) {
new Comment( HumanComment c =
new HumanComment(
new Comment.Key(uuid, file, 1), new Comment.Key(uuid, file, 1),
Account.id(0), Account.id(0),
new Timestamp(0L), new Timestamp(0L),
@@ -91,8 +93,8 @@ public class AbstractParserTest {
} }
/** Returns a List of default comments for testing. */ /** Returns a List of default comments for testing. */
protected static List<Comment> defaultComments() { protected static List<HumanComment> defaultComments() {
List<Comment> comments = new ArrayList<>(); List<HumanComment> comments = new ArrayList<>();
comments.add(newComment("c1", "gerrit-server/test.txt", "comment", 0)); comments.add(newComment("c1", "gerrit-server/test.txt", "comment", 0));
comments.add(newComment("c2", "gerrit-server/test.txt", "comment", 2)); comments.add(newComment("c2", "gerrit-server/test.txt", "comment", 2));
comments.add(newComment("c3", "gerrit-server/test.txt", "comment", 3)); comments.add(newComment("c3", "gerrit-server/test.txt", "comment", 3));

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.mail;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import java.util.List; import java.util.List;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@@ -31,7 +31,7 @@ public abstract class HtmlParserTest extends AbstractParserTest {
MailMessage.Builder b = newMailMessageBuilder(); MailMessage.Builder b = newMailMessageBuilder();
b.htmlContent(newHtmlBody("Looks good to me", null, null, null, null, null, null)); b.htmlContent(newHtmlBody("Looks good to me", null, null, null, null, null, null));
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, ""); List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, "");
assertThat(parsedComments).hasSize(1); assertThat(parsedComments).hasSize(1);
@@ -52,7 +52,7 @@ public abstract class HtmlParserTest extends AbstractParserTest {
null, null,
null)); null));
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, ""); List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, "");
assertThat(parsedComments).hasSize(1); assertThat(parsedComments).hasSize(1);
@@ -73,7 +73,7 @@ public abstract class HtmlParserTest extends AbstractParserTest {
null, null,
null)); null));
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(3); assertThat(parsedComments).hasSize(3);
@@ -96,7 +96,7 @@ public abstract class HtmlParserTest extends AbstractParserTest {
null, null,
null)); null));
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(3); assertThat(parsedComments).hasSize(3);
@@ -121,7 +121,7 @@ public abstract class HtmlParserTest extends AbstractParserTest {
null, null,
null)); null));
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(3); assertThat(parsedComments).hasSize(3);
@@ -135,7 +135,7 @@ public abstract class HtmlParserTest extends AbstractParserTest {
MailMessage.Builder b = newMailMessageBuilder(); MailMessage.Builder b = newMailMessageBuilder();
b.htmlContent(newHtmlBody(null, null, null, null, null, null, null)); b.htmlContent(newHtmlBody(null, null, null, null, null, null, null));
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).isEmpty(); assertThat(parsedComments).isEmpty();
@@ -148,7 +148,7 @@ public abstract class HtmlParserTest extends AbstractParserTest {
newHtmlBody( newHtmlBody(
null, null, null, "Also have a comment here.", "This is a nice file", null, null)); null, null, null, "Also have a comment here.", "This is a nice file", null, null));
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(2); assertThat(parsedComments).hasSize(2);
@@ -164,7 +164,7 @@ public abstract class HtmlParserTest extends AbstractParserTest {
MailMessage.Builder b = newMailMessageBuilder(); MailMessage.Builder b = newMailMessageBuilder();
b.htmlContent(newHtmlBody(htmlMessage, null, null, htmlMessage, htmlMessage, null, null)); b.htmlContent(newHtmlBody(htmlMessage, null, null, htmlMessage, htmlMessage, null, null));
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = HtmlParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(3); assertThat(parsedComments).hasSize(3);

View File

@@ -16,7 +16,7 @@ package com.google.gerrit.mail;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
@@ -39,7 +39,7 @@ public class TextParserTest extends AbstractParserTest {
MailMessage.Builder b = newMailMessageBuilder(); MailMessage.Builder b = newMailMessageBuilder();
b.textContent("Looks good to me\n" + quotedFooter); b.textContent("Looks good to me\n" + quotedFooter);
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(1); assertThat(parsedComments).hasSize(1);
@@ -60,7 +60,7 @@ public class TextParserTest extends AbstractParserTest {
null) null)
+ quotedFooter); + quotedFooter);
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(3); assertThat(parsedComments).hasSize(3);
@@ -83,7 +83,7 @@ public class TextParserTest extends AbstractParserTest {
null) null)
+ quotedFooter); + quotedFooter);
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(3); assertThat(parsedComments).hasSize(3);
@@ -97,7 +97,7 @@ public class TextParserTest extends AbstractParserTest {
MailMessage.Builder b = newMailMessageBuilder(); MailMessage.Builder b = newMailMessageBuilder();
b.textContent(newPlaintextBody(null, null, null, null, null, null, null) + quotedFooter); b.textContent(newPlaintextBody(null, null, null, null, null, null, null) + quotedFooter);
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).isEmpty(); assertThat(parsedComments).isEmpty();
@@ -111,7 +111,7 @@ public class TextParserTest extends AbstractParserTest {
null, null, null, "Also have a comment here.", "This is a nice file", null, null) null, null, null, "Also have a comment here.", "This is a nice file", null, null)
+ quotedFooter); + quotedFooter);
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(2); assertThat(parsedComments).hasSize(2);
@@ -134,7 +134,7 @@ public class TextParserTest extends AbstractParserTest {
+ quotedFooter) + quotedFooter)
.replace("> ", ">> ")); .replace("> ", ">> "));
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(3); assertThat(parsedComments).hasSize(3);
@@ -157,7 +157,7 @@ public class TextParserTest extends AbstractParserTest {
"Comment in reply to file comment") "Comment in reply to file comment")
+ quotedFooter); + quotedFooter);
List<Comment> comments = defaultComments(); List<HumanComment> comments = defaultComments();
List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL); List<MailComment> parsedComments = TextParser.parse(b.build(), comments, CHANGE_URL);
assertThat(parsedComments).hasSize(2); assertThat(parsedComments).hasSize(2);

View File

@@ -23,7 +23,7 @@ import static com.google.gerrit.server.mail.send.CommentFormatter.BlockType.QUOT
import java.util.List; import java.util.List;
import org.junit.Test; import org.junit.Test;
public class CommentFormatterTest { public class HumanCommentFormatterTest {
private void assertBlock( private void assertBlock(
List<CommentFormatter.Block> list, int index, CommentFormatter.BlockType type, String text) { List<CommentFormatter.Block> list, int index, CommentFormatter.BlockType type, String text) {
CommentFormatter.Block block = list.get(index); CommentFormatter.Block block = list.get(index);

View File

@@ -23,6 +23,7 @@ import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.CommentRange; import com.google.gerrit.entities.CommentRange;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.Project; import com.google.gerrit.entities.Project;
import com.google.gerrit.extensions.config.FactoryModule; import com.google.gerrit.extensions.config.FactoryModule;
@@ -244,7 +245,7 @@ public abstract class AbstractChangeNotesTest {
return label; return label;
} }
protected Comment newComment( protected HumanComment newComment(
PatchSet.Id psId, PatchSet.Id psId,
String filename, String filename,
String UUID, String UUID,
@@ -257,8 +258,8 @@ public abstract class AbstractChangeNotesTest {
short side, short side,
ObjectId commitId, ObjectId commitId,
boolean unresolved) { boolean unresolved) {
Comment c = HumanComment c =
new Comment( new HumanComment(
new Comment.Key(UUID, filename, psId.get()), new Comment.Key(UUID, filename, psId.get()),
commenter.getAccountId(), commenter.getAccountId(),
t, t,

View File

@@ -32,6 +32,7 @@ import com.google.gerrit.entities.AttentionSetUpdate;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.LabelId; import com.google.gerrit.entities.LabelId;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
@@ -714,8 +715,8 @@ public class ChangeNotesStateTest {
@Test @Test
public void serializePublishedComments() throws Exception { public void serializePublishedComments() throws Exception {
Comment c1 = HumanComment c1 =
new Comment( new HumanComment(
new Comment.Key("uuid1", "file1", 1), new Comment.Key("uuid1", "file1", 1),
Account.id(1001), Account.id(1001),
new Timestamp(1212L), new Timestamp(1212L),
@@ -726,8 +727,8 @@ public class ChangeNotesStateTest {
c1.setCommitId(ObjectId.fromString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); c1.setCommitId(ObjectId.fromString("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
String c1Json = Serializer.GSON.toJson(c1); String c1Json = Serializer.GSON.toJson(c1);
Comment c2 = HumanComment c2 =
new Comment( new HumanComment(
new Comment.Key("uuid2", "file2", 2), new Comment.Key("uuid2", "file2", 2),
Account.id(1002), Account.id(1002),
new Timestamp(3434L), new Timestamp(3434L),
@@ -798,7 +799,7 @@ public class ChangeNotesStateTest {
.put("changeMessages", new TypeLiteral<ImmutableList<ChangeMessage>>() {}.getType()) .put("changeMessages", new TypeLiteral<ImmutableList<ChangeMessage>>() {}.getType())
.put( .put(
"publishedComments", "publishedComments",
new TypeLiteral<ImmutableListMultimap<ObjectId, Comment>>() {}.getType()) new TypeLiteral<ImmutableListMultimap<ObjectId, HumanComment>>() {}.getType())
.put("updateCount", int.class) .put("updateCount", int.class)
.build()); .build());
} }
@@ -970,7 +971,7 @@ public class ChangeNotesStateTest {
"startChar", int.class, "startChar", int.class,
"endLine", int.class, "endLine", int.class,
"endChar", int.class)); "endChar", int.class));
assertThatSerializedClass(Comment.class) assertThatSerializedClass(HumanComment.class)
.hasFields( .hasFields(
ImmutableMap.<String, Type>builder() ImmutableMap.<String, Type>builder()
.put("key", Comment.Key.class) .put("key", Comment.Key.class)

View File

@@ -43,8 +43,8 @@ import com.google.gerrit.entities.AttentionSetUpdate.Operation;
import com.google.gerrit.entities.BranchNameKey; import com.google.gerrit.entities.BranchNameKey;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.ChangeMessage; import com.google.gerrit.entities.ChangeMessage;
import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.CommentRange; import com.google.gerrit.entities.CommentRange;
import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.entities.PatchSetApproval; import com.google.gerrit.entities.PatchSetApproval;
import com.google.gerrit.entities.SubmissionId; import com.google.gerrit.entities.SubmissionId;
@@ -123,7 +123,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
RevCommit commit = tr.commit().message("PS2").create(); RevCommit commit = tr.commit().message("PS2").create();
ChangeUpdate update = newUpdate(c, changeOwner); ChangeUpdate update = newUpdate(c, changeOwner);
update.putComment( update.putComment(
Comment.Status.PUBLISHED, HumanComment.Status.PUBLISHED,
newComment( newComment(
c.currentPatchSetId(), c.currentPatchSetId(),
"a.txt", "a.txt",
@@ -142,7 +142,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
ImmutableListMultimap<ObjectId, Comment> comments = notes.getComments(); ImmutableListMultimap<ObjectId, HumanComment> comments = notes.getHumanComments();
assertThat(comments).hasSize(1); assertThat(comments).hasSize(1);
assertThat(comments.entries().asList().get(0).getValue().tag).isEqualTo(tag); assertThat(comments.entries().asList().get(0).getValue().tag).isEqualTo(tag);
} }
@@ -185,7 +185,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
RevCommit commit = tr.commit().message("PS2").create(); RevCommit commit = tr.commit().message("PS2").create();
update = newUpdate(c, changeOwner); update = newUpdate(c, changeOwner);
update.putComment( update.putComment(
Comment.Status.PUBLISHED, HumanComment.Status.PUBLISHED,
newComment( newComment(
c.currentPatchSetId(), c.currentPatchSetId(),
"a.txt", "a.txt",
@@ -216,7 +216,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
assertThat(approval.tag()).hasValue(integrationTag); assertThat(approval.tag()).hasValue(integrationTag);
assertThat(approval.value()).isEqualTo(-1); assertThat(approval.value()).isEqualTo(-1);
ImmutableListMultimap<ObjectId, Comment> comments = notes.getComments(); ImmutableListMultimap<ObjectId, HumanComment> comments = notes.getHumanComments();
assertThat(comments).hasSize(1); assertThat(comments).hasSize(1);
assertThat(comments.entries().asList().get(0).getValue().tag).isEqualTo(coverageTag); assertThat(comments.entries().asList().get(0).getValue().tag).isEqualTo(coverageTag);
@@ -1188,7 +1188,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
update.putApproval("Code-Review", (short) 1); update.putApproval("Code-Review", (short) 1);
update.setChangeMessage("This is a message"); update.setChangeMessage("This is a message");
update.putComment( update.putComment(
Comment.Status.PUBLISHED, HumanComment.Status.PUBLISHED,
newComment( newComment(
c.currentPatchSetId(), c.currentPatchSetId(),
"a.txt", "a.txt",
@@ -1208,7 +1208,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
assertThat(notes.getPatchSets().keySet()).containsExactly(psId1, psId2); assertThat(notes.getPatchSets().keySet()).containsExactly(psId1, psId2);
assertThat(notes.getApprovals()).isNotEmpty(); assertThat(notes.getApprovals()).isNotEmpty();
assertThat(notes.getChangeMessages()).isNotEmpty(); assertThat(notes.getChangeMessages()).isNotEmpty();
assertThat(notes.getComments()).isNotEmpty(); assertThat(notes.getHumanComments()).isNotEmpty();
// publish ps2 // publish ps2
update = newUpdate(c, changeOwner); update = newUpdate(c, changeOwner);
@@ -1224,7 +1224,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
assertThat(notes.getPatchSets().keySet()).containsExactly(psId1); assertThat(notes.getPatchSets().keySet()).containsExactly(psId1);
assertThat(notes.getApprovals()).isEmpty(); assertThat(notes.getApprovals()).isEmpty();
assertThat(notes.getChangeMessages()).isEmpty(); assertThat(notes.getChangeMessages()).isEmpty();
assertThat(notes.getComments()).isEmpty(); assertThat(notes.getHumanComments()).isEmpty();
} }
@Test @Test
@@ -1281,14 +1281,14 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
Map<PatchSet.Id, PatchSet> patchSets = notes.getPatchSets(); Map<PatchSet.Id, PatchSet> patchSets = notes.getPatchSets();
assertThat(patchSets.get(psId1).pushCertificate()).isEmpty(); assertThat(patchSets.get(psId1).pushCertificate()).isEmpty();
assertThat(patchSets.get(psId2).pushCertificate()).hasValue(pushCert); assertThat(patchSets.get(psId2).pushCertificate()).hasValue(pushCert);
assertThat(notes.getComments()).isEmpty(); assertThat(notes.getHumanComments()).isEmpty();
// comment on ps2 // comment on ps2
update = newUpdate(c, changeOwner); update = newUpdate(c, changeOwner);
update.setPatchSetId(psId2); update.setPatchSetId(psId2);
Timestamp ts = TimeUtil.nowTs(); Timestamp ts = TimeUtil.nowTs();
update.putComment( update.putComment(
Comment.Status.PUBLISHED, HumanComment.Status.PUBLISHED,
newComment( newComment(
psId2, psId2,
"a.txt", "a.txt",
@@ -1309,7 +1309,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
patchSets = notes.getPatchSets(); patchSets = notes.getPatchSets();
assertThat(patchSets.get(psId1).pushCertificate()).isEmpty(); assertThat(patchSets.get(psId1).pushCertificate()).isEmpty();
assertThat(patchSets.get(psId2).pushCertificate()).hasValue(pushCert); assertThat(patchSets.get(psId2).pushCertificate()).hasValue(pushCert);
assertThat(notes.getComments()).isNotEmpty(); assertThat(notes.getHumanComments()).isNotEmpty();
} }
@Test @Test
@@ -1358,7 +1358,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
PatchSet.Id psId = c.currentPatchSetId(); PatchSet.Id psId = c.currentPatchSetId();
RevCommit tipCommit; RevCommit tipCommit;
try (NoteDbUpdateManager updateManager = updateManagerFactory.create(project)) { try (NoteDbUpdateManager updateManager = updateManagerFactory.create(project)) {
Comment comment1 = HumanComment comment1 =
newComment( newComment(
psId, psId,
"file1", "file1",
@@ -1373,7 +1373,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"), ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"),
false); false);
update1.setPatchSetId(psId); update1.setPatchSetId(psId);
update1.putComment(Comment.Status.PUBLISHED, comment1); update1.putComment(HumanComment.Status.PUBLISHED, comment1);
updateManager.add(update1); updateManager.add(update1);
ChangeUpdate update2 = newUpdate(c, otherUser); ChangeUpdate update2 = newUpdate(c, otherUser);
@@ -1572,7 +1572,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
PatchSet.Id psId = c.currentPatchSetId(); PatchSet.Id psId = c.currentPatchSetId();
ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
Comment comment = HumanComment comment =
newComment( newComment(
psId, psId,
"file1", "file1",
@@ -1587,11 +1587,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment)); assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment));
} }
@Test @Test
@@ -1602,7 +1602,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
CommentRange range = new CommentRange(1, 0, 2, 0); CommentRange range = new CommentRange(1, 0, 2, 0);
Comment comment = HumanComment comment =
newComment( newComment(
psId, psId,
"file1", "file1",
@@ -1617,11 +1617,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment)); assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment));
} }
@Test @Test
@@ -1632,7 +1632,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
CommentRange range = new CommentRange(0, 0, 0, 0); CommentRange range = new CommentRange(0, 0, 0, 0);
Comment comment = HumanComment comment =
newComment( newComment(
psId, psId,
"file", "file",
@@ -1647,11 +1647,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment)); assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment));
} }
@Test @Test
@@ -1662,7 +1662,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
CommentRange range = new CommentRange(1, 2, 3, 4); CommentRange range = new CommentRange(1, 2, 3, 4);
Comment comment = HumanComment comment =
newComment( newComment(
psId, psId,
"", "",
@@ -1677,11 +1677,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment)); assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment));
} }
@Test @Test
@@ -1701,7 +1701,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
Timestamp time = TimeUtil.nowTs(); Timestamp time = TimeUtil.nowTs();
ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
Comment comment1 = HumanComment comment1 =
newComment( newComment(
psId1, psId1,
"file1", "file1",
@@ -1715,7 +1715,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
(short) 0, (short) 0,
commitId, commitId,
false); false);
Comment comment2 = HumanComment comment2 =
newComment( newComment(
psId1, psId1,
"file1", "file1",
@@ -1729,7 +1729,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
(short) 0, (short) 0,
commitId, commitId,
false); false);
Comment comment3 = HumanComment comment3 =
newComment( newComment(
psId2, psId2,
"file1", "file1",
@@ -1746,13 +1746,13 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(psId2); update.setPatchSetId(psId2);
update.putComment(Comment.Status.PUBLISHED, comment3); update.putComment(HumanComment.Status.PUBLISHED, comment3);
update.putComment(Comment.Status.PUBLISHED, comment2); update.putComment(HumanComment.Status.PUBLISHED, comment2);
update.putComment(Comment.Status.PUBLISHED, comment1); update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getComments()) assertThat(notes.getHumanComments())
.isEqualTo( .isEqualTo(
ImmutableListMultimap.of( ImmutableListMultimap.of(
commitId, comment1, commitId, comment1,
@@ -1772,7 +1772,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
PatchSet.Id psId = c.currentPatchSetId(); PatchSet.Id psId = c.currentPatchSetId();
ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
Comment comment = HumanComment comment =
newComment( newComment(
psId, psId,
"file", "file",
@@ -1788,12 +1788,12 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
false); false);
comment.setRealAuthor(changeOwner.getAccountId()); comment.setRealAuthor(changeOwner.getAccountId());
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment)); assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment));
} }
@Test @Test
@@ -1811,7 +1811,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
Timestamp time = TimeUtil.nowTs(); Timestamp time = TimeUtil.nowTs();
PatchSet.Id psId = c.currentPatchSetId(); PatchSet.Id psId = c.currentPatchSetId();
Comment comment = HumanComment comment =
newComment( newComment(
psId, psId,
"file1", "file1",
@@ -1826,12 +1826,12 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"), ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"),
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getComments()) assertThat(notes.getHumanComments())
.isEqualTo(ImmutableListMultimap.of(comment.getCommitId(), comment)); .isEqualTo(ImmutableListMultimap.of(comment.getCommitId(), comment));
} }
@@ -1849,7 +1849,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
PatchSet.Id psId = c.currentPatchSetId(); PatchSet.Id psId = c.currentPatchSetId();
Comment commentForBase = HumanComment commentForBase =
newComment( newComment(
psId, psId,
"filename", "filename",
@@ -1864,11 +1864,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId1, commitId1,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, commentForBase); update.putComment(HumanComment.Status.PUBLISHED, commentForBase);
update.commit(); update.commit();
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
Comment commentForPS = HumanComment commentForPS =
newComment( newComment(
psId, psId,
"filename", "filename",
@@ -1883,10 +1883,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId2, commitId2,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, commentForPS); update.putComment(HumanComment.Status.PUBLISHED, commentForPS);
update.commit(); update.commit();
assertThat(newNotes(c).getComments()) assertThat(newNotes(c).getHumanComments())
.containsExactlyEntriesIn( .containsExactlyEntriesIn(
ImmutableListMultimap.of( ImmutableListMultimap.of(
commitId1, commentForBase, commitId1, commentForBase,
@@ -1907,7 +1907,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
Timestamp timeForComment1 = TimeUtil.nowTs(); Timestamp timeForComment1 = TimeUtil.nowTs();
Timestamp timeForComment2 = TimeUtil.nowTs(); Timestamp timeForComment2 = TimeUtil.nowTs();
Comment comment1 = HumanComment comment1 =
newComment( newComment(
psId, psId,
filename, filename,
@@ -1922,11 +1922,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment1); update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.commit(); update.commit();
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
Comment comment2 = HumanComment comment2 =
newComment( newComment(
psId, psId,
filename, filename,
@@ -1941,10 +1941,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment2); update.putComment(HumanComment.Status.PUBLISHED, comment2);
update.commit(); update.commit();
assertThat(newNotes(c).getComments()) assertThat(newNotes(c).getHumanComments())
.containsExactlyEntriesIn( .containsExactlyEntriesIn(
ImmutableListMultimap.of( ImmutableListMultimap.of(
commitId, comment1, commitId, comment1,
@@ -1965,7 +1965,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment comment1 = HumanComment comment1 =
newComment( newComment(
psId, psId,
filename1, filename1,
@@ -1980,11 +1980,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment1); update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.commit(); update.commit();
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
Comment comment2 = HumanComment comment2 =
newComment( newComment(
psId, psId,
filename2, filename2,
@@ -1999,10 +1999,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment2); update.putComment(HumanComment.Status.PUBLISHED, comment2);
update.commit(); update.commit();
assertThat(newNotes(c).getComments()) assertThat(newNotes(c).getHumanComments())
.containsExactlyEntriesIn( .containsExactlyEntriesIn(
ImmutableListMultimap.of( ImmutableListMultimap.of(
commitId, comment1, commitId, comment1,
@@ -2023,7 +2023,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment comment1 = HumanComment comment1 =
newComment( newComment(
ps1, ps1,
filename, filename,
@@ -2038,7 +2038,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId1, commitId1,
false); false);
update.setPatchSetId(ps1); update.setPatchSetId(ps1);
update.putComment(Comment.Status.PUBLISHED, comment1); update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.commit(); update.commit();
incrementPatchSet(c); incrementPatchSet(c);
@@ -2046,7 +2046,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
now = TimeUtil.nowTs(); now = TimeUtil.nowTs();
Comment comment2 = HumanComment comment2 =
newComment( newComment(
ps2, ps2,
filename, filename,
@@ -2061,10 +2061,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId2, commitId2,
false); false);
update.setPatchSetId(ps2); update.setPatchSetId(ps2);
update.putComment(Comment.Status.PUBLISHED, comment2); update.putComment(HumanComment.Status.PUBLISHED, comment2);
update.commit(); update.commit();
assertThat(newNotes(c).getComments()) assertThat(newNotes(c).getHumanComments())
.containsExactlyEntriesIn( .containsExactlyEntriesIn(
ImmutableListMultimap.of( ImmutableListMultimap.of(
commitId1, comment1, commitId1, comment1,
@@ -2083,7 +2083,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment comment1 = HumanComment comment1 =
newComment( newComment(
ps1, ps1,
filename, filename,
@@ -2098,22 +2098,22 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(ps1); update.setPatchSetId(ps1);
update.putComment(Comment.Status.DRAFT, comment1); update.putComment(HumanComment.Status.DRAFT, comment1);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)) assertThat(notes.getDraftComments(otherUserId))
.containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1)); .containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1));
assertThat(notes.getComments()).isEmpty(); assertThat(notes.getHumanComments()).isEmpty();
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
update.setPatchSetId(ps1); update.setPatchSetId(ps1);
update.putComment(Comment.Status.PUBLISHED, comment1); update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.commit(); update.commit();
notes = newNotes(c); notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)).isEmpty(); assertThat(notes.getDraftComments(otherUserId)).isEmpty();
assertThat(notes.getComments()) assertThat(notes.getHumanComments())
.containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1)); .containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1));
} }
@@ -2133,7 +2133,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
// Write two drafts on the same side of one patch set. // Write two drafts on the same side of one patch set.
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(psId); update.setPatchSetId(psId);
Comment comment1 = HumanComment comment1 =
newComment( newComment(
psId, psId,
filename, filename,
@@ -2147,7 +2147,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId, commitId,
false); false);
Comment comment2 = HumanComment comment2 =
newComment( newComment(
psId, psId,
filename, filename,
@@ -2161,8 +2161,8 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId, commitId,
false); false);
update.putComment(Comment.Status.DRAFT, comment1); update.putComment(HumanComment.Status.DRAFT, comment1);
update.putComment(Comment.Status.DRAFT, comment2); update.putComment(HumanComment.Status.DRAFT, comment2);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
@@ -2172,18 +2172,18 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, comment1, commitId, comment1,
commitId, comment2)) commitId, comment2))
.inOrder(); .inOrder();
assertThat(notes.getComments()).isEmpty(); assertThat(notes.getHumanComments()).isEmpty();
// Publish first draft. // Publish first draft.
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment1); update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.commit(); update.commit();
notes = newNotes(c); notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)) assertThat(notes.getDraftComments(otherUserId))
.containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment2)); .containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment2));
assertThat(notes.getComments()) assertThat(notes.getHumanComments())
.containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1)); .containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1));
} }
@@ -2203,7 +2203,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
// Write two drafts, one on each side of the patchset. // Write two drafts, one on each side of the patchset.
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(psId); update.setPatchSetId(psId);
Comment baseComment = HumanComment baseComment =
newComment( newComment(
psId, psId,
filename, filename,
@@ -2217,7 +2217,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
(short) 0, (short) 0,
commitId1, commitId1,
false); false);
Comment psComment = HumanComment psComment =
newComment( newComment(
psId, psId,
filename, filename,
@@ -2232,8 +2232,8 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId2, commitId2,
false); false);
update.putComment(Comment.Status.DRAFT, baseComment); update.putComment(HumanComment.Status.DRAFT, baseComment);
update.putComment(Comment.Status.DRAFT, psComment); update.putComment(HumanComment.Status.DRAFT, psComment);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
@@ -2242,19 +2242,19 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ImmutableListMultimap.of( ImmutableListMultimap.of(
commitId1, baseComment, commitId1, baseComment,
commitId2, psComment)); commitId2, psComment));
assertThat(notes.getComments()).isEmpty(); assertThat(notes.getHumanComments()).isEmpty();
// Publish both comments. // Publish both comments.
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, baseComment); update.putComment(HumanComment.Status.PUBLISHED, baseComment);
update.putComment(Comment.Status.PUBLISHED, psComment); update.putComment(HumanComment.Status.PUBLISHED, psComment);
update.commit(); update.commit();
notes = newNotes(c); notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)).isEmpty(); assertThat(notes.getDraftComments(otherUserId)).isEmpty();
assertThat(notes.getComments()) assertThat(notes.getHumanComments())
.containsExactlyEntriesIn( .containsExactlyEntriesIn(
ImmutableListMultimap.of( ImmutableListMultimap.of(
commitId1, baseComment, commitId1, baseComment,
@@ -2273,7 +2273,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment comment = HumanComment comment =
newComment( newComment(
psId, psId,
filename, filename,
@@ -2288,7 +2288,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.DRAFT, comment); update.putComment(HumanComment.Status.DRAFT, comment);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
@@ -2318,7 +2318,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment comment1 = HumanComment comment1 =
newComment( newComment(
ps1, ps1,
filename, filename,
@@ -2333,7 +2333,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId1, commitId1,
false); false);
update.setPatchSetId(ps1); update.setPatchSetId(ps1);
update.putComment(Comment.Status.DRAFT, comment1); update.putComment(HumanComment.Status.DRAFT, comment1);
update.commit(); update.commit();
incrementPatchSet(c); incrementPatchSet(c);
@@ -2341,7 +2341,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
now = TimeUtil.nowTs(); now = TimeUtil.nowTs();
Comment comment2 = HumanComment comment2 =
newComment( newComment(
ps2, ps2,
filename, filename,
@@ -2356,7 +2356,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId2, commitId2,
false); false);
update.setPatchSetId(ps2); update.setPatchSetId(ps2);
update.putComment(Comment.Status.DRAFT, comment2); update.putComment(HumanComment.Status.DRAFT, comment2);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
@@ -2386,7 +2386,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment comment = HumanComment comment =
newComment( newComment(
ps1, ps1,
filename, filename,
@@ -2400,7 +2400,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId, commitId,
false); false);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
assertThat(repo.exactRef(changeMetaRef(c.getId()))).isNotNull(); assertThat(repo.exactRef(changeMetaRef(c.getId()))).isNotNull();
@@ -2419,7 +2419,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment draft = HumanComment draft =
newComment( newComment(
ps1, ps1,
filename, filename,
@@ -2433,7 +2433,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId, commitId,
false); false);
update.putComment(Comment.Status.DRAFT, draft); update.putComment(HumanComment.Status.DRAFT, draft);
update.commit(); update.commit();
String draftRef = refsDraftComments(c.getId(), otherUser.getAccountId()); String draftRef = refsDraftComments(c.getId(), otherUser.getAccountId());
@@ -2441,7 +2441,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
assertThat(old).isNotNull(); assertThat(old).isNotNull();
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
Comment pub = HumanComment pub =
newComment( newComment(
ps1, ps1,
filename, filename,
@@ -2455,7 +2455,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId, commitId,
false); false);
update.putComment(Comment.Status.PUBLISHED, pub); update.putComment(HumanComment.Status.PUBLISHED, pub);
update.commit(); update.commit();
assertThat(exactRefAllUsers(draftRef)).isEqualTo(old); assertThat(exactRefAllUsers(draftRef)).isEqualTo(old);
@@ -2471,7 +2471,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
PatchSet.Id psId = c.currentPatchSetId(); PatchSet.Id psId = c.currentPatchSetId();
Comment comment = HumanComment comment =
newComment( newComment(
psId, psId,
"filename", "filename",
@@ -2486,10 +2486,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
assertThat(newNotes(c).getComments()) assertThat(newNotes(c).getHumanComments())
.containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment)); .containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment));
} }
@@ -2503,7 +2503,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
PatchSet.Id psId = c.currentPatchSetId(); PatchSet.Id psId = c.currentPatchSetId();
Comment comment = HumanComment comment =
newComment( newComment(
psId, psId,
"filename", "filename",
@@ -2518,10 +2518,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
commitId, commitId,
false); false);
update.setPatchSetId(psId); update.setPatchSetId(psId);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
assertThat(newNotes(c).getComments()) assertThat(newNotes(c).getHumanComments())
.containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment)); .containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment));
} }
@@ -2542,7 +2542,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(ps2); update.setPatchSetId(ps2);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment comment1 = HumanComment comment1 =
newComment( newComment(
ps1, ps1,
filename, filename,
@@ -2556,7 +2556,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId1, commitId1,
false); false);
Comment comment2 = HumanComment comment2 =
newComment( newComment(
ps2, ps2,
filename, filename,
@@ -2570,23 +2570,23 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId2, commitId2,
false); false);
update.putComment(Comment.Status.DRAFT, comment1); update.putComment(HumanComment.Status.DRAFT, comment1);
update.putComment(Comment.Status.DRAFT, comment2); update.putComment(HumanComment.Status.DRAFT, comment2);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)).hasSize(2); assertThat(notes.getDraftComments(otherUserId)).hasSize(2);
assertThat(notes.getComments()).isEmpty(); assertThat(notes.getHumanComments()).isEmpty();
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
update.setPatchSetId(ps2); update.setPatchSetId(ps2);
update.putComment(Comment.Status.PUBLISHED, comment1); update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.putComment(Comment.Status.PUBLISHED, comment2); update.putComment(HumanComment.Status.PUBLISHED, comment2);
update.commit(); update.commit();
notes = newNotes(c); notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)).isEmpty(); assertThat(notes.getDraftComments(otherUserId)).isEmpty();
assertThat(notes.getComments()).hasSize(2); assertThat(notes.getHumanComments()).hasSize(2);
} }
@Test @Test
@@ -2600,7 +2600,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(ps1); update.setPatchSetId(ps1);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment comment1 = HumanComment comment1 =
newComment( newComment(
ps1, ps1,
"file1", "file1",
@@ -2614,7 +2614,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId1, commitId1,
false); false);
Comment comment2 = HumanComment comment2 =
newComment( newComment(
ps1, ps1,
"file2", "file2",
@@ -2628,23 +2628,23 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId1, commitId1,
false); false);
update.putComment(Comment.Status.DRAFT, comment1); update.putComment(HumanComment.Status.DRAFT, comment1);
update.putComment(Comment.Status.DRAFT, comment2); update.putComment(HumanComment.Status.DRAFT, comment2);
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId).get(commitId1)) assertThat(notes.getDraftComments(otherUserId).get(commitId1))
.containsExactly(comment1, comment2); .containsExactly(comment1, comment2);
assertThat(notes.getComments()).isEmpty(); assertThat(notes.getHumanComments()).isEmpty();
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
update.setPatchSetId(ps1); update.setPatchSetId(ps1);
update.putComment(Comment.Status.PUBLISHED, comment2); update.putComment(HumanComment.Status.PUBLISHED, comment2);
update.commit(); update.commit();
notes = newNotes(c); notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId).get(commitId1)).containsExactly(comment1); assertThat(notes.getDraftComments(otherUserId).get(commitId1)).containsExactly(comment1);
assertThat(notes.getComments().get(commitId1)).containsExactly(comment2); assertThat(notes.getHumanComments().get(commitId1)).containsExactly(comment2);
} }
@Test @Test
@@ -2673,7 +2673,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
Timestamp now = TimeUtil.nowTs(); Timestamp now = TimeUtil.nowTs();
Comment comment1 = HumanComment comment1 =
newComment( newComment(
ps1, ps1,
"file1", "file1",
@@ -2687,7 +2687,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId1, commitId1,
false); false);
Comment comment2 = HumanComment comment2 =
newComment( newComment(
ps1, ps1,
"file2", "file2",
@@ -2701,8 +2701,8 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
side, side,
commitId1, commitId1,
false); false);
update.putComment(Comment.Status.DRAFT, comment1); update.putComment(HumanComment.Status.DRAFT, comment1);
update.putComment(Comment.Status.DRAFT, comment2); update.putComment(HumanComment.Status.DRAFT, comment2);
update.commit(); update.commit();
String refName = refsDraftComments(c.getId(), otherUserId); String refName = refsDraftComments(c.getId(), otherUserId);
@@ -2710,7 +2710,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
update.setPatchSetId(ps1); update.setPatchSetId(ps1);
update.putComment(Comment.Status.PUBLISHED, comment2); update.putComment(HumanComment.Status.PUBLISHED, comment2);
update.commit(); update.commit();
assertThat(exactRefAllUsers(refName)).isNotNull(); assertThat(exactRefAllUsers(refName)).isNotNull();
assertThat(exactRefAllUsers(refName)).isNotEqualTo(oldDraftId); assertThat(exactRefAllUsers(refName)).isNotEqualTo(oldDraftId);
@@ -2732,11 +2732,11 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
// Zombie comment is filtered out of drafts via ChangeNotes. // Zombie comment is filtered out of drafts via ChangeNotes.
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId).get(commitId1)).containsExactly(comment1); assertThat(notes.getDraftComments(otherUserId).get(commitId1)).containsExactly(comment1);
assertThat(notes.getComments().get(commitId1)).containsExactly(comment2); assertThat(notes.getHumanComments().get(commitId1)).containsExactly(comment2);
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
update.setPatchSetId(ps1); update.setPatchSetId(ps1);
update.putComment(Comment.Status.PUBLISHED, comment1); update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.commit(); update.commit();
// Updating an unrelated comment causes the zombie comment to get fixed up. // Updating an unrelated comment causes the zombie comment to get fixed up.
@@ -2750,7 +2750,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"); ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
ChangeUpdate update1 = newUpdate(c, otherUser); ChangeUpdate update1 = newUpdate(c, otherUser);
Comment comment1 = HumanComment comment1 =
newComment( newComment(
c.currentPatchSetId(), c.currentPatchSetId(),
"filename", "filename",
@@ -2764,10 +2764,10 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
(short) 1, (short) 1,
commitId, commitId,
false); false);
update1.putComment(Comment.Status.PUBLISHED, comment1); update1.putComment(HumanComment.Status.PUBLISHED, comment1);
ChangeUpdate update2 = newUpdate(c, otherUser); ChangeUpdate update2 = newUpdate(c, otherUser);
Comment comment2 = HumanComment comment2 =
newComment( newComment(
c.currentPatchSetId(), c.currentPatchSetId(),
"filename", "filename",
@@ -2781,7 +2781,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
(short) 1, (short) 1,
commitId, commitId,
false); false);
update2.putComment(Comment.Status.PUBLISHED, comment2); update2.putComment(HumanComment.Status.PUBLISHED, comment2);
try (NoteDbUpdateManager manager = updateManagerFactory.create(project)) { try (NoteDbUpdateManager manager = updateManagerFactory.create(project)) {
manager.add(update1); manager.add(update1);
@@ -2790,7 +2790,7 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
} }
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
List<Comment> comments = notes.getComments().get(commitId); List<HumanComment> comments = notes.getHumanComments().get(commitId);
assertThat(comments).hasSize(2); assertThat(comments).hasSize(2);
assertThat(comments.get(0).message).isEqualTo("comment 1"); assertThat(comments.get(0).message).isEqualTo("comment 1");
assertThat(comments.get(1).message).isEqualTo("comment 2"); assertThat(comments.get(1).message).isEqualTo("comment 2");
@@ -2817,14 +2817,14 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
int numMessages = notes.getChangeMessages().size(); int numMessages = notes.getChangeMessages().size();
int numPatchSets = notes.getPatchSets().size(); int numPatchSets = notes.getPatchSets().size();
int numApprovals = notes.getApprovals().size(); int numApprovals = notes.getApprovals().size();
int numComments = notes.getComments().size(); int numComments = notes.getHumanComments().size();
ChangeUpdate update = newUpdate(c, changeOwner); ChangeUpdate update = newUpdate(c, changeOwner);
update.setPatchSetId(PatchSet.id(c.getId(), c.currentPatchSetId().get() + 1)); update.setPatchSetId(PatchSet.id(c.getId(), c.currentPatchSetId().get() + 1));
update.setChangeMessage("Should be ignored"); update.setChangeMessage("Should be ignored");
update.putApproval("Code-Review", (short) 2); update.putApproval("Code-Review", (short) 2);
CommentRange range = new CommentRange(1, 1, 2, 1); CommentRange range = new CommentRange(1, 1, 2, 1);
Comment comment = HumanComment comment =
newComment( newComment(
update.getPatchSetId(), update.getPatchSetId(),
"filename", "filename",
@@ -2838,14 +2838,14 @@ public class ChangeNotesTest extends AbstractChangeNotesTest {
(short) 1, (short) 1,
ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"), ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"),
false); false);
update.putComment(Comment.Status.PUBLISHED, comment); update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit(); update.commit();
notes = newNotes(c); notes = newNotes(c);
assertThat(notes.getChangeMessages()).hasSize(numMessages); assertThat(notes.getChangeMessages()).hasSize(numMessages);
assertThat(notes.getPatchSets()).hasSize(numPatchSets); assertThat(notes.getPatchSets()).hasSize(numPatchSets);
assertThat(notes.getApprovals()).hasSize(numApprovals); assertThat(notes.getApprovals()).hasSize(numApprovals);
assertThat(notes.getComments()).hasSize(numComments); assertThat(notes.getHumanComments()).hasSize(numComments);
} }
@Test @Test

View File

@@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.entities.Account; import com.google.gerrit.entities.Account;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.Comment;
import com.google.gerrit.entities.HumanComment;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import java.sql.Timestamp; import java.sql.Timestamp;
@@ -151,7 +152,7 @@ public class CommentTimestampAdapterTest {
@Test @Test
public void newAdapterRoundTripOfWholeComment() { public void newAdapterRoundTripOfWholeComment() {
Comment c = Comment c =
new Comment( new HumanComment(
new Comment.Key("uuid", "filename", 1), new Comment.Key("uuid", "filename", 1),
Account.id(100), Account.id(100),
NON_DST_TS, NON_DST_TS,
@@ -165,7 +166,7 @@ public class CommentTimestampAdapterTest {
String json = gson.toJson(c); String json = gson.toJson(c);
assertThat(json).contains("\"writtenOn\": \"" + NON_DST_STR_TRUNC + "\","); assertThat(json).contains("\"writtenOn\": \"" + NON_DST_STR_TRUNC + "\",");
Comment result = gson.fromJson(json, Comment.class); Comment result = gson.fromJson(json, HumanComment.class);
// Round-trip lossily truncates ms, but that's ok. // Round-trip lossily truncates ms, but that's ok.
assertThat(result.writtenOn).isEqualTo(NON_DST_TS_TRUNC); assertThat(result.writtenOn).isEqualTo(NON_DST_TS_TRUNC);
result.writtenOn = NON_DST_TS; result.writtenOn = NON_DST_TS;

View File

@@ -17,7 +17,7 @@ package com.google.gerrit.server.notedb;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.entities.Change; import com.google.gerrit.entities.Change;
import com.google.gerrit.entities.Comment; import com.google.gerrit.entities.HumanComment;
import com.google.gerrit.entities.PatchSet; import com.google.gerrit.entities.PatchSet;
import com.google.gerrit.server.util.time.TimeUtil; import com.google.gerrit.server.util.time.TimeUtil;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
@@ -31,7 +31,7 @@ public class DraftCommentNotesTest extends AbstractChangeNotesTest {
Change c = newChange(); Change c = newChange();
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(c.currentPatchSetId()); update.setPatchSetId(c.currentPatchSetId());
update.putComment(Comment.Status.PUBLISHED, comment(c.currentPatchSetId())); update.putComment(HumanComment.Status.PUBLISHED, comment(c.currentPatchSetId()));
update.commit(); update.commit();
assertThat(newNotes(c).getDraftComments(otherUserId)).isEmpty(); assertThat(newNotes(c).getDraftComments(otherUserId)).isEmpty();
@@ -44,13 +44,13 @@ public class DraftCommentNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(c.currentPatchSetId()); update.setPatchSetId(c.currentPatchSetId());
update.putComment(Comment.Status.DRAFT, comment(c.currentPatchSetId())); update.putComment(HumanComment.Status.DRAFT, comment(c.currentPatchSetId()));
update.commit(); update.commit();
assertThat(newNotes(c).getDraftComments(otherUserId)).hasSize(1); assertThat(newNotes(c).getDraftComments(otherUserId)).hasSize(1);
assertableFanOutExecutor.assertInteractions(0); assertableFanOutExecutor.assertInteractions(0);
update = newUpdate(c, otherUser); update = newUpdate(c, otherUser);
update.putComment(Comment.Status.PUBLISHED, comment(c.currentPatchSetId())); update.putComment(HumanComment.Status.PUBLISHED, comment(c.currentPatchSetId()));
update.commit(); update.commit();
assertThat(newNotes(c).getDraftComments(otherUserId)).isEmpty(); assertThat(newNotes(c).getDraftComments(otherUserId)).isEmpty();
@@ -63,7 +63,7 @@ public class DraftCommentNotesTest extends AbstractChangeNotesTest {
ChangeUpdate update = newUpdate(c, otherUser); ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(c.currentPatchSetId()); update.setPatchSetId(c.currentPatchSetId());
update.putComment(Comment.Status.DRAFT, comment(c.currentPatchSetId())); update.putComment(HumanComment.Status.DRAFT, comment(c.currentPatchSetId()));
update.commit(); update.commit();
ChangeNotes notes = newNotes(c); ChangeNotes notes = newNotes(c);
@@ -80,7 +80,7 @@ public class DraftCommentNotesTest extends AbstractChangeNotesTest {
assertableFanOutExecutor.assertInteractions(0); assertableFanOutExecutor.assertInteractions(0);
} }
private Comment comment(PatchSet.Id psId) { private HumanComment comment(PatchSet.Id psId) {
return newComment( return newComment(
psId, psId,
"filename", "filename",