From: Sébastien Lesaint Date: Thu, 28 Sep 2017 08:31:28 +0000 (+0200) Subject: SONAR-9725 support singular in subject of new issue notifications X-Git-Tag: 6.6-RC1~119 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d5d34de3b57dc1e533d4ba2cc61c5ffea9dd4dd7;p=sonarqube.git SONAR-9725 support singular in subject of new issue notifications --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java index ec3ccd8a803..8f6626c70a1 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java @@ -111,9 +111,11 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate { protected abstract boolean shouldNotFormat(Notification notification); protected String subject(Notification notification, String fullProjectName) { - return String.format("%s: %s new issues (new debt: %s)", + int issueCount = Integer.parseInt(notification.getFieldValue(Metric.RULE_TYPE + COUNT)); + return String.format("%s: %s new issue%s (new debt: %s)", fullProjectName, - notification.getFieldValue(Metric.RULE_TYPE + COUNT), + issueCount, + issueCount > 1 ? "s" : "", notification.getFieldValue(Metric.EFFORT + COUNT)); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplate.java b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplate.java index fcf02e34b46..dd75a4cf95c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplate.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplate.java @@ -47,8 +47,10 @@ public class MyNewIssuesEmailTemplate extends AbstractNewIssuesEmailTemplate { @Override protected String subject(Notification notification, String fullProjectName) { - return String.format("You have %s new issues on project %s", - notification.getFieldValue(Metric.RULE_TYPE + COUNT), + int issueCount = Integer.parseInt(notification.getFieldValue(Metric.RULE_TYPE + COUNT)); + return String.format("You have %s new issue%s on project %s", + issueCount, + issueCount > 1 ? "s" : "", fullProjectName); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java index 98741da80e7..1c88818d3c3 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java @@ -185,6 +185,8 @@ public class MyNewIssuesEmailTemplateTest { EmailMessage message = underTest.format(notification); + assertThat(message.getSubject()) + .isEqualTo("You have 1 new issue on project Struts"); assertThat(message.getMessage()) .contains("1 new issue (new debt: 1d3h)\n"); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java index 36d78f01ae0..d674904afe2 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java @@ -167,6 +167,8 @@ public class NewIssuesEmailTemplateTest { EmailMessage message = template.format(notification); + assertThat(message.getSubject()) + .isEqualTo("Struts: 1 new issue (new debt: 1d3h)"); assertThat(message.getMessage()) .contains("1 new issue (new debt: 1d3h)\n"); }