use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class AbstractPushForReview method publishCommentsOnPushPublishesDraftsOnAllRevisions.
@Test
public void publishCommentsOnPushPublishesDraftsOnAllRevisions() throws Exception {
PushOneCommit.Result r = createChange();
String rev1 = r.getCommit().name();
CommentInfo c1 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment1"));
CommentInfo c2 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment2"));
r = amendChange(r.getChangeId());
String rev2 = r.getCommit().name();
CommentInfo c3 = addDraft(r.getChangeId(), rev2, newDraft(FILE_NAME, 1, "comment3"));
assertThat(getPublishedComments(r.getChangeId())).isEmpty();
gApi.changes().id(r.getChangeId()).addReviewer(user.email);
sender.clear();
amendChange(r.getChangeId(), "refs/for/master%publish-comments");
Collection<CommentInfo> comments = getPublishedComments(r.getChangeId());
assertThat(comments.stream().map(c -> c.id)).containsExactly(c1.id, c2.id, c3.id);
assertThat(comments.stream().map(c -> c.message)).containsExactly("comment1", "comment2", "comment3");
assertThat(getLastMessage(r.getChangeId())).isEqualTo("Uploaded patch set 3.\n\n(3 comments)");
List<String> messages = sender.getMessages().stream().map(m -> m.body()).sorted(Comparator.comparingInt(m -> m.contains("reexamine") ? 0 : 1)).collect(toList());
assertThat(messages).hasSize(2);
assertThat(messages.get(0)).contains("Gerrit-MessageType: newpatchset");
assertThat(messages.get(0)).contains("I'd like you to reexamine a change");
assertThat(messages.get(0)).doesNotContain("Uploaded patch set 3");
assertThat(messages.get(1)).contains("Gerrit-MessageType: comment");
assertThat(messages.get(1)).containsMatch(Pattern.compile(// then, this test documents the current behavior.
"Uploaded patch set 3\\.\n" + "\n" + "\\(3 comments\\)\\n.*" + "PS1, Line 1:.*" + "comment1\\n.*" + "PS1, Line 1:.*" + "comment2\\n.*" + "PS2, Line 1:.*" + "comment3\\n", Pattern.DOTALL));
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf.
@Test
public void voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf() throws Exception {
allowRunAs();
PushOneCommit.Result r = createChange();
setApiUser(user);
DraftInput di = new DraftInput();
di.path = Patch.COMMIT_MSG;
di.side = Side.REVISION;
di.line = 1;
di.message = "inline comment";
gApi.changes().id(r.getChangeId()).current().createDraft(di);
setApiUser(admin);
// Things that aren't allowed with on_behalf_of:
// - no labels.
// - publish other user's drafts.
ReviewInput in = new ReviewInput();
in.message = "message";
in.drafts = DraftHandling.PUBLISH;
RestResponse res = adminRestSession.postWithHeader("/changes/" + r.getChangeId() + "/revisions/current/review", in, runAsHeader(user.id));
res.assertOK();
ChangeMessageInfo m = Iterables.getLast(gApi.changes().id(r.getChangeId()).get().messages);
assertThat(m.message).endsWith(in.message);
assertThat(m.author._accountId).isEqualTo(user.id.get());
CommentInfo c = Iterables.getOnlyElement(gApi.changes().id(r.getChangeId()).comments().get(di.path));
assertThat(c.author._accountId).isEqualTo(user.id.get());
assertThat(c.message).isEqualTo(di.message);
setApiUser(user);
assertThat(gApi.changes().id(r.getChangeId()).drafts()).isEmpty();
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class CommentsIT method commentTags.
@Test
public void commentTags() throws Exception {
PushOneCommit.Result r = createChange();
CommentInput pub = new CommentInput();
pub.line = 1;
pub.message = "published comment";
pub.path = FILE_NAME;
ReviewInput rin = newInput(pub);
rin.tag = "tag1";
gApi.changes().id(r.getChangeId()).current().review(rin);
List<CommentInfo> comments = gApi.changes().id(r.getChangeId()).current().commentsAsList();
assertThat(comments).hasSize(1);
assertThat(comments.get(0).tag).isEqualTo("tag1");
DraftInput draft = new DraftInput();
draft.line = 2;
draft.message = "draft comment";
draft.path = FILE_NAME;
draft.tag = "tag2";
addDraft(r.getChangeId(), r.getCommit().name(), draft);
List<CommentInfo> drafts = gApi.changes().id(r.getChangeId()).current().draftsAsList();
assertThat(drafts).hasSize(1);
assertThat(drafts.get(0).tag).isEqualTo("tag2");
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class CommentsIT method putDraft.
@Test
public void putDraft() throws Exception {
for (Integer line : lines) {
PushOneCommit.Result r = createChange();
Timestamp origLastUpdated = r.getChange().change().getLastUpdatedOn();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
String path = "file1";
DraftInput comment = newDraft(path, Side.REVISION, line, "comment 1");
addDraft(changeId, revId, comment);
Map<String, List<CommentInfo>> result = getDraftComments(changeId, revId);
CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
String uuid = actual.id;
comment.message = "updated comment 1";
updateDraft(changeId, revId, comment, uuid);
result = getDraftComments(changeId, revId);
actual = Iterables.getOnlyElement(result.get(comment.path));
assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
// Posting a draft comment doesn't cause lastUpdatedOn to change.
assertThat(r.getChange().change().getLastUpdatedOn()).isEqualTo(origLastUpdated);
}
}
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 = 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(Lists.transform(actualComments, infoToDraft(file))).containsExactlyElementsIn(expectedDrafts);
}
Aggregations