Expose instanceName in the subject template

Add a variable `instanceName` to the variables offered in the subject
template.

Remove the instanceAndProjectName as it is easy to reconstruct it using
the projectName and instanceName variables. It was also incorrect, as
it relied on the short name and not on the project name.

It was introduced recently, so _I_ don't think any gerrit instance will
break.

Change-Id: Iaf46fcbc1df6db637cb95711bac84a4ead5fc036
This commit is contained in:
Maxime Guerreiro
2018-04-24 18:03:17 +00:00
parent e7cc57dc17
commit eb4d2d8da7
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}