From: Janos Gyerik Date: Thu, 31 Aug 2017 15:39:02 +0000 (+0200) Subject: SONAR-916 Do not include branch name in quality gate notifs X-Git-Tag: 6.6-RC1~380^2~26 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7e4aac6e3e592e0909bbdfd7a93716778dc67fad;p=sonarqube.git SONAR-916 Do not include branch name in quality gate notifs --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java index 8897c682e25..7d3a5f13c35 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java @@ -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); } diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java index 72033929cd9..11ed77dee8d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java @@ -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); + } + }