Search in sources :

Example 11 with CherryPickInput

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

the class RevisionIT method cherryPickToSameBranchWithRebase.

@Test
public void cherryPickToSameBranchWithRebase() throws Exception {
    // Push a new change, then merge it
    PushOneCommit.Result baseChange = createChange();
    String triplet = project.get() + "~master~" + baseChange.getChangeId();
    RevisionApi baseRevision = gApi.changes().id(triplet).current();
    baseRevision.review(ReviewInput.approve());
    baseRevision.submit();
    // Push a new change (change 1)
    PushOneCommit.Result r1 = createChange();
    // Push another new change (change 2)
    String subject = "Test change\n\nChange-Id: Ideadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
    PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, subject, "another_file.txt", "another content");
    PushOneCommit.Result r2 = push.to("refs/for/master");
    // Change 2's parent should be change 1
    assertThat(r2.getCommit().getParents()[0].name()).isEqualTo(r1.getCommit().name());
    // Cherry pick change 2 onto the same branch
    triplet = project.get() + "~master~" + r2.getChangeId();
    ChangeApi orig = gApi.changes().id(triplet);
    CherryPickInput in = new CherryPickInput();
    in.destination = "master";
    in.message = subject;
    ChangeApi cherry = orig.revision(r2.getCommit().name()).cherryPick(in);
    ChangeInfo cherryInfo = cherry.get();
    assertThat(cherryInfo.messages).hasSize(2);
    Iterator<ChangeMessageInfo> cherryIt = cherryInfo.messages.iterator();
    assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 1.");
    assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 2.");
    // Parent of change 2 should now be the change that was merged, i.e.
    // change 2 is rebased onto the head of the master branch.
    String newParent = cherryInfo.revisions.get(cherryInfo.currentRevision).commit.parents.get(0).commit;
    assertThat(newParent).isEqualTo(baseChange.getCommit().name());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with CherryPickInput

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

the class RevisionIT method cherryPickKeepReviewers.

@Test
public void cherryPickKeepReviewers() throws Exception {
    createBranch(BranchNameKey.create(project, "stable"));
    // Change is created by 'admin'.
    PushOneCommit.Result r = createChange();
    // Change is approved by 'admin2'. Change is CC'd to 'user'.
    requestScopeOperations.setApiUser(accountCreator.admin2().id());
    ReviewInput in = ReviewInput.approve();
    in.reviewer(user.email(), ReviewerState.CC, true);
    gApi.changes().id(r.getChangeId()).current().review(in);
    // Change is cherrypicked by 'user2'.
    requestScopeOperations.setApiUser(accountCreator.user2().id());
    CherryPickInput cin = new CherryPickInput();
    cin.message = "this need to go to stable";
    cin.destination = "stable";
    cin.keepReviewers = true;
    Map<ReviewerState, Collection<AccountInfo>> result = gApi.changes().id(r.getChangeId()).current().cherryPick(cin).get().reviewers;
    // 'admin' should be a reviewer as the old owner.
    // 'admin2' should be a reviewer as the old reviewer.
    // 'user' should be on CC.
    assertThat(result).containsKey(ReviewerState.REVIEWER);
    List<Integer> reviewers = result.get(ReviewerState.REVIEWER).stream().map(a -> a._accountId).collect(toList());
    assertThat(result).containsKey(ReviewerState.CC);
    List<Integer> ccs = result.get(ReviewerState.CC).stream().map(a -> a._accountId).collect(toList());
    assertThat(ccs).containsExactly(user.id().get());
    assertThat(reviewers).containsExactly(admin.id().get(), accountCreator.admin2().id().get());
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) ChangeIndexedListener(com.google.gerrit.extensions.events.ChangeIndexedListener) NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ListMultimap(com.google.common.collect.ListMultimap) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PATCH(com.google.gerrit.acceptance.PushOneCommit.PATCH) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Map(java.util.Map) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) PatchSetWebLink(com.google.gerrit.extensions.webui.PatchSetWebLink) RefSpec(org.eclipse.jgit.transport.RefSpec) HEAD(org.eclipse.jgit.lib.Constants.HEAD) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) UseClockStep(com.google.gerrit.acceptance.UseClockStep) CountDownLatch(java.util.concurrent.CountDownLatch) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Iterables(com.google.common.collect.Iterables) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) MERGE_LIST(com.google.gerrit.entities.Patch.MERGE_LIST) SimpleDateFormat(java.text.SimpleDateFormat) Callable(java.util.concurrent.Callable) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) TestRepository(org.eclipse.jgit.junit.TestRepository) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) ObjectIds.abbreviateName(com.google.gerrit.git.ObjectIds.abbreviateName) Test(org.junit.Test) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchOrderSection(com.google.gerrit.entities.BranchOrderSection) Repository(org.eclipse.jgit.lib.Repository) PATCH_FILE_ONLY(com.google.gerrit.acceptance.PushOneCommit.PATCH_FILE_ONLY) ALL_REVISIONS(com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) FILE_CONTENT(com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) DraftApi(com.google.gerrit.extensions.api.changes.DraftApi) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Locale(java.util.Locale) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) DateFormat(java.text.DateFormat) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) SubmitType(com.google.gerrit.extensions.client.SubmitType) Collection(java.util.Collection) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) Account(com.google.gerrit.entities.Account) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Optional(java.util.Optional) GitPerson(com.google.gerrit.extensions.common.GitPerson) MergeableInfo(com.google.gerrit.extensions.common.MergeableInfo) LabelId(com.google.gerrit.entities.LabelId) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Iterators(com.google.common.collect.Iterators) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Change(com.google.gerrit.entities.Change) FileInfo(com.google.gerrit.extensions.common.FileInfo) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) CommitValidationException(com.google.gerrit.server.git.validators.CommitValidationException) 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) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) Collectors.toList(java.util.stream.Collectors.toList) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) RecipientType(com.google.gerrit.extensions.api.changes.RecipientType) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) ResolveConflictsWebLink(com.google.gerrit.extensions.webui.ResolveConflictsWebLink) Collections(java.util.Collections) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) Collection(java.util.Collection) 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 13 with CherryPickInput

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

