Skip to content

Commit

Permalink
Convert remaining email templates to Soy
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wyattallen committed Aug 31, 2016
1 parent 93ccc93 commit 42639e4
Show file tree
Hide file tree
Showing 17 changed files with 312 additions and 275 deletions.
Expand Up @@ -100,17 +100,17 @@ public void run() throws Exception {
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");
Expand Down
Expand Up @@ -80,7 +80,7 @@ protected boolean shouldSendMessage() {

@Override
protected void format() throws EmailException {
appendText(velocifyFile("AddKey.vm"));
appendText(textTemplate("AddKey"));
}

public String getEmail() {
Expand Down
Expand Up @@ -121,7 +121,7 @@ public void setChangeMessage(String cm, Timestamp t) {
@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()) {
Expand Down Expand Up @@ -200,7 +200,7 @@ private void setCommitIdHeader() {
}

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. */
Expand Down Expand Up @@ -455,6 +455,16 @@ protected void setupSoyContext() {
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());
Expand Down
Expand Up @@ -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"
Expand Down
Expand Up @@ -67,7 +67,7 @@ protected void init() throws EmailException {

@Override
protected void formatChange() throws EmailException {
appendText(velocifyFile("NewChange.vm"));
appendText(textTemplate("NewChange"));
}

public List<String> getReviewerNames() {
Expand Down
Expand Up @@ -51,7 +51,7 @@ protected void init() throws EmailException {

@Override
protected void format() throws EmailException {
appendText(velocifyFile("RegisterNewEmail.vm"));
appendText(textTemplate("RegisterNewEmail"));
}

public String getUserNameEmail() {
Expand Down
@@ -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}

This file was deleted.

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

This file was deleted.

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

0 comments on commit 42639e4

Please sign in to comment.