use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class CommentsIT method listComments.
@Test
public void listComments() throws Exception {
String file = "file";
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();
assertThat(getPublishedComments(changeId, revId)).isEmpty();
assertThat(getPublishedCommentsAsList(changeId)).isEmpty();
List<CommentInput> expectedComments = new ArrayList<>();
for (Integer line : lines) {
ReviewInput input = new ReviewInput();
CommentInput comment = CommentsUtil.newComment(file, Side.REVISION, line, "comment " + line, false);
expectedComments.add(comment);
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();
List<CommentInfo> actualComments = result.get(file);
assertThat(actualComments.stream().map(infoToInput(file))).containsExactlyElementsIn(expectedComments);
List<CommentInfo> list = getPublishedCommentsAsList(changeId);
assertThat(list.stream().map(infoToInput(file))).containsExactlyElementsIn(expectedComments);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class CommentsIT method publishPartialDraftsAllRevisions.
@Test
public void publishPartialDraftsAllRevisions() 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");
PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "File content in PS2\n", r1.getChangeId()).to("refs/for/master");
CommentInfo draftOnePs1 = addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 10), "comment 1"));
CommentInfo draftTwoPs1 = addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 15), "comment 2"));
CommentInfo draftThreePs2 = addDraft(r1.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(3, 12), "comment 3"));
ReviewInput reviewInput = createReviewInput(DraftHandling.PUBLISH_ALL_REVISIONS, "review message", /* draftIdsToPublish= */
ImmutableList.of(draftOnePs1.id, draftThreePs2.id));
gApi.changes().id(r1.getChangeId()).current().review(reviewInput);
assertThat(gApi.changes().id(r1.getChangeId()).commentsRequest().getAsList().stream().map(c -> c.id)).containsExactly(draftOnePs1.id, draftThreePs2.id);
assertThat(gApi.changes().id(r1.getChangeId()).draftsRequest().getAsList().stream().map(c -> c.id)).containsExactly(draftTwoPs1.id);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class CommentsIT method publishPartialDrafts_whenDraftHandlingIsKeep_doesNotPublishDrafts.
@Test
public void publishPartialDrafts_whenDraftHandlingIsKeep_doesNotPublishDrafts() 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");
CommentInfo draftPs1 = addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 10), "comment 1"));
ReviewInput reviewInput = createReviewInput(DraftHandling.KEEP, "review message", /* draftIdsToPublish= */
ImmutableList.of(draftPs1.id));
gApi.changes().id(r1.getChangeId()).current().review(reviewInput);
assertThat(gApi.changes().id(r1.getChangeId()).commentsRequest().getAsList()).isEmpty();
assertThat(gApi.changes().id(r1.getChangeId()).draftsRequest().getAsList().stream().map(c -> c.id)).containsExactly(draftPs1.id);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class CommentsIT method publishCommentsAllRevisions.
@Test
public void publishCommentsAllRevisions() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "initial content\n", changeId).to("refs/heads/master");
PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "old boring content\n").to("refs/for/master");
PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "new interesting\ncntent\n", r1.getChangeId()).to("refs/for/master");
addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 10), "Is it that bad?"));
addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, createLineRange(0, 7), "what happened to this?"));
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 15), "better now"));
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 2, "typo: content"));
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, 1, "comment 1 on base"));
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, 2, "comment 2 on base"));
PushOneCommit.Result other = createChange();
// Drafts on other changes aren't returned.
addDraft(other.getChangeId(), other.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 1, "unrelated comment"));
requestScopeOperations.setApiUser(admin.id());
// Drafts by other users aren't returned.
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 2, "oops"));
requestScopeOperations.setApiUser(user.id());
ReviewInput reviewInput = new ReviewInput();
reviewInput.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
reviewInput.message = "comments";
gApi.changes().id(r2.getChangeId()).current().review(reviewInput);
assertThat(gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).drafts()).isEmpty();
Map<String, List<CommentInfo>> ps1Map = gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).comments();
assertThat(ps1Map.keySet()).containsExactly(FILE_NAME);
List<CommentInfo> ps1List = ps1Map.get(FILE_NAME);
assertThat(ps1List).hasSize(2);
assertThat(ps1List.get(0).message).isEqualTo("what happened to this?");
assertThat(ps1List.get(0).side).isEqualTo(Side.PARENT);
assertThat(ps1List.get(1).message).isEqualTo("Is it that bad?");
assertThat(ps1List.get(1).side).isNull();
assertThat(gApi.changes().id(r2.getChangeId()).revision(r2.getCommit().name()).drafts()).isEmpty();
Map<String, List<CommentInfo>> ps2Map = gApi.changes().id(r2.getChangeId()).revision(r2.getCommit().name()).comments();
assertThat(ps2Map.keySet()).containsExactly(FILE_NAME);
List<CommentInfo> ps2List = ps2Map.get(FILE_NAME);
assertThat(ps2List).hasSize(4);
assertThat(ps2List.get(0).message).isEqualTo("comment 1 on base");
assertThat(ps2List.get(1).message).isEqualTo("comment 2 on base");
assertThat(ps2List.get(2).message).isEqualTo("better now");
assertThat(ps2List.get(3).message).isEqualTo("typo: content");
List<Message> messages = email.getMessages(r2.getChangeId(), "comment");
assertThat(messages).hasSize(1);
String url = canonicalWebUrl.get();
int c = r1.getChange().getId().get();
assertThat(extractComments(messages.get(0).body())).isEqualTo("Patch Set 2:\n" + "\n" + "(6 comments)\n" + "\n" + "comments\n" + "\n" + "File a.txt:\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps1List.get(0).id + " \n" + "PS1, Line 1: initial\n" + "what happened to this?\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps1List.get(1).id + " \n" + "PS1, Line 1: boring\n" + "Is it that bad?\n" + "\n" + "\n" + "File a.txt:\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(0).id + " \n" + "PS2, Line 1: initial content\n" + "comment 1 on base\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(1).id + " \n" + "PS2, Line 2: \n" + "comment 2 on base\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(2).id + " \n" + "PS2, Line 1: interesting\n" + "better now\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(3).id + " \n" + "PS2, Line 2: cntent\n" + "typo: content\n" + "\n" + "\n");
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class CommentsIT method createReviewInput.
private ReviewInput createReviewInput(DraftHandling handling, String message, List<String> draftIdsToPublish) {
ReviewInput reviewInput = new ReviewInput();
reviewInput.drafts = handling;
reviewInput.message = message;
reviewInput.draftIdsToPublish = draftIdsToPublish;
return reviewInput;
}
Aggregations