diff options
author | Sven Selberg <svense@axis.com> | 2024-02-23 13:36:46 +0100 |
---|---|---|
committer | Sven Selberg <svense@axis.com> | 2024-04-11 08:06:10 +0200 |
commit | 22e19f2965b1ad1a53db8a083b6ed08f1b13ccf6 (patch) | |
tree | 59bf4f953a92ffed5d20eebffd53033f8a0c4da2 | |
parent | 0ca10457d3a8668c7a04d2acf4ac039a373114ae (diff) |
ReviewCommand: When available use project when identifying a change
Changes#id(String, int) is guaranteed to unambiguously identify exactly
one change if such a change is available. If project is provided in
CLI call use this method to get ChangeApi.
If project was not provided lookup the ChangeApi with only the
change-number through Changes#id(String) which may identify several
changes and throw an Exception (e.g. if changes have been imported
from another Gerrit instance so that two changes have the same
change-number).
Release-Notes: ReviewCommand identify change with project,change-number if project is provided in CLI call.
Change-Id: I04eb63949f7768f7e719f0d49ce4f7d64834e37f
-rw-r--r-- | java/com/google/gerrit/sshd/commands/ReviewCommand.java | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/java/com/google/gerrit/sshd/commands/ReviewCommand.java b/java/com/google/gerrit/sshd/commands/ReviewCommand.java index c27167610e..e004940f40 100644 --- a/java/com/google/gerrit/sshd/commands/ReviewCommand.java +++ b/java/com/google/gerrit/sshd/commands/ReviewCommand.java @@ -254,10 +254,7 @@ public class ReviewCommand extends SshCommand { ActionType.CHANGE_UPDATE, "applyReview", () -> { - gApi.changes() - .id(patchSet.id().changeId().get()) - .revision(patchSet.number()) - .review(review); + getRevisionApi(patchSet).review(review); return null; }) .call(); @@ -295,11 +292,11 @@ public class ReviewCommand extends SshCommand { AbandonInput input = new AbandonInput(); input.message = Strings.emptyToNull(changeComment); applyReview(patchSet, review); - changeApi(patchSet).abandon(input); + getChangeApi(patchSet).abandon(input); } else if (restoreChange) { RestoreInput input = new RestoreInput(); input.message = Strings.emptyToNull(changeComment); - changeApi(patchSet).restore(input); + getChangeApi(patchSet).restore(input); applyReview(patchSet, review); } else { applyReview(patchSet, review); @@ -309,15 +306,15 @@ public class ReviewCommand extends SshCommand { MoveInput moveInput = new MoveInput(); moveInput.destinationBranch = moveToBranch; moveInput.message = Strings.emptyToNull(changeComment); - changeApi(patchSet).move(moveInput); + getChangeApi(patchSet).move(moveInput); } if (rebaseChange) { - revisionApi(patchSet).rebase(); + getRevisionApi(patchSet).rebase(); } if (submitChange) { - revisionApi(patchSet).submit(); + getRevisionApi(patchSet).submit(); } } catch (IllegalStateException | RestApiException e) { @@ -325,12 +322,19 @@ public class ReviewCommand extends SshCommand { } } - private ChangeApi changeApi(PatchSet patchSet) throws RestApiException { - return gApi.changes().id(patchSet.id().changeId().get()); + private ChangeApi getChangeApi(PatchSet patchSet) throws RestApiException { + if (projectState != null) { + return gApi.changes().id(projectState.getName(), patchSet.id().changeId().get()); + } + /* Since we didn't get a project from the CLI we have to use the ambiguous + * Changes#id(String) that may fail to identify one single change and throw + * an exception. + */ + return gApi.changes().id(String.valueOf(patchSet.id().changeId().get())); } - private RevisionApi revisionApi(PatchSet patchSet) throws RestApiException { - return changeApi(patchSet).revision(patchSet.commitId().name()); + private RevisionApi getRevisionApi(PatchSet patchSet) throws RestApiException { + return getChangeApi(patchSet).revision(patchSet.commitId().name()); } @Override |