Search in sources :

Example 51 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 52 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 53 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)

Example 54 with Comment

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

the class ChangeNotesTest method updateCommentsInSequentialUpdates.

@Test
public void updateCommentsInSequentialUpdates() throws Exception {
    Change c = newChange();
    CommentRange range = new CommentRange(1, 1, 2, 1);
    String rev = "abcd1234abcd1234abcd1234abcd1234abcd1234";
    ChangeUpdate update1 = newUpdate(c, otherUser);
    Comment comment1 = newComment(c.currentPatchSetId(), "filename", "uuid1", range, range.getEndLine(), otherUser, null, new Timestamp(update1.getWhen().getTime()), "comment 1", (short) 1, rev, false);
    update1.putComment(Status.PUBLISHED, comment1);
    ChangeUpdate update2 = newUpdate(c, otherUser);
    Comment comment2 = newComment(c.currentPatchSetId(), "filename", "uuid2", range, range.getEndLine(), otherUser, null, new Timestamp(update2.getWhen().getTime()), "comment 2", (short) 1, rev, false);
    update2.putComment(Status.PUBLISHED, comment2);
    try (NoteDbUpdateManager manager = updateManagerFactory.create(project)) {
        manager.add(update1);
        manager.add(update2);
        manager.execute();
    }
    ChangeNotes notes = newNotes(c);
    List<Comment> comments = notes.getComments().get(new RevId(rev));
    assertThat(comments).hasSize(2);
    assertThat(comments.get(0).message).isEqualTo("comment 1");
    assertThat(comments.get(1).message).isEqualTo("comment 2");
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp) RevId(com.google.gerrit.reviewdb.client.RevId) Test(org.junit.Test)

Example 55 with Comment

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

the class ChangeNotesTest method multipleTags.

@Test
public void multipleTags() throws Exception {
    String ipTag = "ip";
    String coverageTag = "coverage";
    String integrationTag = "integration";
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval("Verified", (short) -1);
    update.setChangeMessage("integration verification");
    update.setTag(integrationTag);
    update.commit();
    RevCommit commit = tr.commit().message("PS2").create();
    update = newUpdate(c, changeOwner);
    update.putComment(Status.PUBLISHED, newComment(c.currentPatchSetId(), "a.txt", "uuid1", new CommentRange(1, 2, 3, 4), 1, changeOwner, null, TimeUtil.nowTs(), "Comment", (short) 1, commit.name(), false));
    update.setChangeMessage("coverage verification");
    update.setTag(coverageTag);
    update.commit();
    update = newUpdate(c, changeOwner);
    update.setChangeMessage("ip clear");
    update.setTag(ipTag);
    update.commit();
    ChangeNotes notes = newNotes(c);
    ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals = notes.getApprovals();
    assertThat(approvals).hasSize(1);
    PatchSetApproval approval = approvals.entries().asList().get(0).getValue();
    assertThat(approval.getTag()).isEqualTo(integrationTag);
    assertThat(approval.getValue()).isEqualTo(-1);
    ImmutableListMultimap<RevId, Comment> comments = notes.getComments();
    assertThat(comments).hasSize(1);
    assertThat(comments.entries().asList().get(0).getValue().tag).isEqualTo(coverageTag);
    ImmutableList<ChangeMessage> messages = notes.getChangeMessages();
    assertThat(messages).hasSize(3);
    assertThat(messages.get(0).getTag()).isEqualTo(integrationTag);
    assertThat(messages.get(1).getTag()).isEqualTo(coverageTag);
    assertThat(messages.get(2).getTag()).isEqualTo(ipTag);
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) RevId(com.google.gerrit.reviewdb.client.RevId) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) RequestId(com.google.gerrit.server.util.RequestId) GerritServerId(com.google.gerrit.server.config.GerritServerId) ObjectId(org.eclipse.jgit.lib.ObjectId) RevId(com.google.gerrit.reviewdb.client.RevId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

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