Cut down to below 73 characters when reverting changes Whenever a change is reverted, "Revert" is added and the subject of the change that is being reverted is copied. However, if the subject is around 73 characters and the word "Revert" is added, then the subject will be above 73 characters. This change checks the length of the subject, and if the subject length is above 63, it will shorten it to 60 and add "..." in the end. Thus, the final length will always be below 73. Change-Id: I07e36ef60f8add83f34f41b01c0d2d41bfc9b448
diff --git a/Documentation/rest-api-changes.txt b/Documentation/rest-api-changes.txt index 4b7a659..1396cf5 100644 --- a/Documentation/rest-api-changes.txt +++ b/Documentation/rest-api-changes.txt
@@ -1457,6 +1457,10 @@ Reverts a change. +The subject of the newly created change will be +'Revert "<subject-of-reverted-change>"'. If the subject of the change reverted is +above 63 characters, it will be cut down to 59 characters with "..." in the end. + The request body does not need to include a link:#revert-input[ RevertInput] entity if no review comment is added. @@ -1515,7 +1519,9 @@ 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". +The subject of each revert change will be 'Revert "<subject-of-reverted-change"'. +If the subject is above 63 characters, the subject will be cut to 59 characters +with "..." in the end. 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
diff --git a/java/com/google/gerrit/server/git/CommitUtil.java b/java/com/google/gerrit/server/git/CommitUtil.java index 476037b..393ccb7 100644 --- a/java/com/google/gerrit/server/git/CommitUtil.java +++ b/java/com/google/gerrit/server/git/CommitUtil.java
@@ -146,12 +146,14 @@ revertCommitBuilder.setCommitter(authorIdent); Change changeToRevert = notes.getChange(); + String subject = changeToRevert.getSubject(); + if (subject.length() > 63) { + subject = subject.substring(0, 59) + "..."; + } if (message == null) { message = MessageFormat.format( - ChangeMessages.get().revertChangeDefaultMessage, - changeToRevert.getSubject(), - patch.commitId().name()); + ChangeMessages.get().revertChangeDefaultMessage, subject, patch.commitId().name()); } if (generatedChangeId != null) { revertCommitBuilder.setMessage(ChangeIdUtil.insertId(message, generatedChangeId, true));
diff --git a/java/com/google/gerrit/server/restapi/change/RevertSubmission.java b/java/com/google/gerrit/server/restapi/change/RevertSubmission.java index df4c83e..a7d19d1 100644 --- a/java/com/google/gerrit/server/restapi/change/RevertSubmission.java +++ b/java/com/google/gerrit/server/restapi/change/RevertSubmission.java
@@ -313,6 +313,9 @@ private String getMessage(RevertInput revertInput, ChangeNotes changeNotes) { String subject = changeNotes.getChange().getSubject(); + if (subject.length() > 63) { + subject = subject.substring(0, 59) + "..."; + } if (revertInput.message == null) { return MessageFormat.format( ChangeMessages.get().revertChangeDefaultMessage,
diff --git a/javatests/com/google/gerrit/acceptance/api/change/RevertIT.java b/javatests/com/google/gerrit/acceptance/api/change/RevertIT.java index f1ea319..7703b1c 100644 --- a/javatests/com/google/gerrit/acceptance/api/change/RevertIT.java +++ b/javatests/com/google/gerrit/acceptance/api/change/RevertIT.java
@@ -284,6 +284,27 @@ } @Test + public void revertChangeWithLongSubject() throws Exception { + String changeTitle = + "This change has a very long title and therefore it will be cut to 50 characters when the" + + " revert change will revert this change"; + String result = createChange(changeTitle, "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).revert(revertInput).get(); + assertThat(revertChange.subject) + .isEqualTo(String.format("Revert \"%s...\"", changeTitle.substring(0, 59))); + assertThat(gApi.changes().id(revertChange.id).current().commit(false).message) + .isEqualTo( + String.format( + "Revert \"%s...\"\n\nThis reverts commit %s.\n\nChange-Id: %s\n", + changeTitle.substring(0, 59), + gApi.changes().id(result).get().currentRevision, + revertChange.changeId)); + } + + @Test public void revertNotifications() throws Exception { PushOneCommit.Result r = createChange(); gApi.changes().id(r.getChangeId()).addReviewer(user.email()); @@ -705,6 +726,28 @@ } @Test + public void revertSubmissionRevertsChangeWithLongSubject() throws Exception { + String changeTitle = + "This change has a very long title and therefore it will be cut to 50 characters when the" + + " revert change will revert this change"; + String result = createChange(changeTitle, "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(String.format("Revert \"%s...\"", changeTitle.substring(0, 59))); + assertThat(gApi.changes().id(revertChange.id).current().commit(false).message) + .isEqualTo( + String.format( + "Revert \"%s...\"\n\nThis reverts commit %s.\n\nChange-Id: %s\n", + changeTitle.substring(0, 59), + gApi.changes().id(result).get().currentRevision, + revertChange.changeId)); + } + + @Test @GerritConfig(name = "change.submitWholeTopic", value = "true") public void revertSubmissionDifferentRepositoriesWithDependantChange() throws Exception { projectOperations.newProject().name("secondProject").create();