use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method deleteOneCommentMultipleTimes.
@Test
public void deleteOneCommentMultipleTimes() throws Exception {
PushOneCommit.Result result = createChange();
Change.Id id = result.getChange().getId();
String changeId = result.getChangeId();
String ps1 = result.getCommit().name();
CommentInput c1 = CommentsUtil.newComment(FILE_NAME, "comment 1");
CommentInput c2 = CommentsUtil.newComment(FILE_NAME, "comment 2");
CommentInput c3 = CommentsUtil.newComment(FILE_NAME, "comment 3");
CommentsUtil.addComments(gApi, changeId, ps1, c1);
CommentsUtil.addComments(gApi, changeId, ps1, c2);
CommentsUtil.addComments(gApi, changeId, ps1, c3);
List<CommentInfo> commentsBeforeDelete = getChangeSortedComments(id.get());
assertThat(commentsBeforeDelete).hasSize(3);
Optional<CommentInfo> targetComment = commentsBeforeDelete.stream().filter(c -> c.message.equals("comment 2")).findFirst();
assertThat(targetComment).isPresent();
String uuid = targetComment.get().id;
CommentInfo oldComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
List<RevCommit> commitsBeforeDelete = getChangeMetaCommitsInReverseOrder(id);
requestScopeOperations.setApiUser(admin.id());
for (int i = 0; i < 3; i++) {
DeleteCommentInput input = new DeleteCommentInput("delete comment 2, iteration: " + i);
gApi.changes().id(changeId).revision(ps1).comment(uuid).delete(input);
}
CommentInfo updatedComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
String expectedMsg = String.format("Comment removed by: %s; Reason: %s", admin.fullName(), "delete comment 2, iteration: 2");
assertThat(updatedComment.message).isEqualTo(expectedMsg);
oldComment.message = expectedMsg;
assertThat(updatedComment).isEqualTo(oldComment);
assertMetaBranchCommitsAfterRewriting(commitsBeforeDelete, id, uuid, expectedMsg);
assertThat(getChangeSortedComments(id.get())).hasSize(3);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method postCommentOnMergeCommitChange.
@Test
public void postCommentOnMergeCommitChange() throws Exception {
for (Integer line : lines) {
String file = "foo";
PushOneCommit.Result r = createMergeCommitChange("refs/for/master", file);
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
ReviewInput input = new ReviewInput();
CommentInput c1 = CommentsUtil.newComment(file, Side.REVISION, line, "ps-1", false);
CommentInput c2 = CommentsUtil.newComment(file, Side.PARENT, line, "auto-merge of ps-1", false);
CommentInput c3 = CommentsUtil.newCommentOnParent(file, 1, line, "parent-1 of ps-1");
CommentInput c4 = CommentsUtil.newCommentOnParent(file, 2, line, "parent-2 of ps-1");
input.comments = new HashMap<>();
input.comments.put(file, ImmutableList.of(c1, c2, c3, c4));
revision(r).review(input);
Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
assertThat(result).isNotEmpty();
assertThat(result.get(file).stream().map(infoToInput(file))).containsExactly(c1, c2, c3, c4);
List<CommentInfo> list = getPublishedCommentsAsList(changeId);
assertThat(list.stream().map(infoToInput(file))).containsExactly(c1, c2, c3, c4);
}
// for the commit message comments on the auto-merge are not possible
for (Integer line : lines) {
String file = Patch.COMMIT_MSG;
PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
ReviewInput input = new ReviewInput();
CommentInput c1 = CommentsUtil.newComment(file, Side.REVISION, line, "ps-1", false);
CommentInput c2 = CommentsUtil.newCommentOnParent(file, 1, line, "parent-1 of ps-1");
CommentInput c3 = CommentsUtil.newCommentOnParent(file, 2, line, "parent-2 of ps-1");
input.comments = new HashMap<>();
input.comments.put(file, ImmutableList.of(c1, c2, c3));
revision(r).review(input);
Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
assertThat(result).isNotEmpty();
assertThat(result.get(file).stream().map(infoToInput(file))).containsExactly(c1, c2, c3);
List<CommentInfo> list = getPublishedCommentsAsList(changeId);
assertThat(list.stream().map(infoToInput(file))).containsExactly(c1, c2, c3);
}
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method canCreateHumanCommentWithRobotCommentAsParentAndUnsetUnresolved.
@Test
public void canCreateHumanCommentWithRobotCommentAsParentAndUnsetUnresolved() 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;
createdCommentInput.unresolved = null;
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);
// Default unresolved is false.
assertThat(resultNewComment.unresolved).isFalse();
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method patchsetLevelCommentCantHaveRange.
@Test
public void patchsetLevelCommentCantHaveRange() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
String ps1 = result.getCommit().name();
CommentInput input = CommentsUtil.newCommentWithOnlyMandatoryFields(PATCHSET_LEVEL, "comment");
input.range = createLineRange(1, 3);
BadRequestException ex = assertThrows(BadRequestException.class, () -> CommentsUtil.addComments(gApi, changeId, ps1, input));
assertThat(ex.getMessage()).contains("range");
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method commentsOnRootCommitsAreIncludedInEmails.
@Test
public void commentsOnRootCommitsAreIncludedInEmails() throws Exception {
// Create a change in a new branch, making the patch-set commit a root commit.
ChangeInfo changeInfo = createChangeInNewBranch("newBranch");
Change.Id changeId = Change.Id.tryParse(Integer.toString(changeInfo._number)).get();
// Add a file.
gApi.changes().id(changeId.get()).edit().modifyFile("f1.txt", RawInputUtil.create("content"));
gApi.changes().id(changeId.get()).edit().publish();
email.clear();
ReviewerInput reviewerInput = new ReviewerInput();
reviewerInput.reviewer = admin.email();
gApi.changes().id(changeId.get()).addReviewer(reviewerInput);
changeInfo = gApi.changes().id(changeId.get()).get();
assertThat(email.getMessages()).hasSize(1);
Message message = email.getMessages().get(0);
assertThat(message.body()).contains("f1.txt");
email.clear();
// Send a comment. Make sure the email that is sent includes the comment text.
CommentInput c1 = CommentsUtil.newComment("f1.txt", Side.REVISION, /* line= */
1, /* message= */
"Comment text", /* unresolved= */
false);
CommentsUtil.addComments(gApi, changeId.toString(), changeInfo.currentRevision, c1);
assertThat(email.getMessages()).hasSize(1);
Message commentMessage = email.getMessages().get(0);
assertThat(commentMessage.body()).contains("Patch Set 2:\n" + "\n" + "(1 comment)\n" + "\n" + "File f1.txt:");
assertThat(commentMessage.body()).contains("PS2, Line 1: content\n" + "Comment text");
}
Aggregations