Use a template to set the footer on ChangeEmails.
Add an admin editable ChangeFooter.vm template used to format the footer in ChangeEmails. Change-Id: I8f6f80b7a3e1fdb39ee1ea20aa84738286bce826
This commit is contained in:
@@ -25,6 +25,12 @@ are listed below. Change emails are influenced by two additional templates,
|
|||||||
one to set the subject line, and one to set the footer which gets appended to
|
one to set the subject line, and one to set the footer which gets appended to
|
||||||
all the change emails (see `ChangeSubject.vm` and `ChangeFooter.vm` below.)
|
all the change emails (see `ChangeSubject.vm` and `ChangeFooter.vm` below.)
|
||||||
|
|
||||||
|
ChangeFooter.vm
|
||||||
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
The `ChangeFooter.vm` template will determine the contents of the footer
|
||||||
|
text that will be appended to emails related to changes (all `ChangeEmails)`.
|
||||||
|
|
||||||
ChangeSubject.vm
|
ChangeSubject.vm
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@@ -85,6 +85,7 @@ public class SitePathInitializer {
|
|||||||
extract(site.gerrit_sh, Init.class, "gerrit.sh");
|
extract(site.gerrit_sh, Init.class, "gerrit.sh");
|
||||||
chmod(0755, site.gerrit_sh);
|
chmod(0755, site.gerrit_sh);
|
||||||
|
|
||||||
|
extractMailExample("ChangeFooter.vm");
|
||||||
extractMailExample("ChangeSubject.vm");
|
extractMailExample("ChangeSubject.vm");
|
||||||
extractMailExample("Merged.vm");
|
extractMailExample("Merged.vm");
|
||||||
|
|
||||||
|
@@ -52,7 +52,6 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
|||||||
|
|
||||||
private ProjectState projectState;
|
private ProjectState projectState;
|
||||||
protected ChangeData changeData;
|
protected ChangeData changeData;
|
||||||
private boolean inFooter;
|
|
||||||
|
|
||||||
protected ChangeEmail(EmailArguments ea, final Change c, final String mc) {
|
protected ChangeEmail(EmailArguments ea, final Change c, final String mc) {
|
||||||
super(ea, mc);
|
super(ea, mc);
|
||||||
@@ -76,29 +75,7 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
|||||||
/** Format the message body by calling {@link #appendText(String)}. */
|
/** Format the message body by calling {@link #appendText(String)}. */
|
||||||
protected void format() throws EmailException {
|
protected void format() throws EmailException {
|
||||||
formatChange();
|
formatChange();
|
||||||
if (getChangeUrl() != null) {
|
appendText(velocifyFile("ChangeFooter.vm"));
|
||||||
openFooter();
|
|
||||||
appendText("To view visit ");
|
|
||||||
appendText(getChangeUrl());
|
|
||||||
appendText("\n");
|
|
||||||
}
|
|
||||||
if (getSettingsUrl() != null) {
|
|
||||||
openFooter();
|
|
||||||
appendText("To unsubscribe, visit ");
|
|
||||||
appendText(getSettingsUrl());
|
|
||||||
appendText("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inFooter) {
|
|
||||||
appendText("\n");
|
|
||||||
} else {
|
|
||||||
openFooter();
|
|
||||||
}
|
|
||||||
appendText("Gerrit-MessageType: " + messageClass + "\n");
|
|
||||||
appendText("Gerrit-Project: " + projectName + "\n");
|
|
||||||
appendText("Gerrit-Branch: " + change.getDest().getShortName() + "\n");
|
|
||||||
appendText("Gerrit-Owner: " + getNameEmailFor(change.getOwner()) + "\n");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HashSet<Account.Id> reviewers = new HashSet<Account.Id>();
|
HashSet<Account.Id> reviewers = new HashSet<Account.Id>();
|
||||||
for (PatchSetApproval p : args.db.get().patchSetApprovals().byChange(
|
for (PatchSetApproval p : args.db.get().patchSetApprovals().byChange(
|
||||||
@@ -158,8 +135,6 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
|||||||
setListIdHeader();
|
setListIdHeader();
|
||||||
setChangeUrlHeader();
|
setChangeUrlHeader();
|
||||||
setCommitIdHeader();
|
setCommitIdHeader();
|
||||||
|
|
||||||
inFooter = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setListIdHeader() {
|
private void setListIdHeader() {
|
||||||
@@ -223,13 +198,6 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
|||||||
return r.toString();
|
return r.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openFooter() {
|
|
||||||
if (!inFooter) {
|
|
||||||
inFooter = true;
|
|
||||||
appendText("-- \n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Format the sender's "cover letter", {@link #getCoverLetter()}. */
|
/** Format the sender's "cover letter", {@link #getCoverLetter()}. */
|
||||||
protected void formatCoverLetter() {
|
protected void formatCoverLetter() {
|
||||||
final String cover = getCoverLetter();
|
final String cover = getCoverLetter();
|
||||||
|
@@ -168,7 +168,7 @@ public abstract class OutgoingEmail {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getGerritHost() {
|
public String getGerritHost() {
|
||||||
if (getGerritUrl() != null) {
|
if (getGerritUrl() != null) {
|
||||||
try {
|
try {
|
||||||
return new URL(getGerritUrl()).getHost();
|
return new URL(getGerritUrl()).getHost();
|
||||||
@@ -194,7 +194,7 @@ public abstract class OutgoingEmail {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getGerritUrl() {
|
public String getGerritUrl() {
|
||||||
return args.urlProvider.get();
|
return args.urlProvider.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -237,7 +237,7 @@ public abstract class OutgoingEmail {
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getNameEmailFor(Account.Id accountId) {
|
public String getNameEmailFor(Account.Id accountId) {
|
||||||
AccountState who = args.accountCache.get(accountId);
|
AccountState who = args.accountCache.get(accountId);
|
||||||
String name = who.getAccount().getFullName();
|
String name = who.getAccount().getFullName();
|
||||||
String email = who.getAccount().getPreferredEmail();
|
String email = who.getAccount().getPreferredEmail();
|
||||||
|
@@ -0,0 +1,49 @@
|
|||||||
|
## 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 ChangeFooter.vm template will determine the contents of the footer
|
||||||
|
## text that will be appended to ALL emails related to changes.
|
||||||
|
##
|
||||||
|
--
|
||||||
|
#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 == 1)
|
||||||
|
|
||||||
|
#end
|
||||||
|
Gerrit-MessageType: $messageClass
|
||||||
|
Gerrit-Project: $projectName
|
||||||
|
Gerrit-Branch: $branch.shortName
|
||||||
|
Gerrit-Owner: $email.getNameEmailFor($change.owner)
|
Reference in New Issue
Block a user