import java.util.Date;
import java.util.Iterator;
import java.util.Locale;
+import javax.annotation.Nullable;
import org.sonar.api.config.EmailSettings;
import org.sonar.api.i18n.I18n;
import org.sonar.api.notifications.Notification;
return null;
}
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(projectName).append(NEW_LINE).append(NEW_LINE);
+ message.append("Project: ").append(fullProjectName).append(NEW_LINE).append(NEW_LINE);
appendRuleType(message, notification);
appendAssignees(message, notification);
appendRules(message, notification);
return new EmailMessage()
.setMessageId(notification.getType() + "/" + notification.getFieldValue(FIELD_PROJECT_KEY))
- .setSubject(subject(notification, projectName))
+ .setSubject(subject(notification, fullProjectName))
.setMessage(message.toString());
}
+ private static String computeFullProjectName(String projectName, @Nullable String branchName) {
+ if (branchName == null || branchName.isEmpty()) {
+ return projectName;
+ }
+ return String.format("%s (%s)", projectName, branchName);
+ }
+
protected abstract boolean shouldNotFormat(Notification notification);
- protected String subject(Notification notification, String projectName) {
+ protected String subject(Notification notification, String fullProjectName) {
return String.format("%s: %s new issues (new debt: %s)",
- projectName,
+ fullProjectName,
notification.getFieldValue(Metric.RULE_TYPE + COUNT),
notification.getFieldValue(Metric.EFFORT + COUNT));
}
Date date = DateUtils.parseDateTime(dateString);
String url = String.format("%s/project/issues?id=%s",
settings.getServerBaseURL(), encode(projectKey));
- String branchName = notification.getFieldValue("branch");
+ String branchName = notification.getFieldValue(FIELD_BRANCH);
if (branchName != null) {
url += "&branch=" + encode(branchName);
}
*/
package org.sonar.server.issue.notification;
+import java.util.Date;
import org.sonar.api.config.EmailSettings;
import org.sonar.api.i18n.I18n;
import org.sonar.api.notifications.Notification;
import org.sonar.api.utils.DateUtils;
import org.sonar.server.issue.notification.NewIssuesStatistics.Metric;
-import java.util.Date;
-
/**
* Creates email message for notification "my-new-issues".
*/
}
@Override
- protected String subject(Notification notification, String projectName) {
+ protected String subject(Notification notification, String fullProjectName) {
return String.format("You have %s new issues on project %s",
notification.getFieldValue(Metric.RULE_TYPE + COUNT),
- projectName);
+ fullProjectName);
}
@Override
assertThat(message.getSubject()).isEqualTo("You have 32 new issues on project Struts");
}
+ @Test
+ public void subject_on_branch() {
+ Notification notification = newNotification(32)
+ .setFieldValue("branch", "feature1");
+
+ EmailMessage message = underTest.format(notification);
+
+ assertThat(message.getSubject()).isEqualTo("You have 32 new issues on project Struts (feature1)");
+ }
+
@Test
public void format_email_with_no_assignees_tags_nor_components() throws Exception {
Notification notification = newNotification(32);
// TODO datetime to be completed when test is isolated from JVM timezone
assertThat(message.getMessage())
- .startsWith("Project: Struts\n" +
+ .startsWith("Project: Struts (feature1)\n" +
"\n" +
"32 new issues (new debt: 1d3h)\n" +
"\n" +
assertThat(message.getSubject()).isEqualTo("Struts: 32 new issues (new debt: 1d3h)");
}
+ @Test
+ public void subject_on_branch() throws Exception {
+ Notification notification = newNotification(32)
+ .setFieldValue("branch", "feature1");
+
+ EmailMessage message = template.format(notification);
+
+ assertThat(message.getSubject()).isEqualTo("Struts (feature1): 32 new issues (new debt: 1d3h)");
+ }
+
@Test
public void format_email_with_all_fields_filled() throws Exception {
Notification notification = newNotification(32);
// TODO datetime to be completed when test is isolated from JVM timezone
assertThat(message.getMessage())
- .startsWith("Project: Struts\n" +
+ .startsWith("Project: Struts (feature1)\n" +
"\n" +
"32 new issues (new debt: 1d3h)\n" +
"\n" +