use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class CommitIT method cherryPickCommitToExistingCherryPickedChange.
@Test
public void cherryPickCommitToExistingCherryPickedChange() throws Exception {
String destBranch = "foo";
createBranch(BranchNameKey.create(project, destBranch));
PushOneCommit.Result r = createChange("refs/for/" + destBranch);
ChangeInfo existingDestChange = info(r.getChangeId());
r = createChange();
ChangeInfo changeToCherryPick = info(r.getChangeId());
RevCommit commitToCherryPick = r.getCommit();
CherryPickInput input = new CherryPickInput();
input.destination = destBranch;
input.message = String.format("it goes to foo branch\n\nChange-Id: %s\n", existingDestChange.changeId);
input.allowConflicts = true;
input.allowEmpty = true;
// Use RevisionAPI to submit initial cherryPick.
ChangeInfo cherryPickResult = gApi.changes().id(changeToCherryPick.changeId).current().cherryPick(input).get();
assertThat(cherryPickResult.changeId).isEqualTo(existingDestChange.changeId);
// Cherry-pick was set.
assertThat(cherryPickResult.cherryPickOfChange).isEqualTo(changeToCherryPick._number);
assertThat(cherryPickResult.cherryPickOfPatchSet).isEqualTo(1);
RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
assertThat(revInfo).isNotNull();
assertThat(revInfo.commit.message).isEqualTo(input.message);
// Use CommitApi to update the cherryPick change.
cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.getName()).cherryPick(input).get();
assertThat(cherryPickResult.changeId).isEqualTo(existingDestChange.changeId);
assertThat(cherryPickResult.messages).hasSize(3);
Iterator<ChangeMessageInfo> messageIterator = cherryPickResult.messages.iterator();
assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 1.");
assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 2.");
assertThat(messageIterator.next().message).isEqualTo("Uploaded patch set 3.");
// Cherry-pick was reset to empty value.
assertThat(cherryPickResult._number).isEqualTo(existingDestChange._number);
assertThat(cherryPickResult.cherryPickOfChange).isNull();
assertThat(cherryPickResult.cherryPickOfPatchSet).isNull();
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class CommitIT method cherryPickCommitWithoutChangeIdCreateNewChange.
@Test
public void cherryPickCommitWithoutChangeIdCreateNewChange() throws Exception {
String destBranch = "foo";
createBranch(BranchNameKey.create(project, destBranch));
CherryPickInput input = new CherryPickInput();
input.destination = destBranch;
input.message = "it goes to foo branch";
RevCommit commitToCherryPick = createNewCommitWithoutChangeId("refs/heads/master", "a.txt", "content");
ChangeInfo cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.getName()).cherryPick(input).get();
assertThat(cherryPickResult.messages).hasSize(1);
Iterator<ChangeMessageInfo> messageIterator = cherryPickResult.messages.iterator();
String expectedMessage = String.format("Patch Set 1: Cherry Picked from commit %s.", commitToCherryPick.getName());
assertThat(messageIterator.next().message).isEqualTo(expectedMessage);
RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
assertThat(revInfo).isNotNull();
CommitInfo commitInfo = revInfo.commit;
assertThat(commitInfo.message).isEqualTo(input.message + "\n\nChange-Id: " + cherryPickResult.changeId + "\n");
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class ChangeMessagesIT method getChangeMessagesWithTemplate.
@Test
public void getChangeMessagesWithTemplate() throws Exception {
String changeId = createChange().getChangeId();
String messageTemplate = "Review by " + AccountTemplateUtil.getAccountTemplate(admin.id());
postMessage(changeId, messageTemplate);
assertMessage(messageTemplate, Iterables.getLast(gApi.changes().id(changeId).get(MESSAGES).messages).message);
Collection<ChangeMessageInfo> listMessages = gApi.changes().id(changeId).messages();
assertThat(listMessages).hasSize(2);
ChangeMessageInfo changeMessageApi = Iterables.getLast(gApi.changes().id(changeId).messages());
assertMessage("Review by " + admin.getNameEmail(), changeMessageApi.message);
assertMessage("Review by " + admin.getNameEmail(), gApi.changes().id(changeId).message(changeMessageApi.id).get().message);
DeleteChangeMessageInput input = new DeleteChangeMessageInput("message deleted");
assertThat(gApi.changes().id(changeId).message(changeMessageApi.id).delete(input).message).isEqualTo(String.format("Change message removed by: %s\nReason: message deleted", admin.getNameEmail()));
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class ChangeMessagesIT method messagesReturnedInChronologicalOrder.
@Test
public void messagesReturnedInChronologicalOrder() throws Exception {
String changeId = createChange().getChangeId();
String firstMessage = "Some nits need to be fixed.";
postMessage(changeId, firstMessage);
String secondMessage = "I like this feature.";
postMessage(changeId, secondMessage);
ChangeInfo c = get(changeId, MESSAGES);
assertThat(c.messages).isNotNull();
assertThat(c.messages).hasSize(3);
Iterator<ChangeMessageInfo> it = c.messages.iterator();
assertThat(it.next().message).isEqualTo("Uploaded patch set 1.");
assertMessage(firstMessage, it.next().message);
assertMessage(secondMessage, it.next().message);
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class MailProcessorIT method parseAndPersistFileComment.
@Test
public void parseAndPersistFileComment() throws Exception {
String changeId = createChangeWithReview();
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
// Build Message
MailMessage.Builder b = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", null, null, "Some Comment on File 1");
b.textContent(txt + textFooterForChange(changeInfo._number, ts));
mailProcessor.process(b.build());
// Assert messages
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages;
assertThat(messages).hasSize(3);
assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n\n(1 comment)");
assertThat(Iterables.getLast(messages).tag).isEqualTo("mailMessageId=some id");
// Assert comment
List<CommentInfo> comments = gApi.changes().id(changeId).current().commentsAsList();
assertThat(comments).hasSize(3);
assertThat(comments.get(0).message).isEqualTo("Some Comment on File 1");
assertThat(comments.get(0).inReplyTo).isNull();
assertThat(comments.get(0).tag).isEqualTo("mailMessageId=some id");
assertThat(comments.get(0).path).isEqualTo("gerrit-server/test.txt");
}
Aggregations