Search in sources :

Example 66 with ReviewerInput

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

the class CommentsIT method commentsOnRootCommitsAreIncludedInEmails.

@Test
public void commentsOnRootCommitsAreIncludedInEmails() throws Exception {
    // Create a change in a new branch, making the patch-set commit a root commit.
    ChangeInfo changeInfo = createChangeInNewBranch("newBranch");
    Change.Id changeId = Change.Id.tryParse(Integer.toString(changeInfo._number)).get();
    // Add a file.
    gApi.changes().id(changeId.get()).edit().modifyFile("f1.txt", RawInputUtil.create("content"));
    gApi.changes().id(changeId.get()).edit().publish();
    email.clear();
    ReviewerInput reviewerInput = new ReviewerInput();
    reviewerInput.reviewer = admin.email();
    gApi.changes().id(changeId.get()).addReviewer(reviewerInput);
    changeInfo = gApi.changes().id(changeId.get()).get();
    assertThat(email.getMessages()).hasSize(1);
    Message message = email.getMessages().get(0);
    assertThat(message.body()).contains("f1.txt");
    email.clear();
    // Send a comment. Make sure the email that is sent includes the comment text.
    CommentInput c1 = CommentsUtil.newComment("f1.txt", Side.REVISION, /* line= */
    1, /* message= */
    "Comment text", /* unresolved= */
    false);
    CommentsUtil.addComments(gApi, changeId.toString(), changeInfo.currentRevision, c1);
    assertThat(email.getMessages()).hasSize(1);
    Message commentMessage = email.getMessages().get(0);
    assertThat(commentMessage.body()).contains("Patch Set 2:\n" + "\n" + "(1 comment)\n" + "\n" + "File f1.txt:");
    assertThat(commentMessage.body()).contains("PS2, Line 1: content\n" + "Comment text");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testing.FakeEmailSender.Message) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) Change(com.google.gerrit.entities.Change) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 67 with ReviewerInput

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

the class CustomLabelIT method customLabelAnyWithBlock_Addreviewer_ZeroVote.

