]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-916 Do not include branch name in quality gate notifs
authorJanos Gyerik <janos.gyerik@sonarsource.com>
Thu, 31 Aug 2017 15:39:02 +0000 (17:39 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:56 +0000 (11:34 +0200)
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java

index 8897c682e25eeb601b0ed54e5a2bdc5c1170d66a..7d3a5f13c35a9189151f4de647d4d993a302a104 100644 (file)
@@ -132,7 +132,8 @@ public class QualityGateEventsStep implements ComputationStep {
       .setFieldValue("alertText", rawStatus.getText())
       .setFieldValue("alertLevel", rawStatus.getStatus().toString())
       .setFieldValue("isNewAlert", Boolean.toString(isNewAlert));
-    analysisMetadataHolder.getBranch().ifPresent(branch -> notification.setFieldValue("branch", branch.getName()));
+    analysisMetadataHolder.getBranch().filter(b -> !b.isMain())
+      .ifPresent(branch -> notification.setFieldValue("branch", branch.getName()));
     notificationService.deliver(notification);
   }
 
index 72033929cd953be278ff1de09382c362b85747e6..11ed77dee8d0021e7268beed9e9680dbc0158671 100644 (file)
@@ -250,9 +250,14 @@ public class QualityGateEventsStepTest {
   }
 
   @Test
-  public void verify_branch_name_is_set_in_notification() {
+  public void verify_branch_name_is_set_in_notification_when_not_main() {
     String branchName = "feature1";
-    analysisMetadataHolder.setBranch(new DefaultBranchImpl(branchName));
+    analysisMetadataHolder.setBranch(new DefaultBranchImpl(branchName) {
+      @Override
+      public boolean isMain() {
+        return false;
+      }
+    });
 
     when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(WARN_QUALITY_GATE_STATUS).createNoValue()));
     when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(
@@ -271,4 +276,25 @@ public class QualityGateEventsStepTest {
     reset(measureRepository, eventRepository, notificationService);
   }
 
+  @Test
+  public void verify_branch_name_is_not_set_in_notification_when_main() {
+    analysisMetadataHolder.setBranch(new DefaultBranchImpl());
+
+    when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(WARN_QUALITY_GATE_STATUS).createNoValue()));
+    when(measureRepository.getBaseMeasure(PROJECT_COMPONENT, alertStatusMetric)).thenReturn(
+      of(Measure.newMeasureBuilder().setQualityGateStatus(new QualityGateStatus(ERROR)).createNoValue()));
+
+    underTest.execute();
+
+    verify(notificationService).deliver(notificationArgumentCaptor.capture());
+    Notification notification = notificationArgumentCaptor.getValue();
+    assertThat(notification.getType()).isEqualTo("alerts");
+    assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getPublicKey());
+    assertThat(notification.getFieldValue("projectUuid")).isEqualTo(PROJECT_COMPONENT.getUuid());
+    assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
+    assertThat(notification.getFieldValue("branch")).isEqualTo(null);
+
+    reset(measureRepository, eventRepository, notificationService);
+  }
+
 }