Use a template to set the contents of the MergedEmails.
Add an admin editable Merged.vm template used to format the contents of the merged change emails. Change-Id: I79823c2135383a7dbf7f245abea3d693db025150
This commit is contained in:
@@ -31,6 +31,13 @@ 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.
|
||||||
|
|
||||||
|
Merged.vm
|
||||||
|
~~~~~~~~~
|
||||||
|
|
||||||
|
The `Merged.vm` template will determine the contents of the email related to
|
||||||
|
a change successfully merged to the head. It is a `ChangeEmail`: see
|
||||||
|
`ChangeSubject.vm` and `ChangeFooter.vm`.
|
||||||
|
|
||||||
|
|
||||||
Mail Variables and Methods
|
Mail Variables and Methods
|
||||||
--------------------------
|
--------------------------
|
||||||
|
@@ -86,6 +86,7 @@ public class SitePathInitializer {
|
|||||||
chmod(0755, site.gerrit_sh);
|
chmod(0755, site.gerrit_sh);
|
||||||
|
|
||||||
extractMailExample("ChangeSubject.vm");
|
extractMailExample("ChangeSubject.vm");
|
||||||
|
extractMailExample("Merged.vm");
|
||||||
|
|
||||||
if (!ui.isBatch()) {
|
if (!ui.isBatch()) {
|
||||||
System.err.println();
|
System.err.println();
|
||||||
|
@@ -252,21 +252,27 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
|||||||
|
|
||||||
/** Format the change message and the affected file list. */
|
/** Format the change message and the affected file list. */
|
||||||
protected void formatChangeDetail() {
|
protected void formatChangeDetail() {
|
||||||
|
appendText(getChangeDetail());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Create the change message and the affected file list. */
|
||||||
|
public String getChangeDetail() {
|
||||||
|
StringBuilder detail = new StringBuilder();
|
||||||
|
|
||||||
if (patchSetInfo != null) {
|
if (patchSetInfo != null) {
|
||||||
appendText(patchSetInfo.getMessage().trim());
|
detail.append(patchSetInfo.getMessage().trim() + "\n");
|
||||||
appendText("\n");
|
|
||||||
} else {
|
} else {
|
||||||
appendText(change.getSubject().trim());
|
detail.append(change.getSubject().trim() + "\n");
|
||||||
appendText("\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (patchSet != null) {
|
if (patchSet != null) {
|
||||||
appendText("---\n");
|
detail.append("---\n");
|
||||||
for (PatchListEntry p : getPatchList().getPatches()) {
|
for (PatchListEntry p : getPatchList().getPatches()) {
|
||||||
appendText(p.getChangeType().getCode() + " " + p.getNewName() + "\n");
|
detail.append(p.getChangeType().getCode() + " " + p.getNewName() + "\n");
|
||||||
}
|
}
|
||||||
appendText("\n");
|
detail.append("\n");
|
||||||
}
|
}
|
||||||
|
return detail.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the patch list corresponding to this patch set. */
|
/** Get the patch list corresponding to this patch set. */
|
||||||
|
@@ -62,21 +62,10 @@ public class MergedSender extends ReplyToChangeSender {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void formatChange() throws EmailException {
|
protected void formatChange() throws EmailException {
|
||||||
appendText("Change " + change.getKey().abbreviate());
|
appendText(velocifyFile("Merged.vm"));
|
||||||
if (patchSetInfo != null && patchSetInfo.getAuthor() != null
|
|
||||||
&& patchSetInfo.getAuthor().getName() != null) {
|
|
||||||
appendText(" by ");
|
|
||||||
appendText(patchSetInfo.getAuthor().getName());
|
|
||||||
}
|
|
||||||
appendText(" submitted to ");
|
|
||||||
appendText(dest.getShortName());
|
|
||||||
appendText(":\n\n");
|
|
||||||
formatChangeDetail();
|
|
||||||
formatApprovals();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void formatApprovals() {
|
public String getApprovals() {
|
||||||
if (patchSet != null) {
|
|
||||||
try {
|
try {
|
||||||
final Map<Account.Id, Map<ApprovalCategory.Id, PatchSetApproval>> pos =
|
final Map<Account.Id, Map<ApprovalCategory.Id, PatchSetApproval>> pos =
|
||||||
new HashMap<Account.Id, Map<ApprovalCategory.Id, PatchSetApproval>>();
|
new HashMap<Account.Id, Map<ApprovalCategory.Id, PatchSetApproval>>();
|
||||||
@@ -93,26 +82,26 @@ public class MergedSender extends ReplyToChangeSender {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
format("Approvals", pos);
|
return format("Approvals", pos) + format("Objections", neg);
|
||||||
format("Objections", neg);
|
|
||||||
} catch (OrmException err) {
|
} catch (OrmException err) {
|
||||||
// Don't list the approvals
|
// Don't list the approvals
|
||||||
}
|
}
|
||||||
}
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void format(final String type,
|
private String format(final String type,
|
||||||
final Map<Account.Id, Map<ApprovalCategory.Id, PatchSetApproval>> list) {
|
final Map<Account.Id, Map<ApprovalCategory.Id, PatchSetApproval>> list) {
|
||||||
|
StringBuilder txt = new StringBuilder();
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return;
|
return "";
|
||||||
}
|
}
|
||||||
appendText(type + ":\n");
|
txt.append(type + ":\n");
|
||||||
for (final Map.Entry<Account.Id, Map<ApprovalCategory.Id, PatchSetApproval>> ent : list
|
for (final Map.Entry<Account.Id, Map<ApprovalCategory.Id, PatchSetApproval>> ent : list
|
||||||
.entrySet()) {
|
.entrySet()) {
|
||||||
final Map<ApprovalCategory.Id, PatchSetApproval> l = ent.getValue();
|
final Map<ApprovalCategory.Id, PatchSetApproval> l = ent.getValue();
|
||||||
appendText(" ");
|
txt.append(" ");
|
||||||
appendText(getNameFor(ent.getKey()));
|
txt.append(getNameFor(ent.getKey()));
|
||||||
appendText(": ");
|
txt.append(": ");
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (ApprovalType at : approvalTypes.getApprovalTypes()) {
|
for (ApprovalType at : approvalTypes.getApprovalTypes()) {
|
||||||
final PatchSetApproval ca = l.get(at.getCategory().getId());
|
final PatchSetApproval ca = l.get(at.getCategory().getId());
|
||||||
@@ -123,24 +112,25 @@ public class MergedSender extends ReplyToChangeSender {
|
|||||||
if (first) {
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
} else {
|
} else {
|
||||||
appendText("; ");
|
txt.append("; ");
|
||||||
}
|
}
|
||||||
|
|
||||||
final ApprovalCategoryValue v = at.getValue(ca);
|
final ApprovalCategoryValue v = at.getValue(ca);
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
appendText(v.getName());
|
txt.append(v.getName());
|
||||||
} else {
|
} else {
|
||||||
appendText(at.getCategory().getName());
|
txt.append(at.getCategory().getName());
|
||||||
appendText("=");
|
txt.append("=");
|
||||||
if (ca.getValue() > 0) {
|
if (ca.getValue() > 0) {
|
||||||
appendText("+");
|
txt.append("+");
|
||||||
}
|
}
|
||||||
appendText("" + ca.getValue());
|
txt.append("" + ca.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
appendText("\n");
|
txt.append("\n");
|
||||||
}
|
}
|
||||||
appendText("\n");
|
txt.append("\n");
|
||||||
|
return txt.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insert(
|
private void insert(
|
||||||
|
@@ -0,0 +1,38 @@
|
|||||||
|
## 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 Merged.vm template will determine the contents of the email related to
|
||||||
|
## a change successfully merged to the head. It is a ChangeEmail: see
|
||||||
|
## ChangeSubject.vm and ChangeFooter.vm.
|
||||||
|
##
|
||||||
|
Change $changeId.abbreviate()#if ($patchSetInfo.author.name)
|
||||||
|
by $patchSetInfo.author.name#end submitted to $change.dest.shortName:
|
||||||
|
|
||||||
|
$email.changeDetail$email.approvals
|
Reference in New Issue
Block a user