Add title of reverted change in RevertSubmission

Currently, changes being reverted through the RevertSubmission endpoint
have the same commit message.
This will still be the case, except for the title. Now, the title of
all changes created by RevertSubmission will be
"Revert <Change_Reverted>". All other information in the commit message
will remain.

Change-Id: I77949ad9f2d87f75f76da18c31a11bacee093b00
This commit is contained in:
Gal Paikin
2019-12-18 18:10:08 +01:00
parent 2de4e017a2
commit affd024dce
3 changed files with 44 additions and 11 deletions

View File

@@ -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}`.

View File

@@ -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

View File

@@ -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