]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14157 Rename quality gate events to Passed/Failed instead of Green/Red
authorJulien HENRY <julien.henry@sonarsource.com>
Fri, 27 Nov 2020 15:27:33 +0000 (16:27 +0100)
committersonartech <sonartech@sonarsource.com>
Thu, 3 Dec 2020 20:06:38 +0000 (20:06 +0000)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/measure/Measure.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java
server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/notification/QGChangeEmailTemplateTest.java

index 9c402044507e17413055c535b8c77773bd67b17b..1f68a763091875b8daa6a073842b5ae221acc7ba 100644 (file)
@@ -38,8 +38,8 @@ public interface Measure {
   }
 
   enum Level {
-    OK("Green"),
-    ERROR("Red"),
+    OK("Passed"),
+    ERROR("Failed"),
 
     /**
      * @deprecated since 7.6, warning quality gates doesn't exist anymore on new analysis
@@ -47,14 +47,14 @@ public interface Measure {
     @Deprecated
     WARN("Orange");
 
-    private final String colorName;
+    private final String label;
 
-    Level(String colorName) {
-      this.colorName = colorName;
+    Level(String label) {
+      this.label = label;
     }
 
-    public String getColorName() {
-      return colorName;
+    public String getLabel() {
+      return label;
     }
 
     public static Optional<Level> toLevel(@Nullable String level) {
index eadc16956fecd9e8b1802c229675449fd650d5ba..c4ef6855868f832626cdda68a0d2421fd3de66a3 100644 (file)
@@ -110,33 +110,31 @@ public class QualityGateEventsStep implements ComputationStep {
 
     if (baseStatus.getStatus() != rawStatus.getStatus()) {
       // The QualityGate status has changed
-      String label = String.format("%s (was %s)", rawStatus.getStatus().getColorName(), baseStatus.getStatus().getColorName());
-      createEvent(project, label, rawStatus.getText());
+      createEvent(project, rawStatus.getStatus().getLabel(), rawStatus.getText());
       boolean isNewKo = rawStatus.getStatus() == Measure.Level.OK;
-      notifyUsers(project, label, rawStatus, isNewKo);
+      notifyUsers(project, rawStatus, isNewKo);
     }
   }
 
   private void checkNewQualityGate(Component project, QualityGateStatus rawStatus) {
     if (rawStatus.getStatus() != Measure.Level.OK) {
       // There were no defined alerts before, so this one is a new one
-      createEvent(project, rawStatus.getStatus().getColorName(), rawStatus.getText());
-      notifyUsers(project, rawStatus.getStatus().getColorName(), rawStatus, true);
+      createEvent(project, rawStatus.getStatus().getLabel(), rawStatus.getText());
+      notifyUsers(project, rawStatus, true);
     }
   }
 
   /**
-   * @param label "Red (was Green)"
    * @param rawStatus OK or ERROR + optional text
    */
-  private void notifyUsers(Component project, String label, QualityGateStatus rawStatus, boolean isNewAlert) {
+  private void notifyUsers(Component project, QualityGateStatus rawStatus, boolean isNewAlert) {
     QGChangeNotification notification = new QGChangeNotification();
     notification
-      .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label))
+      .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), rawStatus.getStatus().getLabel()))
       .setFieldValue("projectName", project.getName())
       .setFieldValue("projectKey", project.getKey())
       .setFieldValue("projectVersion", project.getProjectAttributes().getProjectVersion())
-      .setFieldValue("alertName", label)
+      .setFieldValue("alertName", rawStatus.getStatus().getLabel())
       .setFieldValue("alertText", rawStatus.getText())
       .setFieldValue("alertLevel", rawStatus.getStatus().toString())
       .setFieldValue("isNewAlert", Boolean.toString(isNewAlert));
