Search in sources :

Example 31 with AddReviewerInput

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

the class ChangeIT method createNewPatchSetOnVisibleDraftPatchSet.

@Test
public void createNewPatchSetOnVisibleDraftPatchSet() throws Exception {
    // Clone separate repositories of the same project as admin and as user
    TestRepository<InMemoryRepository> adminTestRepo = cloneProject(project, admin);
    TestRepository<InMemoryRepository> userTestRepo = cloneProject(project, user);
    // Create change as admin
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), adminTestRepo);
    PushOneCommit.Result r1 = push.to("refs/for/master");
    r1.assertOkStatus();
    // Amend draft as admin
    PushOneCommit.Result r2 = amendChange(r1.getChangeId(), "refs/drafts/master", admin, adminTestRepo);
    r2.assertOkStatus();
    // Add user as reviewer to make this patch set visible
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r1.getChangeId()).addReviewer(in);
    // Fetch change
    GitUtil.fetch(userTestRepo, r2.getPatchSet().getRefName() + ":ps");
    userTestRepo.reset("ps");
    // Amend change as user
    PushOneCommit.Result r3 = amendChange(r2.getChangeId(), "refs/drafts/master", user, userTestRepo);
    r3.assertOkStatus();
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 32 with AddReviewerInput

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

the class ChangeIT method addReviewer.

@Test
public void addReviewer() throws Exception {
    TestTimeUtil.resetWithClockStep(1, SECONDS);
    PushOneCommit.Result r = createChange();
    ChangeResource rsrc = parseResource(r);
    String oldETag = rsrc.getETag();
    Timestamp oldTs = rsrc.getChange().getLastUpdatedOn();
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.emailAddress);
    assertThat(m.body()).contains("Hello " + user.fullName + ",\n");
    assertThat(m.body()).contains("I'd like you to do a code review.");
    assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
    assertMailReplyTo(m, admin.email);
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    // When NoteDb is enabled adding a reviewer records that user as reviewer
    // in NoteDb. When NoteDb is disabled adding a reviewer results in a dummy 0
    // approval on the change which is treated as CC when the ChangeInfo is
    // created.
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.getId().get());
    // Ensure ETag and lastUpdatedOn are updated.
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
    assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) Message(com.google.gerrit.testutil.FakeEmailSender.Message) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 33 with AddReviewerInput

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

the class ChangeIT method checkReviewedFlagBeforeAndAfterReview.

@Test
public void checkReviewedFlagBeforeAndAfterReview() throws Exception {
    PushOneCommit.Result r = createChange();
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    setApiUser(user);
    assertThat(get(r.getChangeId()).reviewed).isNull();
    revision(r).review(ReviewInput.recommend());
    assertThat(get(r.getChangeId()).reviewed).isTrue();
}
Also used : PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 34 with AddReviewerInput

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

the class ChangeIT method addReviewerWithNoteDbWhenDummyApprovalInReviewDbExists.

@Test
public void addReviewerWithNoteDbWhenDummyApprovalInReviewDbExists() throws Exception {
    assume().that(notesMigration.enabled()).isTrue();
    assume().that(notesMigration.changePrimaryStorage()).isEqualTo(PrimaryStorage.REVIEW_DB);
    PushOneCommit.Result r = createChange();
    // insert dummy approval in ReviewDb
    PatchSetApproval psa = new PatchSetApproval(new PatchSetApproval.Key(r.getPatchSetId(), user.id, new LabelId("Code-Review")), (short) 0, TimeUtil.nowTs());
    db.patchSetApprovals().insert(Collections.singleton(psa));
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
}
Also used : LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 35 with AddReviewerInput

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

the class ChangeReviewersByEmailIT method reviewersByEmailAreServedFromIndex.

@Test
public void reviewersByEmailAreServedFromIndex() throws Exception {
    assume().that(notesMigration.enabled()).isTrue();
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        AddReviewerInput input = new AddReviewerInput();
        input.reviewer = toRfcAddressString(acc);
        input.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(input);
        notesMigration.setFailOnLoad(true);
        try {
            ChangeInfo info = Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).withOption(ListChangesOption.DETAILED_LABELS).get());
            assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(acc)));
        } finally {
            notesMigration.setFailOnLoad(false);
        }
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)45 Test (org.junit.Test)38 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)34 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)30 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)15 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)13 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)9 Message (com.google.gerrit.testutil.FakeEmailSender.Message)8 AddReviewerResult (com.google.gerrit.extensions.api.changes.AddReviewerResult)7 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)5 Change (com.google.gerrit.reviewdb.client.Change)5 TestAccount (com.google.gerrit.acceptance.TestAccount)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)4 Account (com.google.gerrit.reviewdb.client.Account)4 Project (com.google.gerrit.reviewdb.client.Project)4 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)4 OrmException (com.google.gwtorm.server.OrmException)4 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)3 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)3 UpdateException (com.google.gerrit.server.update.UpdateException)3