Include the original reviewers of a change on its revert

Bug: Issue 4141
Change-Id: I719bb4aa51327c414018d9cacf3e21c417b36c74
This commit is contained in:
Andrew Bonventre
2016-05-26 15:08:32 -04:00
parent 4892e4b43f
commit 4af9d8c18d
2 changed files with 29 additions and 1 deletions

View File

@@ -187,6 +187,19 @@ The `Submit` button is available if the change is submittable and
the link:access-control.html#category_submit[Submit] access right is the link:access-control.html#category_submit[Submit] access right is
assigned. assigned.
** [[revert]]`Revert`:
+
Reverts the change via creating a new one.
+
The `Revert` button is available if the change has been submitted.
+
When the `Revert` button is pressed, a panel will appear to allow
the user to enter a commit message for the reverting change.
+
Once a revert change is created, the original author and any reviewers
of the original change are added as reviewers and a message is posted
to the original change linking to the revert.
** [[abandon]]`Abandon`: ** [[abandon]]`Abandon`:
+ +
Abandons the change. Abandons the change.

View File

@@ -24,12 +24,14 @@ import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
import com.google.gerrit.extensions.restapi.RestApiException; import com.google.gerrit.extensions.restapi.RestApiException;
import com.google.gerrit.extensions.restapi.RestModifyView; import com.google.gerrit.extensions.restapi.RestModifyView;
import com.google.gerrit.extensions.webui.UiAction; import com.google.gerrit.extensions.webui.UiAction;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change; import com.google.gerrit.reviewdb.client.Change;
import com.google.gerrit.reviewdb.client.Change.Status; import com.google.gerrit.reviewdb.client.Change.Status;
import com.google.gerrit.reviewdb.client.ChangeMessage; import com.google.gerrit.reviewdb.client.ChangeMessage;
import com.google.gerrit.reviewdb.client.PatchSet; import com.google.gerrit.reviewdb.client.PatchSet;
import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.server.ReviewDb; import com.google.gerrit.reviewdb.server.ReviewDb;
import com.google.gerrit.server.ApprovalsUtil;
import com.google.gerrit.server.ChangeMessagesUtil; import com.google.gerrit.server.ChangeMessagesUtil;
import com.google.gerrit.server.ChangeUtil; import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.CurrentUser; import com.google.gerrit.server.CurrentUser;
@@ -43,6 +45,7 @@ import com.google.gerrit.server.git.GitRepositoryManager;
import com.google.gerrit.server.git.UpdateException; import com.google.gerrit.server.git.UpdateException;
import com.google.gerrit.server.git.validators.CommitValidators; import com.google.gerrit.server.git.validators.CommitValidators;
import com.google.gerrit.server.mail.RevertedSender; import com.google.gerrit.server.mail.RevertedSender;
import com.google.gerrit.server.notedb.ReviewerStateInternal;
import com.google.gerrit.server.project.ChangeControl; import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException; import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.RefControl; import com.google.gerrit.server.project.RefControl;
@@ -66,6 +69,8 @@ import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Set;
@Singleton @Singleton
public class Revert implements RestModifyView<ChangeResource, RevertInput>, public class Revert implements RestModifyView<ChangeResource, RevertInput>,
@@ -82,6 +87,7 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
private final RevertedSender.Factory revertedSenderFactory; private final RevertedSender.Factory revertedSenderFactory;
private final ChangeJson.Factory json; private final ChangeJson.Factory json;
private final PersonIdent serverIdent; private final PersonIdent serverIdent;
private final ApprovalsUtil approvalsUtil;
@Inject @Inject
Revert(Provider<ReviewDb> db, Revert(Provider<ReviewDb> db,
@@ -93,7 +99,8 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
PatchSetUtil psUtil, PatchSetUtil psUtil,
RevertedSender.Factory revertedSenderFactory, RevertedSender.Factory revertedSenderFactory,
ChangeJson.Factory json, ChangeJson.Factory json,
@GerritPersonIdent PersonIdent serverIdent) { @GerritPersonIdent PersonIdent serverIdent,
ApprovalsUtil approvalsUtil) {
this.db = db; this.db = db;
this.repoManager = repoManager; this.repoManager = repoManager;
this.changeInserterFactory = changeInserterFactory; this.changeInserterFactory = changeInserterFactory;
@@ -104,6 +111,7 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
this.revertedSenderFactory = revertedSenderFactory; this.revertedSenderFactory = revertedSenderFactory;
this.json = json; this.json = json;
this.serverIdent = serverIdent; this.serverIdent = serverIdent;
this.approvalsUtil = approvalsUtil;
} }
@Override @Override
@@ -182,6 +190,13 @@ public class Revert implements RestModifyView<ChangeResource, RevertInput>,
.setTopic(changeToRevert.getTopic()); .setTopic(changeToRevert.getTopic());
ins.setMessage("Uploaded patch set 1."); ins.setMessage("Uploaded patch set 1.");
Set<Account.Id> reviewers = new HashSet<>();
reviewers.add(changeToRevert.getOwner());
reviewers.addAll(
approvalsUtil.getReviewers(db.get(), ctl.getNotes()).all());
reviewers.remove(user.getAccountId());
ins.setReviewers(reviewers);
try (BatchUpdate bu = updateFactory.create( try (BatchUpdate bu = updateFactory.create(
db.get(), project, user, now)) { db.get(), project, user, now)) {
bu.setRepository(git, revWalk, oi); bu.setRepository(git, revWalk, oi);