Search in sources :

Example 36 with Comment

use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.

the class CommentDetail method orderComments.

/**
   * Order the comments based on their parent_uuid parent. It is possible to do this by iterating
   * over the list only once but it's probably overkill since the number of comments on a given line
   * will be small most of the time.
   *
   * @param comments The list of comments for a given line.
   * @return The comments sorted as they should appear in the UI
   */
private static List<Comment> orderComments(List<Comment> comments) {
    // Map of comments keyed by their parent. The values are lists of comments since it is
    // possible for several comments to have the same parent (this can happen if two reviewers
    // click Reply on the same comment at the same time). Such comments will be displayed under
    // their correct parent in chronological order.
    Map<String, List<Comment>> parentMap = new HashMap<>();
    // It's possible to have more than one root comment if two reviewers create a comment on the
    // same line at the same time
    List<Comment> rootComments = new ArrayList<>();
    // Store all the comments in parentMap, keyed by their parent
    for (Comment c : comments) {
        String parentUuid = c.parentUuid;
        List<Comment> l = parentMap.get(parentUuid);
        if (l == null) {
            l = new ArrayList<>();
            parentMap.put(parentUuid, l);
        }
        l.add(c);
        if (parentUuid == null) {
            rootComments.add(c);
        }
    }
    // Add the comments in the list, starting with the head and then going through all the
    // comments that have it as a parent, and so on
    List<Comment> result = new ArrayList<>();
    addChildren(parentMap, rootComments, result);
    return result;
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 37 with Comment

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;
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) Account(com.google.gerrit.reviewdb.client.Account) Timestamp(java.sql.Timestamp)

Example 38 with Comment

use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.

the class DeleteCommentRewriter method getPutInComments.

/**
   * Gets the comments put in by the current commit. The message of the target comment will be
   * replaced by the new message.
   *
   * @param parMap the comment map of the parent commit.
   * @param curMap the comment map of the current commit.
   * @return The comments put in by the current commit.
   */
private List<Comment> getPutInComments(Map<String, Comment> parMap, Map<String, Comment> curMap) {
    List<Comment> comments = new ArrayList<>();
    for (String key : curMap.keySet()) {
        if (!parMap.containsKey(key)) {
            Comment comment = curMap.get(key);
            if (key.equals(uuid)) {
                comment.message = newMessage;
            }
            comments.add(comment);
        }
    }
    return comments;
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) ArrayList(java.util.ArrayList)

Example 39 with Comment

use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.

the class DraftCommentNotes method onLoad.

@Override
protected void onLoad(LoadHandle handle) throws IOException, ConfigInvalidException {
    ObjectId rev = handle.id();
    if (rev == null) {
        loadDefaults();
        return;
    }
    RevCommit tipCommit = handle.walk().parseCommit(rev);
    ObjectReader reader = handle.walk().getObjectReader();
    revisionNoteMap = RevisionNoteMap.parse(args.noteUtil, getChangeId(), reader, NoteMap.read(reader, tipCommit), PatchLineComment.Status.DRAFT);
    ListMultimap<RevId, Comment> cs = MultimapBuilder.hashKeys().arrayListValues().build();
    for (ChangeRevisionNote rn : revisionNoteMap.revisionNotes.values()) {
        for (Comment c : rn.getComments()) {
            cs.put(new RevId(c.revId), c);
        }
    }
    comments = ImmutableListMultimap.copyOf(cs);
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Comment(com.google.gerrit.reviewdb.client.Comment) ObjectId(org.eclipse.jgit.lib.ObjectId) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RevId(com.google.gerrit.reviewdb.client.RevId) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 40 with Comment

use of com.google.gerrit.reviewdb.client.Comment in project gerrit by GerritCodeReview.

the class ChangeNotesParser method parseNotes.

private void parseNotes() throws IOException, ConfigInvalidException {
    ObjectReader reader = walk.getObjectReader();
    ChangeNotesCommit tipCommit = walk.parseCommit(tip);
    revisionNoteMap = RevisionNoteMap.parse(noteUtil, id, reader, NoteMap.read(reader, tipCommit), PatchLineComment.Status.PUBLISHED);
    Map<RevId, ChangeRevisionNote> rns = revisionNoteMap.revisionNotes;
    for (Map.Entry<RevId, ChangeRevisionNote> e : rns.entrySet()) {
        for (Comment c : e.getValue().getComments()) {
            comments.put(e.getKey(), c);
        }
    }
    for (PatchSet ps : patchSets.values()) {
        ChangeRevisionNote rn = rns.get(ps.getRevision());
        if (rn != null && rn.getPushCert() != null) {
            ps.setPushCertificate(rn.getPushCert());
        }
    }
}
Also used : PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Comment(com.google.gerrit.reviewdb.client.Comment) ObjectReader(org.eclipse.jgit.lib.ObjectReader) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) RevId(com.google.gerrit.reviewdb.client.RevId) Map(java.util.Map) NoteMap(org.eclipse.jgit.notes.NoteMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Comment (com.google.gerrit.reviewdb.client.Comment)73 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)38 Change (com.google.gerrit.reviewdb.client.Change)35 Test (org.junit.Test)34 CommentRange (com.google.gerrit.reviewdb.client.CommentRange)29 Timestamp (java.sql.Timestamp)29 RevId (com.google.gerrit.reviewdb.client.RevId)27 ObjectId (org.eclipse.jgit.lib.ObjectId)14 ArrayList (java.util.ArrayList)12 RobotComment (com.google.gerrit.reviewdb.client.RobotComment)11 Account (com.google.gerrit.reviewdb.client.Account)9 PatchLineComment (com.google.gerrit.reviewdb.client.PatchLineComment)8 ChangeNotesRevWalk (com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk)7 Map (java.util.Map)6 Note (org.eclipse.jgit.notes.Note)6 NoteMap (org.eclipse.jgit.notes.NoteMap)6 RevWalk (org.eclipse.jgit.revwalk.RevWalk)6 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)4 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)4