Merge "Add WIP awareness to PutMessage notifications"
This commit is contained in:
		@@ -39,6 +39,7 @@ import com.google.gerrit.extensions.client.ListChangesOption;
 | 
			
		||||
import com.google.gerrit.extensions.common.AccountInfo;
 | 
			
		||||
import com.google.gerrit.extensions.common.ChangeInfo;
 | 
			
		||||
import com.google.gerrit.extensions.common.CommentInfo;
 | 
			
		||||
import com.google.gerrit.extensions.common.CommitMessageInput;
 | 
			
		||||
import com.google.gerrit.extensions.common.EditInfo;
 | 
			
		||||
import com.google.gerrit.extensions.common.MergePatchSetInput;
 | 
			
		||||
import com.google.gerrit.extensions.common.RobotCommentInfo;
 | 
			
		||||
@@ -515,11 +516,16 @@ class ChangeApiImpl implements ChangeApi {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void setMessage(String in) throws RestApiException {
 | 
			
		||||
  public void setMessage(String msg) throws RestApiException {
 | 
			
		||||
    CommitMessageInput in = new CommitMessageInput();
 | 
			
		||||
    in.message = msg;
 | 
			
		||||
    setMessage(in);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Override
 | 
			
		||||
  public void setMessage(CommitMessageInput in) throws RestApiException {
 | 
			
		||||
    try {
 | 
			
		||||
      PutMessage.Input input = new PutMessage.Input();
 | 
			
		||||
      input.message = in;
 | 
			
		||||
      putMessage.apply(change, input);
 | 
			
		||||
      putMessage.apply(change, in);
 | 
			
		||||
    } catch (Exception e) {
 | 
			
		||||
      throw asRestApiException("Cannot edit commit message", e);
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@ import static com.google.common.base.Preconditions.checkState;
 | 
			
		||||
import static com.google.gerrit.server.notedb.ReviewerStateInternal.CC;
 | 
			
		||||
import static com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER;
 | 
			
		||||
 | 
			
		||||
import com.google.common.base.Preconditions;
 | 
			
		||||
import com.google.common.collect.ImmutableListMultimap;
 | 
			
		||||
import com.google.common.collect.ListMultimap;
 | 
			
		||||
import com.google.gerrit.extensions.api.changes.NotifyHandling;
 | 
			
		||||
@@ -180,7 +181,7 @@ public class PatchSetInserter implements BatchUpdateOp {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public PatchSetInserter setNotify(NotifyHandling notify) {
 | 
			
		||||
    this.notify = notify;
 | 
			
		||||
    this.notify = Preconditions.checkNotNull(notify);
 | 
			
		||||
    return this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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