Convert remaining email templates to Soy

Building on a change that converted templates used by subclasses of
ReplyToChangeSender, convert the remaining email templates. Add a new
Soy template datum for abbreviated change subjects, replicating a string
manipulation that was formerly implemented inside the ChangeSubject.vm
template.

Feature: Issue 4345
Change-Id: I1bc5574a45ea60bf74c945a5ed81fe2ea7536e7d
This commit is contained in:
Wyatt Allen
2016-08-30 13:37:27 -07:00
parent 93ccc93607
commit 42639e4314
17 changed files with 312 additions and 275 deletions

View File

@@ -100,17 +100,17 @@ public class SitePathInitializer {
chmod(0700, site.tmp_dir);
extractMailExample("Abandoned.soy");
extractMailExample("AddKey.vm");
extractMailExample("ChangeFooter.vm");
extractMailExample("ChangeSubject.vm");
extractMailExample("AddKey.soy");
extractMailExample("ChangeFooter.soy");
extractMailExample("ChangeSubject.soy");
extractMailExample("Comment.soy");
extractMailExample("CommentFooter.soy");
extractMailExample("DeleteReviewer.soy");
extractMailExample("DeleteVote.soy");
extractMailExample("Footer.soy");
extractMailExample("Merged.soy");
extractMailExample("NewChange.vm");
extractMailExample("RegisterNewEmail.vm");
extractMailExample("NewChange.soy");
extractMailExample("RegisterNewEmail.soy");
extractMailExample("ReplacePatchSet.soy");
extractMailExample("Restored.soy");
extractMailExample("Reverted.soy");

View File

@@ -80,7 +80,7 @@ public class AddKeySender extends OutgoingEmail {
@Override
protected void format() throws EmailException {
appendText(velocifyFile("AddKey.vm"));
appendText(textTemplate("AddKey"));
}
public String getEmail() {

View File

@@ -121,7 +121,7 @@ public abstract class ChangeEmail extends NotificationEmail {
@Override
protected void format() throws EmailException {
formatChange();
appendText(velocifyFile("ChangeFooter.vm"));
appendText(textTemplate("ChangeFooter"));
try {
TreeSet<String> names = new TreeSet<>();
for (Account.Id who : changeData.reviewers().all()) {
@@ -200,7 +200,7 @@ public abstract class ChangeEmail extends NotificationEmail {
}
private void setChangeSubjectHeader() throws EmailException {
setHeader("Subject", velocifyFile("ChangeSubject.vm"));
setHeader("Subject", textTemplate("ChangeSubject"));
}
/** Get a link to the change; null if the server doesn't know its own address. */
@@ -455,6 +455,16 @@ public abstract class ChangeEmail extends NotificationEmail {
changeData.put("ownerEmail", getNameEmailFor(change.getOwner()));
soyContext.put("change", changeData);
String subject = change.getSubject();
changeData.put("subject", subject);
// shortSubject is the subject limited to 63 characters, with an ellipsis if
// it exceeds that.
if (subject.length() < 64) {
changeData.put("shortSubject", subject);
} else {
changeData.put("shortSubject", subject.substring(0, 60) + "...");
}
Map<String, Object> patchSetData = new HashMap<>();
patchSetData.put("patchSetId", patchSet.getPatchSetId());
patchSetData.put("refName", patchSet.getRefName());

View File

@@ -37,12 +37,17 @@ public class MailSoyTofuProvider implements Provider<SoyTofu> {
// Note: will fail to construct the tofu object if this array is empty.
private static final String[] TEMPLATES = {
"Abandoned.soy",
"AddKey.soy",
"ChangeSubject.soy",
"ChangeFooter.soy",
"Comment.soy",
"CommentFooter.soy",
"DeleteReviewer.soy",
"DeleteVote.soy",
"Footer.soy",
"Merged.soy",
"NewChange.soy",
"RegisterNewEmail.soy",
"ReplacePatchSet.soy",
"Restored.soy",
"Reverted.soy"

View File

@@ -67,7 +67,7 @@ public abstract class NewChangeSender extends ChangeEmail {
@Override
protected void formatChange() throws EmailException {
appendText(velocifyFile("NewChange.vm"));
appendText(textTemplate("NewChange"));
}
public List<String> getReviewerNames() {

View File

@@ -51,7 +51,7 @@ public class RegisterNewEmailSender extends OutgoingEmail {
@Override
protected void format() throws EmailException {
appendText(velocifyFile("RegisterNewEmail.vm"));
appendText(textTemplate("RegisterNewEmail"));
}
public String getUserNameEmail() {

View File

@@ -0,0 +1,71 @@
/**
* Copyright (C) 2016 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.
*/
{namespace com.google.gerrit.server.mail.template}
/**
* The .AddKey template will determine the contents of the email related to
* adding a new SSH or GPG key to an account.
* @param email
*/
{template .AddKey autoescape="strict" kind="text"}
One or more new {$email.keyType} keys have been added to Gerrit Code Review at
{sp}{$email.gerritHost}:
{\n}
{\n}
{if $email.sshKey}
{$email.sshKey}
{elseif $email.gpgKeys}
{$email.gpgKeys}
{/if}
{\n}
{\n}
If this is not expected, please contact your Gerrit Administrators
immediately.
{\n}
{\n}
You can also manage your {$email.keyType} keys by visiting
{\n}
{if $email.sshKey}
{$email.gerritUrl}#/settings/ssh-keys
{elseif $email.gpgKeys}
{$email.gerritUrl}#/settings/gpg-keys
{/if}
{\n}
{if $email.userNameEmail}
(while signed in as {$email.userNameEmail})
{else}
(while signed in as {$email.email})
{/if}
{\n}
{\n}
If clicking the link above does not work, copy and paste the URL in a new
browser window instead.
{\n}
{\n}
This is a send-only email address. Replies to this message will not be read
or answered.
{/template}

View File

@@ -1,61 +0,0 @@
## Copyright (C) 2015 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.example file to a .vm
## file and edit it appropriately.
##
## This Template:
## --------------
## The AddKey.vm template will determine the contents of the email
## related to adding a new SSH or GPG key to an account.
##
One or more new ${email.keyType} keys have been added to Gerrit Code Review at ${email.gerritHost}:
#if($email.sshKey)
$email.sshKey
#elseif($email.gpgKeys)
$email.gpgKeys
#end
If this is not expected, please contact your Gerrit Administrators
immediately.
You can also manage your ${email.keyType} keys by visiting
#if($email.sshKey)
$email.gerritUrl#/settings/ssh-keys
#elseif($email.gpgKeys)
$email.gerritUrl#/settings/gpg-keys
#end
#if($email.userNameEmail)
(while signed in as $email.userNameEmail)
#else
(while signed in as $email.email)
#end
If clicking the link above does not work, copy and paste the URL in a
new browser window instead.
This is a send-only email address. Replies to this message will not
be read or answered.

View File

@@ -0,0 +1,52 @@
/**
* Copyright (C) 2016 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.
*/
{namespace com.google.gerrit.server.mail.template}
/**
* The .ChangeFooter template will determine the contents of the footer text
* that will be appended to ALL emails related to changes.
* @param branch
* @param change
* @param changeId
* @param email
* @param messageClass
* @param patchSet
* @param projectName
*/
{template .ChangeFooter autoescape="strict" kind="text"}
--{sp}
{\n}
{if $email.changeUrl}
To view, visit {$email.changeUrl}{\n}
{/if}
{if $email.settingsUrl}
To unsubscribe, visit {$email.settingsUrl}{\n}
{/if}
{if $email.changeUrl or $email.settingsUrl}
{\n}
{/if}
Gerrit-MessageType: {$messageClass}{\n}
Gerrit-Change-Id: {$changeId}{\n}
Gerrit-PatchSet: {$patchSet.patchSetId}{\n}
Gerrit-Project: {$projectName}{\n}
Gerrit-Branch: {$branch.shortName}{\n}
Gerrit-Owner: {$change.ownerEmail}{\n}
{/template}

View File

@@ -1,52 +0,0 @@
## 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.example file to a .vm
## file and edit it appropriately.
##
## This Template:
## --------------
## The ChangeFooter.vm template will determine the contents of the footer
## text that will be appended to ALL emails related to changes.
##
#set ($SPACE = " ")
--$SPACE
#if ($email.changeUrl)
To view, visit $email.changeUrl
#set ($notblank = 1)
#end
#if ($email.settingsUrl)
To unsubscribe, visit $email.settingsUrl
#set ($notblank = 1)
#end
#if ($notblank)
#end
Gerrit-MessageType: $messageClass
Gerrit-Change-Id: $changeId
Gerrit-PatchSet: $patchSet.patchSetId
Gerrit-Project: $projectName
Gerrit-Branch: $branch.shortName
Gerrit-Owner: $email.getNameEmailFor($change.owner)

View File

@@ -0,0 +1,28 @@
/**
* Copyright (C) 2016 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.
*/
{namespace com.google.gerrit.server.mail.template}
/**
* The .ChangeSubject template will determine the contents of the email subject
* line for ALL emails related to changes.
* @param branch
* @param change
* @param shortProjectName
*/
{template .ChangeSubject autoescape="strict" kind="text"}
Change in {$shortProjectName}[{$branch.shortName}]: {$change.shortSubject}
{/template}

View File

@@ -1,42 +0,0 @@
## 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.example file to a .vm
## file and edit it appropriately.
##
## This Template:
## --------------
## The ChangeSubject.vm template will determine the contents of the email
## subject line for ALL emails related to changes.
##
## Optionally $change.originalSubject can be used for the first subject
## in a change. This allows subject based email clients such as GMail
## to thread comments together even if subsequent patch sets change the
## first line of the commit message.
##
#macro(ellipsis $length $str)
#if($str.length() > $length)#set($length = $length - 3)${str.substring(0,$length)}...#else$str#end
#end
Change in ${projectName.replaceAll('/.*/', '...')}[$branch.shortName]: #ellipsis(63, $change.subject)

View File

@@ -17,7 +17,7 @@
{namespace com.google.gerrit.server.mail.template}
/**
* The footer template will determine the contents of the footer text
* The .Footer template will determine the contents of the footer text
* appended to the end of all outgoing emails after the ChangeFooter and
* CommentFooter.
*/

View File

@@ -0,0 +1,81 @@
/**
* Copyright (C) 2016 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.
*/
{namespace com.google.gerrit.server.mail.template}
/**
* The .NewChange template will determine the contents of the email related to a
* user submitting a new change for review.
* @param change
* @param email
* @param fromName
* @param patchSet
* @param projectName
*/
{template .NewChange autoescape="strict" kind="text"}
{if $email.reviewerNames}
Hello{sp}
{foreach $reviewerName in $email.reviewerNames}
{if not isFirst($reviewerName)},{sp}{/if}
{$reviewerName}
{/foreach},
{\n}
{\n}
I'd like you to do a code review.
{if $email.changeUrl}
{sp}Please visit
{\n}
{\n}
{sp}{sp}{sp}{sp}{$email.changeUrl}
{\n}
{\n}
to review the following change.
{/if}
{else}
{$fromName} has uploaded a new change for review.
{if $email.changeUrl} ( {$email.changeUrl}{/if}
{/if}{\n}
{\n}
{\n}
Change subject: {$change.subject}{\n}
......................................................................{\n}
{\n}
{$email.changeDetail}{\n}
{if $email.sshHost}
{\n}
{sp}{sp}git pull ssh:{print '//'}{$email.sshHost}/{$projectName}
{sp}{$patchSet.refName}
{\n}
{/if}
{if $email.includeDiff}
{\n}
{$email.unifiedDiff}
{\n}
{/if}
{/template}

View File

@@ -1,60 +0,0 @@
## 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.example file to a .vm
## file and edit it appropriately.
##
## This Template:
## --------------
## The NewChange.vm template will determine the contents of the email related
## to a user submitting a new change for review. It is a ChangeEmail: see
## ChangeSubject.vm and ChangeFooter.vm.
##
#if($email.reviewerNames)
Hello $email.joinStrings($email.reviewerNames, ', '),
I'd like you to do a code review.#if($email.changeUrl) Please visit
$email.changeUrl
to review the following change.
#end
#else
$fromName has uploaded a new change for review.#**
*##if($email.changeUrl) ( $email.changeUrl )#end
#end
Change subject: $change.subject
......................................................................
$email.changeDetail
#if($email.sshHost)
git pull ssh://$email.sshHost/$projectName $patchSet.refName
#end
#if($email.includeDiff)
$email.UnifiedDiff
#end

View File

@@ -0,0 +1,54 @@
/**
* Copyright (C) 2016 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.
*/
{namespace com.google.gerrit.server.mail.template}
/**
* The .RegisterNewEmail template will determine the contents of the email
* related to registering new email accounts.
* @param email
*/
{template .RegisterNewEmail autoescape="strict" kind="text"}
Welcome to Gerrit Code Review at {$email.gerritHost}.{\n}
{\n}
To add a verified email address to your user account, please{\n}
click on the following link
{if $email.userNameEmail}
{sp}while signed in as {$email.userNameEmail}
{/if}:{\n}
{\n}
{$email.gerritUrl}#/VE/{$email.emailRegistrationToken}{\n}
{\n}
If you have received this mail in error, you do not need to take any{\n}
action to cancel the account. The address will not be activated, and{\n}
you will not receive any further emails.{\n}
{\n}
If clicking the link above does not work, copy and paste the URL in a{\n}
new browser window instead.{\n}
{\n}
This is a send-only email address. Replies to this message will not{\n}
be read or answered.{\n}
{/template}

View File

@@ -1,49 +0,0 @@
## 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.example file to a .vm
## file and edit it appropriately.
##
## This Template:
## --------------
## The RegisterNewEmail.vm template will determine the contents of the email
## related to registering new email accounts.
##
Welcome to Gerrit Code Review at ${email.gerritHost}.
To add a verified email address to your user account, please
click on the following link#if($email.userNameEmail) while signed in as $email.userNameEmail#end:
$email.gerritUrl#/VE/$email.emailRegistrationToken
If you have received this mail in error, you do not need to take any
action to cancel the account. The address will not be activated, and
you will not receive any further emails.
If clicking the link above does not work, copy and paste the URL in a
new browser window instead.
This is a send-only email address. Replies to this message will not
be read or answered.