Search in sources :

Example 46 with Comment

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;
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) RobotComment(com.google.gerrit.reviewdb.client.RobotComment) ImmutableSet(com.google.common.collect.ImmutableSet)

Example 47 with Comment

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();
    }
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) RobotComment(com.google.gerrit.reviewdb.client.RobotComment) Repository(org.eclipse.jgit.lib.Repository)

Example 48 with Comment

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;
}
Also used : PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) OrmException(com.google.gwtorm.server.OrmException) Change(com.google.gerrit.reviewdb.client.Change) Protocol(com.google.gerrit.server.mail.receive.Protocol) Inject(com.google.inject.Inject) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) CommentsUtil(com.google.gerrit.server.CommentsUtil) Patch(com.google.gerrit.reviewdb.client.Patch) HashMap(java.util.HashMap) KeyUtil(com.google.gwtorm.client.KeyUtil) ArrayList(java.util.ArrayList) Assisted(com.google.inject.assistedinject.Assisted) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) Comment(com.google.gerrit.reviewdb.client.Comment) Config(org.eclipse.jgit.lib.Config) Map(java.util.Map) MailUtil(com.google.gerrit.server.mail.MailUtil) PatchList(com.google.gerrit.server.patch.PatchList) Project(com.google.gerrit.reviewdb.client.Project) Logger(org.slf4j.Logger) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) EmailException(com.google.gerrit.common.errors.EmailException) Set(java.util.Set) IOException(java.io.IOException) NotifyType(com.google.gerrit.server.account.WatchConfig.NotifyType) ZoneId(java.time.ZoneId) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) Collectors.toList(java.util.stream.Collectors.toList) FilenameComparator(com.google.gerrit.common.data.FilenameComparator) List(java.util.List) Ordering(com.google.common.collect.Ordering) LabelVote(com.google.gerrit.server.util.LabelVote) Optional(java.util.Optional) NoSuchEntityException(com.google.gerrit.common.errors.NoSuchEntityException) PatchFile(com.google.gerrit.server.patch.PatchFile) Comparator(java.util.Comparator) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) RobotComment(com.google.gerrit.reviewdb.client.RobotComment) Comment(com.google.gerrit.reviewdb.client.Comment) RobotComment(com.google.gerrit.reviewdb.client.RobotComment) PatchList(com.google.gerrit.server.patch.PatchList) PatchFile(com.google.gerrit.server.patch.PatchFile) PatchListNotAvailableException(com.google.gerrit.server.patch.PatchListNotAvailableException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 49 with Comment

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

Example 50 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)

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