Search in sources :

Example 11 with RobotCommentInput

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

the class ImpersonationIT method voteOnBehalfOfWithRobotComment.

@GerritConfig(name = "notedb.writeJson", value = "true")
@Test
public void voteOnBehalfOfWithRobotComment() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id.toString();
    in.label("Code-Review", 1);
    RobotCommentInput ci = new RobotCommentInput();
    ci.robotId = "my-robot";
    ci.robotRunId = "abcd1234";
    ci.path = Patch.COMMIT_MSG;
    ci.side = Side.REVISION;
    ci.line = 1;
    ci.message = "message";
    in.robotComments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
    gApi.changes().id(r.getChangeId()).current().review(in);
    ChangeData cd = r.getChange();
    RobotComment c = Iterables.getOnlyElement(commentsUtil.robotCommentsByChange(cd.notes()));
    assertThat(c.message).isEqualTo(ci.message);
    assertThat(c.robotId).isEqualTo(ci.robotId);
    assertThat(c.robotRunId).isEqualTo(ci.robotRunId);
    assertThat(c.author.getId()).isEqualTo(user.id);
    assertThat(c.getRealAuthor().getId()).isEqualTo(admin.id);
}
Also used : RobotComment(com.google.gerrit.reviewdb.client.RobotComment) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with RobotCommentInput

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

the class PostReview method checkRobotComments.

private void checkRobotComments(RevisionResource revision, Map<String, List<RobotCommentInput>> in) throws BadRequestException, OrmException {
    cleanUpComments(in);
    for (Map.Entry<String, List<RobotCommentInput>> e : in.entrySet()) {
        String commentPath = e.getKey();
        for (RobotCommentInput c : e.getValue()) {
            ensureSizeOfJsonInputIsWithinBounds(c);
            ensureRobotIdIsSet(c.robotId, commentPath);
            ensureRobotRunIdIsSet(c.robotRunId, commentPath);
            ensureFixSuggestionsAreAddable(c.fixSuggestions, commentPath);
        }
    }
    checkComments(revision, in);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with RobotCommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput 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

RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)13 Test (org.junit.Test)10 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)7 List (java.util.List)6 Collectors.toList (java.util.stream.Collectors.toList)6 ImmutableList (com.google.common.collect.ImmutableList)5 RobotCommentInfoSubject.assertThatList (com.google.gerrit.extensions.common.RobotCommentInfoSubject.assertThatList)4 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 MoreObjects (com.google.common.base.MoreObjects)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 ThrowableSubject (com.google.common.truth.ThrowableSubject)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 TruthJUnit.assume (com.google.common.truth.TruthJUnit.assume)1