use of com.google.gerrit.reviewdb.client.RobotComment in project gerrit by GerritCodeReview.
the class RobotCommentUpdate method storeCommentsInNotes.
private CommitBuilder storeCommentsInNotes(RevWalk rw, ObjectInserter ins, ObjectId curr, CommitBuilder cb) throws ConfigInvalidException, OrmException, IOException {
RevisionNoteMap<RobotCommentsRevisionNote> rnm = getRevisionNoteMap(rw, curr);
Set<RevId> updatedRevs = Sets.newHashSetWithExpectedSize(rnm.revisionNotes.size());
RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(rnm);
for (RobotComment c : put) {
cache.get(new RevId(c.revId)).putComment(c);
}
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, true);
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.RobotComment in project gerrit by GerritCodeReview.
the class CommentSender method getCommentGroupsTemplateData.
/**
* @return 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("link", group.getLink());
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<>();
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);
// Set the comment link.
if (comment.lineNbr == 0) {
commentData.put("link", group.getLink());
} else if (comment.side == 0) {
commentData.put("link", group.getLink() + "@a" + startLine);
} else {
commentData.put("link", group.getLink() + '@' + startLine);
}
// 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<Comment> 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.reviewdb.client.RobotComment in project gerrit by GerritCodeReview.
the class RobotComments method parse.
@Override
public RobotCommentResource parse(RevisionResource rev, IdString id) throws ResourceNotFoundException, OrmException {
String uuid = id.get();
ChangeNotes notes = rev.getNotes();
for (RobotComment c : commentsUtil.robotCommentsByPatchSet(notes, rev.getPatchSet().getId())) {
if (uuid.equals(c.key.uuid)) {
return new RobotCommentResource(rev, c);
}
}
throw new ResourceNotFoundException(id);
}
use of com.google.gerrit.reviewdb.client.RobotComment in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteOnBehalfOfWithRobotComment.
@GerritConfig(name = "notedb.writeJson", value = "true")
@Test
public void voteOnBehalfOfWithRobotComment() throws Exception {
assume().that(notesMigration.readChanges()).isTrue();
allowCodeReviewOnBehalfOf();
PushOneCommit.Result r = createChange();
ReviewInput in = new ReviewInput();
in.onBehalfOf = user.id.toString();
in.label("Code-Review", 1);
RobotCommentInput ci = new RobotCommentInput();
ci.robotId = "my-robot";
ci.robotRunId = "abcd1234";
ci.path = Patch.COMMIT_MSG;
ci.side = Side.REVISION;
ci.line = 1;
ci.message = "message";
in.robotComments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
gApi.changes().id(r.getChangeId()).current().review(in);
ChangeData cd = r.getChange();
RobotComment c = Iterables.getOnlyElement(commentsUtil.robotCommentsByChange(cd.notes()));
assertThat(c.message).isEqualTo(ci.message);
assertThat(c.robotId).isEqualTo(ci.robotId);
assertThat(c.robotRunId).isEqualTo(ci.robotRunId);
assertThat(c.author.getId()).isEqualTo(user.id);
assertThat(c.getRealAuthor().getId()).isEqualTo(admin.id);
}
use of com.google.gerrit.reviewdb.client.RobotComment in project gerrit by GerritCodeReview.
the class Fixes method parse.
@Override
public FixResource parse(RevisionResource revisionResource, IdString id) throws ResourceNotFoundException, OrmException {
String fixId = id.get();
ChangeNotes changeNotes = revisionResource.getNotes();
List<RobotComment> robotComments = commentsUtil.robotCommentsByPatchSet(changeNotes, revisionResource.getPatchSet().getId());
for (RobotComment robotComment : robotComments) {
for (FixSuggestion fixSuggestion : robotComment.fixSuggestions) {
if (Objects.equals(fixId, fixSuggestion.fixId)) {
return new FixResource(revisionResource, fixSuggestion.replacements);
}
}
}
throw new ResourceNotFoundException(id);
}
Aggregations