From 0d5be4f5c54a422da0cd7ecbc7ba9f0629b0da9f Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Wed, 14 Mar 2018 16:54:24 +0100 Subject: [PATCH] Support notify options in RevertInput Change-Id: I8ba31e6101fc510ea7451bee649c0fe7fe1b2af9 Signed-off-by: Edwin Kempin --- Documentation/rest-api-changes.txt | 16 ++++++-- .../extensions/api/changes/RevertInput.java | 6 +++ .../gerrit/server/restapi/change/Revert.java | 39 +++++++++++++++---- .../acceptance/api/change/ChangeIT.java | 16 ++++++++ 4 files changed, 65 insertions(+), 12 deletions(-) diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt index c1ca595c5d..70c00fff64 100644 --- a/Documentation/rest-api-changes.txt +++ b/Documentation/rest-api-changes.txt @@ -6653,12 +6653,20 @@ change. The `RevertInput` entity contains information for reverting a change. [options="header",cols="1,^1,5"] -|=========================== -|Field Name ||Description -|`message` |optional| +|============================= +|Field Name ||Description +|`message` |optional| Message to be added as review comment to the change when reverting the change. -|=========================== +|`notify` |optional| +Notify handling that defines to whom email notifications should be sent +for reverting the change. + +Allowed values are `NONE`, `OWNER`, `OWNER_REVIEWERS` and `ALL`. + +If not set, the default is `ALL`. +|`notify_details`|optional| +Additional information about whom to notify about the revert as a map +of recipient type to link:#notify-info[NotifyInfo] entity. +|============================= [[review-info]] === ReviewInfo diff --git a/java/com/google/gerrit/extensions/api/changes/RevertInput.java b/java/com/google/gerrit/extensions/api/changes/RevertInput.java index 893472eb75..c1be9b04f0 100644 --- a/java/com/google/gerrit/extensions/api/changes/RevertInput.java +++ b/java/com/google/gerrit/extensions/api/changes/RevertInput.java @@ -15,7 +15,13 @@ package com.google.gerrit.extensions.api.changes; import com.google.gerrit.extensions.restapi.DefaultInput; +import java.util.Map; public class RevertInput { @DefaultInput public String message; + + /** Who to send email notifications to after change is created. */ + public NotifyHandling notify = NotifyHandling.ALL; + + public Map notifyDetails; } diff --git a/java/com/google/gerrit/server/restapi/change/Revert.java b/java/com/google/gerrit/server/restapi/change/Revert.java index 14ebab90d4..45457941cc 100644 --- a/java/com/google/gerrit/server/restapi/change/Revert.java +++ b/java/com/google/gerrit/server/restapi/change/Revert.java @@ -18,7 +18,10 @@ import static com.google.gerrit.extensions.conditions.BooleanCondition.and; import static com.google.gerrit.server.permissions.RefPermission.CREATE_CHANGE; import com.google.common.base.Strings; +import com.google.common.collect.ListMultimap; import com.google.gerrit.common.TimeUtil; +import com.google.gerrit.extensions.api.changes.NotifyHandling; +import com.google.gerrit.extensions.api.changes.RecipientType; import com.google.gerrit.extensions.api.changes.RevertInput; import com.google.gerrit.extensions.common.ChangeInfo; import com.google.gerrit.extensions.restapi.ResourceConflictException; @@ -43,6 +46,7 @@ import com.google.gerrit.server.change.ChangeInserter; import com.google.gerrit.server.change.ChangeJson; import com.google.gerrit.server.change.ChangeMessages; import com.google.gerrit.server.change.ChangeResource; +import com.google.gerrit.server.change.NotifyUtil; import com.google.gerrit.server.extensions.events.ChangeReverted; import com.google.gerrit.server.git.GitRepositoryManager; import com.google.gerrit.server.mail.send.RevertedSender; @@ -70,6 +74,7 @@ import java.sql.Timestamp; import java.text.MessageFormat; import java.util.HashSet; import java.util.Set; +import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.errors.RepositoryNotFoundException; import org.eclipse.jgit.lib.CommitBuilder; import org.eclipse.jgit.lib.ObjectId; @@ -102,6 +107,7 @@ public class Revert extends RetryingRestModifyView accountsToNotify = + notifyUtil.resolveAccounts(input.notifyDetails); + ChangeInserter ins = changeInserterFactory .create(changeId, revertCommit, notes.getChange().getDest().get()) .setTopic(changeToRevert.getTopic()); ins.setMessage("Uploaded patch set 1."); + ins.setNotify(input.notify); + ins.setAccountsToNotify(accountsToNotify); ReviewerSet reviewerSet = approvalsUtil.getReviewers(db.get(), notes); @@ -235,7 +248,7 @@ public class Revert extends RetryingRestModifyView accountsToNotify; - NotifyOp(Change change, ChangeInserter ins) { + NotifyOp( + Change change, + ChangeInserter ins, + NotifyHandling notifyHandling, + ListMultimap accountsToNotify) { this.change = change; this.ins = ins; + this.notifyHandling = notifyHandling; + this.accountsToNotify = accountsToNotify; } @Override @@ -281,6 +302,8 @@ public class Revert extends RetryingRestModifyView