the class RevisionIT method cherryPickWorkInProgressChange.

@Test
public void cherryPickWorkInProgressChange() throws Exception {
    PushOneCommit.Result r = pushTo("refs/for/master%wip");
    CherryPickInput in = new CherryPickInput();
    in.destination = "foo";
    in.message = "cherry pick message";
    gApi.projects().name(project.get()).branch(in.destination).create(new BranchInput());
    ChangeApi orig = gApi.changes().id(project.get() + "~master~" + r.getChangeId());
    ChangeApi cherry = orig.revision(r.getCommit().name()).cherryPick(in);
    assertThat(cherry.get().cherryPickOfChange).isEqualTo(orig.get()._number);
    assertThat(cherry.get().cherryPickOfPatchSet).isEqualTo(1);
    assertThat(cherry.get().workInProgress).isTrue();
}
Also used : ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with CherryPickInput

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

the class RevisionIT method cherryPickToSameBranch.

@Test
public void cherryPickToSameBranch() throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeApi change = gApi.changes().id(project.get() + "~master~" + r.getChangeId());
    CherryPickInput in = new CherryPickInput();
    in.destination = "master";
    in.message = "it generates a new patch set\n\nChange-Id: " + r.getChangeId();
    ChangeInfo cherryInfo = change.revision(r.getCommit().name()).cherryPick(in).get();
    assertThat(cherryInfo.messages).hasSize(2);
    Iterator<ChangeMessageInfo> cherryIt = cherryInfo.messages.iterator();
    assertThat(cherryInfo.cherryPickOfChange).isEqualTo(change.get()._number);
    // Existing change was updated.
    assertThat(cherryInfo._number).isEqualTo(change.get()._number);
    assertThat(cherryInfo.cherryPickOfPatchSet).isEqualTo(1);
    assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 1.");
    assertThat(cherryIt.next().message).isEqualTo("Uploaded patch set 2.");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with CherryPickInput

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

the class RevisionIT method cherryPickWithValidationOptions.

@Test
public void cherryPickWithValidationOptions() throws Exception {
    PushOneCommit.Result r = createChange();
    CherryPickInput in = new CherryPickInput();
    in.destination = "foo";
    in.message = "Cherry Pick";
    in.validationOptions = ImmutableMap.of("key", "value");
    gApi.projects().name(project.get()).branch(in.destination).create(new BranchInput());
    TestCommitValidationListener testCommitValidationListener = new TestCommitValidationListener();
    try (Registration registration = extensionRegistry.newRegistration().add(testCommitValidationListener)) {
        gApi.changes().id(r.getChangeId()).current().cherryPickAsInfo(in);
        assertThat(testCommitValidationListener.receiveEvent.pushOptions).containsExactly("key", "value");
    }
}
Also used : Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)57 Test (org.junit.Test)53 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)50 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)49 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)30 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)27 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)15 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)11 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)11 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)8 Result (com.google.gerrit.acceptance.PushOneCommit.Result)7 ObjectId (org.eclipse.jgit.lib.ObjectId)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)6 RefSpec (org.eclipse.jgit.transport.RefSpec)5 CommitInfo (com.google.gerrit.extensions.common.CommitInfo)3 FileInfo (com.google.gerrit.extensions.common.FileInfo)3 AuthException (com.google.gerrit.extensions.restapi.AuthException)3 Iterables (com.google.common.collect.Iterables)2 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)2