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();
}
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();
}
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();
}
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);
}
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;
}
Aggregations