Fix: cannot apply review labels when restoring a change over SSH
When abandoning a change over SSH, it is possible to apply review labels to the change at the same time: gerrit review --abandon --code-review -1 sha1 However it is not possible to do the same when restoring a change: gerrit review --restore --code-review +2 sha1 The change will be restored, but the given review labels will not be applied. This is because the SSH command implementation applies the review labels before the abandon/restore operation. When restoring a change this does not work because it is not allowed to apply a review label to an abandoned change. Refactor the command so that it applies the review labels before the abandon operation, but after the restore operation, thus making it possible to restore a change and apply review labels at the same time. Change-Id: Ief5ca4e329fba6d686fb431f895df08e1a07e884
This commit is contained in:
@@ -193,6 +193,13 @@ public class ReviewCommand extends SshCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void applyReview(final ChangeControl ctl, final PatchSet.Id patchSetId,
|
||||
final PostReview.Input review) throws Exception {
|
||||
reviewProvider.get().apply(new RevisionResource(
|
||||
new ChangeResource(ctl),
|
||||
db.patchSets().get(patchSetId)), review);
|
||||
}
|
||||
|
||||
private void approveOne(final PatchSet.Id patchSetId) throws Exception {
|
||||
|
||||
if (changeComment == null) {
|
||||
@@ -214,14 +221,12 @@ public class ReviewCommand extends SshCommand {
|
||||
try {
|
||||
ChangeControl ctl =
|
||||
changeControlFactory.controlFor(patchSetId.getParentKey());
|
||||
reviewProvider.get().apply(new RevisionResource(
|
||||
new ChangeResource(ctl),
|
||||
db.patchSets().get(patchSetId)), review);
|
||||
|
||||
if (abandonChange) {
|
||||
final Abandon abandon = abandonProvider.get();
|
||||
final Abandon.Input input = new Abandon.Input();
|
||||
input.message = changeComment;
|
||||
applyReview(ctl, patchSetId, review);
|
||||
try {
|
||||
abandon.apply(new ChangeResource(ctl), input);
|
||||
} catch(AuthException e) {
|
||||
@@ -235,12 +240,16 @@ public class ReviewCommand extends SshCommand {
|
||||
input.message = changeComment;
|
||||
try {
|
||||
restore.apply(new ChangeResource(ctl), input);
|
||||
applyReview(ctl, patchSetId, review);
|
||||
} catch(AuthException e) {
|
||||
writeError("error: " + parseError(Type.RESTORE_NOT_PERMITTED) + "\n");
|
||||
} catch(ResourceConflictException e) {
|
||||
writeError("error: " + parseError(Type.CHANGE_NOT_ABANDONED) + "\n");
|
||||
}
|
||||
} else {
|
||||
applyReview(ctl, patchSetId, review);
|
||||
}
|
||||
|
||||
if (submitChange) {
|
||||
Submit submit = submitProvider.get();
|
||||
Submit.Input input = new Submit.Input();
|
||||
|
Reference in New Issue
Block a user