Search in sources :

Example 96 with ReviewInput

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

the class ChangeRebuilderIT method putComment.

private void putComment(TestAccount account, Change.Id id, int line, String msg, String inReplyTo) throws Exception {
    CommentInput in = new CommentInput();
    in.line = line;
    in.message = msg;
    in.inReplyTo = inReplyTo;
    ReviewInput rin = new ReviewInput();
    rin.comments = new HashMap<>();
    rin.comments.put(PushOneCommit.FILE_NAME, ImmutableList.of(in));
    rin.drafts = ReviewInput.DraftHandling.KEEP;
    AcceptanceTestRequestScope.Context old = setApiUser(account);
    try {
        gApi.changes().id(id.get()).current().review(rin);
    } finally {
        atrScope.set(old);
    }
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput)

Example 97 with ReviewInput

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

the class ChangeRebuilderIT method laterEventsDependingOnEarlierPatchSetDontIntefereWithOtherPatchSets.

@Test
public void laterEventsDependingOnEarlierPatchSetDontIntefereWithOtherPatchSets() throws Exception {
    PushOneCommit.Result r1 = createChange();
    ChangeData cd = r1.getChange();
    Change.Id id = cd.getId();
    amendChange(cd.change().getKey().get());
    TestTimeUtil.incrementClock(90, TimeUnit.DAYS);
    ReviewInput rin = ReviewInput.approve();
    rin.message = "Some very late message on PS1";
    gApi.changes().id(id.get()).revision(1).review(rin);
    checker.rebuildAndCheckChanges(id);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 98 with ReviewInput

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

the class ProjectWatchIT method noNotificationForDraftChangesForWatchersInNotifyConfig.

@Test
public void noNotificationForDraftChangesForWatchersInNotifyConfig() 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_CHANGES, 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, "draft change", "a", "a1").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 99 with ReviewInput

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

the class ProjectWatchIT method noNotificationForPrivateChangesForWatchersInNotifyConfig.

@Test
public void noNotificationForPrivateChangesForWatchersInNotifyConfig() 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_CHANGES, NotifyType.ALL_COMMENTS));
    ProjectConfig cfg = projectCache.checkedGet(project).getConfig();
    cfg.putNotifyConfig("team", nc);
    saveProjectConfig(project, cfg);
    sender.clear();
    PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), testRepo, "private change", "a", "a1").to("refs/for/master%private");
    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 100 with ReviewInput

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

the class AbstractQueryChangesTest method refStateFields.

