use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class ChangeNotes method getCommentKeys.
public ImmutableSet<Comment.Key> getCommentKeys() {
if (commentKeys == null) {
ImmutableSet.Builder<Comment.Key> b = ImmutableSet.builder();
for (Comment c : getComments().values()) {
b.add(new Comment.Key(c.key));
}
commentKeys = b.build();
}
return commentKeys;
}
use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class CommentSender method getInlineComments.
/** No longer used outside Velocity. Remove this method when VTL support is removed. */
@Deprecated
public String getInlineComments(int lines) {
try (Repository repo = getRepository()) {
StringBuilder cmts = new StringBuilder();
for (FileCommentGroup group : getGroupedInlineComments(repo)) {
String link = group.getLink();
if (link != null) {
cmts.append(link).append('\n');
}
cmts.append(group.getTitle()).append(":\n\n");
for (Comment c : group.comments) {
appendComment(cmts, lines, group.fileData, c);
}
cmts.append("\n\n");
}
return cmts.toString();
}
}
use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class CommentSender method getGroupedInlineComments.
/**
* @return a list of FileCommentGroup objects representing the inline comments grouped by the
* file.
*/
private List<CommentSender.FileCommentGroup> getGroupedInlineComments(Repository repo) {
List<CommentSender.FileCommentGroup> groups = new ArrayList<>();
// Get the patch list:
PatchList patchList = null;
if (repo != null) {
try {
patchList = getPatchList();
} catch (PatchListNotAvailableException e) {
log.error("Failed to get patch list", e);
}
}
// Loop over the comments and collect them into groups based on the file
// location of the comment.
FileCommentGroup currentGroup = null;
for (Comment c : inlineComments) {
// If it's a new group:
if (currentGroup == null || !c.key.filename.equals(currentGroup.filename) || c.key.patchSetId != currentGroup.patchSetId) {
currentGroup = new FileCommentGroup();
currentGroup.filename = c.key.filename;
currentGroup.patchSetId = c.key.patchSetId;
groups.add(currentGroup);
if (patchList != null) {
try {
currentGroup.fileData = new PatchFile(repo, patchList, c.key.filename);
} catch (IOException e) {
log.warn(String.format("Cannot load %s from %s in %s", c.key.filename, patchList.getNewId().name(), projectState.getProject().getName()), e);
currentGroup.fileData = null;
}
}
}
if (currentGroup.fileData != null) {
currentGroup.comments.add(c);
}
}
Collections.sort(groups, Comparator.comparing(g -> g.filename, FilenameComparator.INSTANCE));
return groups;
}
use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class ChangeDraftUpdate method storeCommentsInNotes.
private CommitBuilder storeCommentsInNotes(RevWalk rw, ObjectInserter ins, ObjectId curr, CommitBuilder cb) throws ConfigInvalidException, OrmException, IOException {
RevisionNoteMap<ChangeRevisionNote> rnm = getRevisionNoteMap(rw, curr);
Set<RevId> updatedRevs = Sets.newHashSetWithExpectedSize(rnm.revisionNotes.size());
RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(rnm);
for (Comment c : put) {
if (!delete.contains(key(c))) {
cache.get(new RevId(c.revId)).putComment(c);
}
}
for (Key k : delete) {
cache.get(new RevId(k.revId())).deleteComment(k.key());
}
Map<RevId, RevisionNoteBuilder> builders = cache.getBuilders();
boolean touchedAnyRevs = false;
boolean hasComments = false;
for (Map.Entry<RevId, RevisionNoteBuilder> e : builders.entrySet()) {
updatedRevs.add(e.getKey());
ObjectId id = ObjectId.fromString(e.getKey().get());
byte[] data = e.getValue().build(noteUtil, noteUtil.getWriteJson());
if (!Arrays.equals(data, e.getValue().baseRaw)) {
touchedAnyRevs = true;
}
if (data.length == 0) {
rnm.noteMap.remove(id);
} else {
hasComments = true;
ObjectId dataBlob = ins.insert(OBJ_BLOB, data);
rnm.noteMap.set(id, dataBlob);
}
}
// data yet.
if (!touchedAnyRevs) {
return NO_OP_UPDATE;
}
// If we touched every revision and there are no comments left, tell the
// caller to delete the entire ref.
boolean touchedAllRevs = updatedRevs.equals(rnm.revisionNotes.keySet());
if (touchedAllRevs && !hasComments) {
return null;
}
cb.setTreeId(rnm.noteMap.writeTree(ins));
return cb;
}
use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.
the class AbstractParserTest method newComment.
protected static Comment newComment(String uuid, String file, String message, int line) {
Comment c = new Comment(new Comment.Key(uuid, file, 1), new Account.Id(0), new Timestamp(0L), (short) 0, message, "", false);
c.lineNbr = line;
return c;
}
Aggregations