use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class MailMetadataIT method metadataOnNewComment.
@Test
public void metadataOnNewComment() throws Exception {
PushOneCommit.Result newChange = createChange();
gApi.changes().id(newChange.getChangeId()).addReviewer(user.getId().toString());
sender.clear();
// Review change
ReviewInput input = new ReviewInput();
input.message = "Test";
revision(newChange).review(input);
setApiUser(user);
Collection<ChangeMessageInfo> result = gApi.changes().id(newChange.getChangeId()).get().messages;
assertThat(result).isNotEmpty();
List<FakeEmailSender.Message> emails = sender.getMessages();
assertThat(emails).hasSize(1);
FakeEmailSender.Message message = emails.get(0);
String changeURL = "<" + canonicalWebUrl.get() + newChange.getChange().getId().get() + ">";
Map<String, Object> expectedHeaders = new HashMap<>();
expectedHeaders.put("Gerrit-PatchSet", "1");
expectedHeaders.put("Gerrit-Change-Id", newChange.getChangeId());
expectedHeaders.put("Gerrit-MessageType", "comment");
expectedHeaders.put("Gerrit-Commit", newChange.getCommit().getId().name());
expectedHeaders.put("Gerrit-ChangeURL", changeURL);
expectedHeaders.put("Gerrit-Comment-Date", Iterables.getLast(result).date);
assertHeaders(message.headers(), expectedHeaders);
// Remove metadata that is not present in email
expectedHeaders.remove("Gerrit-ChangeURL");
expectedHeaders.remove("Gerrit-Commit");
assertTextFooter(message.body(), expectedHeaders);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method publishDrafts.
private void publishDrafts(TestAccount account, Change.Id id) throws Exception {
ReviewInput rin = new ReviewInput();
rin.drafts = ReviewInput.DraftHandling.PUBLISH_ALL_REVISIONS;
AcceptanceTestRequestScope.Context old = setApiUser(account);
try {
gApi.changes().id(id.get()).current().review(rin);
} finally {
atrScope.set(old);
}
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class CommentAddedEventIT method newChangeWithVote.
@Test
public void newChangeWithVote() throws Exception {
saveLabelConfig();
// push a new change with -1 vote
PushOneCommit.Result r = createChange();
ReviewInput reviewInput = new ReviewInput().label(label.getName(), (short) -1);
revision(r).review(reviewInput);
ApprovalValues attr = getApprovalValues(label);
assertThat(attr.oldValue).isEqualTo(0);
assertThat(attr.value).isEqualTo(-1);
assertThat(lastCommentAddedEvent.getComment()).isEqualTo(String.format("Patch Set 1: %s-1", label.getName()));
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class AbstractMailIT method createChangeWithReview.
protected String createChangeWithReview(TestAccount reviewer) throws Exception {
// Create change
String file = "gerrit-server/test.txt";
String contents = "contents \nlorem \nipsum \nlorem";
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "first subject", file, contents);
PushOneCommit.Result r = push.to("refs/for/master");
String changeId = r.getChangeId();
// Review it
setApiUser(reviewer);
ReviewInput input = new ReviewInput();
input.message = "I have two comments";
input.comments = new HashMap<>();
CommentInput c1 = newComment(file, Side.REVISION, 0, "comment on file");
CommentInput c2 = newComment(file, Side.REVISION, 2, "inline comment");
input.comments.put(c1.path, ImmutableList.of(c1, c2));
revision(r).review(input);
return changeId;
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class CommentAddedEventIT method reviewChange_MultipleVotes.
@Test
public void reviewChange_MultipleVotes() throws Exception {
saveLabelConfig();
PushOneCommit.Result r = createChange();
ReviewInput reviewInput = new ReviewInput().label(label.getName(), -1);
reviewInput.message = label.getName();
revision(r).review(reviewInput);
ChangeInfo c = get(r.getChangeId());
LabelInfo q = c.labels.get(label.getName());
assertThat(q.all).hasSize(1);
ApprovalValues labelAttr = getApprovalValues(label);
assertThat(labelAttr.oldValue).isEqualTo(0);
assertThat(labelAttr.value).isEqualTo(-1);
assertThat(lastCommentAddedEvent.getComment()).isEqualTo(String.format("Patch Set 1: %s-1\n\n%s", label.getName(), label.getName()));
// there should be 3 approval labels (label, pLabel, and CRVV)
assertThat(lastCommentAddedEvent.getApprovals()).hasSize(3);
// check the approvals that were not voted on
ApprovalValues pLabelAttr = getApprovalValues(pLabel);
assertThat(pLabelAttr.oldValue).isNull();
assertThat(pLabelAttr.value).isEqualTo(0);
LabelType crLabel = LabelType.withDefaultValues("Code-Review");
ApprovalValues crlAttr = getApprovalValues(crLabel);
assertThat(crlAttr.oldValue).isNull();
assertThat(crlAttr.value).isEqualTo(0);
// update pLabel approval
reviewInput = new ReviewInput().label(pLabel.getName(), 1);
reviewInput.message = pLabel.getName();
revision(r).review(reviewInput);
c = get(r.getChangeId());
q = c.labels.get(label.getName());
assertThat(q.all).hasSize(1);
pLabelAttr = getApprovalValues(pLabel);
assertThat(pLabelAttr.oldValue).isEqualTo(0);
assertThat(pLabelAttr.value).isEqualTo(1);
assertThat(lastCommentAddedEvent.getComment()).isEqualTo(String.format("Patch Set 1: %s+1\n\n%s", pLabel.getName(), pLabel.getName()));
// check the approvals that were not voted on
labelAttr = getApprovalValues(label);
assertThat(labelAttr.oldValue).isNull();
assertThat(labelAttr.value).isEqualTo(-1);
crlAttr = getApprovalValues(crLabel);
assertThat(crlAttr.oldValue).isNull();
assertThat(crlAttr.value).isEqualTo(0);
}
Aggregations