Merge "Expose instanceName in the subject template"

This commit is contained in:
Hugo Arès
2018-04-25 13:23:18 +00:00
committed by Gerrit Code Review
4 changed files with 6 additions and 31 deletions

View File

@@ -225,9 +225,10 @@ $shortProjectName::
+
The project name with the path abbreviated.
$instanceAndProjectName::
$instanceName::
+
The Gerrit instance name, followed by the short project name
The Gerrit instance name, as defined in the
link:config-gerrit.html#gerrit.instanceName[configuration].
$addInstanceNameInSubject::
+

View File

@@ -111,11 +111,8 @@ public abstract class NotificationEmail extends OutgoingEmail {
// shortProjectName is the project name with the path abbreviated.
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("instanceName", args.instanceNameProvider.get());
soyContextEmailData.put("sshHost", getSshHost());
@@ -136,14 +133,4 @@ public abstract class NotificationEmail extends OutgoingEmail {
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);
}
}

View File

@@ -19,19 +19,6 @@ import static com.google.common.truth.Truth.assertThat;
import org.junit.Test;
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
public void getShortProjectName() {
assertThat(NotificationEmail.getShortProjectName("/api")).isEqualTo("api");

View File

@@ -22,13 +22,13 @@
* @param branch
* @param change
* @param shortProjectName
* @param instanceAndProjectName
* @param instanceName
* @param addInstanceNameInSubject boolean
*/
{template .ChangeSubject kind="text"}
{if not $addInstanceNameInSubject}
Change in {$shortProjectName}[{$branch.shortName}]: {$change.shortSubject}
{else}
Change in {$instanceAndProjectName}[{$branch.shortName}]: {$change.shortSubject}
[{$instanceName}] Change in {$shortProjectName}[{$branch.shortName}]: {$change.shortSubject}
{/if}
{/template}