Merge "Add title of reverted change in RevertSubmission"
This commit is contained in:
@@ -1515,6 +1515,8 @@ the error message is contained in the response body.
|
||||
|
||||
Creates open revert changes for all of the changes of a certain submission.
|
||||
|
||||
The subject of each revert change will be "Revert <subject-of-reverted-change".
|
||||
|
||||
Details for the revert can be specified in the request body inside a link:#revert-input[
|
||||
RevertInput] The topic of all created revert changes will be
|
||||
`revert-{submission_id}-{random_string_of_size_10}`.
|
||||
|
@@ -250,6 +250,8 @@ public class RevertSubmission
|
||||
if (cherryPickInput.base == null) {
|
||||
cherryPickInput.base = getBase(changeNotes, commitIdsInProjectAndBranch).name();
|
||||
}
|
||||
|
||||
revertInput.message = getMessage(revertInput, changeNotes);
|
||||
// This is the code in case this is the first revert of this project + branch, and the
|
||||
// revert would be on top of the change being reverted.
|
||||
if (cherryPickInput.base.equals(changeNotes.getCurrentPatchSet().commitId().getName())) {
|
||||
@@ -271,13 +273,7 @@ public class RevertSubmission
|
||||
commitUtil.createRevertCommit(revertInput.message, changeNotes, user.get());
|
||||
// TODO (paiking): As a future change, the revert should just be done directly on the
|
||||
// target rather than just creating a commit and then cherry-picking it.
|
||||
cherryPickInput.message =
|
||||
revertInput.message != null
|
||||
? revertInput.message
|
||||
: MessageFormat.format(
|
||||
ChangeMessages.get().revertChangeDefaultMessage,
|
||||
changeNotes.getChange().getSubject(),
|
||||
changeNotes.getCurrentPatchSet().commitId().name());
|
||||
cherryPickInput.message = revertInput.message;
|
||||
ObjectId generatedChangeId = Change.generateChangeId();
|
||||
Change.Id cherryPickRevertChangeId = Change.id(seq.nextChangeId());
|
||||
if (groupName == null) {
|
||||
@@ -315,6 +311,18 @@ public class RevertSubmission
|
||||
return revertSubmissionInfo;
|
||||
}
|
||||
|
||||
private String getMessage(RevertInput revertInput, ChangeNotes changeNotes) {
|
||||
String subject = changeNotes.getChange().getSubject();
|
||||
if (revertInput.message == null) {
|
||||
return MessageFormat.format(
|
||||
ChangeMessages.get().revertChangeDefaultMessage,
|
||||
subject,
|
||||
changeNotes.getCurrentPatchSet().commitId().name());
|
||||
}
|
||||
|
||||
return String.format("Revert \"%s\"\n\n%s", subject, revertInput.message);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function finds the base that the first revert in a project + branch should be based on. It
|
||||
* searches using BFS for the first commit that is either: 1. Has 2 or more parents, and has as
|
||||
|
@@ -672,13 +672,36 @@ public class RevertIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
public void revertSubmissionWithSetMessage() throws Exception {
|
||||
String result = createChange().getChangeId();
|
||||
String result = createChange("change", "a.txt", "message").getChangeId();
|
||||
gApi.changes().id(result).current().review(ReviewInput.approve());
|
||||
gApi.changes().id(result).current().submit();
|
||||
RevertInput revertInput = new RevertInput();
|
||||
revertInput.message = "Message from input";
|
||||
assertThat(gApi.changes().id(result).revertSubmission(revertInput).revertChanges.get(0).subject)
|
||||
.isEqualTo(revertInput.message);
|
||||
String commitMessage = "Message from input";
|
||||
revertInput.message = commitMessage;
|
||||
ChangeInfo revertChange =
|
||||
gApi.changes().id(result).revertSubmission(revertInput).revertChanges.get(0);
|
||||
assertThat(revertChange.subject).isEqualTo("Revert \"change\"");
|
||||
assertThat(gApi.changes().id(revertChange.id).current().commit(false).message)
|
||||
.isEqualTo(
|
||||
String.format(
|
||||
"Revert \"change\"\n\n%s\n\nChange-Id: %s\n",
|
||||
commitMessage, revertChange.changeId));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void revertSubmissionWithoutMessage() throws Exception {
|
||||
String result = createChange("change", "a.txt", "message").getChangeId();
|
||||
gApi.changes().id(result).current().review(ReviewInput.approve());
|
||||
gApi.changes().id(result).current().submit();
|
||||
RevertInput revertInput = new RevertInput();
|
||||
ChangeInfo revertChange =
|
||||
gApi.changes().id(result).revertSubmission(revertInput).revertChanges.get(0);
|
||||
assertThat(revertChange.subject).isEqualTo("Revert \"change\"");
|
||||
assertThat(gApi.changes().id(revertChange.id).current().commit(false).message)
|
||||
.isEqualTo(
|
||||
String.format(
|
||||
"Revert \"change\"\n\nThis reverts commit %s.\n\nChange-Id: %s\n",
|
||||
gApi.changes().id(result).get().currentRevision, revertChange.changeId));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user