diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-06-03 10:14:28 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-06-03 10:14:28 +0200 |
commit | 9252f14cf53c146aaf52862f298d67989874b41f (patch) | |
tree | b93affb77b3086da8fbabfad987f438395ac2e10 /sonar-core | |
parent | da8cc3299f6c6e4f999a6dd04f9efdd070798dd7 (diff) | |
download | sonarqube-9252f14cf53c146aaf52862f298d67989874b41f.tar.gz sonarqube-9252f14cf53c146aaf52862f298d67989874b41f.zip |
Do not send notifications on issue changes when no field diff
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java | 20 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java | 17 |
2 files changed, 29 insertions, 8 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 51c08844168..f10e4da4ff6 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 @@ -35,7 +35,6 @@ import org.sonar.core.i18n.RuleI18nManager; import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.util.Locale; import java.util.Map; @@ -70,22 +69,27 @@ 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 = createNotification(issue, context, rule, project, component, null); + Notification notification = createChangeNotification(issue, context, rule, project, component, null); + if (notification != null) { notificationsManager.scheduleForSending(notification); - return notification; } - return null; + return notification; } @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); + Notification notification = createChangeNotification(issue, context, queryResult.rule(issue), queryResult.project(issue), queryResult.component(issue), comment); + if (notification != null) { + notificationsManager.scheduleForSending(notification); + } return notification; } - private Notification createNotification(DefaultIssue issue, IssueChangeContext context, Rule rule, Component project, @Nullable Component component, @Nullable String comment){ + @CheckForNull + private Notification createChangeNotification(DefaultIssue issue, IssueChangeContext context, Rule rule, Component project, @Nullable Component component, @Nullable String comment) { + if (comment == null && (issue.diffs() == null || issue.diffs().diffs().isEmpty())) { + return null; + } Notification notification = newNotification(project, "issue-changes"); notification.setFieldValue("key", issue.key()); notification.setFieldValue("changeAuthor", context.login()); 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 d94bd13d28f..eae906010a9 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 @@ -111,4 +111,21 @@ public class IssueNotificationsTest { assertThat(notification.getFieldValue("comment")).isEqualTo("I don't know how to fix it?"); Mockito.verify(manager).scheduleForSending(notification); } + + @Test + public void should_not_send_changes_if_no_diffs() throws Exception { + IssueChangeContext context = IssueChangeContext.createScan(new Date()); + DefaultIssue issue = new DefaultIssue() + .setMessage("the message") + .setKey("ABCDE") + .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, null); + + assertThat(notification).isNull(); + Mockito.verifyZeroInteractions(manager); + } } |