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();
}
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");
}
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);
}
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);
}
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()));
}
Aggregations