@Test
public void refStateFields() throws Exception {
    // This test method manages primary storage manually.
    assume().that(notesMigration.changePrimaryStorage()).isEqualTo(PrimaryStorage.REVIEW_DB);
    Account.Id user = createAccount("user");
    Project.NameKey project = new Project.NameKey("repo");
    TestRepository<Repo> repo = createProject(project.get());
    String path = "file";
    RevCommit commit = repo.parseBody(repo.commit().message("one").add(path, "contents").create());
    Change change = insert(repo, newChangeForCommit(repo, commit));
    Change.Id id = change.getId();
    int c = id.get();
    String changeId = change.getKey().get();
    requestContext.setContext(newRequestContext(user));
    // Ensure one of each type of supported ref is present for the change. If
    // any more refs are added, update this test to reflect them.
    // Edit
    gApi.changes().id(changeId).edit().create();
    // Star
    gApi.accounts().self().starChange(change.getId().toString());
    if (notesMigration.readChanges()) {
        // Robot comment.
        ReviewInput rin = new ReviewInput();
        RobotCommentInput rcin = new RobotCommentInput();
        rcin.robotId = "happyRobot";
        rcin.robotRunId = "1";
        rcin.line = 1;
        rcin.message = "nit: trailing whitespace";
        rcin.path = path;
        rin.robotComments = ImmutableMap.of(path, ImmutableList.of(rcin));
        gApi.changes().id(c).current().review(rin);
    }
    // Draft.
    DraftInput din = new DraftInput();
    din.path = path;
    din.line = 1;
    din.message = "draft";
    gApi.changes().id(c).current().createDraft(din);
    if (notesMigration.readChanges()) {
        // Force NoteDb primary.
        change = ReviewDbUtil.unwrapDb(db).changes().get(id);
        change.setNoteDbState(NoteDbChangeState.NOTE_DB_PRIMARY_STATE);
        ReviewDbUtil.unwrapDb(db).changes().update(Collections.singleton(change));
        indexer.index(db, change);
    }
    QueryOptions opts = IndexedChangeQuery.createOptions(indexConfig, 0, 1, StalenessChecker.FIELDS);
    ChangeData cd = indexes.getSearchIndex().get(id, opts).get();
    String cs = RefNames.shard(c);
    int u = user.get();
    String us = RefNames.shard(u);
    List<String> expectedStates = Lists.newArrayList("repo:refs/users/" + us + "/edit-" + c + "/1", "All-Users:refs/starred-changes/" + cs + "/" + u);
    if (notesMigration.readChanges()) {
        expectedStates.add("repo:refs/changes/" + cs + "/meta");
        expectedStates.add("repo:refs/changes/" + cs + "/robot-comments");
        expectedStates.add("All-Users:refs/draft-comments/" + cs + "/" + u);
    }
    assertThat(cd.getRefStates().stream().map(String::new).map(s -> s.substring(0, s.lastIndexOf(':'))).collect(toList())).containsExactlyElementsIn(expectedStates);
    List<String> expectedPatterns = Lists.newArrayList("repo:refs/users/*/edit-" + c + "/*");
    expectedPatterns.add("All-Users:refs/starred-changes/" + cs + "/*");
    if (notesMigration.readChanges()) {
        expectedPatterns.add("All-Users:refs/draft-comments/" + cs + "/*");
    }
    assertThat(cd.getRefStatePatterns().stream().map(String::new).collect(toList())).containsExactlyElementsIn(expectedPatterns);
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) Arrays(java.util.Arrays) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ProjectCache(com.google.gerrit.server.project.ProjectCache) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) HashtagsInput(com.google.gerrit.extensions.api.changes.HashtagsInput) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Config(org.eclipse.jgit.lib.Config) ChangeTriplet(com.google.gerrit.server.change.ChangeTriplet) FluentIterable(com.google.common.collect.FluentIterable) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) Map(java.util.Map) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) ThrowableSubject(com.google.common.truth.ThrowableSubject) Schema(com.google.gerrit.server.index.Schema) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) RefUpdate(org.eclipse.jgit.lib.RefUpdate) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) RefNames(com.google.gerrit.reviewdb.client.RefNames) QueryOptions(com.google.gerrit.server.index.QueryOptions) AuthRequest(com.google.gerrit.server.account.AuthRequest) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) ExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) AccountCache(com.google.gerrit.server.account.AccountCache) Iterables(com.google.common.collect.Iterables) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Change(com.google.gerrit.reviewdb.client.Change) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Sequences(com.google.gerrit.server.Sequences) TestTimeUtil(com.google.gerrit.testutil.TestTimeUtil) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Lists(com.google.common.collect.Lists) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Before(org.junit.Before) QueryRequest(com.google.gerrit.extensions.api.changes.Changes.QueryRequest) Project(com.google.gerrit.reviewdb.client.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) RequestContext(com.google.gerrit.server.util.RequestContext) TimeUtil(com.google.gerrit.common.TimeUtil) MoreObjects(com.google.common.base.MoreObjects) ReviewDbUtil(com.google.gerrit.reviewdb.server.ReviewDbUtil) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Test(org.junit.Test) ManualRequestContext(com.google.gerrit.server.util.ManualRequestContext) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) SystemReader(org.eclipse.jgit.util.SystemReader) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) HOURS(java.util.concurrent.TimeUnit.HOURS) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) FieldDef(com.google.gerrit.server.index.FieldDef) ChangeIndexCollection(com.google.gerrit.server.index.change.ChangeIndexCollection) ObjectReader(org.eclipse.jgit.lib.ObjectReader) AccountManager(com.google.gerrit.server.account.AccountManager) ChangeControl(com.google.gerrit.server.project.ChangeControl) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) Inject(com.google.inject.Inject) PrimaryStorage(com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ChangeIndexer(com.google.gerrit.server.index.change.ChangeIndexer) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) After(org.junit.After) REVIEWED(com.google.gerrit.extensions.client.ListChangesOption.REVIEWED) Assert.fail(org.junit.Assert.fail) OneOffRequestContext(com.google.gerrit.server.util.OneOffRequestContext) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Ref(org.eclipse.jgit.lib.Ref) ConfigSuite(com.google.gerrit.testutil.ConfigSuite) Optional(java.util.Optional) Providers(com.google.inject.util.Providers) Branch(com.google.gerrit.reviewdb.client.Branch) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) InMemoryDatabase(com.google.gerrit.testutil.InMemoryDatabase) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Patch(com.google.gerrit.reviewdb.client.Patch) SchemaCreator(com.google.gerrit.server.schema.SchemaCreator) HashSet(java.util.HashSet) IndexConfig(com.google.gerrit.server.index.IndexConfig) ImmutableList(com.google.common.collect.ImmutableList) Account(com.google.gerrit.reviewdb.client.Account) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) GerritServerTests(com.google.gerrit.testutil.GerritServerTests) CurrentUser(com.google.gerrit.server.CurrentUser) Iterator(java.util.Iterator) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) IndexedChangeQuery(com.google.gerrit.server.index.change.IndexedChangeQuery) Truth.assertThat(com.google.common.truth.Truth.assertThat) SchemaFactory(com.google.gwtorm.server.SchemaFactory) StalenessChecker(com.google.gerrit.server.index.change.StalenessChecker) NoteDbChangeState(com.google.gerrit.server.notedb.NoteDbChangeState) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeField(com.google.gerrit.server.index.change.ChangeField) Injector(com.google.inject.Injector) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) PatchSetInserter(com.google.gerrit.server.change.PatchSetInserter) Provider(com.google.inject.Provider) Ignore(org.junit.Ignore) StarsInput(com.google.gerrit.extensions.api.changes.StarsInput) GerritApi(com.google.gerrit.extensions.api.GerritApi) PatchSetUtil(com.google.gerrit.server.PatchSetUtil) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) StarredChangesUtil(com.google.gerrit.server.StarredChangesUtil) Account(com.google.gerrit.reviewdb.client.Account) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) QueryOptions(com.google.gerrit.server.index.QueryOptions) Project(com.google.gerrit.reviewdb.client.Project) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)103 Test (org.junit.Test)85 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)77 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)70 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)25 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)20 Change (com.google.gerrit.reviewdb.client.Change)16 ArrayList (java.util.ArrayList)15 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)13 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)13 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)12 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)12 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)11 LabelType (com.google.gerrit.common.data.LabelType)10 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 RestResponse (com.google.gerrit.acceptance.RestResponse)8 TestAccount (com.google.gerrit.acceptance.TestAccount)8