use of com.google.gerrit.entities.RobotComment in project gerrit by GerritCodeReview.
the class RobotCommentUpdate method storeCommentsInNotes.
private CommitBuilder storeCommentsInNotes(RevWalk rw, ObjectInserter ins, ObjectId curr, CommitBuilder cb) throws ConfigInvalidException, IOException {
RevisionNoteMap<RobotCommentsRevisionNote> rnm = getRevisionNoteMap(rw, curr);
Set<ObjectId> updatedRevs = Sets.newHashSetWithExpectedSize(rnm.revisionNotes.size());
RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(rnm);
for (RobotComment c : put) {
cache.get(c.getCommitId()).putComment(c);
}
Map<ObjectId, RevisionNoteBuilder> builders = cache.getBuilders();
boolean touchedAnyRevs = false;
boolean hasComments = false;
for (Map.Entry<ObjectId, RevisionNoteBuilder> e : builders.entrySet()) {
ObjectId id = e.getKey();
updatedRevs.add(id);
byte[] data = e.getValue().build(noteUtil);
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.entities.RobotComment in project gerrit by GerritCodeReview.
the class RobotComments method parse.
@Override
public RobotCommentResource parse(RevisionResource rev, IdString id) throws ResourceNotFoundException {
String uuid = id.get();
ChangeNotes notes = rev.getNotes();
for (RobotComment c : commentsUtil.robotCommentsByPatchSet(notes, rev.getPatchSet().id())) {
if (uuid.equals(c.key.uuid)) {
return new RobotCommentResource(rev, c);
}
}
throw new ResourceNotFoundException(id);
}
use of com.google.gerrit.entities.RobotComment in project gerrit by GerritCodeReview.
the class CommentSender method getCommentGroupsTemplateData.
/**
* Returns grouped inline comment data mapped to data structures that are suitable for passing
* into Soy.
*/
private List<Map<String, Object>> getCommentGroupsTemplateData(Repository repo) {
List<Map<String, Object>> commentGroups = new ArrayList<>();
for (CommentSender.FileCommentGroup group : getGroupedInlineComments(repo)) {
Map<String, Object> groupData = new HashMap<>();
groupData.put("title", group.getTitle());
groupData.put("patchSetId", group.patchSetId);
List<Map<String, Object>> commentsList = new ArrayList<>();
for (Comment comment : group.comments) {
Map<String, Object> commentData = new HashMap<>();
if (group.fileData != null) {
commentData.put("lines", getLinesOfComment(comment, group.fileData));
}
commentData.put("message", comment.message.trim());
List<CommentFormatter.Block> blocks = CommentFormatter.parse(comment.message);
commentData.put("messageBlocks", commentBlocksToSoyData(blocks));
// Set the prefix.
String prefix = getCommentLinePrefix(comment);
commentData.put("linePrefix", prefix);
commentData.put("linePrefixEmpty", Strings.padStart(": ", prefix.length(), ' '));
// Set line numbers.
int startLine;
if (comment.range == null) {
startLine = comment.lineNbr;
} else {
startLine = comment.range.startLine;
commentData.put("endLine", comment.range.endLine);
}
commentData.put("startLine", startLine);
if (comment.key.filename.equals(Patch.PATCHSET_LEVEL)) {
if (comment instanceof RobotComment) {
commentData.put("link", group.getFindingsTabLink());
} else {
commentData.put("link", group.getCommentsTabLink());
}
} else {
commentData.put("link", group.getCommentLink(comment.key.uuid));
}
// Set robot comment data.
if (comment instanceof RobotComment) {
RobotComment robotComment = (RobotComment) comment;
commentData.put("isRobotComment", true);
commentData.put("robotId", robotComment.robotId);
commentData.put("robotRunId", robotComment.robotRunId);
commentData.put("robotUrl", robotComment.url);
} else {
commentData.put("isRobotComment", false);
}
// If the comment has a quote, don't bother loading the parent message.
if (!hasQuote(blocks)) {
// Set parent comment info.
Optional<HumanComment> parent = getParent(comment);
if (parent.isPresent()) {
commentData.put("parentMessage", getShortenedCommentMessage(parent.get()));
}
}
commentsList.add(commentData);
}
groupData.put("comments", commentsList);
commentGroups.add(groupData);
}
return commentGroups;
}
use of com.google.gerrit.entities.RobotComment in project gerrit by GerritCodeReview.
the class CommentsUtil method newRobotComment.
public RobotComment newRobotComment(ChangeContext ctx, String path, PatchSet.Id psId, short side, String message, String robotId, String robotRunId) {
RobotComment c = new RobotComment(new Comment.Key(ChangeUtil.messageUuid(), path, psId.get()), ctx.getUser().getAccountId(), ctx.getWhen(), side, message, serverId, robotId, robotRunId);
ctx.getUser().updateRealAccountId(c::setRealAuthor);
return c;
}
use of com.google.gerrit.entities.RobotComment in project gerrit by GerritCodeReview.
the class RobotCommentNotes method onLoad.
@Override
protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException {
metaId = handle.id();
if (metaId == null) {
loadDefaults();
return;
}
metaId = metaId.copy();
logger.atFine().log("Load robot comment notes for change %s of project %s", getChangeId(), getProjectName());
RevCommit tipCommit = handle.walk().parseCommit(metaId);
ObjectReader reader = handle.walk().getObjectReader();
revisionNoteMap = RevisionNoteMap.parseRobotComments(args.changeNoteJson, reader, NoteMap.read(reader, tipCommit));
ImmutableListMultimap.Builder<ObjectId, RobotComment> cs = ImmutableListMultimap.builder();
for (RobotCommentsRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
for (RobotComment c : rn.getEntities()) {
cs.put(c.getCommitId(), c);
}
}
comments = cs.build();
}
Aggregations