Line data Source code
1 : // Copyright (C) 2017 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.common.Nullable; 18 : import com.google.gerrit.extensions.common.PureRevertInfo; 19 : import com.google.gerrit.extensions.restapi.AuthException; 20 : import com.google.gerrit.extensions.restapi.BadRequestException; 21 : import com.google.gerrit.extensions.restapi.ResourceConflictException; 22 : import com.google.gerrit.extensions.restapi.Response; 23 : import com.google.gerrit.extensions.restapi.RestReadView; 24 : import com.google.gerrit.server.change.ChangeResource; 25 : import com.google.gerrit.server.change.PureRevert; 26 : import com.google.inject.Inject; 27 : import java.io.IOException; 28 : import java.util.Optional; 29 : import org.kohsuke.args4j.Option; 30 : 31 : public class GetPureRevert implements RestReadView<ChangeResource> { 32 : 33 : private final PureRevert pureRevert; 34 : @Nullable private String claimedOriginal; 35 : 36 : @Option( 37 : name = "--claimed-original", 38 : aliases = {"-o"}, 39 : usage = "SHA1 (40 digit hex) of the original commit") 40 : public void setClaimedOriginal(String claimedOriginal) { 41 1 : this.claimedOriginal = claimedOriginal; 42 1 : } 43 : 44 : @Inject 45 57 : GetPureRevert(PureRevert pureRevert) { 46 57 : this.pureRevert = pureRevert; 47 57 : } 48 : 49 : @Override 50 : public Response<PureRevertInfo> apply(ChangeResource rsrc) 51 : throws ResourceConflictException, IOException, BadRequestException, AuthException { 52 1 : boolean isPureRevert = pureRevert.get(rsrc.getNotes(), Optional.ofNullable(claimedOriginal)); 53 1 : return Response.ok(new PureRevertInfo(isPureRevert)); 54 : } 55 : }