use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method postCommentOnCommitMessageOnAutoMerge.
@Test
public void postCommentOnCommitMessageOnAutoMerge() throws Exception {
PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
ReviewInput input = new ReviewInput();
CommentInput c = CommentsUtil.newComment(Patch.COMMIT_MSG, Side.PARENT, 0, "comment on auto-merge", false);
input.comments = new HashMap<>();
input.comments.put(Patch.COMMIT_MSG, ImmutableList.of(c));
BadRequestException thrown = assertThrows(BadRequestException.class, () -> revision(r).review(input));
assertThat(thrown).hasMessageThat().contains("cannot comment on " + Patch.COMMIT_MSG + " on auto-merge");
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method canCreateHumanCommentWithRobotCommentAsParent.
@Test
public void canCreateHumanCommentWithRobotCommentAsParent() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
String parentRobotCommentUuid = changeOperations.change(changeId).currentPatchset().newRobotComment().create();
CommentInput createdCommentInput = CommentsUtil.newComment(COMMIT_MSG, "comment reply");
createdCommentInput.inReplyTo = parentRobotCommentUuid;
CommentsUtil.addComments(gApi, changeId, createdCommentInput);
CommentInfo resultNewComment = Iterables.getOnlyElement(getPublishedCommentsAsList(changeId).stream().filter(c -> c.message.equals("comment reply")).collect(toImmutableSet()));
assertThat(resultNewComment.inReplyTo).isEqualTo(parentRobotCommentUuid);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method deleteCommentByRewritingCommitHistory.
@Test
public void deleteCommentByRewritingCommitHistory() throws Exception {
// Creates the following commit history on the meta branch of the test change. Then tries to
// delete the comments one by one, which will rewrite most of the commits on the 'meta' branch.
// Commits will be rewritten N times for N added comments. After each deletion, the meta branch
// should keep its previous state except that the target comment's message should be updated.
// 1st commit: Create PS1.
PushOneCommit.Result result1 = createChange(SUBJECT, "a.txt", "a");
Change.Id id = result1.getChange().getId();
String changeId = result1.getChangeId();
String ps1 = result1.getCommit().name();
// 2nd commit: Add (c1) to PS1.
CommentInput c1 = CommentsUtil.newComment("a.txt", "comment 1");
CommentsUtil.addComments(gApi, changeId, ps1, c1);
// 3rd commit: Add (c2, c3) to PS1.
CommentInput c2 = CommentsUtil.newComment("a.txt", "comment 2");
CommentInput c3 = CommentsUtil.newComment("a.txt", "comment 3");
CommentsUtil.addComments(gApi, changeId, ps1, c2, c3);
// 4th commit: Add (c4) to PS1.
CommentInput c4 = CommentsUtil.newComment("a.txt", "comment 4");
CommentsUtil.addComments(gApi, changeId, ps1, c4);
// 5th commit: Create PS2.
PushOneCommit.Result result2 = amendChange(changeId, "refs/for/master", "b.txt", "b");
String ps2 = result2.getCommit().name();
// 6th commit: Add (c5) to PS1.
CommentInput c5 = CommentsUtil.newComment("a.txt", "comment 5");
CommentsUtil.addComments(gApi, changeId, ps1, c5);
// 7th commit: Add (c6) to PS2.
CommentInput c6 = CommentsUtil.newComment("b.txt", "comment 6");
CommentsUtil.addComments(gApi, changeId, ps2, c6);
// 8th commit: Create PS3.
PushOneCommit.Result result3 = amendChange(changeId);
String ps3 = result3.getCommit().name();
// 9th commit: Create PS4.
PushOneCommit.Result result4 = amendChange(changeId, "refs/for/master", "c.txt", "c");
String ps4 = result4.getCommit().name();
// 10th commit: Add (c7, c8) to PS4.
CommentInput c7 = CommentsUtil.newComment("c.txt", "comment 7");
CommentInput c8 = CommentsUtil.newComment("b.txt", "comment 8");
CommentsUtil.addComments(gApi, changeId, ps4, c7, c8);
// 11th commit: Add (c9) to PS2.
CommentInput c9 = CommentsUtil.newCommentWithOnlyMandatoryFields("b.txt", "comment 9");
CommentsUtil.addComments(gApi, changeId, ps2, c9);
List<CommentInfo> commentsBeforeDelete = getChangeSortedComments(id.get());
assertThat(commentsBeforeDelete).hasSize(9);
// PS1 has comments [c1, c2, c3, c4, c5].
assertThat(getRevisionComments(changeId, ps1)).hasSize(5);
// PS2 has comments [c6, c9].
assertThat(getRevisionComments(changeId, ps2)).hasSize(2);
// PS3 has no comment.
assertThat(getRevisionComments(changeId, ps3)).isEmpty();
// PS4 has comments [c7, c8].
assertThat(getRevisionComments(changeId, ps4)).hasSize(2);
requestScopeOperations.setApiUser(admin.id());
for (int i = 0; i < commentsBeforeDelete.size(); i++) {
List<RevCommit> commitsBeforeDelete = getChangeMetaCommitsInReverseOrder(id);
CommentInfo comment = commentsBeforeDelete.get(i);
String uuid = comment.id;
int patchSet = comment.patchSet;
// 'oldComment' has some fields unset compared with 'comment'.
CommentInfo oldComment = gApi.changes().id(changeId).revision(patchSet).comment(uuid).get();
DeleteCommentInput input = new DeleteCommentInput("delete comment " + uuid);
CommentInfo updatedComment = gApi.changes().id(changeId).revision(patchSet).comment(uuid).delete(input);
String expectedMsg = String.format("Comment removed by: %s; Reason: %s", admin.fullName(), input.reason);
assertThat(updatedComment.message).isEqualTo(expectedMsg);
oldComment.message = expectedMsg;
assertThat(updatedComment).isEqualTo(oldComment);
// Check the NoteDb state after the deletion.
assertMetaBranchCommitsAfterRewriting(commitsBeforeDelete, id, uuid, expectedMsg);
comment.message = expectedMsg;
commentsBeforeDelete.set(i, comment);
List<CommentInfo> commentsAfterDelete = getChangeSortedComments(id.get());
assertThat(commentsAfterDelete).isEqualTo(commentsBeforeDelete);
}
// Make sure that comments can still be added correctly.
CommentInput c10 = CommentsUtil.newComment("a.txt", "comment 10");
CommentInput c11 = CommentsUtil.newComment("b.txt", "comment 11");
CommentInput c12 = CommentsUtil.newComment("a.txt", "comment 12");
CommentInput c13 = CommentsUtil.newComment("c.txt", "comment 13");
CommentsUtil.addComments(gApi, changeId, ps1, c10);
CommentsUtil.addComments(gApi, changeId, ps2, c11);
CommentsUtil.addComments(gApi, changeId, ps3, c12);
CommentsUtil.addComments(gApi, changeId, ps4, c13);
assertThat(getChangeSortedComments(id.get())).hasSize(13);
assertThat(getRevisionComments(changeId, ps1)).hasSize(6);
assertThat(getRevisionComments(changeId, ps2)).hasSize(3);
assertThat(getRevisionComments(changeId, ps3)).hasSize(1);
assertThat(getRevisionComments(changeId, ps4)).hasSize(3);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method postComment.
@Test
public void postComment() throws Exception {
for (Integer line : lines) {
String file = "file";
String contents = "contents " + line;
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "first subject", file, contents);
PushOneCommit.Result r = push.to("refs/for/master");
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
ReviewInput input = new ReviewInput();
CommentInput comment = CommentsUtil.newComment(file, Side.REVISION, line, "comment 1", false);
input.comments = new HashMap<>();
input.comments.put(comment.path, Lists.newArrayList(comment));
revision(r).review(input);
Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
assertThat(result).isNotEmpty();
CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
assertThat(comment).isEqualTo(infoToInput(file).apply(actual));
assertThat(comment).isEqualTo(infoToInput(file).apply(getPublishedComment(changeId, revId, actual.id)));
}
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method insertCommentsWithHistoricTimestamp.
@Test
public void insertCommentsWithHistoricTimestamp() throws Exception {
Instant timestamp = Instant.EPOCH;
for (Integer line : lines) {
String file = "file";
String contents = "contents " + line;
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "first subject", file, contents);
PushOneCommit.Result r = push.to("refs/for/master");
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
Instant origLastUpdated = r.getChange().change().getLastUpdatedOn();
ReviewInput input = new ReviewInput();
CommentInput comment = CommentsUtil.newComment(file, Side.REVISION, line, "comment 1", false);
comment.setUpdated(timestamp);
input.comments = new HashMap<>();
input.comments.put(comment.path, Lists.newArrayList(comment));
ChangeResource changeRsrc = changes.get().parse(TopLevelResource.INSTANCE, IdString.fromDecoded(changeId));
RevisionResource revRsrc = revisions.parse(changeRsrc, IdString.fromDecoded(revId));
postReview.get().apply(revRsrc, input, timestamp);
Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
assertThat(result).isNotEmpty();
CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
CommentInput ci = infoToInput(file).apply(actual);
ci.updated = comment.updated;
assertThat(comment).isEqualTo(ci);
assertThat(actual.updated).isEqualTo(gApi.changes().id(r.getChangeId()).info().created);
// Updating historic comments doesn't cause lastUpdatedOn to regress.
assertThat(r.getChange().change().getLastUpdatedOn()).isEqualTo(origLastUpdated);
}
}
Aggregations