Search in sources :

Example 66 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class PostReviewIT method reviewerToCc.

@Test
public void reviewerToCc() throws Exception {
    // Admin owns the change
    PushOneCommit.Result r = createChange();
    // User adds themselves and changes state
    requestScopeOperations.setApiUser(user.id());
    ReviewInput input = new ReviewInput().reviewer(user.id().toString());
    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.REVIEWER));
    assertThat(reviewer._accountId).isEqualTo(user.id().get());
    // Reviewer -> CC
    ReviewInput input2 = new ReviewInput().reviewer(user.id().toString(), ReviewerState.CC, false);
    gApi.changes().id(r.getChangeId()).current().review(input2);
    Map<ReviewerState, Collection<AccountInfo>> reviewers2 = gApi.changes().id(r.getChangeId()).get().reviewers;
    assertThat(reviewers2).hasSize(1);
    AccountInfo reviewer2 = Iterables.getOnlyElement(reviewers2.get(ReviewerState.CC));
    assertThat(reviewer2._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)

Example 67 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithCcByEmail.

@Test
public void pushForMasterWithCcByEmail() throws Exception {
    ConfigInput conf = new ConfigInput();
    conf.enableReviewerByEmail = InheritableBoolean.TRUE;
    gApi.projects().name(project.get()).config(conf);
    PushOneCommit.Result r = pushTo("refs/for/master%cc=non.existing.1@example.com,cc=non.existing.2@example.com");
    r.assertOkStatus();
    ChangeInfo ci = get(r.getChangeId(), DETAILED_LABELS);
    ImmutableList<AccountInfo> ccs = firstNonNull(ci.reviewers.get(ReviewerState.CC), ImmutableList.<AccountInfo>of()).stream().sorted(comparing((AccountInfo a) -> a.email)).collect(toImmutableList());
    assertThat(ccs).hasSize(2);
    assertThat(ccs.get(0).email).isEqualTo("non.existing.1@example.com");
    assertThat(ccs.get(0)._accountId).isNull();
    assertThat(ccs.get(1).email).isEqualTo("non.existing.2@example.com");
    assertThat(ccs.get(1)._accountId).isNull();
}
Also used : ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 68 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AbstractPushForReview method pushForMasterWithReviewerByEmail.

@Test
public void pushForMasterWithReviewerByEmail() throws Exception {
    ConfigInput conf = new ConfigInput();
    conf.enableReviewerByEmail = InheritableBoolean.TRUE;
    gApi.projects().name(project.get()).config(conf);
    PushOneCommit.Result r = pushTo("refs/for/master%r=non.existing.1@example.com,r=non.existing.2@example.com");
    r.assertOkStatus();
    ChangeInfo ci = get(r.getChangeId(), DETAILED_LABELS);
    ImmutableList<AccountInfo> reviewers = firstNonNull(ci.reviewers.get(ReviewerState.REVIEWER), ImmutableList.<AccountInfo>of()).stream().sorted(comparing((AccountInfo a) -> a.email)).collect(toImmutableList());
    assertThat(reviewers).hasSize(2);
    assertThat(reviewers.get(0).email).isEqualTo("non.existing.1@example.com");
    assertThat(reviewers.get(0)._accountId).isNull();
    assertThat(reviewers.get(1).email).isEqualTo("non.existing.2@example.com");
    assertThat(reviewers.get(1)._accountId).isNull();
}
Also used : ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 69 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AccountApiImpl method get.

@Override
public com.google.gerrit.extensions.common.AccountInfo get() throws RestApiException {
    AccountLoader accountLoader = accountLoaderFactory.create(true);
    try {
        AccountInfo ai = accountLoader.get(account.getUser().getAccountId());
        accountLoader.fill();
        return ai;
    } catch (Exception e) {
        throw asRestApiException("Cannot parse account", e);
    }
}
Also used : AccountLoader(com.google.gerrit.server.account.AccountLoader) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Example 70 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class EventUtil method accountInfo.

public AccountInfo accountInfo(AccountState accountState) {
    if (accountState == null || accountState.account().id() == null) {
        return null;
    }
    Account account = accountState.account();
    AccountInfo accountInfo = new AccountInfo(account.id().get());
    accountInfo.email = account.preferredEmail();
    accountInfo.name = account.fullName();
    accountInfo.username = accountState.userName().orElse(null);
    return accountInfo;
}
Also used : Account(com.google.gerrit.entities.Account) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Aggregations

AccountInfo (com.google.gerrit.extensions.common.AccountInfo)112 Test (org.junit.Test)74 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)51 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)39 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)29 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)23 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)20 Account (com.google.gerrit.entities.Account)19 ArrayList (java.util.ArrayList)18 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)17 TestAccount (com.google.gerrit.acceptance.TestAccount)16 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)15 Message (com.google.gerrit.testing.FakeEmailSender.Message)15 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)14 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)13 Collection (java.util.Collection)12 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)12 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)10 HashMap (java.util.HashMap)10