Search in sources :

Example 36 with ReviewerInput

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

the class ChangeIT method addReviewerToClosedChange.

@Test
public void addReviewerToClosedChange() throws Exception {
    PushOneCommit.Result r = createChange();
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).submit();
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(admin.id().get());
    assertThat(c.reviewers).doesNotContainKey(CC);
    ReviewerInput in = new ReviewerInput();
    in.reviewer = user.email();
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    c = gApi.changes().id(r.getChangeId()).get();
    reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).hasSize(2);
    Iterator<AccountInfo> reviewerIt = reviewers.iterator();
    assertThat(reviewerIt.next()._accountId).isEqualTo(admin.id().get());
    assertThat(reviewerIt.next()._accountId).isEqualTo(user.id().get());
    assertThat(c.reviewers).doesNotContainKey(CC);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 37 with ReviewerInput

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

the class AbstractQueryChangesTest method reviewerAndCcByEmail.

@Test
public void reviewerAndCcByEmail() throws Exception {
    Project.NameKey project = Project.nameKey("repo");
    TestRepository<Repo> repo = createProject(project.get());
    ConfigInput conf = new ConfigInput();
    conf.enableReviewerByEmail = InheritableBoolean.TRUE;
    gApi.projects().name(project.get()).config(conf);
    String userByEmail = "un.registered@reviewer.com";
    String userByEmailWithName = "John Doe <" + userByEmail + ">";
    Change change1 = insert(repo, newChange(repo));
    Change change2 = insert(repo, newChange(repo));
    insert(repo, newChange(repo));
    ReviewerInput rin = new ReviewerInput();
    rin.reviewer = userByEmailWithName;
    rin.state = ReviewerState.REVIEWER;
    gApi.changes().id(change1.getId().get()).addReviewer(rin);
    rin = new ReviewerInput();
    rin.reviewer = userByEmailWithName;
    rin.state = ReviewerState.CC;
    gApi.changes().id(change2.getId().get()).addReviewer(rin);
    assertQuery("reviewer:\"" + userByEmailWithName + "\"", change1);
    assertQuery("cc:\"" + userByEmailWithName + "\"", change2);
    // Omitting the name:
    assertQuery("reviewer:\"" + userByEmail + "\"", change1);
    assertQuery("cc:\"" + userByEmail + "\"", change2);
}
Also used : Project(com.google.gerrit.entities.Project) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) Change(com.google.gerrit.entities.Change) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test)

Example 38 with ReviewerInput

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

the class AbstractQueryChangesTest method attentionSetStored.

@Test
public void attentionSetStored() throws Exception {
    assume().that(getSchema().hasField(ChangeField.ATTENTION_SET_USERS)).isTrue();
    TestRepository<Repo> repo = createProject("repo");
    Change change = insert(repo, newChange(repo));
    AttentionSetInput input = new AttentionSetInput(userId.toString(), "reason 1");
    gApi.changes().id(change.getChangeId()).addToAttentionSet(input);
    Account.Id user2Id = accountManager.authenticate(authRequestFactory.createForUser("anotheruser")).getAccountId();
    // Add the second user as cc to ensure that user took part of the change and can be added to the
    // attention set.
    ReviewerInput reviewerInput = new ReviewerInput();
    reviewerInput.reviewer = user2Id.toString();
    reviewerInput.state = ReviewerState.CC;
    gApi.changes().id(change.getChangeId()).addReviewer(reviewerInput);
    input = new AttentionSetInput(user2Id.toString(), "reason 2");
    gApi.changes().id(change.getChangeId()).addToAttentionSet(input);
    List<ChangeInfo> result = newQuery("attention:" + user2Id.toString()).get();
    assertThat(result).hasSize(1);
    ChangeInfo changeInfo = Iterables.getOnlyElement(result);
    assertThat(changeInfo.attentionSet).isNotNull();
    assertThat(changeInfo.attentionSet.keySet()).containsExactly(userId.get(), user2Id.get());
    assertThat(changeInfo.attentionSet.get(userId.get()).reason).isEqualTo("reason 1");
    assertThat(changeInfo.attentionSet.get(user2Id.get()).reason).isEqualTo("reason 2");
}
Also used : Account(com.google.gerrit.entities.Account) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) Change(com.google.gerrit.entities.Change) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test)

