aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java2
-rw-r--r--sonar-core/src/main/java/org/sonar/core/issue/IssueNotifications.java20
-rw-r--r--sonar-core/src/test/java/org/sonar/core/issue/IssueNotificationsTest.java17
3 files changed, 30 insertions, 9 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java
index d77560fa216..32a3d0a5b22 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/issue/notification/SendIssueNotificationsPostJob.java
@@ -56,7 +56,7 @@ public class SendIssueNotificationsPostJob implements PostJob {
if (issue.isNew() && issue.resolution() == null) {
newIssues++;
}
- if (issue.isChanged() && issue.diffs() != null) {
+ if (issue.isChanged()) {
Rule rule = ruleFinder.findByKey(issue.ruleKey());
// TODO warning - rules with status REMOVED are currently ignored, but should not
if (rule != null) {
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);
+ }
}