Revision API: add cherry pick method
This change adds cherry pick function to the Revision API:
@Inject GerritApi gApi;
[...]
Project.NameKey project = ...
String changeId = ...
String resvision = ...
CherryPickInput in = new CherryPickInput();
in.destination = "foo";
gApi.projects()
.name(project.get())
.branch(in.destination)
.create(new BranchInput());
gApi.projects()
.name(project.get())
.branch(in.destination)
.create(new BranchInput());
ChangeApi cApi = gApi.changes()
.id(changeId)
.revision(resvision)
.cherryPick(in);
cApi.current()
.review(approve());
cApi.current()
.submit();
Change-Id: Ie291a824720bc1e81c8636773e3a570778383953
This commit is contained in:
@@ -15,10 +15,14 @@
|
||||
package com.google.gerrit.server.api.changes;
|
||||
|
||||
import com.google.gerrit.common.errors.EmailException;
|
||||
import com.google.gerrit.extensions.api.changes.ChangeApi;
|
||||
import com.google.gerrit.extensions.api.changes.Changes;
|
||||
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||
import com.google.gerrit.extensions.api.changes.RevisionApi;
|
||||
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
import com.google.gerrit.server.change.CherryPick;
|
||||
import com.google.gerrit.server.change.DeleteDraftPatchSet;
|
||||
import com.google.gerrit.server.change.PostReview;
|
||||
import com.google.gerrit.server.change.Rebase;
|
||||
@@ -36,6 +40,8 @@ class RevisionApiImpl implements RevisionApi {
|
||||
RevisionApiImpl create(RevisionResource r);
|
||||
}
|
||||
|
||||
private final Changes changes;
|
||||
private final Provider<CherryPick> cherryPick;
|
||||
private final Provider<DeleteDraftPatchSet> deleteDraft;
|
||||
private final Provider<Rebase> rebase;
|
||||
private final Provider<PostReview> review;
|
||||
@@ -43,11 +49,15 @@ class RevisionApiImpl implements RevisionApi {
|
||||
private final RevisionResource revision;
|
||||
|
||||
@Inject
|
||||
RevisionApiImpl(Provider<DeleteDraftPatchSet> deleteDraft,
|
||||
RevisionApiImpl(Changes changes,
|
||||
Provider<CherryPick> cherryPick,
|
||||
Provider<DeleteDraftPatchSet> deleteDraft,
|
||||
Provider<Rebase> rebase,
|
||||
Provider<PostReview> review,
|
||||
Provider<Submit> submit,
|
||||
@Assisted RevisionResource r) {
|
||||
this.changes = changes;
|
||||
this.cherryPick = cherryPick;
|
||||
this.deleteDraft = deleteDraft;
|
||||
this.rebase = rebase;
|
||||
this.review = review;
|
||||
@@ -96,13 +106,26 @@ class RevisionApiImpl implements RevisionApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rebase() throws RestApiException {
|
||||
public ChangeApi rebase() throws RestApiException {
|
||||
try {
|
||||
rebase.get().apply(revision, null);
|
||||
return changes.id(rebase.get().apply(revision, null)._number);
|
||||
} catch (OrmException e) {
|
||||
throw new RestApiException("Cannot rebase ps", e);
|
||||
} catch (EmailException e) {
|
||||
throw new RestApiException("Cannot rebase ps", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeApi cherryPick(CherryPickInput in) throws RestApiException {
|
||||
try {
|
||||
return changes.id(cherryPick.get().apply(revision, in)._number);
|
||||
} catch (OrmException e) {
|
||||
throw new RestApiException("Cannot cherry pick", e);
|
||||
} catch (EmailException e) {
|
||||
throw new RestApiException("Cannot cherry pick", e);
|
||||
} catch (IOException e) {
|
||||
throw new RestApiException("Cannot cherry pick", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
package com.google.gerrit.server.change;
|
||||
|
||||
import com.google.gerrit.common.errors.EmailException;
|
||||
import com.google.gerrit.extensions.api.changes.CherryPickInput;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
@@ -25,7 +26,6 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gerrit.server.change.CherryPick.Input;
|
||||
import com.google.gerrit.server.git.MergeException;
|
||||
import com.google.gerrit.server.project.ChangeControl;
|
||||
import com.google.gerrit.server.project.InvalidChangeOperationException;
|
||||
@@ -37,17 +37,12 @@ import com.google.inject.Provider;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class CherryPick implements RestModifyView<RevisionResource, Input>,
|
||||
public class CherryPick implements RestModifyView<RevisionResource, CherryPickInput>,
|
||||
UiAction<RevisionResource> {
|
||||
private final Provider<ReviewDb> dbProvider;
|
||||
private final Provider<CherryPickChange> cherryPickChange;
|
||||
private final ChangeJson json;
|
||||
|
||||
static class Input {
|
||||
String message;
|
||||
String destination;
|
||||
}
|
||||
|
||||
@Inject
|
||||
CherryPick(Provider<ReviewDb> dbProvider,
|
||||
Provider<CherryPickChange> cherryPickChange,
|
||||
@@ -58,7 +53,7 @@ class CherryPick implements RestModifyView<RevisionResource, Input>,
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChangeInfo apply(RevisionResource revision, Input input)
|
||||
public ChangeInfo apply(RevisionResource revision, CherryPickInput input)
|
||||
throws AuthException, BadRequestException, ResourceConflictException,
|
||||
ResourceNotFoundException, OrmException, IOException, EmailException {
|
||||
final ChangeControl control = revision.getControl();
|
||||
|
||||
Reference in New Issue
Block a user