Search in sources :

Example 1 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class AssigneeIT method assigneeAddedAsReviewer.

@Test
public void assigneeAddedAsReviewer() throws Exception {
    ReviewerState state;
    // CC) CC is stored as REVIEWER
    if (notesMigration.readChanges()) {
        state = ReviewerState.CC;
    } else {
        state = ReviewerState.REVIEWER;
    }
    PushOneCommit.Result r = createChange();
    Iterable<AccountInfo> reviewers = getReviewers(r, state);
    assertThat(reviewers).isNull();
    assertThat(setAssignee(r, user.email)._accountId).isEqualTo(user.getId().get());
    reviewers = getReviewers(r, state);
    assertThat(reviewers).hasSize(1);
    AccountInfo reviewer = Iterables.getFirst(reviewers, null);
    assertThat(reviewer._accountId).isEqualTo(user.getId().get());
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class ChangeInfo method reviewers.

public final Map<ReviewerState, List<AccountInfo>> reviewers() {
    NativeMap<JsArray<AccountInfo>> reviewers = _reviewers();
    Map<ReviewerState, List<AccountInfo>> result = new HashMap<>();
    for (String k : reviewers.keySet()) {
        ReviewerState state = ReviewerState.valueOf(k.toUpperCase());
        List<AccountInfo> accounts = result.get(state);
        if (accounts == null) {
            accounts = new ArrayList<>();
            result.put(state, accounts);
        }
        accounts.addAll(Natives.asList(reviewers.get(k)));
    }
    return result;
}
Also used : JsArray(com.google.gwt.core.client.JsArray) HashMap(java.util.HashMap) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) ArrayList(java.util.ArrayList) List(java.util.List) NativeString(com.google.gerrit.client.rpc.NativeString) JsArrayString(com.google.gwt.core.client.JsArrayString)

Example 3 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class PostReviewers method prepareApplication.

public Addition prepareApplication(ChangeResource rsrc, AddReviewerInput input, boolean allowGroup) throws OrmException, IOException, PermissionBackendException {
    String reviewer = input.reviewer;
    ReviewerState state = input.state();
    NotifyHandling notify = input.notify;
    ListMultimap<RecipientType, Account.Id> accountsToNotify = null;
    try {
        accountsToNotify = notifyUtil.resolveAccounts(input.notifyDetails);
    } catch (BadRequestException e) {
        return fail(reviewer, e.getMessage());
    }
    boolean confirmed = input.confirmed();
    boolean allowByEmail = projectCache.checkedGet(rsrc.getProject()).isEnableReviewerByEmail();
    Addition byAccountId = addByAccountId(reviewer, rsrc, state, notify, accountsToNotify, allowGroup, allowByEmail);
    if (byAccountId != null) {
        return byAccountId;
    }
    Addition wholeGroup = addWholeGroup(reviewer, rsrc, state, notify, accountsToNotify, confirmed, allowGroup, allowByEmail);
    if (wholeGroup != null) {
        return wholeGroup;
    }
    return addByEmail(reviewer, rsrc, state, notify, accountsToNotify);
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) RecipientType(com.google.gerrit.extensions.api.changes.RecipientType)

Example 4 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class ChangeJson method reviewerMap.

private Map<ReviewerState, Collection<AccountInfo>> reviewerMap(ReviewerSet reviewers, ReviewerByEmailSet reviewersByEmail, boolean includeRemoved) {
    Map<ReviewerState, Collection<AccountInfo>> reviewerMap = new HashMap<>();
    for (ReviewerStateInternal state : ReviewerStateInternal.values()) {
        if (!includeRemoved && state == ReviewerStateInternal.REMOVED) {
            continue;
        }
        Collection<AccountInfo> reviewersByState = toAccountInfo(reviewers.byState(state));
        reviewersByState.addAll(toAccountInfoByEmail(reviewersByEmail.byState(state)));
        if (!reviewersByState.isEmpty()) {
            reviewerMap.put(state.asReviewerState(), reviewersByState);
        }
    }
    return reviewerMap;
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) ReviewerStateInternal(com.google.gerrit.server.notedb.ReviewerStateInternal) Collection(java.util.Collection) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 5 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class PostReviewIT method commentingMakesUserCC.

@Test
public void commentingMakesUserCC() throws Exception {
    // Admin owns the change
    PushOneCommit.Result r = createChange();
    // User adds themselves and changes state
    requestScopeOperations.setApiUser(user.id());
    ReviewInput input = new ReviewInput().message("Foo bar!");
    gApi.changes().id(r.getChangeId()).current().review(input);
    Map<ReviewerState, Collection<AccountInfo>> reviewers = gApi.changes().id(r.getChangeId()).get().reviewers;
    assertThat(reviewers).hasSize(1);
    AccountInfo reviewer = Iterables.getOnlyElement(reviewers.get(ReviewerState.CC));
    assertThat(reviewer._accountId).isEqualTo(user.id().get());
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ReviewerState (com.google.gerrit.extensions.client.ReviewerState)24 Test (org.junit.Test)20 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)19 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)19 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)18 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)11 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)10 Collection (java.util.Collection)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 List (java.util.List)7 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)4 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)4 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 ImmutableList (com.google.common.collect.ImmutableList)3 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)3 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)3 RequestScopeOperations (com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations)3 BranchNameKey (com.google.gerrit.entities.BranchNameKey)3