Search in sources :

Example 1 with RobotComment

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;
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RobotComment(com.google.gerrit.entities.RobotComment) Map(java.util.Map) NoteMap(org.eclipse.jgit.notes.NoteMap)

Example 2 with RobotComment

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);
}
Also used : RobotComment(com.google.gerrit.entities.RobotComment) RobotCommentResource(com.google.gerrit.server.change.RobotCommentResource) IdString(com.google.gerrit.extensions.restapi.IdString) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException)

Example 3 with RobotComment

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;
}
Also used : Comment(com.google.gerrit.entities.Comment) HumanComment(com.google.gerrit.entities.HumanComment) RobotComment(com.google.gerrit.entities.RobotComment) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RobotComment(com.google.gerrit.entities.RobotComment) HashMap(java.util.HashMap) Map(java.util.Map) HumanComment(com.google.gerrit.entities.HumanComment)

Example 4 with RobotComment

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;
}
Also used : Comment(com.google.gerrit.entities.Comment) HumanComment(com.google.gerrit.entities.HumanComment) RobotComment(com.google.gerrit.entities.RobotComment) RobotComment(com.google.gerrit.entities.RobotComment)

Example 5 with RobotComment

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();
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RobotComment(com.google.gerrit.entities.RobotComment) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Aggregations

RobotComment (com.google.gerrit.entities.RobotComment)7 Comment (com.google.gerrit.entities.Comment)2 HumanComment (com.google.gerrit.entities.HumanComment)2 IdString (com.google.gerrit.extensions.restapi.IdString)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)2 Map (java.util.Map)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 FixSuggestion (com.google.gerrit.entities.FixSuggestion)1 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)1 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)1 FixResource (com.google.gerrit.server.change.FixResource)1 RobotCommentResource (com.google.gerrit.server.change.RobotCommentResource)1 ChangeData (com.google.gerrit.server.query.change.ChangeData)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ObjectReader (org.eclipse.jgit.lib.ObjectReader)1