use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class CommentsIT method listDrafts.
@Test
public void listDrafts() throws Exception {
String file = "file";
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
assertThat(getDraftComments(changeId, revId)).isEmpty();
List<DraftInput> expectedDrafts = new ArrayList<>();
for (Integer line : lines) {
DraftInput comment = CommentsUtil.newDraft(file, Side.REVISION, line, "comment " + line);
expectedDrafts.add(comment);
addDraft(changeId, revId, comment);
}
Map<String, List<CommentInfo>> result = getDraftComments(changeId, revId);
assertThat(result).isNotEmpty();
List<CommentInfo> actualComments = result.get(file);
assertThat(actualComments.stream().map(infoToDraft(file))).containsExactlyElementsIn(expectedDrafts);
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class CommentsIT method canCreateHumanCommentWithHumanCommentAsParent.
@Test
public void canCreateHumanCommentWithHumanCommentAsParent() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
String parentCommentUuid = changeOperations.change(changeId).currentPatchset().newComment().create();
CommentInput createdCommentInput = CommentsUtil.newComment(COMMIT_MSG, "comment reply");
createdCommentInput.inReplyTo = parentCommentUuid;
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(parentCommentUuid);
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class CommentsIT method publishPartialDraftsForAnotherUserIsNotAllowed.
@Test
public void publishPartialDraftsForAnotherUserIsNotAllowed() throws Exception {
pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "initial content\n").to("refs/heads/master");
PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "File content in PS1\n").to("refs/for/master");
// Add drafts with user scope
requestScopeOperations.setApiUser(accountCreator.user1().id());
CommentInfo draft = addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 10), "comment 1"));
ReviewInput reviewInput = createReviewInput(DraftHandling.PUBLISH_ALL_REVISIONS, "review message", /* draftIdsToPublish= */
ImmutableList.of(draft.id));
// Try to publish the drafts using user2 scope
requestScopeOperations.setApiUser(accountCreator.user2().id());
Exception error = assertThrows(BadRequestException.class, () -> gApi.changes().id(r1.getChangeId()).current().review(reviewInput));
assertThat(error).hasMessageThat().isEqualTo(String.format("Non-existing draft IDs: [%s]", draft.id));
// Request will succeed if done by user
requestScopeOperations.setApiUser(accountCreator.user1().id());
gApi.changes().id(r1.getChangeId()).current().review(reviewInput);
assertThat(gApi.changes().id(r1.getChangeId()).commentsRequest().getAsList().stream().map(c -> c.id)).containsExactly(draft.id);
assertThat(gApi.changes().id(r1.getChangeId()).draftsRequest().getAsList()).isEmpty();
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class CommentsIT method deletePatchsetLevelComment.
@Test
public void deletePatchsetLevelComment() throws Exception {
requestScopeOperations.setApiUser(admin.id());
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
String commentMessage = "to be deleted";
CommentInput comment = CommentsUtil.newCommentWithOnlyMandatoryFields(PATCHSET_LEVEL, commentMessage);
CommentsUtil.addComments(gApi, changeId, revId, comment);
Map<String, List<CommentInfo>> results = getPublishedComments(changeId, revId);
CommentInfo oldComment = Iterables.getOnlyElement(results.get(PATCHSET_LEVEL));
DeleteCommentInput input = new DeleteCommentInput("reason");
gApi.changes().id(changeId).revision(revId).comment(oldComment.id).delete(input);
CommentInfo updatedComment = Iterables.getOnlyElement(getPublishedComments(changeId, revId).get(PATCHSET_LEVEL));
assertThat(updatedComment.message).doesNotContain(commentMessage);
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method publishCommentsOnPushPublishesDraftsOnMultipleChanges.
@Test
public void publishCommentsOnPushPublishesDraftsOnMultipleChanges() throws Exception {
ObjectId initialHead = testRepo.getRepository().resolve("HEAD");
List<RevCommit> commits = createChanges(2, "refs/for/master");
String id1 = byCommit(commits.get(0)).change().getKey().get();
String id2 = byCommit(commits.get(1)).change().getKey().get();
CommentInfo c1 = addDraft(id1, commits.get(0).name(), newDraft(FILE_NAME, 1, "comment1"));
CommentInfo c2 = addDraft(id2, commits.get(1).name(), newDraft(FILE_NAME, 1, "comment2"));
assertThat(getPublishedComments(id1)).isEmpty();
assertThat(getPublishedComments(id2)).isEmpty();
amendChanges(initialHead, commits, "refs/for/master%publish-comments");
Collection<CommentInfo> cs1 = getPublishedComments(id1);
List<ChangeMessageInfo> messages1 = getMessages(id1);
assertThat(cs1.stream().map(c -> c.message)).containsExactly("comment1");
assertThat(cs1.stream().map(c -> c.id)).containsExactly(c1.id);
assertThat(messages1.get(0).message).isEqualTo("Uploaded patch set 1.");
assertThat(messages1.get(1).message).isEqualTo("Uploaded patch set 2: Commit message was updated.");
assertThat(messages1.get(2).message).isEqualTo("Patch Set 2:\n\n(1 comment)");
Collection<CommentInfo> cs2 = getPublishedComments(id2);
List<ChangeMessageInfo> messages2 = getMessages(id2);
assertThat(cs2.stream().map(c -> c.message)).containsExactly("comment2");
assertThat(cs2.stream().map(c -> c.id)).containsExactly(c2.id);
assertThat(messages2.get(0).message).isEqualTo("Uploaded patch set 1.");
assertThat(messages2.get(1).message).isEqualTo("Uploaded patch set 2: Commit message was updated.");
assertThat(messages2.get(2).message).isEqualTo("Patch Set 2:\n\n(1 comment)");
}
Aggregations