Search in sources :

Example 41 with HumanComment

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

the class CommentPorterTest method commentsAreNotDroppedWhenRetrievingCommitSha1sHasUnexpectedError.

@Test
public void commentsAreNotDroppedWhenRetrievingCommitSha1sHasUnexpectedError() {
    Project.NameKey project = Project.nameKey("myProject");
    Change.Id changeId = Change.id(1);
    Change change = createChange(project, changeId);
    PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
    PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
    ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2);
    CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
    HumanComment comment = createComment(patchset1.id(), "myFile");
    when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenThrow(IllegalStateException.class);
    ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
    assertThat(portedComments).isNotEmpty();
}
Also used : Project(com.google.gerrit.entities.Project) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 42 with HumanComment

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

the class CommentPorterTest method commentsAreNotDroppedWhenDiffHasUnexpectedError.

@Test
public void commentsAreNotDroppedWhenDiffHasUnexpectedError() throws Exception {
    Project.NameKey project = Project.nameKey("myProject");
    Change.Id changeId = Change.id(1);
    Change change = createChange(project, changeId);
    PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
    PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
    ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2);
    CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
    HumanComment comment = createComment(patchset1.id(), "myFile");
    when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenReturn(Optional.of(dummyObjectId));
    when(diffOperations.listModifiedFiles(any(Project.NameKey.class), any(ObjectId.class), any(ObjectId.class), any(DiffOptions.class))).thenThrow(IllegalStateException.class);
    ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
    assertThat(portedComments).isNotEmpty();
}
Also used : Project(com.google.gerrit.entities.Project) DiffOptions(com.google.gerrit.server.patch.DiffOptions) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) HumanComment(com.google.gerrit.entities.HumanComment) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Test(org.junit.Test)

Example 43 with HumanComment

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

the class CommentPorterTest method commentsAreNotDroppedWhenDiffNotAvailable.

@Test
public void commentsAreNotDroppedWhenDiffNotAvailable() throws Exception {
    Project.NameKey project = Project.nameKey("myProject");
    Change.Id changeId = Change.id(1);
    Change change = createChange(project, changeId);
    PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
    PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
    ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2);
    CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
    HumanComment comment = createComment(patchset1.id(), "myFile");
    when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenReturn(Optional.of(dummyObjectId));
    when(diffOperations.listModifiedFiles(any(Project.NameKey.class), any(ObjectId.class), any(ObjectId.class), any(DiffOptions.class))).thenThrow(DiffNotAvailableException.class);
    ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
    assertThat(portedComments).isNotEmpty();
}
Also used : Project(com.google.gerrit.entities.Project) DiffOptions(com.google.gerrit.server.patch.DiffOptions) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) HumanComment(com.google.gerrit.entities.HumanComment) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Test(org.junit.Test)

Example 44 with HumanComment

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

the class CommentPorterTest method commentsAreMappedToPatchsetLevelOnDiffError.

@Test
public void commentsAreMappedToPatchsetLevelOnDiffError() throws Exception {
    Project.NameKey project = Project.nameKey("myProject");
    Change.Id changeId = Change.id(1);
    Change change = createChange(project, changeId);
    PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
    PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
    ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2);
    CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
    HumanComment comment = createComment(patchset1.id(), "myFile");
    when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenReturn(Optional.of(dummyObjectId));
    when(diffOperations.listModifiedFiles(any(Project.NameKey.class), any(ObjectId.class), any(ObjectId.class), any(DiffOptions.class))).thenThrow(IllegalStateException.class);
    ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
    assertThat(portedComments).comparingElementsUsing(hasFilePath()).containsExactly(Patch.PATCHSET_LEVEL);
}
Also used : Project(com.google.gerrit.entities.Project) DiffOptions(com.google.gerrit.server.patch.DiffOptions) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) HumanComment(com.google.gerrit.entities.HumanComment) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Test(org.junit.Test)

Example 45 with HumanComment

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

the class CommentsUtil method newHumanComment.

public HumanComment newHumanComment(ChangeNotes changeNotes, CurrentUser currentUser, Instant when, String path, PatchSet.Id psId, short side, String message, @Nullable Boolean unresolved, @Nullable String parentUuid) {
    if (unresolved == null) {
        if (parentUuid == null) {
            // Default to false if comment is not descended from another.
            unresolved = false;
        } else {
            // Inherit unresolved value from inReplyTo comment if not specified.
            Comment.Key key = new Comment.Key(parentUuid, path, psId.get());
            Optional<HumanComment> parent = getPublishedHumanComment(changeNotes, key);
            // If the comment was not found, it is descended from a robot comment, or the UUID is
            // invalid. Either way, we use the default.
            unresolved = parent.map(p -> p.unresolved).orElse(false);
        }
    }
    HumanComment c = new HumanComment(new Comment.Key(ChangeUtil.messageUuid(), path, psId.get()), currentUser.getAccountId(), when, side, message, serverId, unresolved);
    c.parentUuid = parentUuid;
    currentUser.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) HumanComment(com.google.gerrit.entities.HumanComment)

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