Search in sources :

Example 41 with AddReviewerInput

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

the class CustomLabelIT method customLabelAnyWithBlock_Addreviewer_ZeroVote.

@Test
public void customLabelAnyWithBlock_Addreviewer_ZeroVote() throws Exception {
    P.setFunctionName("AnyWithBlock");
    saveLabelConfig();
    PushOneCommit.Result r = createChange();
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    ReviewInput input = new ReviewInput().label(P.getName(), 0);
    input.message = "foo";
    revision(r).review(input);
    ChangeInfo c = get(r.getChangeId());
    LabelInfo q = c.labels.get(P.getName());
    assertThat(q.all).hasSize(2);
    assertThat(q.disliked).isNull();
    assertThat(q.rejected).isNull();
    assertThat(q.blocking).isNull();
    assertThat(lastCommentAddedEvent.getComment()).isEqualTo("Patch Set 1:\n\n" + input.message);
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 42 with AddReviewerInput

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

the class AbstractQueryChangesTest method reviewerAndCcByEmailWithQueryForDifferentUser.

@Test
public void reviewerAndCcByEmailWithQueryForDifferentUser() throws Exception {
    assume().that(notesMigration.enabled()).isTrue();
    Project.NameKey project = new 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 = "John Doe <un.registered@reviewer.com>";
    Change change1 = insert(repo, newChange(repo));
    Change change2 = insert(repo, newChange(repo));
    insert(repo, newChange(repo));
    AddReviewerInput rin = new AddReviewerInput();
    rin.reviewer = userByEmail;
    rin.state = ReviewerState.REVIEWER;
    gApi.changes().id(change1.getId().get()).addReviewer(rin);
    rin = new AddReviewerInput();
    rin.reviewer = userByEmail;
    rin.state = ReviewerState.CC;
    gApi.changes().id(change2.getId().get()).addReviewer(rin);
    if (getSchemaVersion() >= 41) {
        assertQuery("reviewer:\"someone@example.com\"");
        assertQuery("cc:\"someone@example.com\"");
    } else {
        assertMissingField(ChangeField.REVIEWER_BY_EMAIL);
        String someoneEmail = "someone@example.com";
        assertFailingQuery("reviewer:\"" + someoneEmail + "\"", "User " + someoneEmail + " not found");
        assertFailingQuery("cc:\"" + someoneEmail + "\"", "User " + someoneEmail + " not found");
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) Change(com.google.gerrit.reviewdb.client.Change) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test)

Example 43 with AddReviewerInput

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

the class AbstractQueryChangesTest method reviewerAndCc.

@Test
public void reviewerAndCc() throws Exception {
    Account.Id user1 = createAccount("user1");
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChange(repo));
    Change change2 = insert(repo, newChange(repo));
    insert(repo, newChange(repo));
    AddReviewerInput rin = new AddReviewerInput();
    rin.reviewer = user1.toString();
    rin.state = ReviewerState.REVIEWER;
    gApi.changes().id(change1.getId().get()).addReviewer(rin);
    rin = new AddReviewerInput();
    rin.reviewer = user1.toString();
    rin.state = ReviewerState.CC;
    gApi.changes().id(change2.getId().get()).addReviewer(rin);
    if (notesMigration.readChanges()) {
        assertQuery("reviewer:" + user1, change1);
        assertQuery("cc:" + user1, change2);
    } else {
        assertQuery("reviewer:" + user1, change2, change1);
        assertQuery("cc:" + user1);
    }
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.reviewdb.client.Change) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test)

Example 44 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput 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) {
        AddReviewerInput input = new AddReviewerInput();
        input.reviewer = reviewer;
        input.confirmed = true;
        String error;
        try {
            error = postReviewers.apply(changeRsrc, input).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.reviewdb.client.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) OrmException(com.google.gwtorm.server.OrmException) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput)

Example 45 with AddReviewerInput

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

the class PutAssignee method addAssigneeAsCC.

private Addition addAssigneeAsCC(ChangeResource rsrc, String assignee) throws OrmException, IOException, PermissionBackendException {
    AddReviewerInput reviewerInput = new AddReviewerInput();
    reviewerInput.reviewer = assignee;
    reviewerInput.state = ReviewerState.CC;
    reviewerInput.confirmed = true;
    reviewerInput.notify = NotifyHandling.NONE;
    return postReviewers.prepareApplication(rsrc, reviewerInput, false);
}
Also used : AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput)

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