}
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);
return new EmailMessage()
.setMessageId(notification.getType() + "/" + notification.getFieldValue(FIELD_PROJECT_KEY))
- .setSubject(subject(notification, fullProjectName))
+ .setSubject(subject(notification, computeFullProjectName(projectName, branchName)))
.setMessage(message.toString());
}
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())
// 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()
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");
}
// 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" +
// 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" +
// 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" +
// 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" +
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" +
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" +
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" +
Action
+Branch: feature1
Rule: Avoid Cycles
Message: Has 3 cycles