diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-30 15:46:13 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-05-30 15:58:30 +0200 |
commit | 73b1299333b3e0707a4d73e4c4fad1874a158eac (patch) | |
tree | 9a33551344bec217d436f790d0c94e831eb74c04 /sonar-core/src | |
parent | 84ffe3e150f3718e51873f8839663c1d8940210c (diff) | |
download | sonarqube-73b1299333b3e0707a4d73e4c4fad1874a158eac.tar.gz sonarqube-73b1299333b3e0707a4d73e4c4fad1874a158eac.zip |
SONAR-4283 Add notification on new comment, and change emails subject
Diffstat (limited to 'sonar-core/src')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java | 49 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java | 20 |
2 files changed, 54 insertions, 15 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java b/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java index 0fc2debfc09..b7cc1fc5504 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java @@ -32,6 +32,7 @@ import org.sonar.core.i18n.RuleI18nManager; import javax.annotation.CheckForNull; import javax.annotation.Nullable; + import java.util.Locale; import java.util.Map; @@ -67,28 +68,46 @@ public class IssueNotifications implements BatchComponent, ServerComponent { @CheckForNull public Notification sendChanges(DefaultIssue issue, IssueChangeContext context, Rule rule, Component project, @Nullable Component component) { if (issue.diffs() != null) { - Notification notification = newNotification(project, "issue-changes"); - notification.setFieldValue("key", issue.key()); - notification.setFieldValue("changeAuthor", context.login()); - notification.setFieldValue("reporter", issue.reporter()); - notification.setFieldValue("assignee", issue.assignee()); - notification.setFieldValue("message", issue.message()); - notification.setFieldValue("ruleName", ruleName(rule)); - notification.setFieldValue("componentKey", issue.componentKey()); - if (component != null) { - notification.setFieldValue("componentName", component.name()); - } + Notification notification = createNotification(issue, context, rule, project, component, null); + notificationsManager.scheduleForSending(notification); + return notification; + } + return null; + } - for (Map.Entry<String, FieldDiffs.Diff> entry : issue.diffs().diffs().entrySet()) { + @CheckForNull + public Notification sendChanges(DefaultIssue issue, IssueChangeContext context, IssueQueryResult queryResult, @Nullable String comment) { + Notification notification = createNotification(issue, context, queryResult.rule(issue), queryResult.project(issue), queryResult.component(issue), comment); + notificationsManager.scheduleForSending(notification); + return notification; + } + + private Notification createNotification(DefaultIssue issue, IssueChangeContext context, Rule rule, Component project, @Nullable Component component, @Nullable String comment){ + Notification notification = newNotification(project, "issue-changes"); + notification.setFieldValue("key", issue.key()); + notification.setFieldValue("changeAuthor", context.login()); + notification.setFieldValue("reporter", issue.reporter()); + notification.setFieldValue("assignee", issue.assignee()); + notification.setFieldValue("message", issue.message()); + notification.setFieldValue("ruleName", ruleName(rule)); + notification.setFieldValue("componentKey", issue.componentKey()); + if (component != null) { + notification.setFieldValue("componentName", component.name()); + } + if (comment != null) { + notification.setFieldValue("comment", comment); + } + + FieldDiffs diffs = issue.diffs(); + if (diffs != null) { + for (Map.Entry<String, FieldDiffs.Diff> entry : diffs.diffs().entrySet()) { String type = entry.getKey(); FieldDiffs.Diff diff = entry.getValue(); notification.setFieldValue("old." + type, diff.oldValue() != null ? diff.oldValue().toString() : null); notification.setFieldValue("new." + type, diff.newValue() != null ? diff.newValue().toString() : null); } - notificationsManager.scheduleForSending(notification); - return notification; } - return null; + return notification; } private String ruleName(@Nullable Rule rule) { diff --git a/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java b/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java index 34789bb72ce..af263e33b44 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java @@ -89,4 +89,24 @@ public class IssueNotificationsTest { assertThat(notification.getFieldValue("new.status")).isEqualTo("RESOLVED"); Mockito.verify(manager).scheduleForSending(notification); } + + @Test + public void sendChangesWithComment() throws Exception { + IssueChangeContext context = IssueChangeContext.createScan(new Date()); + DefaultIssue issue = new DefaultIssue() + .setMessage("the message") + .setKey("ABCDE") + .setAssignee("freddy") + .setComponentKey("struts:Action") + .setProjectKey("struts"); + DefaultIssueQueryResult queryResult = new DefaultIssueQueryResult(Arrays.<Issue>asList(issue)); + queryResult.addProjects(Arrays.<Component>asList(new Project("struts"))); + + Notification notification = issueNotifications.sendChanges(issue, context, queryResult, "I don't know how to fix it?"); + + assertThat(notification.getFieldValue("message")).isEqualTo("the message"); + assertThat(notification.getFieldValue("key")).isEqualTo("ABCDE"); + assertThat(notification.getFieldValue("comment")).isEqualTo("I don't know how to fix it?"); + Mockito.verify(manager).scheduleForSending(notification); + } } |