Example 39 with ReviewerInput

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

the class ReviewerModifier method prepare.

public ReviewerModificationList prepare(ChangeNotes notes, CurrentUser user, Iterable<? extends ReviewerInput> inputs, boolean allowGroup) throws IOException, PermissionBackendException, ConfigInvalidException {
    // Process CC ops before reviewer ops, so a user that appears in both lists ends up as a
    // reviewer; the last call to ChangeUpdate#putReviewer wins. This can happen if the caller
    // specifies the same string twice, or less obviously if they specify multiple groups with
    // overlapping members.
    // TODO(dborowitz): Consider changing interface to allow excluding reviewers that were
    // previously processed, to proactively prevent overlap so we don't have to rely on this subtle
    // behavior.
    ImmutableList<ReviewerInput> sorted = Streams.stream(inputs).sorted(comparing(ReviewerInput::state, Ordering.explicit(ReviewerState.CC, ReviewerState.REVIEWER))).collect(toImmutableList());
    List<ReviewerModification> additions = new ArrayList<>();
    for (ReviewerInput input : sorted) {
        ReviewerModification addition = prepare(notes, user, input, allowGroup);
        if (addition.op != null) {
            // Assume any callers preparing a list of batch insertions are handling their own email.
            addition.op.suppressEmail();
        }
        additions.add(addition);
    }
    return new ReviewerModificationList(additions);
}
Also used : ArrayList(java.util.ArrayList) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput)

Example 40 with ReviewerInput

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

the class SetReviewersCommand method modifyOne.

private boolean modifyOne(ChangeResource changeRsrc) throws Exception {
    boolean ok = true;
    // 
    for (Account.Id reviewer : toRemove) {
        ReviewerResource rsrc = reviewerFactory.create(changeRsrc, reviewer);
        String error = null;
        try {
            deleteReviewer.apply(rsrc, new DeleteReviewerInput());
        } catch (ResourceNotFoundException e) {
            error = String.format("could not remove %s: not found", reviewer);
        } catch (Exception e) {
            error = String.format("could not remove %s: %s", reviewer, e.getMessage());
        }
        if (error != null) {
            ok = false;
            writeError("error", error);
        }
    }
    // 
    for (String reviewer : toAdd) {
        ReviewerInput input = new ReviewerInput();
        input.reviewer = reviewer;
        input.confirmed = true;
        String error;
        try {
            error = postReviewers.apply(changeRsrc, input).value().error;
        } catch (Exception e) {
            error = String.format("could not add %s: %s", reviewer, e.getMessage());
        }
        if (error != null) {
            ok = false;
            writeError("error", error);
        }
    }
    return ok;
}
Also used : Account(com.google.gerrit.entities.Account) ReviewerResource(com.google.gerrit.server.change.ReviewerResource) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) StorageException(com.google.gerrit.exceptions.StorageException) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput)

Aggregations

ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)72 Test (org.junit.Test)67 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)60 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)46 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)25 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)22 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)20 TestAccount (com.google.gerrit.acceptance.TestAccount)14 Message (com.google.gerrit.testing.FakeEmailSender.Message)14 ReviewerResult (com.google.gerrit.extensions.api.changes.ReviewerResult)13 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)11 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)11 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 Account (com.google.gerrit.entities.Account)10 Change (com.google.gerrit.entities.Change)7 UseClockStep (com.google.gerrit.acceptance.UseClockStep)5 ReviewerInfo (com.google.gerrit.extensions.api.changes.ReviewerInfo)5 Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)5 Instant (java.time.Instant)5 ArrayList (java.util.ArrayList)5