Use a template to set the contents of the CommentEmails.

Add an admin editable Comment.vm template used to format the
contents of the comment emails.

Change-Id: Ic8e9cf6c3b60ae0c4a0e8a05537cf308a40ee694
This commit is contained in:
Martin Fick
2010-07-27 17:09:33 -06:00
parent 82bd12c409
commit 382e0a8972
5 changed files with 71 additions and 23 deletions

View File

@@ -37,6 +37,12 @@ ChangeSubject.vm
The `ChangeSubject.vm` template will determine the contents of the email The `ChangeSubject.vm` template will determine the contents of the email
subject line for ALL emails related to changes. subject line for ALL emails related to changes.
Comment.vm
~~~~~~~~~~
The `Comment.vm` template will determine the contents of the email related to
a user submitting comments on changes. It is a `ChangeEmail`: see
Merged.vm Merged.vm
~~~~~~~~~ ~~~~~~~~~

View File

@@ -87,6 +87,7 @@ public class SitePathInitializer {
extractMailExample("ChangeFooter.vm"); extractMailExample("ChangeFooter.vm");
extractMailExample("ChangeSubject.vm"); extractMailExample("ChangeSubject.vm");
extractMailExample("Comment.vm");
extractMailExample("Merged.vm"); extractMailExample("Merged.vm");
if (!ui.isBatch()) { if (!ui.isBatch()) {

View File

@@ -174,7 +174,7 @@ public abstract class ChangeEmail extends OutgoingEmail {
} }
/** Get a link to the change; null if the server doesn't know its own address. */ /** Get a link to the change; null if the server doesn't know its own address. */
protected String getChangeUrl() { public String getChangeUrl() {
if (change != null && getGerritUrl() != null) { if (change != null && getGerritUrl() != null) {
final StringBuilder r = new StringBuilder(); final StringBuilder r = new StringBuilder();
r.append(getGerritUrl()); r.append(getGerritUrl());
@@ -208,7 +208,7 @@ public abstract class ChangeEmail extends OutgoingEmail {
} }
/** Get the text of the "cover letter", from {@link ChangeMessage}. */ /** Get the text of the "cover letter", from {@link ChangeMessage}. */
protected String getCoverLetter() { public String getCoverLetter() {
if (changeMessage != null) { if (changeMessage != null) {
final String txt = changeMessage.getMessage(); final String txt = changeMessage.getMessage();
if (txt != null) { if (txt != null) {

View File

@@ -66,19 +66,12 @@ public class CommentSender extends ReplyToChangeSender {
@Override @Override
protected void formatChange() throws EmailException { protected void formatChange() throws EmailException {
if (!"".equals(getCoverLetter()) || !inlineComments.isEmpty()) { appendText(velocifyFile("Comment.vm"));
appendText("Comments on Patch Set " + patchSet.getPatchSetId() + ":\n");
appendText("\n");
formatCoverLetter();
formatInlineComments();
if (getChangeUrl() != null) {
appendText("To respond, visit " + getChangeUrl() + "\n");
appendText("\n");
}
}
} }
private void formatInlineComments() { public String getInlineComments() {
StringBuilder cmts = new StringBuilder();
final Repository repo = getRepository(); final Repository repo = getRepository();
try { try {
final PatchList patchList = repo != null ? getPatchList() : null; final PatchList patchList = repo != null ? getPatchList() : null;
@@ -91,10 +84,10 @@ public class CommentSender extends ReplyToChangeSender {
final short side = c.getSide(); final short side = c.getSide();
if (!pk.equals(currentFileKey)) { if (!pk.equals(currentFileKey)) {
appendText("....................................................\n"); cmts.append("....................................................\n");
appendText("File "); cmts.append("File ");
appendText(pk.get()); cmts.append(pk.get());
appendText("\n"); cmts.append("\n");
currentFileKey = pk; currentFileKey = pk;
if (patchList != null) { if (patchList != null) {
@@ -109,26 +102,27 @@ public class CommentSender extends ReplyToChangeSender {
} }
} }
appendText("Line " + lineNbr); cmts.append("Line " + lineNbr);
if (currentFileData != null) { if (currentFileData != null) {
try { try {
final String lineStr = currentFileData.getLine(side, lineNbr); final String lineStr = currentFileData.getLine(side, lineNbr);
appendText(": "); cmts.append(": ");
appendText(lineStr); cmts.append(lineStr);
} catch (Throwable cce) { } catch (Throwable cce) {
// Don't quote the line if we can't safely convert it. // Don't quote the line if we can't safely convert it.
} }
} }
appendText("\n"); cmts.append("\n");
appendText(c.getMessage().trim()); cmts.append(c.getMessage().trim());
appendText("\n\n"); cmts.append("\n\n");
} }
} finally { } finally {
if (repo != null) { if (repo != null) {
repo.close(); repo.close();
} }
} }
return cmts.toString();
} }
private Repository getRepository() { private Repository getRepository() {

View File

@@ -0,0 +1,47 @@
## Copyright (C) 2010 The Android Open Source Project
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##
## Template Type:
## -------------
## This is a velocity mail template, see: http://velocity.apache.org and the
## gerrit-docs:config-mail.txt for more info on modifying gerrit mail templates.
##
## Template File Names and extensions:
## ----------------------------------
## Gerrit will use templates ending in ".vm" but will ignore templates ending
## in ".vm.example". If a .vm template does not exist, the default internal
## gerrit template which is the same as the .vm.example will be used. If you
## want to override the default template, copy the .vm.exmaple file to a .vm
## file and edit it appropriately.
##
## This Template:
## --------------
## The Comment.vm template will determine the contents of the email related to
## a user submitting comments on changes. It is a ChangeEmail: see
## ChangeSubject.vm and ChangeFooter.vm.
##
#if ($email.coverLetter || $email.inlineComments)
Comments on Patch Set $patchSet.patchSetId:
#if ($email.coverLetter)
$email.coverLetter
#end
#if($email.inlineComments)$email.inlineComments#end
#if ($email.changeUrl)
To respond, visit $email.changeUrl
#end
#end