index 0dde36f3940193b8441e41bf4d2b353ab7669a17..3abd5b928949eddc89a4d3247f1d6c5cc66f2dd0 100644 (file)
@@ -142,7 +142,7 @@ public class PersistEventsStepTest extends BaseStepTest {
   public void persist_alert_events_on_root() {
     when(system2.now()).thenReturn(NOW);
     treeRootHolder.setRoot(ROOT);
-    Event alert = Event.createAlert("Red (was Orange)", null, "Open issues > 0");
+    Event alert = Event.createAlert("Failed", null, "Open issues > 0");
     when(eventRepository.getEvents(ROOT)).thenReturn(ImmutableList.of(alert));
 
     underTest.execute(new TestComputationStepContext());
index da29a1f29b37cea6a62202816888c2ee5e0f41d6..9af840e7d1befeae273d5815e01e2b06d5f6326a 100644 (file)
@@ -152,12 +152,12 @@ public class QualityGateEventsStepTest {
 
   @Test
   public void event_created_if_base_ALERT_STATUS_has_no_alertStatus_and_raw_is_ERROR() {
-    verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Red");
+    verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Failed");
   }
 
   @Test
   public void event_created_if_base_ALERT_STATUS_has_invalid_alertStatus_and_raw_is_ERROR() {
-    verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Red");
+    verify_event_created_if_no_base_ALERT_STATUS_measure(ERROR, "Failed");
   }
 
   private void verify_event_created_if_no_base_ALERT_STATUS_measure(Measure.Level rawAlterStatus, String expectedLabel) {
@@ -211,8 +211,8 @@ public class QualityGateEventsStepTest {
 
   @Test
   public void event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed() {
-    verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(OK, ERROR_QUALITY_GATE_STATUS, "Red (was Green)");
-    verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(ERROR, OK_QUALITY_GATE_STATUS, "Green (was Red)");
+    verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(OK, ERROR_QUALITY_GATE_STATUS, "Failed");
+    verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(ERROR, OK_QUALITY_GATE_STATUS, "Passed");
   }
 
   private void verify_event_created_if_base_ALERT_STATUS_measure_exists_and_status_has_changed(Measure.Level previousAlertStatus,
index 217ac9cc0bd97b10910db0d2cd3c3fa6565a6f04..e4b81762ec6ee6b40a8e15e0b7ae67521cab2779 100644 (file)
@@ -51,7 +51,7 @@ public class QGChangeEmailTemplateTest {
 
   @Test
   public void shouldFormatAlertWithSeveralMessages() {
-    Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "false");
+    Notification notification = createNotification("Failed", "violations > 4, coverage < 75%", "ERROR", "false");
 
     EmailMessage message = template.format(notification);
     assertThat(message.getMessageId(), is("alerts/45"));
@@ -59,7 +59,7 @@ public class QGChangeEmailTemplateTest {
     assertThat(message.getMessage(), is("" +
       "Project: Foo\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Red (was Green)\n" +
+      "Quality gate status: Failed\n" +
       "\n" +
       "Quality gate thresholds:\n" +
       "  - violations > 4\n" +
@@ -70,7 +70,7 @@ public class QGChangeEmailTemplateTest {
 
   @Test
   public void shouldFormatAlertWithSeveralMessagesOnBranch() {
-    Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "false")
+    Notification notification = createNotification("Failed", "violations > 4, coverage < 75%", "ERROR", "false")
         .setFieldValue("branch", "feature");
 
     EmailMessage message = template.format(notification);
@@ -80,7 +80,7 @@ public class QGChangeEmailTemplateTest {
       "Project: Foo\n" +
       "Branch: feature\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Red (was Green)\n" +
+      "Quality gate status: Failed\n" +
       "\n" +
       "Quality gate thresholds:\n" +
       "  - violations > 4\n" +
@@ -91,7 +91,7 @@ public class QGChangeEmailTemplateTest {
 
   @Test
   public void shouldFormatNewAlertWithSeveralMessages() {
-    Notification notification = createNotification("Red (was Green)", "violations > 4, coverage < 75%", "ERROR", "true");
+    Notification notification = createNotification("Failed", "violations > 4, coverage < 75%", "ERROR", "true");
 
     EmailMessage message = template.format(notification);
     assertThat(message.getMessageId(), is("alerts/45"));
@@ -99,7 +99,7 @@ public class QGChangeEmailTemplateTest {
     assertThat(message.getMessage(), is("" +
       "Project: Foo\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Red (was Green)\n" +
+      "Quality gate status: Failed\n" +
       "\n" +
       "New quality gate thresholds:\n" +
       "  - violations > 4\n" +
@@ -110,7 +110,7 @@ public class QGChangeEmailTemplateTest {
 
   @Test
   public void shouldFormatNewAlertWithOneMessage() {
-    Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true");
+    Notification notification = createNotification("Failed", "violations > 4", "ERROR", "true");
 
     EmailMessage message = template.format(notification);
     assertThat(message.getMessageId(), is("alerts/45"));
@@ -118,7 +118,7 @@ public class QGChangeEmailTemplateTest {
     assertThat(message.getMessage(), is("" +
       "Project: Foo\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Red (was Green)\n" +
+      "Quality gate status: Failed\n" +
       "\n" +
       "New quality gate threshold: violations > 4\n" +
       "\n" +
@@ -127,7 +127,7 @@ public class QGChangeEmailTemplateTest {
 
   @Test
   public void shouldFormatNewAlertWithoutVersion() {
-    Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true")
+    Notification notification = createNotification("Failed", "violations > 4", "ERROR", "true")
         .setFieldValue("projectVersion", null);
 
     EmailMessage message = template.format(notification);
@@ -135,7 +135,7 @@ public class QGChangeEmailTemplateTest {
     assertThat(message.getSubject(), is("New quality gate threshold reached on \"Foo\""));
     assertThat(message.getMessage(), is("" +
       "Project: Foo\n" +
-      "Quality gate status: Red (was Green)\n" +
+      "Quality gate status: Failed\n" +
       "\n" +
       "New quality gate threshold: violations > 4\n" +
       "\n" +
@@ -144,7 +144,7 @@ public class QGChangeEmailTemplateTest {
 
   @Test
   public void shouldFormatNewAlertWithOneMessageOnBranch() {
-    Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true")
+    Notification notification = createNotification("Failed", "violations > 4", "ERROR", "true")
       .setFieldValue("branch", "feature");
 
     EmailMessage message = template.format(notification);
@@ -154,7 +154,7 @@ public class QGChangeEmailTemplateTest {
       "Project: Foo\n" +
       "Branch: feature\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Red (was Green)\n" +
+      "Quality gate status: Failed\n" +
       "\n" +
       "New quality gate threshold: violations > 4\n" +
       "\n" +
@@ -163,7 +163,7 @@ public class QGChangeEmailTemplateTest {
 
   @Test
   public void shouldFormatBackToGreenMessage() {
-    Notification notification = createNotification("Green (was Red)", "", "OK", "false");
+    Notification notification = createNotification("Passed", "", "OK", "false");
 
     EmailMessage message = template.format(notification);
     assertThat(message.getMessageId(), is("alerts/45"));
@@ -171,7 +171,7 @@ public class QGChangeEmailTemplateTest {
     assertThat(message.getMessage(), is("" +
       "Project: Foo\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Green (was Red)\n" +
+      "Quality gate status: Passed\n" +
       "\n" +
       "\n" +
       "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo"));
@@ -179,7 +179,7 @@ public class QGChangeEmailTemplateTest {
 
   @Test
   public void shouldFormatBackToGreenMessageOnBranch() {
-    Notification notification = createNotification("Green (was Red)", "", "OK", "false")
+    Notification notification = createNotification("Passed", "", "OK", "false")
         .setFieldValue("branch", "feature");
 
     EmailMessage message = template.format(notification);
@@ -189,7 +189,7 @@ public class QGChangeEmailTemplateTest {
       "Project: Foo\n" +
       "Branch: feature\n" +
       "Version: V1-SNAP\n" +
-      "Quality gate status: Green (was Red)\n" +
+      "Quality gate status: Passed\n" +
       "\n" +
       "\n" +
       "More details at: http://nemo.sonarsource.org/dashboard?id=org.sonar.foo:foo&branch=feature"));