Search in sources :

Example 6 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class RevertIT method revertSubmissionPreservesReviewersAndCcs.

@Test
public void revertSubmissionPreservesReviewersAndCcs() throws Exception {
    String change = createChange("first change", "a.txt", "message").getChangeId();
    ReviewInput in = ReviewInput.approve();
    in.reviewer(user.email());
    in.reviewer(accountCreator.user2().email(), ReviewerState.CC, true);
    // Add user as reviewer that will create the revert
    in.reviewer(accountCreator.admin2().email());
    gApi.changes().id(change).current().review(in);
    gApi.changes().id(change).current().submit();
    // expect both the original reviewers and CCs to be preserved
    // original owner should be added as reviewer, user requesting the revert (new owner) removed
    requestScopeOperations.setApiUser(accountCreator.admin2().id());
    Map<ReviewerState, Collection<AccountInfo>> result = getChangeApis(gApi.changes().id(change).revertSubmission()).get(0).get().reviewers;
    assertThat(result).containsKey(ReviewerState.REVIEWER);
    List<Integer> reviewers = result.get(ReviewerState.REVIEWER).stream().map(a -> a._accountId).collect(toList());
    assertThat(result).containsKey(ReviewerState.CC);
    List<Integer> ccs = result.get(ReviewerState.CC).stream().map(a -> a._accountId).collect(toList());
    assertThat(ccs).containsExactly(accountCreator.user2().id().get());
    assertThat(reviewers).containsExactly(user.id().get(), admin.id().get());
}
Also used : TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ArrayList(java.util.ArrayList) PureRevertInfo(com.google.gerrit.extensions.common.PureRevertInfo) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AuthException(com.google.gerrit.extensions.restapi.AuthException) ChangeUtil(com.google.gerrit.server.ChangeUtil) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) TestRepository(org.eclipse.jgit.junit.TestRepository) RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) RefSpec(org.eclipse.jgit.transport.RefSpec) Collection(java.util.Collection) Permission(com.google.gerrit.entities.Permission) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Test(org.junit.Test) ProjectState(com.google.gerrit.extensions.client.ProjectState) Truth.assertThat(com.google.common.truth.Truth.assertThat) PermissionDeniedException(com.google.gerrit.server.permissions.PermissionDeniedException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Message(com.google.gerrit.testing.FakeEmailSender.Message) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Project(com.google.gerrit.entities.Project) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 7 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class RevertIT method revertPreservesReviewersAndCcs.

@Test
public void revertPreservesReviewersAndCcs() throws Exception {
    PushOneCommit.Result r = createChange();
    ReviewInput in = ReviewInput.approve();
    in.reviewer(user.email());
    in.reviewer(accountCreator.user2().email(), ReviewerState.CC, true);
    // Add user as reviewer that will create the revert
    in.reviewer(accountCreator.admin2().email());
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(in);
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).submit();
    // expect both the original reviewers and CCs to be preserved
    // original owner should be added as reviewer, user requesting the revert (new owner) removed
    requestScopeOperations.setApiUser(accountCreator.admin2().id());
    Map<ReviewerState, Collection<AccountInfo>> result = gApi.changes().id(r.getChangeId()).revert().get().reviewers;
    assertThat(result).containsKey(ReviewerState.REVIEWER);
    List<Integer> reviewers = result.get(ReviewerState.REVIEWER).stream().map(a -> a._accountId).collect(toList());
    assertThat(result).containsKey(ReviewerState.CC);
    List<Integer> ccs = result.get(ReviewerState.CC).stream().map(a -> a._accountId).collect(toList());
    assertThat(ccs).containsExactly(accountCreator.user2().id().get());
    assertThat(reviewers).containsExactly(user.id().get(), admin.id().get());
}
Also used : TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ArrayList(java.util.ArrayList) PureRevertInfo(com.google.gerrit.extensions.common.PureRevertInfo) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AuthException(com.google.gerrit.extensions.restapi.AuthException) ChangeUtil(com.google.gerrit.server.ChangeUtil) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) TestRepository(org.eclipse.jgit.junit.TestRepository) RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) RefSpec(org.eclipse.jgit.transport.RefSpec) Collection(java.util.Collection) Permission(com.google.gerrit.entities.Permission) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Test(org.junit.Test) ProjectState(com.google.gerrit.extensions.client.ProjectState) Truth.assertThat(com.google.common.truth.Truth.assertThat) PermissionDeniedException(com.google.gerrit.server.permissions.PermissionDeniedException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Message(com.google.gerrit.testing.FakeEmailSender.Message) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Project(com.google.gerrit.entities.Project) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 8 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class PostReviewIT method ccToReviewer.

@Test
public void ccToReviewer() throws Exception {
    PushOneCommit.Result r = createChange();
    // User adds themselves and changes state
    requestScopeOperations.setApiUser(user.id());
    ReviewInput input = new ReviewInput().reviewer(user.id().toString(), ReviewerState.CC, false);
    gApi.changes().id(r.getChangeId()).current().review(input);
    Map<ReviewerState, Collection<AccountInfo>> reviewers = gApi.changes().id(r.getChangeId()).get().reviewers;
    assertThat(reviewers).hasSize(1);
    AccountInfo reviewer = Iterables.getOnlyElement(reviewers.get(ReviewerState.CC));
    assertThat(reviewer._accountId).isEqualTo(user.id().get());
    // CC -> Reviewer
    ReviewInput input2 = new ReviewInput().reviewer(user.id().toString());
    gApi.changes().id(r.getChangeId()).current().review(input2);
    Map<ReviewerState, Collection<AccountInfo>> reviewers2 = gApi.changes().id(r.getChangeId()).get().reviewers;
    assertThat(reviewers2).hasSize(1);
    AccountInfo reviewer2 = Iterables.getOnlyElement(reviewers2.get(ReviewerState.REVIEWER));
    assertThat(reviewer2._accountId).isEqualTo(user.id().get());
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class RevisionIT method cherryPickKeepReviewers.

@Test
public void cherryPickKeepReviewers() throws Exception {
    createBranch(BranchNameKey.create(project, "stable"));
    // Change is created by 'admin'.
    PushOneCommit.Result r = createChange();
    // Change is approved by 'admin2'. Change is CC'd to 'user'.
    requestScopeOperations.setApiUser(accountCreator.admin2().id());
    ReviewInput in = ReviewInput.approve();
    in.reviewer(user.email(), ReviewerState.CC, true);
    gApi.changes().id(r.getChangeId()).current().review(in);
    // Change is cherrypicked by 'user2'.
    requestScopeOperations.setApiUser(accountCreator.user2().id());
    CherryPickInput cin = new CherryPickInput();
    cin.message = "this need to go to stable";
    cin.destination = "stable";
    cin.keepReviewers = true;
    Map<ReviewerState, Collection<AccountInfo>> result = gApi.changes().id(r.getChangeId()).current().cherryPick(cin).get().reviewers;
    // 'admin' should be a reviewer as the old owner.
    // 'admin2' should be a reviewer as the old reviewer.
    // 'user' should be on CC.
    assertThat(result).containsKey(ReviewerState.REVIEWER);
    List<Integer> reviewers = result.get(ReviewerState.REVIEWER).stream().map(a -> a._accountId).collect(toList());
    assertThat(result).containsKey(ReviewerState.CC);
    List<Integer> ccs = result.get(ReviewerState.CC).stream().map(a -> a._accountId).collect(toList());
    assertThat(ccs).containsExactly(user.id().get());
    assertThat(reviewers).containsExactly(admin.id().get(), accountCreator.admin2().id().get());
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) ChangeIndexedListener(com.google.gerrit.extensions.events.ChangeIndexedListener) NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ListMultimap(com.google.common.collect.ListMultimap) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PATCH(com.google.gerrit.acceptance.PushOneCommit.PATCH) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Map(java.util.Map) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) PatchSetWebLink(com.google.gerrit.extensions.webui.PatchSetWebLink) RefSpec(org.eclipse.jgit.transport.RefSpec) HEAD(org.eclipse.jgit.lib.Constants.HEAD) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) UseClockStep(com.google.gerrit.acceptance.UseClockStep) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Iterables(com.google.common.collect.Iterables) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) MERGE_LIST(com.google.gerrit.entities.Patch.MERGE_LIST) SimpleDateFormat(java.text.SimpleDateFormat) Callable(java.util.concurrent.Callable) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) TestRepository(org.eclipse.jgit.junit.TestRepository) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) ObjectIds.abbreviateName(com.google.gerrit.git.ObjectIds.abbreviateName) Test(org.junit.Test) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchOrderSection(com.google.gerrit.entities.BranchOrderSection) Repository(org.eclipse.jgit.lib.Repository) PATCH_FILE_ONLY(com.google.gerrit.acceptance.PushOneCommit.PATCH_FILE_ONLY) ALL_REVISIONS(com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) FILE_CONTENT(com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) DraftApi(com.google.gerrit.extensions.api.changes.DraftApi) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Locale(java.util.Locale) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) DateFormat(java.text.DateFormat) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) SubmitType(com.google.gerrit.extensions.client.SubmitType) Collection(java.util.Collection) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) Account(com.google.gerrit.entities.Account) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Optional(java.util.Optional) GitPerson(com.google.gerrit.extensions.common.GitPerson) MergeableInfo(com.google.gerrit.extensions.common.MergeableInfo) LabelId(com.google.gerrit.entities.LabelId) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Iterators(com.google.common.collect.Iterators) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Change(com.google.gerrit.entities.Change) FileInfo(com.google.gerrit.extensions.common.FileInfo) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) CommitValidationException(com.google.gerrit.server.git.validators.CommitValidationException) Iterator(java.util.Iterator) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Permission(com.google.gerrit.entities.Permission) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) Collectors.toList(java.util.stream.Collectors.toList) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) RecipientType(com.google.gerrit.extensions.api.changes.RecipientType) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) ResolveConflictsWebLink(com.google.gerrit.extensions.webui.ResolveConflictsWebLink) Collections(java.util.Collections) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class ChangeReviewersByEmailIT method addByEmail.

@Test
public void addByEmail() throws Exception {
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        ReviewerInput input = new ReviewerInput();
        input.reviewer = toRfcAddressString(acc);
        input.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(input);
        ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
        assertThat(info.reviewers).containsExactly(state, ImmutableList.of(acc));
        // All reviewers added by email should be removable
        assertThat(info.removableReviewers).containsExactly(acc);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ReviewerState (com.google.gerrit.extensions.client.ReviewerState)24 Test (org.junit.Test)20 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)19 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)19 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)18 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)11 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)10 Collection (java.util.Collection)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 List (java.util.List)7 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)4 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)4 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 ImmutableList (com.google.common.collect.ImmutableList)3 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)3 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)3 RequestScopeOperations (com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations)3 BranchNameKey (com.google.gerrit.entities.BranchNameKey)3