Search in sources :

Example 21 with RevertInput

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

the class RevertIT method revertSubmissionSuppressNotifications.

@Test
public void revertSubmissionSuppressNotifications() throws Exception {
    String firstResult = createChange("first change", "a.txt", "message").getChangeId();
    approve(firstResult);
    gApi.changes().id(firstResult).addReviewer(user.email());
    String secondResult = createChange("second change", "b.txt", "other").getChangeId();
    approve(secondResult);
    gApi.changes().id(secondResult).addReviewer(user.email());
    gApi.changes().id(secondResult).current().submit();
    sender.clear();
    RevertInput revertInput = new RevertInput();
    revertInput.notify = NotifyHandling.NONE;
    gApi.changes().id(secondResult).revertSubmission(revertInput);
    assertThat(sender.getMessages()).isEmpty();
}
Also used : RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 22 with RevertInput

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

the class RevertSubmission method revertSubmission.

private RevertSubmissionInfo revertSubmission(List<ChangeData> changeData, RevertInput revertInput) throws RestApiException, IOException, UpdateException, ConfigInvalidException, StorageException, PermissionBackendException {
    Multimap<BranchNameKey, ChangeData> changesPerProjectAndBranch = ArrayListMultimap.create();
    changeData.stream().forEach(c -> changesPerProjectAndBranch.put(c.change().getDest(), c));
    cherryPickInput = createCherryPickInput(revertInput);
    Instant timestamp = TimeUtil.now();
    for (BranchNameKey projectAndBranch : changesPerProjectAndBranch.keySet()) {
        cherryPickInput.base = null;
        Project.NameKey project = projectAndBranch.project();
        cherryPickInput.destination = projectAndBranch.branch();
        if (revertInput.workInProgress) {
            cherryPickInput.notify = firstNonNull(cherryPickInput.notify, NotifyHandling.OWNER);
        }
        Collection<ChangeData> changesInProjectAndBranch = changesPerProjectAndBranch.get(projectAndBranch);
        // Sort the changes topologically.
        Iterator<PatchSetData> sortedChangesInProjectAndBranch = sorter.sort(changesInProjectAndBranch).iterator();
        Set<ObjectId> commitIdsInProjectAndBranch = changesInProjectAndBranch.stream().map(c -> c.currentPatchSet().commitId()).collect(Collectors.toSet());
        revertAllChangesInProjectAndBranch(revertInput, project, sortedChangesInProjectAndBranch, commitIdsInProjectAndBranch, timestamp);
    }
    results.sort(Comparator.comparing(c -> c.revertOf));
    RevertSubmissionInfo revertSubmissionInfo = new RevertSubmissionInfo();
    revertSubmissionInfo.revertChanges = results;
    return revertSubmissionInfo;
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) Arrays(java.util.Arrays) CommitMessageUtil(com.google.gerrit.server.util.CommitMessageUtil) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) ProjectCache(com.google.gerrit.server.project.ProjectCache) Inject(com.google.inject.Inject) BooleanCondition.and(com.google.gerrit.extensions.conditions.BooleanCondition.and) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) UpdateException(com.google.gerrit.server.update.UpdateException) RestModifyView(com.google.gerrit.extensions.restapi.RestModifyView) RevWalk(org.eclipse.jgit.revwalk.RevWalk) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) Matcher(java.util.regex.Matcher) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) UiAction(com.google.gerrit.extensions.webui.UiAction) CREATE_CHANGE(com.google.gerrit.server.permissions.RefPermission.CREATE_CHANGE) REVERT(com.google.gerrit.server.permissions.ChangePermission.REVERT) RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) Collection(java.util.Collection) ChangeMessages(com.google.gerrit.server.change.ChangeMessages) Set(java.util.Set) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) BranchNameKey(com.google.gerrit.entities.BranchNameKey) CommitUtil(com.google.gerrit.server.git.CommitUtil) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) ChangeReverted(com.google.gerrit.server.extensions.events.ChangeReverted) InternalChangeQuery(com.google.gerrit.server.query.change.InternalChangeQuery) ChangeJson(com.google.gerrit.server.change.ChangeJson) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) Pattern(java.util.regex.Pattern) FluentLogger(com.google.common.flogger.FluentLogger) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) Iterables(com.google.common.collect.Iterables) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) WalkSorter(com.google.gerrit.server.change.WalkSorter) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ChangePermission(com.google.gerrit.server.permissions.ChangePermission) Multimap(com.google.common.collect.Multimap) Response(com.google.gerrit.extensions.restapi.Response) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) MessageIdGenerator(com.google.gerrit.server.mail.send.MessageIdGenerator) ChangeResource(com.google.gerrit.server.change.ChangeResource) PostUpdateContext(com.google.gerrit.server.update.PostUpdateContext) Objects.requireNonNull(java.util.Objects.requireNonNull) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RevertedSender(com.google.gerrit.server.mail.send.RevertedSender) Change(com.google.gerrit.entities.Change) ContributorAgreementsChecker(com.google.gerrit.server.project.ContributorAgreementsChecker) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ChangeUtil(com.google.gerrit.server.ChangeUtil) ChangeContext(com.google.gerrit.server.update.ChangeContext) PatchSetData(com.google.gerrit.server.change.WalkSorter.PatchSetData) ProjectCache.illegalState(com.google.gerrit.server.project.ProjectCache.illegalState) CurrentUser(com.google.gerrit.server.CurrentUser) RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) NotifyResolver(com.google.gerrit.server.change.NotifyResolver) Sequences(com.google.gerrit.server.notedb.Sequences) Iterator(java.util.Iterator) StorageException(com.google.gerrit.exceptions.StorageException) ProjectState(com.google.gerrit.server.project.ProjectState) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) IOException(java.io.IOException) ObjectId(org.eclipse.jgit.lib.ObjectId) Provider(com.google.inject.Provider) GitRepositoryManager(com.google.gerrit.server.git.GitRepositoryManager) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) RevisionResource(com.google.gerrit.server.change.RevisionResource) Project(com.google.gerrit.entities.Project) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) Result(com.google.gerrit.server.restapi.change.CherryPickChange.Result) Comparator(java.util.Comparator) PatchSetUtil(com.google.gerrit.server.PatchSetUtil) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Repository(org.eclipse.jgit.lib.Repository) PatchSetData(com.google.gerrit.server.change.WalkSorter.PatchSetData) ObjectId(org.eclipse.jgit.lib.ObjectId) Instant(java.time.Instant) ChangeData(com.google.gerrit.server.query.change.ChangeData) Project(com.google.gerrit.entities.Project) RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) BranchNameKey(com.google.gerrit.entities.BranchNameKey)

Aggregations

RevertInput (com.google.gerrit.extensions.api.changes.RevertInput)22 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)20 Test (org.junit.Test)20 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)7 RevertSubmissionInfo (com.google.gerrit.extensions.common.RevertSubmissionInfo)3 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Strings (com.google.common.base.Strings)1 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)1 Iterables (com.google.common.collect.Iterables)1 Multimap (com.google.common.collect.Multimap)1 FluentLogger (com.google.common.flogger.FluentLogger)1 BranchNameKey (com.google.gerrit.entities.BranchNameKey)1 Change (com.google.gerrit.entities.Change)1 Project (com.google.gerrit.entities.Project)1 RefNames (com.google.gerrit.entities.RefNames)1 StorageException (com.google.gerrit.exceptions.StorageException)1 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)1 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)1 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)1