Search in sources :

Example 31 with ReviewInput

use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.

the class StickyApprovalsIT method stickyVoteStoredOnUploadWithRealAccount.

@Test
public void stickyVoteStoredOnUploadWithRealAccount() throws Exception {
    // Give "user" permission to vote on behalf of other users.
    projectOperations.project(project).forUpdate().add(allowLabel(TestLabels.codeReview().getName()).impersonation(true).ref("refs/heads/*").group(REGISTERED_USERS).range(-1, 1)).update();
    // Code-Review will be sticky.
    String label = LabelId.CODE_REVIEW;
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().updateLabelType(label, b -> b.setCopyAnyScore(true));
        u.save();
    }
    PushOneCommit.Result r = createChange();
    // Add a new vote as user
    requestScopeOperations.setApiUser(user.id());
    ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
    input.onBehalfOf = admin.email();
    gApi.changes().id(r.getChangeId()).current().review(input);
    // Make a new patchset, keeping the Code-Review +1 vote.
    amendChange(r.getChangeId());
    List<PatchSetApproval> patchSetApprovals = r.getChange().notes().getApprovalsWithCopied().values().stream().sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList());
    PatchSetApproval nonCopied = patchSetApprovals.get(0);
    assertThat(nonCopied.patchSetId().get()).isEqualTo(1);
    assertThat(nonCopied.accountId().get()).isEqualTo(admin.id().get());
    assertThat(nonCopied.realAccountId().get()).isEqualTo(user.id().get());
    assertThat(nonCopied.label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(nonCopied.value()).isEqualTo((short) 1);
    assertThat(nonCopied.copied()).isFalse();
    PatchSetApproval copied = patchSetApprovals.get(1);
    assertThat(copied.patchSetId().get()).isEqualTo(2);
    assertThat(copied.accountId().get()).isEqualTo(admin.id().get());
    assertThat(copied.realAccountId().get()).isEqualTo(user.id().get());
    assertThat(copied.label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(copied.value()).isEqualTo((short) 1);
    assertThat(copied.copied()).isTrue();
}
Also used : ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 32 with ReviewInput

use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.

the class ChangeReviewersIT method removeReviewerWithVoteOnMergedChangeForChangeOwnerFails.

@Test
public void removeReviewerWithVoteOnMergedChangeForChangeOwnerFails() throws Exception {
    PushOneCommit.Result r = createChange();
    requestScopeOperations.setApiUser(user.id());
    gApi.changes().id(r.getChangeId()).current().review(new ReviewInput().label(LabelId.CODE_REVIEW, 1));
    requestScopeOperations.setApiUser(admin.id());
    gApi.changes().id(r.getChangeId()).current().review(new ReviewInput().label(LabelId.CODE_REVIEW, 2));
    gApi.changes().id(r.getChangeId()).current().submit();
    assertThat(gApi.changes().id(r.getChangeId()).get().removableReviewers).isEmpty();
    AuthException thrown = assertThrows(AuthException.class, () -> gApi.changes().id(r.getChangeId()).reviewer(user.email()).remove());
    assertThat(thrown).hasMessageThat().contains("remove reviewer not permitted");
}
Also used : AuthException(com.google.gerrit.extensions.restapi.AuthException) 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 33 with ReviewInput

use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveChangeKeepAllVotesNoLabelInDestination.

@Test
public void moveChangeKeepAllVotesNoLabelInDestination() throws Exception {
    BranchNameKey destinationBranch = BranchNameKey.create(project, "dest");
    createBranch(destinationBranch);
    BranchNameKey sourceBranch = BranchNameKey.create(project, "source");
    createBranch(sourceBranch);
    String testLabelA = "Label-A";
    // The label has the range [-1; 1]
    configLabel(testLabelA, LabelFunction.NO_BLOCK, ImmutableList.of(sourceBranch.branch()));
    // Registered users have permissions for the entire range [-1; 1] on all branches.
    projectOperations.project(project).forUpdate().add(allowLabel(testLabelA).ref("refs/heads/*").group(REGISTERED_USERS).range(-1, +1)).update();
    String changeId = createChangeInBranch(sourceBranch.branch()).getChangeId();
    requestScopeOperations.setApiUser(user.id());
    ReviewInput userReviewInput = new ReviewInput();
    userReviewInput.label(testLabelA, 1);
    gApi.changes().id(changeId).current().review(userReviewInput);
    assertLabelVote(user, changeId, testLabelA, (short) 1);
    requestScopeOperations.setApiUser(admin.id());
    assertThat(atrScope.get().getUser().getAccountId()).isEqualTo(admin.id());
    // Move the change to the destination branch.
    assertThat(info(changeId).branch).isEqualTo(sourceBranch.shortName());
    move(changeId, destinationBranch.shortName(), true);
    assertThat(info(changeId).branch).isEqualTo(destinationBranch.shortName());
    // Label is missing in the destination branch.
    assertThat(gApi.changes().id(changeId).current().reviewer(user.email()).votes()).isEmpty();
    // Move the change back to the source, the label is kept.
    move(changeId, sourceBranch.shortName(), true);
    assertThat(info(changeId).branch).isEqualTo(sourceBranch.shortName());
    assertLabelVote(user, changeId, testLabelA, (short) 1);
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 34 with ReviewInput

use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveToBranchThatDoesNotHaveCustomLabel.

@Test
public void moveToBranchThatDoesNotHaveCustomLabel() throws Exception {
    createBranch(BranchNameKey.create(project, "foo"));
    String testLabelA = "Label-A";
    configLabel(testLabelA, LabelFunction.MAX_WITH_BLOCK, Arrays.asList("refs/heads/master"));
    projectOperations.project(project).forUpdate().add(allowLabel(testLabelA).ref("refs/heads/master").group(REGISTERED_USERS).range(-1, +1)).update();
    String changeId = createChange().getChangeId();
    ReviewInput input = new ReviewInput();
    input.label(testLabelA, -1);
    gApi.changes().id(changeId).current().review(input);
    assertThat(gApi.changes().id(changeId).current().reviewer(admin.email()).votes().keySet()).containsExactly(testLabelA);
    assertThat(gApi.changes().id(changeId).current().reviewer(admin.email()).votes().values()).containsExactly((short) -1);
    move(changeId, "foo");
    // "foo" branch does not have the custom label
    assertThat(gApi.changes().id(changeId).current().reviewer(admin.email()).votes().keySet()).isEmpty();
    // Move back to master and confirm that the custom label score is still there
    move(changeId, "master");
    assertThat(gApi.changes().id(changeId).current().reviewer(admin.email()).votes().keySet()).containsExactly(testLabelA);
    assertThat(gApi.changes().id(changeId).current().reviewer(admin.email()).votes().values()).containsExactly((short) -1);
}
Also used : ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 35 with ReviewInput

use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.

the class MoveChangeIT method moveChangeWithCurrentPatchSetLocked.

@Test
public void moveChangeWithCurrentPatchSetLocked() throws Exception {
    // Move change that is locked
    PushOneCommit.Result r = createChange();
    BranchNameKey newBranch = BranchNameKey.create(r.getChange().change().getProject(), "moveTest");
    createBranch(newBranch);
    LabelType patchSetLock = TestLabels.patchSetLock();
    try (ProjectConfigUpdate u = updateProject(project)) {
        u.getConfig().upsertLabelType(patchSetLock);
        u.save();
    }
    projectOperations.project(project).forUpdate().add(allowLabel(patchSetLock.getName()).ref("refs/heads/*").group(REGISTERED_USERS).range(0, 1)).update();
    revision(r).review(new ReviewInput().label("Patch-Set-Lock", 1));
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> move(r.getChangeId(), newBranch.branch()));
    assertThat(thrown).hasMessageThat().contains(String.format("The current patch set of change %s is locked", r.getChange().getId()));
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) LabelType(com.google.gerrit.entities.LabelType) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)254 Test (org.junit.Test)217 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)198 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)178 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)47 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)35 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)30 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)26 List (java.util.List)25 Collectors.toList (java.util.stream.Collectors.toList)24 ImmutableList (com.google.common.collect.ImmutableList)23 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)23 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)22 AuthException (com.google.gerrit.extensions.restapi.AuthException)22 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)21 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)20 ArrayList (java.util.ArrayList)20 TestAccount (com.google.gerrit.acceptance.TestAccount)18 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)18 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)18