Search in sources :

Example 56 with ChangeMessageInfo

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;
}
Also used : AccountLoader(com.google.gerrit.server.account.AccountLoader) ChangeMessage(com.google.gerrit.entities.ChangeMessage) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo)

Example 57 with ChangeMessageInfo

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);
}
Also used : ChangeMessage(com.google.gerrit.entities.ChangeMessage) AccountLoader(com.google.gerrit.server.account.AccountLoader) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) List(java.util.List) RestReadView(com.google.gerrit.extensions.restapi.RestReadView) ChangeResource(com.google.gerrit.server.change.ChangeResource) Inject(com.google.inject.Inject) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Response(com.google.gerrit.extensions.restapi.Response) Collectors(java.util.stream.Collectors) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) Singleton(com.google.inject.Singleton) AccountLoader(com.google.gerrit.server.account.AccountLoader) ChangeMessage(com.google.gerrit.entities.ChangeMessage) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo)

Example 58 with ChangeMessageInfo

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()));
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 59 with ChangeMessageInfo

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());
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 60 with ChangeMessageInfo

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);
}
Also used : Result(com.google.gerrit.acceptance.PushOneCommit.Result) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)75 Test (org.junit.Test)61 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)47 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)47 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)37 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)13 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)10 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)10 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)9 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)8 ArrayList (java.util.ArrayList)8 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)6 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)5 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)5 CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)5 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 List (java.util.List)5 Change (com.google.gerrit.entities.Change)4