Search in sources :

Example 1 with ReviewInput

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

the class RobotCommentsIT method robotCommentsNotSupportedWithoutNoteDb.

@Test
public void robotCommentsNotSupportedWithoutNoteDb() throws Exception {
    assume().that(notesMigration.readChanges()).isFalse();
    RobotCommentInput in = createRobotCommentInput();
    ReviewInput reviewInput = new ReviewInput();
    Map<String, List<RobotCommentInput>> robotComments = new HashMap<>();
    robotComments.put(in.path, ImmutableList.of(in));
    reviewInput.robotComments = robotComments;
    reviewInput.message = "comment test";
    exception.expect(MethodNotAllowedException.class);
    exception.expectMessage("robot comments not supported");
    gApi.changes().id(changeId).current().review(reviewInput);
}
Also used : HashMap(java.util.HashMap) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) RobotCommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.RobotCommentInfoSubject.assertThatList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with ReviewInput

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

the class SuggestReviewersIT method reviewerRanking.

@Test
@GerritConfig(name = "suggest.maxSuggestedReviewers", value = "10")
public void reviewerRanking() throws Exception {
    // Assert that user are ranked by the number of times they have applied a
    // a label to a change (highest), added comments (medium) or owned a
    // change (low).
    String fullName = "Primum Finalis";
    TestAccount userWhoOwns = user("customuser1", fullName);
    TestAccount reviewer1 = user("customuser2", fullName);
    TestAccount reviewer2 = user("customuser3", fullName);
    TestAccount userWhoComments = user("customuser4", fullName);
    TestAccount userWhoLooksForSuggestions = user("customuser5", fullName);
    // Create a change as userWhoOwns and add some reviews
    setApiUser(userWhoOwns);
    String changeId1 = createChangeFromApi();
    setApiUser(reviewer1);
    reviewChange(changeId1);
    setApiUser(user1);
    String changeId2 = createChangeFromApi();
    setApiUser(reviewer1);
    reviewChange(changeId2);
    setApiUser(reviewer2);
    reviewChange(changeId2);
    // Create a comment as a different user
    setApiUser(userWhoComments);
    ReviewInput ri = new ReviewInput();
    ri.message = "Test";
    gApi.changes().id(changeId1).revision(1).review(ri);
    // Create a change as a new user to assert that we receive the correct
    // ranking
    setApiUser(userWhoLooksForSuggestions);
    List<SuggestedReviewerInfo> reviewers = suggestReviewers(createChangeFromApi(), "Pri", 4);
    assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer1.id.get(), reviewer2.id.get(), userWhoOwns.id.get(), userWhoComments.id.get()).inOrder();
}
Also used : SuggestedReviewerInfo(com.google.gerrit.extensions.common.SuggestedReviewerInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with ReviewInput

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

the class ProjectWatchIT method noNotificationForDraftPatchSetsForWatchersInNotifyConfig.

@Test
public void noNotificationForDraftPatchSetsForWatchersInNotifyConfig() throws Exception {
    Address addr = new Address("Watcher", "watcher@example.com");
    NotifyConfig nc = new NotifyConfig();
    nc.addEmail(addr);
    nc.setName("team");
    nc.setHeader(NotifyConfig.Header.TO);
    nc.setTypes(EnumSet.of(NotifyType.NEW_PATCHSETS, NotifyType.ALL_COMMENTS));
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    cfg.putNotifyConfig("team", nc);
    saveProjectConfig(project, cfg);
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), testRepo, "subject", "a", "a1").to("refs/for/master");
    r.assertOkStatus();
    sender.clear();
    r = pushFactory.create(db, admin.getIdent(), testRepo, "subject", "a", "a2", r.getChangeId()).to("refs/for/master%draft");
    r.assertOkStatus();
    assertThat(sender.getMessages()).isEmpty();
    setApiUser(admin);
    ReviewInput in = new ReviewInput();
    in.message = "comment";
    gApi.changes().id(r.getChangeId()).current().review(in);
    assertThat(sender.getMessages()).isEmpty();
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Address(com.google.gerrit.server.mail.Address) NotifyConfig(com.google.gerrit.server.git.NotifyConfig) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with ReviewInput

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

the class AbstractQueryChangesTest method byDraftByExcludesZombieDrafts.

@Test
public void byDraftByExcludesZombieDrafts() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    Project.NameKey project = new Project.NameKey("repo");
    TestRepository<Repo> repo = createProject(project.get());
    Change change = insert(repo, newChange(repo));
    Change.Id id = change.getId();
    DraftInput in = new DraftInput();
    in.line = 1;
    in.message = "nit: trailing whitespace";
    in.path = Patch.COMMIT_MSG;
    gApi.changes().id(id.get()).current().createDraft(in);
    assertQuery("draftby:" + userId, change);
    assertQuery("commentby:" + userId);
    TestRepository<Repo> allUsers = new TestRepository<>(repoManager.openRepository(allUsersName));
    Ref draftsRef = allUsers.getRepository().exactRef(RefNames.refsDraftComments(id, userId));
    assertThat(draftsRef).isNotNull();
    ReviewInput rin = ReviewInput.dislike();
    rin.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
    gApi.changes().id(id.get()).current().review(rin);
    assertQuery("draftby:" + userId);
    assertQuery("commentby:" + userId, change);
    assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNull();
    // Re-add drafts ref and ensure it gets filtered out during indexing.
    allUsers.update(draftsRef.getName(), draftsRef.getObjectId());
    assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNotNull();
    if (PrimaryStorage.of(change) == PrimaryStorage.REVIEW_DB && !notesMigration.disableChangeReviewDb()) {
        // Record draft ref in noteDbState as well.
        ReviewDb db = ReviewDbUtil.unwrapDb(this.db);
        change = db.changes().get(id);
        NoteDbChangeState.applyDelta(change, NoteDbChangeState.Delta.create(id, Optional.empty(), ImmutableMap.of(userId, draftsRef.getObjectId())));
        db.changes().update(Collections.singleton(change));
    }
    indexer.index(db, project, id);
    assertQuery("draftby:" + userId);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) Ref(org.eclipse.jgit.lib.Ref) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) Test(org.junit.Test)

Example 5 with ReviewInput

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

the class ChangeIT method implicitlyCcOnNonVotingReviewGwtStyle.

@Test
public void implicitlyCcOnNonVotingReviewGwtStyle() throws Exception {
    PushOneCommit.Result r = createChange();
    setApiUser(user);
    assertThat(getReviewerState(r.getChangeId(), user.id)).isEmpty();
    // Exact request format made by GWT UI at ddc6b7160fe416fed9e7e3180489d44c82fd64f8.
    ReviewInput in = new ReviewInput();
    in.labels = ImmutableMap.of("Code-Review", (short) 0);
    in.strictLabels = true;
    in.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
    in.message = "comment";
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(in);
    // If we're not reading from NoteDb, then the CCed user will be returned in the REVIEWER state.
    assertThat(getReviewerState(r.getChangeId(), user.id)).hasValue(notesMigration.readChanges() ? CC : REVIEWER);
}
Also used : ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)254 Test (org.junit.Test)217 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)198 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)178 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)47 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)35 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)30 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)26 List (java.util.List)25 Collectors.toList (java.util.stream.Collectors.toList)24 ImmutableList (com.google.common.collect.ImmutableList)23 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)23 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)22 AuthException (com.google.gerrit.extensions.restapi.AuthException)22 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)21 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)20 ArrayList (java.util.ArrayList)20 TestAccount (com.google.gerrit.acceptance.TestAccount)18 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)18 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)18