Add HTML template for change comment emails

Upgrade comment emails to emit HTML bodies in addition to the existing
plain-text message bodies. The format of the HTML body is remains
similar to the plain-text format, with the following small changes:

* File links are anchor tags rather than plain URLs.
* Parent comment quotations are set in BLOCKQUOTE tags rather than
  prefixed by the > character.
* Code quotations are monospaced rather than set in a
  proportionate-width font.
* Mult-line code quotations are set in BLOCKQUOTE tags rather than
  being prefixed by spaces followed by a colon.
* File groupings are set in nested UL & and LI tags rather than
  separating groups with an extra line feed.

Change-Id: I2ac21961b6d48e3fb3455ca6a3e30d86e50b567c
This commit is contained in:
Wyatt Allen
2016-09-28 12:51:32 -07:00
parent 11bff0a6c6
commit 2223cb7c52
6 changed files with 179 additions and 1 deletions

View File

@@ -26,6 +26,11 @@
* @param projectName
*/
{template .ChangeFooterHtml autoescape="strict" kind="html"}
{let $footerStyle kind="css"}
color: #555;
margin: 10px 0 0 0;
{/let}
{if $email.changeUrl or $email.settingsUrl}
<p>
{if $email.changeUrl}
@@ -38,7 +43,7 @@
</p>
{/if}
<p style="color: #555;">
<p style="{$footerStyle}">
Gerrit-MessageType: {$messageClass}<br/>
Gerrit-Change-Id: {$changeId}<br/>
Gerrit-PatchSet: {$patchSet.patchSetId}<br/>

View File

@@ -0,0 +1,35 @@
/**
* 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}
/**
* @param commentFiles
*/
{template .CommentFooterHtml autoescape="strict" kind="html"}
{let $footerStyle kind="css"}
color: #555;
margin: 0;
{/let}
<p style="{$footerStyle}">
{if length($commentFiles) > 0}
Gerrit-HasComments: Yes
{else}
Gerrit-HasComments: No
{/if}
</p>
{/template}

View File

@@ -0,0 +1,122 @@
/**
* 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}
/**
* @param change
* @param commentFiles
* @param coverLetter
* @param email
* @param fromName
*/
{template .CommentHtml autoescape="strict" kind="html"}
{let $commentHeaderStyle kind="css"}
margin-bottom: 4px;
{/let}
{let $blockquoteStyle kind="css"}
border-left: 1px solid #aaa;
margin: 10px 0;
padding: 0 10px;
{/let}
{let $messageStyle kind="css"}
white-space: pre-wrap;
{/let}
{let $ulStyle kind="css"}
padding-left: 20px;
{/let}
<p>
{$fromName} has posted comments on this change.
</p>
{if $email.changeUrl}
<p>
{call .ViewChangeButton data="all" /}
</p>
{/if}
<p>
Change subject: {$change.subject}
</p>
<hr/>
{if $coverLetter}
<pre>{$coverLetter}</pre>
{/if}
<ul style="{$ulStyle}">
{foreach $group in $commentFiles}
<li>
<p>
<strong><a href="{$group.link}">{$group.title}:</a></strong>
</p>
<ul style="{$ulStyle}">
{foreach $comment in $group.comments}
<li>
{if $comment.isRobotComment}
<p style="{$commentHeaderStyle}">
Robot Comment from{sp}
{if $comment.robotUrl}<a href="{$comment.robotUrl}">{/if}
{$comment.robotId}
{if $comment.robotUrl}</a>{/if}{sp}
(run ID {$comment.robotRunId}):
</p>
{/if}
<p style="{$commentHeaderStyle}">
{if length($comment.lines) > 0}
Patch Set #{$group.patchSetId}, Line {$comment.startLine}:{sp}
{/if}
{if length($comment.lines) == 1}
<code>{$comment.lines[0]}</code>
{/if}
</p>
{if length($comment.lines) > 1}
<p>
<blockquote style="{$blockquoteStyle}">
<pre>
{foreach $line in $comment.lines}
{$line}{\n}
{/foreach}
</pre>
</blockquote>
</p>
{/if}
{if $comment.parentMessage}
<p>
<blockquote style="{$blockquoteStyle}">
{$comment.parentMessage}
</blockquote>
</p>
{/if}
<p style="{$messageStyle}">
{$comment.message}
</p>
</li>
{/foreach}
</ul>
</li>
{/foreach}
</ul>
{/template}