use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class DeleteChangeMessage method createUpdatedChangeMessageInfo.
private ChangeMessageInfo createUpdatedChangeMessageInfo(Change.Id cId, Project.NameKey project, int targetIdx) throws PermissionBackendException {
List<ChangeMessage> messages = changeMessagesUtil.byChange(notesFactory.createChecked(project, cId));
ChangeMessage updatedChangeMessage = messages.get(targetIdx);
AccountLoader accountLoader = accountLoaderFactory.create(true);
ChangeMessageInfo info = changeMessagesUtil.createChangeMessageInfoWithReplacedTemplates(updatedChangeMessage, accountLoader);
accountLoader.fill();
return info;
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class ListChangeMessages method apply.
@Override
public Response<List<ChangeMessageInfo>> apply(ChangeResource resource) throws PermissionBackendException {
AccountLoader accountLoader = accountLoaderFactory.create(true);
List<ChangeMessage> messages = changeMessagesUtil.byChange(resource.getNotes());
List<ChangeMessageInfo> messageInfos = messages.stream().map(m -> changeMessagesUtil.createChangeMessageInfoWithReplacedTemplates(m, accountLoader)).collect(Collectors.toList());
accountLoader.fill();
return Response.ok(messageInfos);
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class ChangeIT method deleteVote.
@Test
public void deleteVote() throws Exception {
PushOneCommit.Result r = createChange();
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
requestScopeOperations.setApiUser(user.id());
recommend(r.getChangeId());
requestScopeOperations.setApiUser(admin.id());
sender.clear();
gApi.changes().id(r.getChangeId()).reviewer(user.id().toString()).deleteVote(LabelId.CODE_REVIEW);
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message msg = messages.get(0);
assertThat(msg.rcpt()).containsExactly(user.getNameEmail());
assertThat(msg.body()).contains(admin.fullName() + " has removed a vote from this change.");
assertThat(msg.body()).contains("Removed Code-Review+1 by " + user.fullName() + " <" + user.email() + ">\n");
Map<String, Short> m = gApi.changes().id(r.getChangeId()).reviewer(user.id().toString()).votes();
// Dummy 0 approval on the change to block vote copying to this patch set.
assertThat(m).containsExactly(LabelId.CODE_REVIEW, Short.valueOf((short) 0));
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
ChangeMessageInfo message = Iterables.getLast(c.messages);
assertThat(message.author._accountId).isEqualTo(admin.id().get());
assertThat(message.message).isEqualTo("Removed Code-Review+1 by " + AccountTemplateUtil.getAccountTemplate(user.id()) + "\n");
assertThat(message.accountsInMessage).containsExactly(getAccountInfo(user.id()));
assertThat(gApi.changes().id(r.getChangeId()).message(message.id).get().message).isEqualTo("Removed Code-Review+1 by User1 <user1@example.com>\n");
assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactlyElementsIn(ImmutableSet.of(admin.id(), user.id()));
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class ChangeIT method testRemoveReviewer.
private void testRemoveReviewer(boolean notify) throws Exception {
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
gApi.changes().id(changeId).revision(r.getCommit().name()).review(ReviewInput.approve());
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(changeId).revision(r.getCommit().name()).review(ReviewInput.recommend());
Collection<AccountInfo> reviewers = gApi.changes().id(changeId).get().reviewers.get(REVIEWER);
assertThat(reviewers).hasSize(2);
Iterator<AccountInfo> reviewerIt = reviewers.iterator();
assertThat(reviewerIt.next()._accountId).isEqualTo(admin.id().get());
assertThat(reviewerIt.next()._accountId).isEqualTo(user.id().get());
sender.clear();
requestScopeOperations.setApiUser(admin.id());
DeleteReviewerInput input = new DeleteReviewerInput();
if (!notify) {
input.notify = NotifyHandling.NONE;
}
gApi.changes().id(changeId).reviewer(user.id().toString()).remove(input);
if (notify) {
assertThat(sender.getMessages()).hasSize(1);
Message message = sender.getMessages().get(0);
assertThat(message.body()).contains("Removed reviewer " + user.getNameEmail() + " with the following votes");
assertThat(message.body()).contains("* Code-Review+1 by " + user.getNameEmail());
ChangeMessageInfo changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).messages());
assertThat(changeMessageInfo.message).contains("Removed reviewer " + user.getNameEmail() + " with the following votes");
assertThat(changeMessageInfo.message).contains("* Code-Review+1 by " + user.getNameEmail());
changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).get().messages);
assertThat(changeMessageInfo.message).contains("Removed reviewer " + AccountTemplateUtil.getAccountTemplate(user.id()) + " with the following votes");
assertThat(changeMessageInfo.message).contains("* Code-Review+1 by " + AccountTemplateUtil.getAccountTemplate(user.id()));
assertThat(changeMessageInfo.accountsInMessage).containsExactly(getAccountInfo(user.id()));
} else {
assertThat(sender.getMessages()).isEmpty();
}
reviewers = gApi.changes().id(changeId).get().reviewers.get(REVIEWER);
assertThat(reviewers).hasSize(1);
reviewerIt = reviewers.iterator();
assertThat(reviewerIt.next()._accountId).isEqualTo(admin.id().get());
eventRecorder.assertReviewerDeletedEvents(changeId, user.email());
}
use of com.google.gerrit.extensions.common.ChangeMessageInfo in project gerrit by GerritCodeReview.
the class CommitIT method cherryPickCommitWithChangeIdCreateNewChange.
@Test
public void cherryPickCommitWithChangeIdCreateNewChange() throws Exception {
String destBranch = "foo";
createBranch(BranchNameKey.create(project, destBranch));
PushOneCommit.Result r = createChange();
ChangeInfo changeToCherryPick = info(r.getChangeId());
RevCommit commitToCherryPick = r.getCommit();
List<String> footers = commitToCherryPick.getFooterLines("Change-Id");
assertThat(footers).hasSize(1);
String changeId = footers.get(0);
CherryPickInput input = new CherryPickInput();
input.destination = destBranch;
input.message = String.format("it goes to foo branch\n\nChange-Id: Ideadbeefdeadbeefdeadbeefdeadbeefdeadbeef\n\nChange-Id: %s\n", changeId);
ChangeInfo cherryPickResult = gApi.projects().name(project.get()).commit(commitToCherryPick.getName()).cherryPick(input).get();
// No change was found in destination branch with the provided Change-Id.
assertThat(cherryPickResult._number).isGreaterThan(changeToCherryPick._number);
assertThat(cherryPickResult.changeId).isEqualTo(changeId);
assertThat(cherryPickResult.revisions).hasSize(1);
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);
// Cherry-pick of is not set, because the source change was not provided.
assertThat(cherryPickResult.cherryPickOfChange).isNull();
assertThat(cherryPickResult.cherryPickOfPatchSet).isNull();
RevisionInfo revInfo = cherryPickResult.revisions.get(cherryPickResult.currentRevision);
assertThat(revInfo).isNotNull();
assertThat(revInfo.commit.message).isEqualTo(input.message);
}
Aggregations