use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class PostReviewIT method extendChangeMessageFromPlugin.
@Test
public void extendChangeMessageFromPlugin() throws Exception {
PushOneCommit.Result r = createChange();
String testMessage = "hello from plugin";
TestOnPostReview testOnPostReview = new TestOnPostReview(testMessage);
try (Registration registration = extensionRegistry.newRegistration().add(testOnPostReview)) {
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
gApi.changes().id(r.getChangeId()).current().review(input);
Collection<ChangeMessageInfo> messages = gApi.changes().id(r.getChangeId()).get().messages;
assertThat(Iterables.getLast(messages).message).isEqualTo(String.format("Patch Set 1: Code-Review+1\n\n%s\n", testMessage));
}
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class PostReviewIT method extendChangeMessageFromMultiplePlugins.
@Test
public void extendChangeMessageFromMultiplePlugins() throws Exception {
PushOneCommit.Result r = createChange();
String testMessage1 = "hello from plugin 1";
String testMessage2 = "message from plugin 2";
TestOnPostReview testOnPostReview1 = new TestOnPostReview(testMessage1);
TestOnPostReview testOnPostReview2 = new TestOnPostReview(testMessage2);
try (Registration registration = extensionRegistry.newRegistration().add(testOnPostReview1).add(testOnPostReview2)) {
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
gApi.changes().id(r.getChangeId()).current().review(input);
Collection<ChangeMessageInfo> messages = gApi.changes().id(r.getChangeId()).get().messages;
assertThat(Iterables.getLast(messages).message).isEqualTo(String.format("Patch Set 1: Code-Review+1\n\n%s\n\n%s\n", testMessage1, testMessage2));
}
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class PostReviewIT method validateCommentsInChangeMessage_messageOK.
@Test
public void validateCommentsInChangeMessage_messageOK() throws Exception {
PushOneCommit.Result r = createChange();
when(mockCommentValidator.validateComments(eq(contextFor(r)), captor.capture())).thenReturn(ImmutableList.of());
ReviewInput input = new ReviewInput().message(COMMENT_TEXT);
int numMessages = gApi.changes().id(r.getChangeId()).get().messages.size();
gApi.changes().id(r.getChangeId()).current().review(input);
assertValidatorCalledWith(CHANGE_MESSAGE_FOR_VALIDATION);
assertThat(gApi.changes().id(r.getChangeId()).get().messages).hasSize(numMessages + 1);
ChangeMessageInfo message = Iterables.getLast(gApi.changes().id(r.getChangeId()).get().messages);
assertThat(message.message).contains(COMMENT_TEXT);
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class CreateMergePatchSetIT method createMergePatchSet.
@Test
public void createMergePatchSet() throws Exception {
RevCommit initialHead = projectOperations.project(project).getHead("master");
createBranch(BranchNameKey.create(project, "dev"));
// create a change for master
String changeId = createChange().getChangeId();
testRepo.reset(initialHead);
PushOneCommit.Result currentMaster = pushTo("refs/heads/master");
currentMaster.assertOkStatus();
String parent = currentMaster.getCommit().getName();
// push a commit into dev branch
testRepo.reset(initialHead);
PushOneCommit.Result changeA = pushFactory.create(user.newIdent(), testRepo, "change A", "A.txt", "A content").to("refs/heads/dev");
changeA.assertOkStatus();
MergeInput mergeInput = new MergeInput();
mergeInput.source = "dev";
MergePatchSetInput in = new MergePatchSetInput();
in.merge = mergeInput;
String subject = "update change by merge ps2";
in.subject = subject;
TestWorkInProgressStateChangedListener wipStateChangedListener = new TestWorkInProgressStateChangedListener();
try (ExtensionRegistry.Registration registration = extensionRegistry.newRegistration().add(wipStateChangedListener)) {
ChangeInfo changeInfo = gApi.changes().id(changeId).createMergePatchSet(in);
assertThat(changeInfo.subject).isEqualTo(in.subject);
assertThat(changeInfo.containsGitConflicts).isNull();
assertThat(changeInfo.workInProgress).isNull();
}
assertThat(wipStateChangedListener.invoked).isFalse();
// To get the revisions, we must retrieve the change with more change options.
ChangeInfo changeInfo = gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
assertThat(changeInfo.revisions).hasSize(2);
assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit).isEqualTo(parent);
// Verify the message that has been posted on the change.
List<ChangeMessageInfo> messages = gApi.changes().id(changeId).messages();
assertThat(messages).hasSize(2);
assertThat(Iterables.getLast(messages).message).isEqualTo("Uploaded patch set 2.");
assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.message).contains(subject);
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class CreateMergePatchSetIT method createMergePatchSetWithOtherAuthor.
@Test
public void createMergePatchSetWithOtherAuthor() throws Exception {
RevCommit initialHead = projectOperations.project(project).getHead("master");
createBranch(BranchNameKey.create(project, "dev"));
// create a change for master
String changeId = createChange().getChangeId();
testRepo.reset(initialHead);
PushOneCommit.Result currentMaster = pushTo("refs/heads/master");
currentMaster.assertOkStatus();
String parent = currentMaster.getCommit().getName();
// push a commit into dev branch
testRepo.reset(initialHead);
PushOneCommit.Result changeA = pushFactory.create(user.newIdent(), testRepo, "change A", "A.txt", "A content").to("refs/heads/dev");
changeA.assertOkStatus();
MergeInput mergeInput = new MergeInput();
mergeInput.source = "dev";
MergePatchSetInput in = new MergePatchSetInput();
in.merge = mergeInput;
String subject = "update change by merge ps2";
in.subject = subject;
in.author = new AccountInput();
in.author.name = "Other Author";
in.author.email = "otherauthor@example.com";
gApi.changes().id(changeId).createMergePatchSet(in);
// To get the revisions, we must retrieve the change with more change options.
ChangeInfo changeInfo = gApi.changes().id(changeId).get(ALL_REVISIONS, CURRENT_COMMIT, CURRENT_REVISION);
assertThat(changeInfo.revisions).hasSize(2);
assertThat(changeInfo.revisions.get(changeInfo.currentRevision).commit.parents.get(0).commit).isEqualTo(parent);
// Verify the message that has been posted on the change.
List<ChangeMessageInfo> messages = gApi.changes().id(changeId).messages();
assertThat(messages).hasSize(2);
assertThat(Iterables.getLast(messages).message).isEqualTo("Uploaded patch set 2.");
CommitInfo commitInfo = changeInfo.revisions.get(changeInfo.currentRevision).commit;
assertThat(commitInfo.message).contains(subject);
assertThat(commitInfo.author.name).isEqualTo("Other Author");
assertThat(commitInfo.author.email).isEqualTo("otherauthor@example.com");
}
Aggregations