Convert 3 email classes to file based templates.
Convert the NewChange, RegisterNewEmail and ReplacePatchSet classes to use file based velocity templates which an admin may edit. Factor out getChangeDetail and getReviewersNames from formatChangeDetail and formatSalutation respectively to enable this. Change-Id: I36aa7051f06c7641114e2e681639267769846c22
This commit is contained in:
@@ -62,6 +62,25 @@ MergeFail.vm
|
||||
|
||||
The `MergeFail.vm` template will determine the contents of the email related
|
||||
to a failure upon attempting to merge a change to the head. It is a
|
||||
|
||||
NewChange.vm
|
||||
~~~~~~~~~~~~
|
||||
|
||||
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`.
|
||||
|
||||
RegisterNewEmail.vm
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The `RegisterNewEmail.vm` template will determine the contents of the email
|
||||
related to registering new email accounts.
|
||||
|
||||
ReplacePatchSet.vm
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The `ReplacePatchSet.vm` template will determine the contents of the email
|
||||
related to a user submitting a new patchset for a change. It is a
|
||||
`ChangeEmail`: see `ChangeSubject.vm` and `ChangeFooter.vm`.
|
||||
|
||||
|
||||
|
@@ -91,6 +91,9 @@ public class SitePathInitializer {
|
||||
extractMailExample("Comment.vm");
|
||||
extractMailExample("Merged.vm");
|
||||
extractMailExample("MergeFail.vm");
|
||||
extractMailExample("NewChange.vm");
|
||||
extractMailExample("RegisterNewEmail.vm");
|
||||
extractMailExample("ReplacePatchSet.vm");
|
||||
|
||||
if (!ui.isBatch()) {
|
||||
System.err.println();
|
||||
|
@@ -243,6 +243,7 @@ public abstract class ChangeEmail extends OutgoingEmail {
|
||||
return detail.toString();
|
||||
}
|
||||
|
||||
|
||||
/** Get the patch list corresponding to this patch set. */
|
||||
protected PatchList getPatchList() {
|
||||
if (patchSet != null) {
|
||||
|
@@ -20,6 +20,7 @@ import com.google.gerrit.server.ssh.SshInfo;
|
||||
|
||||
import com.jcraft.jsch.HostKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -58,73 +59,18 @@ public abstract class NewChangeSender extends ChangeEmail {
|
||||
|
||||
@Override
|
||||
protected void formatChange() throws EmailException {
|
||||
formatSalutation();
|
||||
formatChangeDetail();
|
||||
|
||||
appendText("\n");
|
||||
appendText(" " + getPullUrl() + "\n");
|
||||
appendText(velocifyFile("NewChange.vm"));
|
||||
}
|
||||
|
||||
private void formatSalutation() {
|
||||
final String changeUrl = getChangeUrl();
|
||||
|
||||
public List<String> getReviewerNames() {
|
||||
if (reviewers.isEmpty()) {
|
||||
formatDest();
|
||||
if (changeUrl != null) {
|
||||
appendText("\n");
|
||||
appendText(" " + changeUrl + "\n");
|
||||
appendText("\n");
|
||||
}
|
||||
appendText("\n");
|
||||
|
||||
} else {
|
||||
appendText("Hello");
|
||||
for (final Iterator<Account.Id> i = reviewers.iterator(); i.hasNext();) {
|
||||
appendText(" ");
|
||||
appendText(getNameFor(i.next()));
|
||||
appendText(",");
|
||||
}
|
||||
appendText("\n");
|
||||
appendText("\n");
|
||||
|
||||
appendText("I'd like you to do a code review.");
|
||||
if (changeUrl != null) {
|
||||
appendText(" Please visit\n");
|
||||
appendText("\n");
|
||||
appendText(" " + changeUrl + "\n");
|
||||
appendText("\n");
|
||||
appendText("to review the following change:\n");
|
||||
}
|
||||
appendText("\n");
|
||||
|
||||
formatDest();
|
||||
appendText("\n");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void formatDest() {
|
||||
appendText("Change " + change.getKey().abbreviate());
|
||||
appendText(" for ");
|
||||
appendText(change.getDest().getShortName());
|
||||
appendText(" in ");
|
||||
appendText(projectName);
|
||||
appendText(":\n");
|
||||
}
|
||||
|
||||
private String getPullUrl() {
|
||||
final String host = getSshHost();
|
||||
if (host == null) {
|
||||
return "";
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (Account.Id id : reviewers) {
|
||||
names.add(getNameFor(id));
|
||||
}
|
||||
|
||||
final StringBuilder r = new StringBuilder();
|
||||
r.append("git pull ssh://");
|
||||
r.append(host);
|
||||
r.append("/");
|
||||
r.append(projectName);
|
||||
r.append(" ");
|
||||
r.append(patchSet.getRefName());
|
||||
return r.toString();
|
||||
return names;
|
||||
}
|
||||
|
||||
public String getSshHost() {
|
||||
|
@@ -53,38 +53,7 @@ public class RegisterNewEmailSender extends OutgoingEmail {
|
||||
|
||||
@Override
|
||||
protected void format() throws EmailException {
|
||||
final StringBuilder url = new StringBuilder();
|
||||
url.append(getGerritUrl());
|
||||
url.append("#VE,");
|
||||
url.append(getEmailRegistrationToken());
|
||||
|
||||
appendText("Welcome to Gerrit Code Review at ");
|
||||
appendText(getGerritHost());
|
||||
appendText(".\n");
|
||||
|
||||
appendText("\n");
|
||||
appendText("To add a verified email address to your user account, please\n");
|
||||
appendText("click on the following link:\n");
|
||||
appendText("\n");
|
||||
appendText(url.toString());
|
||||
appendText("\n");
|
||||
|
||||
appendText("\n");
|
||||
appendText("If you have received this mail in error,"
|
||||
+ " you do not need to take any\n");
|
||||
appendText("action to cancel the account."
|
||||
+ " The account will not be activated, and\n");
|
||||
appendText("you will not receive any further emails.\n");
|
||||
|
||||
appendText("\n");
|
||||
appendText("If clicking the link above does not work,"
|
||||
+ " copy and paste the URL in a\n");
|
||||
appendText("new browser window instead.\n");
|
||||
|
||||
appendText("\n");
|
||||
appendText("This is a send-only email address."
|
||||
+ " Replies to this message will not\n");
|
||||
appendText("be read or answered.\n");
|
||||
appendText(velocifyFile("RegisterNewEmail.vm"));
|
||||
}
|
||||
|
||||
public String getEmailRegistrationToken() {
|
||||
|
@@ -22,6 +22,7 @@ import com.google.inject.assistedinject.Assisted;
|
||||
|
||||
import com.jcraft.jsch.HostKey;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -68,76 +69,18 @@ public class ReplacePatchSetSender extends ReplyToChangeSender {
|
||||
|
||||
@Override
|
||||
protected void formatChange() throws EmailException {
|
||||
formatSalutation();
|
||||
formatChangeDetail();
|
||||
|
||||
appendText("\n");
|
||||
appendText(" " + getPullUrl() + "\n");
|
||||
appendText(velocifyFile("ReplacePatchSet.vm"));
|
||||
}
|
||||
|
||||
private void formatSalutation() {
|
||||
final String changeUrl = getChangeUrl();
|
||||
|
||||
public List<String> getReviewerNames() {
|
||||
if (reviewers.isEmpty()) {
|
||||
formatDest();
|
||||
if (changeUrl != null) {
|
||||
appendText("\n");
|
||||
appendText(" " + changeUrl + "\n");
|
||||
appendText("\n");
|
||||
}
|
||||
appendText("\n");
|
||||
|
||||
} else {
|
||||
appendText("Hello");
|
||||
for (final Iterator<Account.Id> i = reviewers.iterator(); i.hasNext();) {
|
||||
appendText(" ");
|
||||
appendText(getNameFor(i.next()));
|
||||
appendText(",");
|
||||
}
|
||||
appendText("\n");
|
||||
appendText("\n");
|
||||
|
||||
appendText("I'd like you to reexamine change "
|
||||
+ change.getKey().abbreviate() + ".");
|
||||
if (changeUrl != null) {
|
||||
appendText(" Please visit\n");
|
||||
appendText("\n");
|
||||
appendText(" " + changeUrl + "\n");
|
||||
appendText("\n");
|
||||
appendText("to look at patch set " + patchSet.getPatchSetId());
|
||||
appendText(":\n");
|
||||
}
|
||||
appendText("\n");
|
||||
|
||||
formatDest();
|
||||
appendText("\n");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void formatDest() {
|
||||
appendText("Change " + change.getKey().abbreviate());
|
||||
appendText(" (patch set " + patchSet.getPatchSetId() + ")");
|
||||
appendText(" for ");
|
||||
appendText(change.getDest().getShortName());
|
||||
appendText(" in ");
|
||||
appendText(projectName);
|
||||
appendText(":\n");
|
||||
}
|
||||
|
||||
private String getPullUrl() {
|
||||
final String host = getSshHost();
|
||||
if (host == null) {
|
||||
return "";
|
||||
List<String> names = new ArrayList<String>();
|
||||
for (Account.Id id : reviewers) {
|
||||
names.add(getNameFor(id));
|
||||
}
|
||||
|
||||
final StringBuilder r = new StringBuilder();
|
||||
r.append("git pull ssh://");
|
||||
r.append(host);
|
||||
r.append("/");
|
||||
r.append(projectName);
|
||||
r.append(" ");
|
||||
r.append(patchSet.getRefName());
|
||||
return r.toString();
|
||||
return names;
|
||||
}
|
||||
|
||||
public String getSshHost() {
|
||||
|
@@ -0,0 +1,57 @@
|
||||
## 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 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.
|
||||
##
|
||||
#set ($destination = "Change $changeId.abbreviate() for $branch.shortName in $projectName:")
|
||||
#if($email.reviewerNames)
|
||||
Hello $StringUtils.join($email.reviewerNames, ' ,'),
|
||||
|
||||
I'd like you to do a code review.#if($email.changeUrl) Please visit
|
||||
|
||||
$email.changeUrl
|
||||
|
||||
to review the following change:
|
||||
#end
|
||||
|
||||
$destination
|
||||
#else
|
||||
$destination
|
||||
#if($email.changeUrl)
|
||||
|
||||
$email.changeUrl
|
||||
|
||||
#end
|
||||
#end
|
||||
|
||||
$email.changeDetail
|
||||
git pull ssh://$email.sshHost/$projectName $patchSet.refName
|
@@ -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 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:
|
||||
|
||||
$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 account 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.
|
@@ -0,0 +1,57 @@
|
||||
## 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 ReplacePatchSet.vm template will determine the contents of the email
|
||||
## related to a user submitting a new patchset for a change. It is a
|
||||
## ChangeEmail: see ChangeSubject.vm and ChangeFooter.vm.
|
||||
##
|
||||
#set ($destination = "Change $changeId.abbreviate() (patch set $patchSet.patchSetId) for $branch.shortName in $projectName:")
|
||||
#if($email.reviewerNames)
|
||||
Hello $StringUtils.join($email.reviewerNames, ' ,'),
|
||||
|
||||
I'd like you to reexamine change ${changeId.abbreviate()}.#if($email.changeUrl) Please visit
|
||||
|
||||
$email.changeUrl
|
||||
|
||||
to look at patch set $patchSet.patchSetId
|
||||
#end
|
||||
|
||||
$destination
|
||||
#else
|
||||
$destination
|
||||
#if($email.changeUrl)
|
||||
|
||||
$email.changeUrl
|
||||
|
||||
#end
|
||||
#end
|
||||
|
||||
$email.changeDetail
|
||||
git pull ssh://$email.sshHost/$projectName $patchSet.refName
|
Reference in New Issue
Block a user