@@ -78,10 +78,12 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { | |||
} | |||
String projectName = checkNotNull(notification.getFieldValue(FIELD_PROJECT_NAME)); | |||
String branchName = notification.getFieldValue(FIELD_BRANCH); | |||
String fullProjectName = computeFullProjectName(projectName, branchName); | |||
StringBuilder message = new StringBuilder(); | |||
message.append("Project: ").append(fullProjectName).append(NEW_LINE); | |||
message.append("Project: ").append(projectName).append(NEW_LINE); | |||
if (branchName != null) { | |||
message.append("Branch: ").append(branchName).append(NEW_LINE); | |||
} | |||
String version = notification.getFieldValue(FIELD_PROJECT_VERSION); | |||
if (version != null) { | |||
message.append("Version: ").append(version).append(NEW_LINE); | |||
@@ -96,7 +98,7 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { | |||
return new EmailMessage() | |||
.setMessageId(notification.getType() + "/" + notification.getFieldValue(FIELD_PROJECT_KEY)) | |||
.setSubject(subject(notification, fullProjectName)) | |||
.setSubject(subject(notification, computeFullProjectName(projectName, branchName))) | |||
.setMessage(message.toString()); | |||
} | |||
@@ -99,11 +99,15 @@ public class IssueChangesEmailTemplate extends EmailTemplate { | |||
private static void appendHeader(Notification notif, StringBuilder sb) { | |||
appendLine(sb, StringUtils.defaultString(notif.getFieldValue("componentName"), notif.getFieldValue("componentKey"))); | |||
String branchName = notif.getFieldValue("branch"); | |||
if (branchName != null) { | |||
appendField(sb, "Branch", null, branchName); | |||
} | |||
appendField(sb, "Rule", null, notif.getFieldValue("ruleName")); | |||
appendField(sb, "Message", null, notif.getFieldValue("message")); | |||
} | |||
private void appendFooter(StringBuilder sb, Notification notification){ | |||
private void appendFooter(StringBuilder sb, Notification notification) { | |||
String issueKey = notification.getFieldValue("key"); | |||
try { | |||
sb.append("More details at: ").append(settings.getServerBaseURL()) |
@@ -60,7 +60,7 @@ public class AlertsEmailTemplate extends EmailTemplate { | |||
// Generate text | |||
String subject = generateSubject(fullProjectName, alertLevel, isNewAlert); | |||
String messageBody = generateMessageBody(fullProjectName, projectKey, projectVersion, branchName, alertName, alertText, isNewAlert); | |||
String messageBody = generateMessageBody(projectName, projectKey, projectVersion, branchName, alertName, alertText, isNewAlert); | |||
// And finally return the email that will be sent | |||
return new EmailMessage() | |||
@@ -88,11 +88,14 @@ public class AlertsEmailTemplate extends EmailTemplate { | |||
return subjectBuilder.toString(); | |||
} | |||
private String generateMessageBody(String fullProjectName, String projectKey, | |||
private String generateMessageBody(String projectName, String projectKey, | |||
@Nullable String projectVersion, @Nullable String branchName, | |||
String alertName, String alertText, boolean isNewAlert) { | |||
StringBuilder messageBody = new StringBuilder(); | |||
messageBody.append("Project: ").append(fullProjectName).append("\n"); | |||
messageBody.append("Project: ").append(projectName).append("\n"); | |||
if (branchName != null) { | |||
messageBody.append("Branch: ").append(branchName).append("\n"); | |||
} | |||
if (projectVersion != null) { | |||
messageBody.append("Version: ").append(projectVersion).append("\n"); | |||
} |
@@ -168,7 +168,8 @@ public class MyNewIssuesEmailTemplateTest { | |||
// TODO datetime to be completed when test is isolated from JVM timezone | |||
assertThat(message.getMessage()) | |||
.startsWith("Project: Struts (feature1)\n" + | |||
.startsWith("Project: Struts\n" + | |||
"Branch: feature1\n" + | |||
"Version: 52.0\n" + | |||
"\n" + | |||
"32 new issues (new debt: 1d3h)\n" + | |||
@@ -200,7 +201,8 @@ public class MyNewIssuesEmailTemplateTest { | |||
// TODO datetime to be completed when test is isolated from JVM timezone | |||
assertThat(message.getMessage()) | |||
.startsWith("Project: Struts (feature1)\n" + | |||
.startsWith("Project: Struts\n" + | |||
"Branch: feature1\n" + | |||
"\n" + | |||
"32 new issues (new debt: 1d3h)\n" + | |||
"\n" + |
@@ -182,7 +182,8 @@ public class NewIssuesEmailTemplateTest { | |||
// TODO datetime to be completed when test is isolated from JVM timezone | |||
assertThat(message.getMessage()) | |||
.startsWith("Project: Struts (feature1)\n" + | |||
.startsWith("Project: Struts\n" + | |||
"Branch: feature1\n" + | |||
"\n" + | |||
"32 new issues (new debt: 1d3h)\n" + | |||
"\n" + | |||
@@ -202,7 +203,8 @@ public class NewIssuesEmailTemplateTest { | |||
// TODO datetime to be completed when test is isolated from JVM timezone | |||
assertThat(message.getMessage()) | |||
.startsWith("Project: Struts (feature1)\n" + | |||
.startsWith("Project: Struts\n" + | |||
"Branch: feature1\n" + | |||
"Version: 42.1.1\n" + | |||
"\n" + | |||
"32 new issues (new debt: 1d3h)\n" + |
@@ -77,7 +77,8 @@ public class AlertsEmailTemplateTest { | |||
assertThat(message.getMessageId(), is("alerts/45")); | |||
assertThat(message.getSubject(), is("Quality gate status changed on \"Foo (feature)\"")); | |||
assertThat(message.getMessage(), is("" + | |||
"Project: Foo (feature)\n" + | |||
"Project: Foo\n" + | |||
"Branch: feature\n" + | |||
"Version: V1-SNAP\n" + | |||
"Quality gate status: Orange (was Red)\n" + | |||
"\n" + | |||
@@ -150,7 +151,8 @@ public class AlertsEmailTemplateTest { | |||
assertThat(message.getMessageId(), is("alerts/45")); | |||
assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo (feature)\"")); | |||
assertThat(message.getMessage(), is("" + | |||
"Project: Foo (feature)\n" + | |||
"Project: Foo\n" + | |||
"Branch: feature\n" + | |||
"Version: V1-SNAP\n" + | |||
"Quality gate status: Orange (was Red)\n" + | |||
"\n" + | |||
@@ -184,7 +186,8 @@ public class AlertsEmailTemplateTest { | |||
assertThat(message.getMessageId(), is("alerts/45")); | |||
assertThat(message.getSubject(), is("\"Foo (feature)\" is back to green")); | |||
assertThat(message.getMessage(), is("" + | |||
"Project: Foo (feature)\n" + | |||
"Project: Foo\n" + | |||
"Branch: feature\n" + | |||
"Version: V1-SNAP\n" + | |||
"Quality gate status: Green (was Red)\n" + | |||
"\n" + |
@@ -1,4 +1,5 @@ | |||
Action | |||
Branch: feature1 | |||
Rule: Avoid Cycles | |||
Message: Has 3 cycles | |||