Insert two newline chars when generating change message
This adds a newline char when parsing change messages for inbound
emails and fixes a bug where notifications sent out for these messages
would not contain the change message.
Change-Id: Ifa720236c1ded0207e5f4cf499a0879fa4ccff21
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/mail/MailProcessorIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/mail/MailProcessorIT.java
index d423a2d..6b10edb9 100644
--- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/mail/MailProcessorIT.java
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/server/mail/MailProcessorIT.java
@@ -67,7 +67,7 @@
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages;
assertThat(messages).hasSize(3);
- assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\nTest Message");
+ assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n\nTest Message");
assertThat(Iterables.getLast(messages).tag).isEqualTo("mailMessageId=some id");
}
@@ -96,7 +96,7 @@
// Assert messages
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages;
assertThat(messages).hasSize(3);
- assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n(1 comment)");
+ assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n\n(1 comment)");
assertThat(Iterables.getLast(messages).tag).isEqualTo("mailMessageId=some id");
// Assert comment
@@ -132,7 +132,7 @@
// Assert messages
Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages;
assertThat(messages).hasSize(3);
- assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n(1 comment)");
+ assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n\n(1 comment)");
assertThat(Iterables.getLast(messages).tag).isEqualTo("mailMessageId=some id");
// Assert comment
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/receive/MailProcessor.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/receive/MailProcessor.java
index 54b30c7..599278f 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/mail/receive/MailProcessor.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/receive/MailProcessor.java
@@ -231,12 +231,13 @@
String changeMsg = "Patch Set " + psId.get() + ":";
if (parsedComments.get(0).type == MailComment.CommentType.CHANGE_MESSAGE) {
+ // Add a blank line after Patch Set to follow the default format
if (parsedComments.size() > 1) {
- changeMsg += "\n" + numComments(parsedComments.size() - 1);
+ changeMsg += "\n\n" + numComments(parsedComments.size() - 1);
}
- changeMsg += "\n" + parsedComments.get(0).message;
+ changeMsg += "\n\n" + parsedComments.get(0).message;
} else {
- changeMsg += "\n" + numComments(parsedComments.size());
+ changeMsg += "\n\n" + numComments(parsedComments.size());
}
changeMessage = ChangeMessagesUtil.newMessage(ctx, changeMsg, tag);