use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class MoveChangeIT method moveChangeKeepAllVotesOutOfUserPermissionRange.
@Test
public void moveChangeKeepAllVotesOutOfUserPermissionRange() 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 [-2; 2]
configLabel(project, testLabelA, LabelFunction.NO_BLOCK, value(2, "Passes"), value(1, "Mostly ok"), value(0, "No score"), value(-1, "Needs work"), value(-2, "Failed"));
// Registered users have [-2; 2] permissions on the source.
projectOperations.project(project).forUpdate().add(allowLabel(testLabelA).ref(sourceBranch.branch()).group(REGISTERED_USERS).range(-2, +2)).update();
// Registered users have [-1; 1] permissions on the destination.
projectOperations.project(project).forUpdate().add(allowLabel(testLabelA).ref(destinationBranch.branch()).group(REGISTERED_USERS).range(-1, +1)).update();
String changeId = createChangeInBranch(sourceBranch.branch()).getChangeId();
requestScopeOperations.setApiUser(user.id());
// Vote within the range of the source branch.
ReviewInput userReviewInput = new ReviewInput();
userReviewInput.label(testLabelA, 2);
gApi.changes().id(changeId).current().review(userReviewInput);
assertLabelVote(user, changeId, testLabelA, (short) 2);
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.branch(), true);
// User does not have label permissions for the same vote on the destination branch.
requestScopeOperations.setApiUser(user.id());
AuthException thrown = assertThrows(AuthException.class, () -> gApi.changes().id(changeId).current().review(userReviewInput));
assertThat(thrown).hasMessageThat().isEqualTo(String.format("Applying label \"%s\": 2 is restricted", testLabelA));
// Label is kept even though the user's permission range is different from the source.
// Since we do not squash users votes based on the destination branch access label
// configuration, this is working as intended.
// It's the same behavior as when a project owner reduces user's permission range on label.
// Administrators should take this into account.
assertThat(info(changeId).branch).isEqualTo(destinationBranch.shortName());
assertLabelVote(user, changeId, testLabelA, (short) 2);
requestScopeOperations.setApiUser(admin.id());
// 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) 2);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput 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());
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class ChangeEditIT method editCommitMessageCopiesLabelScores.
@Test
public void editCommitMessageCopiesLabelScores() throws Exception {
String cr = LabelId.CODE_REVIEW;
try (ProjectConfigUpdate u = updateProject(project)) {
LabelType codeReview = TestLabels.codeReview();
u.getConfig().upsertLabelType(codeReview);
u.getConfig().updateLabelType(codeReview.getName(), lt -> lt.setCopyAllScoresIfNoCodeChange(true));
u.save();
}
ReviewInput r = new ReviewInput();
r.labels = ImmutableMap.of(cr, (short) 1);
gApi.changes().id(changeId).current().review(r);
createEmptyEditFor(changeId);
String newSubj = "New commit message";
String newMsg = newSubj + "\n\nChange-Id: " + changeId + "\n";
gApi.changes().id(changeId).edit().modifyCommitMessage(newMsg);
PublishChangeEditInput publishInput = new PublishChangeEditInput();
publishInput.notify = NotifyHandling.NONE;
gApi.changes().id(changeId).edit().publish(publishInput);
ChangeInfo info = get(changeId, DETAILED_LABELS);
assertThat(info.subject).isEqualTo(newSubj);
List<ApprovalInfo> approvals = info.labels.get(cr).all;
assertThat(approvals).hasSize(1);
assertThat(approvals.get(0).value).isEqualTo(1);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class RevisionIT method postSubmitDeleteApprovalNotAllowed.
@Test
public void postSubmitDeleteApprovalNotAllowed() throws Exception {
PushOneCommit.Result r = createChange();
revision(r).review(ReviewInput.approve());
revision(r).submit();
ReviewInput in = new ReviewInput();
in.label(LabelId.CODE_REVIEW, 0);
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> revision(r).review(in));
assertThat(thrown).hasMessageThat().contains("Cannot reduce vote on labels for closed change: Code-Review");
}
use of com.google.gerrit.extensions.api.changes.ReviewInput in project gerrit by GerritCodeReview.
the class RevisionIT method comments.
@Test
public void comments() throws Exception {
PushOneCommit.Result r = createChange();
CommentInput in = new CommentInput();
in.line = 1;
in.message = "nit: trailing whitespace";
in.path = FILE_NAME;
ReviewInput reviewInput = new ReviewInput();
Map<String, List<CommentInput>> comments = new HashMap<>();
comments.put(FILE_NAME, Collections.singletonList(in));
reviewInput.comments = comments;
reviewInput.message = "comment test";
gApi.changes().id(r.getChangeId()).current().review(reviewInput);
Map<String, List<CommentInfo>> out = gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).comments();
assertThat(out).hasSize(1);
CommentInfo comment = Iterables.getOnlyElement(out.get(FILE_NAME));
assertThat(comment.message).isEqualTo(in.message);
assertThat(comment.author.email).isEqualTo(admin.email());
assertThat(comment.path).isNull();
List<CommentInfo> list = gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).commentsAsList();
assertThat(list).hasSize(1);
CommentInfo comment2 = list.get(0);
assertThat(comment2.path).isEqualTo(FILE_NAME);
assertThat(comment2.line).isEqualTo(comment.line);
assertThat(comment2.message).isEqualTo(comment.message);
assertThat(comment2.author.email).isEqualTo(comment.author.email);
assertThat(gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).comment(comment.id).get().message).isEqualTo(in.message);
}
Aggregations