Line data Source code
1 : // Copyright (C) 2014 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.server.restapi.change; 16 : 17 : import com.google.gerrit.entities.Project; 18 : import com.google.gerrit.extensions.common.Input; 19 : import com.google.gerrit.extensions.restapi.AuthException; 20 : import com.google.gerrit.extensions.restapi.ResourceConflictException; 21 : import com.google.gerrit.extensions.restapi.Response; 22 : import com.google.gerrit.extensions.restapi.RestModifyView; 23 : import com.google.gerrit.server.change.ChangeResource; 24 : import com.google.gerrit.server.edit.ChangeEditModifier; 25 : import com.google.gerrit.server.git.GitRepositoryManager; 26 : import com.google.gerrit.server.permissions.PermissionBackendException; 27 : import com.google.gerrit.server.project.InvalidChangeOperationException; 28 : import com.google.inject.Inject; 29 : import com.google.inject.Singleton; 30 : import java.io.IOException; 31 : import org.eclipse.jgit.lib.Repository; 32 : 33 : @Singleton 34 : public class RebaseChangeEdit implements RestModifyView<ChangeResource, Input> { 35 : private final GitRepositoryManager repositoryManager; 36 : private final ChangeEditModifier editModifier; 37 : 38 : @Inject 39 145 : RebaseChangeEdit(GitRepositoryManager repositoryManager, ChangeEditModifier editModifier) { 40 145 : this.repositoryManager = repositoryManager; 41 145 : this.editModifier = editModifier; 42 145 : } 43 : 44 : @Override 45 : public Response<Object> apply(ChangeResource rsrc, Input in) 46 : throws AuthException, ResourceConflictException, IOException, PermissionBackendException { 47 2 : Project.NameKey project = rsrc.getProject(); 48 2 : try (Repository repository = repositoryManager.openRepository(project)) { 49 1 : editModifier.rebaseEdit(repository, rsrc.getNotes()); 50 1 : } catch (InvalidChangeOperationException e) { 51 1 : throw new ResourceConflictException(e.getMessage()); 52 1 : } 53 1 : return Response.none(); 54 : } 55 : }