Add WIP awareness to PutMessage notifications
This change adds notification integration tests for this new API endpoint. For convenience, PutMessage.Input is moved to common extensions and renamed MessageInput, so it can be incorporated into the ChangeApi interface. Bug: Issue 6615 Change-Id: If419d713e4586038f04cc079245fed825acfb647
This commit is contained in:
@@ -17,11 +17,9 @@ package com.google.gerrit.server.change;
|
||||
import com.google.gerrit.common.FooterConstants;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
|
||||
import com.google.gerrit.extensions.api.changes.NotifyInfo;
|
||||
import com.google.gerrit.extensions.api.changes.RecipientType;
|
||||
import com.google.gerrit.extensions.common.CommitMessageInput;
|
||||
import com.google.gerrit.extensions.restapi.AuthException;
|
||||
import com.google.gerrit.extensions.restapi.BadRequestException;
|
||||
import com.google.gerrit.extensions.restapi.DefaultInput;
|
||||
import com.google.gerrit.extensions.restapi.ResourceConflictException;
|
||||
import com.google.gerrit.extensions.restapi.Response;
|
||||
import com.google.gerrit.extensions.restapi.RestApiException;
|
||||
@@ -46,7 +44,6 @@ import com.google.gwtorm.server.OrmException;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
@@ -63,15 +60,7 @@ import org.eclipse.jgit.revwalk.RevWalk;
|
||||
|
||||
@Singleton
|
||||
public class PutMessage
|
||||
extends RetryingRestModifyView<ChangeResource, PutMessage.Input, Response<?>> {
|
||||
|
||||
public static class Input {
|
||||
@DefaultInput public String message;
|
||||
|
||||
public NotifyHandling notify = NotifyHandling.ALL;
|
||||
|
||||
public Map<RecipientType, NotifyInfo> notifyDetails;
|
||||
}
|
||||
extends RetryingRestModifyView<ChangeResource, CommitMessageInput, Response<?>> {
|
||||
|
||||
private final GitRepositoryManager repositoryManager;
|
||||
private final Provider<CurrentUser> currentUserProvider;
|
||||
@@ -106,7 +95,7 @@ public class PutMessage
|
||||
|
||||
@Override
|
||||
protected Response<String> applyImpl(
|
||||
BatchUpdate.Factory updateFactory, ChangeResource resource, Input input)
|
||||
BatchUpdate.Factory updateFactory, ChangeResource resource, CommitMessageInput input)
|
||||
throws IOException, UnchangedCommitMessageException, RestApiException, UpdateException,
|
||||
PermissionBackendException, OrmException, ConfigInvalidException {
|
||||
PatchSet ps = psUtil.current(db.get(), resource.getNotes());
|
||||
@@ -127,6 +116,11 @@ public class PutMessage
|
||||
resource.getChange().getKey().get(),
|
||||
sanitizedCommitMessage);
|
||||
|
||||
NotifyHandling notify = input.notify;
|
||||
if (notify == null) {
|
||||
notify = resource.getChange().isWorkInProgress() ? NotifyHandling.OWNER : NotifyHandling.ALL;
|
||||
}
|
||||
|
||||
try (Repository repository = repositoryManager.openRepository(resource.getProject());
|
||||
RevWalk revWalk = new RevWalk(repository);
|
||||
ObjectInserter objectInserter = repository.newObjectInserter()) {
|
||||
@@ -152,7 +146,7 @@ public class PutMessage
|
||||
inserter.setMessage(
|
||||
String.format("Patch Set %s: Commit message was updated.", psId.getId()));
|
||||
inserter.setDescription("Edit commit message");
|
||||
inserter.setNotify(input.notify);
|
||||
inserter.setNotify(notify);
|
||||
inserter.setAccountsToNotify(notifyUtil.resolveAccounts(input.notifyDetails));
|
||||
bu.addOp(resource.getChange().getId(), inserter);
|
||||
bu.execute();
|
||||
|
||||
Reference in New Issue
Block a user