Search in sources :

Example 36 with ReviewInput

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);
}
Also used : BranchNameKey(com.google.gerrit.entities.BranchNameKey) AuthException(com.google.gerrit.extensions.restapi.AuthException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 37 with ReviewInput

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());
}
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 38 with ReviewInput

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);
}
Also used : ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) LabelType(com.google.gerrit.entities.LabelType) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 39 with ReviewInput

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");
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) 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 40 with ReviewInput

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);
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) HashMap(java.util.HashMap) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

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