@Test
public void customLabelAnyWithBlock_Addreviewer_ZeroVote() throws Exception {
    TestListener testListener = new TestListener();
    try (Registration registration = extensionRegistry.newRegistration().add(testListener)) {
        saveLabelConfig(P.toBuilder().setFunction(ANY_WITH_BLOCK));
        PushOneCommit.Result r = createChange();
        ReviewerInput in = new ReviewerInput();
        in.reviewer = user.email();
        gApi.changes().id(r.getChangeId()).addReviewer(in);
        ReviewInput input = new ReviewInput().label(P_LABEL_NAME, 0);
        input.message = "foo";
        revision(r).review(input);
        ChangeInfo c = getWithLabels(r);
        LabelInfo q = c.labels.get(P_LABEL_NAME);
        assertThat(q.all).hasSize(1);
        assertThat(q.approved).isNull();
        assertThat(q.recommended).isNull();
        assertThat(q.disliked).isNull();
        assertThat(q.rejected).isNull();
        assertThat(q.blocking).isNull();
        assertThat(testListener.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) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 68 with ReviewerInput

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

the class SuggestReviewersIT method suggestReviewerAsCc.

@Test
public void suggestReviewerAsCc() throws Exception {
    requestScopeOperations.setApiUser(user.id());
    String changeId = createChangeFromApi();
    String changeIdReviewed = createChangeFromApi();
    String name = name("foo");
    TestAccount foo1 = accountCreator.create(name + "-1");
    reviewChange(changeIdReviewed, foo1);
    TestAccount foo2 = accountCreator.create(name + "-2");
    reviewChange(changeIdReviewed, foo2);
    assertReviewers(suggestCcs(changeId, name), ImmutableList.of(foo1, foo2), ImmutableList.of());
    ReviewerInput reviewerInput = new ReviewerInput();
    reviewerInput.reviewer = foo2.id().toString();
    reviewerInput.state = ReviewerState.REVIEWER;
    gApi.changes().id(changeId).addReviewer(reviewerInput);
    assertReviewers(suggestCcs(changeId, name), ImmutableList.of(foo1, foo2), ImmutableList.of());
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 69 with ReviewerInput

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

the class SuggestReviewersIT method suggestCcAsReviewer.

@Test
public void suggestCcAsReviewer() throws Exception {
    requestScopeOperations.setApiUser(user.id());
    String changeId = createChangeFromApi();
    String changeIdReviewed = createChangeFromApi();
    String name = name("foo");
    TestAccount foo1 = accountCreator.create(name + "-1");
    reviewChange(changeIdReviewed, foo1);
    TestAccount foo2 = accountCreator.create(name + "-2");
    reviewChange(changeIdReviewed, foo2);
    assertReviewers(suggestReviewers(changeId, name), ImmutableList.of(foo1, foo2), ImmutableList.of());
    ReviewerInput reviewerInput = new ReviewerInput();
    reviewerInput.reviewer = foo2.id().toString();
    reviewerInput.state = ReviewerState.CC;
    gApi.changes().id(changeId).addReviewer(reviewerInput);
    assertReviewers(suggestReviewers(changeId, name), ImmutableList.of(foo1, foo2), ImmutableList.of());
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 70 with ReviewerInput

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

the class AbstractQueryChangesTest method reviewerin.

@Test
public void reviewerin() throws Exception {
    Account.Id user1 = accountManager.authenticate(authRequestFactory.createForUser("user1")).getAccountId();
    Account.Id user2 = accountManager.authenticate(authRequestFactory.createForUser("user2")).getAccountId();
    Account.Id user3 = accountManager.authenticate(authRequestFactory.createForUser("user3")).getAccountId();
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChange(repo));
    Change change2 = insert(repo, newChange(repo));
    Change change3 = insert(repo, newChange(repo));
    ReviewerInput rin = new ReviewerInput();
    rin.reviewer = user1.toString();
    rin.state = ReviewerState.REVIEWER;
    gApi.changes().id(change1.getId().get()).addReviewer(rin);
    rin = new ReviewerInput();
    rin.reviewer = user2.toString();
    rin.state = ReviewerState.REVIEWER;
    gApi.changes().id(change2.getId().get()).addReviewer(rin);
    rin = new ReviewerInput();
    rin.reviewer = user3.toString();
    rin.state = ReviewerState.CC;
    gApi.changes().id(change3.getId().get()).addReviewer(rin);
    String group = gApi.groups().create("foo").get().name;
    gApi.groups().id(group).addMembers(user2.toString(), user3.toString());
    List<String> members = gApi.groups().id(group).members().stream().map(a -> a._accountId.toString()).collect(toList());
    assertThat(members).contains(user2.toString());
    assertQuery("reviewerin:\"Registered Users\"", change2, change1);
    assertQuery("reviewerin:" + group, change2);
    gApi.changes().id(change2.getId().get()).current().review(ReviewInput.approve());
    gApi.changes().id(change2.getId().get()).current().submit();
    assertQuery("reviewerin:" + group, change2);
    assertQuery("project:repo reviewerin:" + group, change2);
    assertQuery("status:merged reviewerin:" + group, change2);
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) Arrays(java.util.Arrays) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ProjectCache(com.google.gerrit.server.project.ProjectCache) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) HashtagsInput(com.google.gerrit.extensions.api.changes.HashtagsInput) Accounts(com.google.gerrit.server.account.Accounts) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ChangeTriplet(com.google.gerrit.server.change.ChangeTriplet) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) 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) AnonymousUser(com.google.gerrit.server.AnonymousUser) ThrowableSubject(com.google.common.truth.ThrowableSubject) FieldDef(com.google.gerrit.index.FieldDef) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) RefUpdate(org.eclipse.jgit.lib.RefUpdate) TestLabels.label(com.google.gerrit.server.project.testing.TestLabels.label) TestLabels.value(com.google.gerrit.server.project.testing.TestLabels.value) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) BranchNameKey(com.google.gerrit.entities.BranchNameKey) PersonIdent(org.eclipse.jgit.lib.PersonIdent) AuthRequest(com.google.gerrit.server.account.AuthRequest) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) IndexPreloadingUtil(com.google.gerrit.httpd.raw.IndexPreloadingUtil) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) AccountCache(com.google.gerrit.server.account.AccountCache) Iterables(com.google.common.collect.Iterables) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) RawInputUtil(com.google.gerrit.common.RawInputUtil) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Multimaps(com.google.common.collect.Multimaps) ArrayList(java.util.ArrayList) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Lists(com.google.common.collect.Lists) IndexPredicate(com.google.gerrit.index.query.IndexPredicate) PatchSet(com.google.gerrit.entities.PatchSet) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) Predicate(com.google.gerrit.index.query.Predicate) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) AccountGroup(com.google.gerrit.entities.AccountGroup) QueryRequest(com.google.gerrit.extensions.api.changes.Changes.QueryRequest) TestRepository(org.eclipse.jgit.junit.TestRepository) NotifyResolver(com.google.gerrit.server.change.NotifyResolver) Sequences(com.google.gerrit.server.notedb.Sequences) RequestContext(com.google.gerrit.server.util.RequestContext) MoreObjects(com.google.common.base.MoreObjects) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) Test(org.junit.Test) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ManualRequestContext(com.google.gerrit.server.util.ManualRequestContext) 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) Project(com.google.gerrit.entities.Project) HOURS(java.util.concurrent.TimeUnit.HOURS) InMemoryRepositoryManager(com.google.gerrit.testing.InMemoryRepositoryManager) ChangeIndexCollection(com.google.gerrit.server.index.change.ChangeIndexCollection) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) ObjectReader(org.eclipse.jgit.lib.ObjectReader) AccountManager(com.google.gerrit.server.account.AccountManager) Patch(com.google.gerrit.entities.Patch) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) Inject(com.google.inject.Inject) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ChangeIndexer(com.google.gerrit.server.index.change.ChangeIndexer) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) LabelType(com.google.gerrit.entities.LabelType) VersionedAccountQueries(com.google.gerrit.server.account.VersionedAccountQueries) After(org.junit.After) REVIEWED(com.google.gerrit.extensions.client.ListChangesOption.REVIEWED) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) Assert.fail(org.junit.Assert.fail) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) OneOffRequestContext(com.google.gerrit.server.util.OneOffRequestContext) Schema(com.google.gerrit.index.Schema) ImmutableSet(com.google.common.collect.ImmutableSet) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) Account(com.google.gerrit.entities.Account) Streams(com.google.common.collect.Streams) Instant(java.time.Instant) GroupReference(com.google.gerrit.entities.GroupReference) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) ExperimentFeaturesConstants(com.google.gerrit.server.experiments.ExperimentFeaturesConstants) FakeSubmitRule(com.google.gerrit.acceptance.FakeSubmitRule) ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) Ref(org.eclipse.jgit.lib.Ref) TestProjectUpdate.allowLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel) TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) LabelId(com.google.gerrit.entities.LabelId) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) IndexConfig(com.google.gerrit.index.IndexConfig) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Multimap(com.google.common.collect.Multimap) SchemaCreator(com.google.gerrit.server.schema.SchemaCreator) ImmutableList(com.google.common.collect.ImmutableList) QueryParseException(com.google.gerrit.index.query.QueryParseException) PermissionRule(com.google.gerrit.entities.PermissionRule) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ExternalIdFactory(com.google.gerrit.server.account.externalids.ExternalIdFactory) GerritServerTests(com.google.gerrit.testing.GerritServerTests) Change(com.google.gerrit.entities.Change) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) AssigneeInput(com.google.gerrit.extensions.api.changes.AssigneeInput) AccountsUpdate(com.google.gerrit.server.account.AccountsUpdate) TestTimeUtil(com.google.gerrit.testing.TestTimeUtil) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) CurrentUser(com.google.gerrit.server.CurrentUser) Iterator(java.util.Iterator) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Permission(com.google.gerrit.entities.Permission) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) IndexedChangeQuery(com.google.gerrit.server.index.change.IndexedChangeQuery) Truth.assertThat(com.google.common.truth.Truth.assertThat) Maps(com.google.common.collect.Maps) 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) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ServerInitiated(com.google.gerrit.server.ServerInitiated) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AttentionSetInput(com.google.gerrit.extensions.api.changes.AttentionSetInput) GerritApi(com.google.gerrit.extensions.api.GerritApi) PatchSetUtil(com.google.gerrit.server.PatchSetUtil) SECONDS(java.util.concurrent.TimeUnit.SECONDS) StarredChangesUtil(com.google.gerrit.server.StarredChangesUtil) Account(com.google.gerrit.entities.Account) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test)

Aggregations

ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)72 Test (org.junit.Test)67 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)60 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)46 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)25 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)22 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)20 TestAccount (com.google.gerrit.acceptance.TestAccount)14 Message (com.google.gerrit.testing.FakeEmailSender.Message)14 ReviewerResult (com.google.gerrit.extensions.api.changes.ReviewerResult)13 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)11 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)11 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 Account (com.google.gerrit.entities.Account)10 Change (com.google.gerrit.entities.Change)7 UseClockStep (com.google.gerrit.acceptance.UseClockStep)5 ReviewerInfo (com.google.gerrit.extensions.api.changes.ReviewerInfo)5 Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)5 Instant (java.time.Instant)5 ArrayList (java.util.ArrayList)5