Revert "Expose instanceName in the subject template"
This reverts commit eb4d2d8da7.
Reason for revert:
we observe
com.google.template.soy.tofu.SoyTofuException: In 'print' tag, expression "$instanceAndProjectName" evaluates to undefined.
at com.google.gerrit.server.mail.template.ChangeSubject(ChangeSubject.soy:9)
in production
Change-Id: I1701b5bcb4720086783536c5c987866bf73e54f4
This commit is contained in:
committed by
Han-Wen Nienhuys
parent
eb4d2d8da7
commit
bfd75384c2
@@ -225,10 +225,9 @@ $shortProjectName::
|
|||||||
+
|
+
|
||||||
The project name with the path abbreviated.
|
The project name with the path abbreviated.
|
||||||
|
|
||||||
$instanceName::
|
$instanceAndProjectName::
|
||||||
+
|
+
|
||||||
The Gerrit instance name, as defined in the
|
The Gerrit instance name, followed by the short project name
|
||||||
link:config-gerrit.html#gerrit.instanceName[configuration].
|
|
||||||
|
|
||||||
$addInstanceNameInSubject::
|
$addInstanceNameInSubject::
|
||||||
+
|
+
|
||||||
|
|||||||
@@ -111,8 +111,11 @@ public abstract class NotificationEmail extends OutgoingEmail {
|
|||||||
// shortProjectName is the project name with the path abbreviated.
|
// shortProjectName is the project name with the path abbreviated.
|
||||||
soyContext.put("shortProjectName", getShortProjectName(projectName));
|
soyContext.put("shortProjectName", getShortProjectName(projectName));
|
||||||
|
|
||||||
|
// instanceAndProjectName is the instance's name followed by the abbreviated project path
|
||||||
|
soyContext.put(
|
||||||
|
"instanceAndProjectName",
|
||||||
|
getInstanceAndProjectName(args.instanceNameProvider.get(), projectName));
|
||||||
soyContext.put("addInstanceNameInSubject", args.addInstanceNameInSubject);
|
soyContext.put("addInstanceNameInSubject", args.addInstanceNameInSubject);
|
||||||
soyContext.put("instanceName", args.instanceNameProvider.get());
|
|
||||||
|
|
||||||
soyContextEmailData.put("sshHost", getSshHost());
|
soyContextEmailData.put("sshHost", getSshHost());
|
||||||
|
|
||||||
@@ -133,4 +136,14 @@ public abstract class NotificationEmail extends OutgoingEmail {
|
|||||||
|
|
||||||
return "..." + projectName.substring(lastIndexSlash + 1);
|
return "..." + projectName.substring(lastIndexSlash + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
protected static String getInstanceAndProjectName(String instanceName, String projectName) {
|
||||||
|
if (instanceName == null || instanceName.isEmpty()) {
|
||||||
|
return getShortProjectName(projectName);
|
||||||
|
}
|
||||||
|
// Extract the project name (everything after the last slash) and prepends it with gerrit's
|
||||||
|
// instance name
|
||||||
|
return instanceName + "/" + projectName.substring(projectName.lastIndexOf('/') + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,19 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class NotificationEmailTest {
|
public class NotificationEmailTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getInstanceAndProjectName_returnsTheRightValue() {
|
||||||
|
String instanceAndProjectName = NotificationEmail.getInstanceAndProjectName("test", "/my/api");
|
||||||
|
assertThat(instanceAndProjectName).isEqualTo("test/api");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getInstanceAndProjectName_handlesNull() {
|
||||||
|
String instanceAndProjectName = NotificationEmail.getInstanceAndProjectName(null, "/my/api");
|
||||||
|
assertThat(instanceAndProjectName).isEqualTo("...api");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getShortProjectName() {
|
public void getShortProjectName() {
|
||||||
assertThat(NotificationEmail.getShortProjectName("/api")).isEqualTo("api");
|
assertThat(NotificationEmail.getShortProjectName("/api")).isEqualTo("api");
|
||||||
|
|||||||
@@ -22,13 +22,13 @@
|
|||||||
* @param branch
|
* @param branch
|
||||||
* @param change
|
* @param change
|
||||||
* @param shortProjectName
|
* @param shortProjectName
|
||||||
* @param instanceName
|
* @param instanceAndProjectName
|
||||||
* @param addInstanceNameInSubject boolean
|
* @param addInstanceNameInSubject boolean
|
||||||
*/
|
*/
|
||||||
{template .ChangeSubject kind="text"}
|
{template .ChangeSubject kind="text"}
|
||||||
{if not $addInstanceNameInSubject}
|
{if not $addInstanceNameInSubject}
|
||||||
Change in {$shortProjectName}[{$branch.shortName}]: {$change.shortSubject}
|
Change in {$shortProjectName}[{$branch.shortName}]: {$change.shortSubject}
|
||||||
{else}
|
{else}
|
||||||
[{$instanceName}] Change in {$shortProjectName}[{$branch.shortName}]: {$change.shortSubject}
|
Change in {$instanceAndProjectName}[{$branch.shortName}]: {$change.shortSubject}
|
||||||
{/if}
|
{/if}
|
||||||
{/template}
|
{/template}
|
||||||
|
|||||||
Reference in New Issue
Block a user