Introduce InputWithMessage
InputWithMessage is similar to InputWithCommitMessage but is intended for messages other than commit messages, i.e. a message added to the change review history. We can't simply use the existing InputWithCommitMessage for this since the message field is named 'commitMessage' and this would be a breaking API change. Change-Id: I5383dfc5c2b08e50675daec4a1a07b538d90ae15
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// Copyright (C) 2019 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.extensions.common;
|
||||
|
||||
import com.google.gerrit.common.Nullable;
|
||||
|
||||
/**
|
||||
* A generic input with a message only.
|
||||
*
|
||||
* <p>See also {@link InputWithCommitMessage}.
|
||||
*/
|
||||
public class InputWithMessage {
|
||||
@Nullable public String message;
|
||||
|
||||
public InputWithMessage() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public InputWithMessage(@Nullable String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@@ -48,6 +48,7 @@ import com.google.gerrit.extensions.common.ChangeMessageInfo;
|
||||
import com.google.gerrit.extensions.common.CommentInfo;
|
||||
import com.google.gerrit.extensions.common.CommitMessageInput;
|
||||
import com.google.gerrit.extensions.common.Input;
|
||||
import com.google.gerrit.extensions.common.InputWithMessage;
|
||||
import com.google.gerrit.extensions.common.MergePatchSetInput;
|
||||
import com.google.gerrit.extensions.common.PureRevertInfo;
|
||||
import com.google.gerrit.extensions.common.RevertSubmissionInfo;
|
||||
@@ -63,7 +64,6 @@ import com.google.gerrit.server.StarredChangesUtil;
|
||||
import com.google.gerrit.server.StarredChangesUtil.IllegalLabelException;
|
||||
import com.google.gerrit.server.change.ChangeMessageResource;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
import com.google.gerrit.server.change.SetPrivateOp;
|
||||
import com.google.gerrit.server.change.WorkInProgressOp;
|
||||
import com.google.gerrit.server.restapi.change.Abandon;
|
||||
import com.google.gerrit.server.restapi.change.ChangeIncludedIn;
|
||||
@@ -324,7 +324,7 @@ class ChangeApiImpl implements ChangeApi {
|
||||
@Override
|
||||
public void setPrivate(boolean value, @Nullable String message) throws RestApiException {
|
||||
try {
|
||||
SetPrivateOp.Input input = new SetPrivateOp.Input(message);
|
||||
InputWithMessage input = new InputWithMessage(message);
|
||||
if (value) {
|
||||
postPrivate.apply(change, input);
|
||||
} else {
|
||||
|
@@ -19,6 +19,7 @@ import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.entities.Change;
|
||||
import com.google.gerrit.entities.ChangeMessage;
|
||||
import com.google.gerrit.entities.PatchSet;
|
||||
import com.google.gerrit.extensions.common.InputWithMessage;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
@@ -34,25 +35,15 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
public class SetPrivateOp implements BatchUpdateOp {
|
||||
public static class Input {
|
||||
String message;
|
||||
|
||||
public Input() {}
|
||||
|
||||
public Input(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
public interface Factory {
|
||||
SetPrivateOp create(boolean isPrivate, @Nullable Input input);
|
||||
SetPrivateOp create(boolean isPrivate, @Nullable InputWithMessage input);
|
||||
}
|
||||
|
||||
private final PrivateStateChanged privateStateChanged;
|
||||
private final PatchSetUtil psUtil;
|
||||
private final ChangeMessagesUtil cmUtil;
|
||||
private final boolean isPrivate;
|
||||
@Nullable private final Input input;
|
||||
@Nullable private final InputWithMessage input;
|
||||
|
||||
private Change change;
|
||||
private PatchSet ps;
|
||||
@@ -64,7 +55,7 @@ public class SetPrivateOp implements BatchUpdateOp {
|
||||
PatchSetUtil psUtil,
|
||||
ChangeMessagesUtil cmUtil,
|
||||
@Assisted boolean isPrivate,
|
||||
@Assisted @Nullable Input input) {
|
||||
@Assisted @Nullable InputWithMessage input) {
|
||||
this.privateStateChanged = privateStateChanged;
|
||||
this.psUtil = psUtil;
|
||||
this.cmUtil = cmUtil;
|
||||
|
@@ -21,6 +21,7 @@ import com.google.gerrit.entities.Change;
|
||||
import com.google.gerrit.entities.ChangeMessage;
|
||||
import com.google.gerrit.entities.PatchSet;
|
||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||
import com.google.gerrit.extensions.common.InputWithMessage;
|
||||
import com.google.gerrit.server.ChangeMessagesUtil;
|
||||
import com.google.gerrit.server.PatchSetUtil;
|
||||
import com.google.gerrit.server.extensions.events.WorkInProgressStateChanged;
|
||||
@@ -34,15 +35,15 @@ import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
/* Set work in progress or ready for review state on a change */
|
||||
public class WorkInProgressOp implements BatchUpdateOp {
|
||||
public static class Input {
|
||||
@Nullable public String message;
|
||||
|
||||
public static class Input extends InputWithMessage {
|
||||
@Nullable public NotifyHandling notify;
|
||||
|
||||
public Input() {}
|
||||
public Input() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public Input(String message) {
|
||||
this.message = message;
|
||||
public Input(@Nullable String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -17,6 +17,7 @@ package com.google.gerrit.server.restapi.change;
|
||||
import static com.google.gerrit.extensions.conditions.BooleanCondition.or;
|
||||
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.extensions.common.InputWithMessage;
|
||||
import com.google.gerrit.extensions.conditions.BooleanCondition;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
@@ -36,7 +37,7 @@ import com.google.inject.Singleton;
|
||||
|
||||
@Singleton
|
||||
public class DeletePrivate
|
||||
extends RetryingRestModifyView<ChangeResource, SetPrivateOp.Input, String> {
|
||||
extends RetryingRestModifyView<ChangeResource, InputWithMessage, String> {
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final SetPrivateOp.Factory setPrivateOpFactory;
|
||||
|
||||
@@ -52,7 +53,7 @@ public class DeletePrivate
|
||||
|
||||
@Override
|
||||
protected Response<String> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, ChangeResource rsrc, @Nullable SetPrivateOp.Input input)
|
||||
BatchUpdate.Factory updateFactory, ChangeResource rsrc, @Nullable InputWithMessage input)
|
||||
throws RestApiException, UpdateException {
|
||||
if (!canDeletePrivate(rsrc).value()) {
|
||||
throw new AuthException("not allowed to unmark private");
|
||||
|
@@ -18,6 +18,7 @@ import static com.google.gerrit.extensions.conditions.BooleanCondition.and;
|
||||
import static com.google.gerrit.extensions.conditions.BooleanCondition.or;
|
||||
|
||||
import com.google.gerrit.entities.Change;
|
||||
import com.google.gerrit.extensions.common.InputWithMessage;
|
||||
import com.google.gerrit.extensions.conditions.BooleanCondition;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.MethodNotAllowedException;
|
||||
@@ -39,7 +40,7 @@ import com.google.inject.Singleton;
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
|
||||
@Singleton
|
||||
public class PostPrivate extends RetryingRestModifyView<ChangeResource, SetPrivateOp.Input, String>
|
||||
public class PostPrivate extends RetryingRestModifyView<ChangeResource, InputWithMessage, String>
|
||||
implements UiAction<ChangeResource> {
|
||||
private final PermissionBackend permissionBackend;
|
||||
private final SetPrivateOp.Factory setPrivateOpFactory;
|
||||
@@ -59,7 +60,7 @@ public class PostPrivate extends RetryingRestModifyView<ChangeResource, SetPriva
|
||||
|
||||
@Override
|
||||
public Response<String> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, ChangeResource rsrc, SetPrivateOp.Input input)
|
||||
BatchUpdate.Factory updateFactory, ChangeResource rsrc, InputWithMessage input)
|
||||
throws RestApiException, UpdateException {
|
||||
if (disablePrivateChanges) {
|
||||
throw new MethodNotAllowedException("private changes are disabled");
|
||||
|
Reference in New Issue
Block a user