Search in sources :

Example 16 with HumanComment

use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.

the class ChangeNotesTest method patchLineCommentEmptyFilename.

@Test
public void patchLineCommentEmptyFilename() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, otherUser);
    PatchSet.Id psId = c.currentPatchSetId();
    ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
    CommentRange range = new CommentRange(1, 2, 3, 4);
    HumanComment comment = newComment(psId, "", "uuid", range, range.getEndLine(), otherUser, null, TimeUtil.now(), "message", (short) 1, commitId, false);
    update.setPatchSetId(psId);
    update.putComment(HumanComment.Status.PUBLISHED, comment);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment));
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) CommentRange(com.google.gerrit.entities.CommentRange) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 17 with HumanComment

use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.

the class ChangeUpdate method storeRevisionNotes.

/**
 * Returns the tree id for the updated tree
 */
private ObjectId storeRevisionNotes(RevWalk rw, ObjectInserter inserter, ObjectId curr) throws ConfigInvalidException, IOException {
    if (submitRequirementResults == null && comments.isEmpty() && pushCert == null) {
        return null;
    }
    RevisionNoteMap<ChangeRevisionNote> rnm = getRevisionNoteMap(rw, curr);
    RevisionNoteBuilder.Cache cache = new RevisionNoteBuilder.Cache(rnm);
    for (HumanComment c : comments) {
        c.tag = tag;
        cache.get(c.getCommitId()).putComment(c);
    }
    if (submitRequirementResults != null) {
        if (submitRequirementResults.isEmpty()) {
            ObjectId latestPsCommitId = Iterables.getLast(getNotes().getPatchSets().values()).commitId();
            cache.get(latestPsCommitId).createEmptySubmitRequirementResults();
        } else {
            for (SubmitRequirementResult sr : submitRequirementResults) {
                cache.get(sr.patchSetCommitId()).putSubmitRequirementResult(sr);
            }
        }
    }
    if (pushCert != null) {
        checkState(commit != null);
        cache.get(ObjectId.fromString(commit)).setPushCertificate(pushCert);
    }
    Map<ObjectId, RevisionNoteBuilder> builders = cache.getBuilders();
    checkComments(rnm.revisionNotes, builders);
    for (Map.Entry<ObjectId, RevisionNoteBuilder> e : builders.entrySet()) {
        ObjectId data = inserter.insert(OBJ_BLOB, e.getValue().build(noteUtil.getChangeNoteJson()));
        rnm.noteMap.set(e.getKey(), data);
    }
    return rnm.noteMap.writeTree(inserter);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) HumanComment(com.google.gerrit.entities.HumanComment) Map(java.util.Map) NoteMap(org.eclipse.jgit.notes.NoteMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProjectCache(com.google.gerrit.server.project.ProjectCache)

Example 18 with HumanComment

use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.

the class CommentThreadsTest method threadsIgnoreDuplicateChildren.

@Test
public void threadsIgnoreDuplicateChildren() {
    HumanComment root = createComment("root");
    HumanComment child1 = asReply(createComment("child1"), "root");
    ImmutableList<HumanComment> comments = ImmutableList.of(root, child1, child1);
    ImmutableSet<CommentThread<HumanComment>> commentThreads = CommentThreads.forComments(comments).getThreads();
    ImmutableSet<CommentThread<HumanComment>> expectedThreads = ImmutableSet.of(toThread(root, child1));
    assertThat(commentThreads).isEqualTo(expectedThreads);
}
Also used : HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 19 with HumanComment

use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.

the class CommentThreadsTest method threadsCanBeCreatedFromUnorderedComments.

@Test
public void threadsCanBeCreatedFromUnorderedComments() {
    HumanComment root = createComment("root");
    HumanComment child1 = asReply(createComment("child1"), "root");
    HumanComment child2 = asReply(createComment("child2"), "child1");
    HumanComment child3 = asReply(createComment("child3"), "child2");
    ImmutableList<HumanComment> comments = ImmutableList.of(child2, child1, root, child3);
    ImmutableSet<CommentThread<HumanComment>> commentThreads = CommentThreads.forComments(comments).getThreads();
    ImmutableSet<CommentThread<HumanComment>> expectedThreads = ImmutableSet.of(toThread(root, child1, child2, child3));
    assertThat(commentThreads).isEqualTo(expectedThreads);
}
Also used : HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 20 with HumanComment

use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.

the class CommentThreadsTest method requestedThreadsDoNotNeedToContainReply.

@Test
public void requestedThreadsDoNotNeedToContainReply() {
    HumanComment thread1Root = createComment("thread1Root");
    HumanComment thread2Root = createComment("thread2Root");
    HumanComment thread1Reply = asReply(createComment("thread1Reply"), "thread1Root");
    ImmutableList<HumanComment> comments = ImmutableList.of(thread1Root, thread2Root);
    ImmutableSet<CommentThread<HumanComment>> commentThreads = CommentThreads.forComments(comments).getThreadsForChildren(ImmutableList.of(thread1Reply));
    ImmutableSet<CommentThread<HumanComment>> expectedThreads = ImmutableSet.of(toThread(thread1Root));
    assertThat(commentThreads).isEqualTo(expectedThreads);
}
Also used : HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Aggregations

HumanComment (com.google.gerrit.entities.HumanComment)87 Test (org.junit.Test)53 Change (com.google.gerrit.entities.Change)39 PatchSet (com.google.gerrit.entities.PatchSet)39 ObjectId (org.eclipse.jgit.lib.ObjectId)39 CommentRange (com.google.gerrit.entities.CommentRange)25 Instant (java.time.Instant)20 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)14 Comment (com.google.gerrit.entities.Comment)11 Project (com.google.gerrit.entities.Project)11 Map (java.util.Map)11 ArrayList (java.util.ArrayList)8 RevCommit (org.eclipse.jgit.revwalk.RevCommit)8 HashMap (java.util.HashMap)7 NoteMap (org.eclipse.jgit.notes.NoteMap)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 TraceTimer (com.google.gerrit.server.logging.TraceContext.TraceTimer)6 FluentLogger (com.google.common.flogger.FluentLogger)5 Account (com.google.gerrit.entities.Account)5 BranchNameKey (com.google.gerrit.entities.BranchNameKey)5