]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-13471 Deprecate periods in api/qualitygates/project_status
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Thu, 13 Aug 2020 19:23:09 +0000 (14:23 -0500)
committersonartech <sonartech@sonarsource.com>
Fri, 14 Aug 2020 20:16:19 +0000 (20:16 +0000)
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatter.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/project_status-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java
server/sonar-webserver-webapi/src/test/resources/org/sonar/server/qualitygate/ws/ProjectStatusActionTest/measure_data.json
sonar-ws/src/main/protobuf/ws-qualitygates.proto

index 5b31a34239cb4f6dadccbce7a49ef9fb1d6ebfe9..bdf3567d1b2b70438c730c3553cdec6a33427479 100644 (file)
@@ -90,8 +90,9 @@ public class ProjectStatusAction implements QualityGatesWsAction {
       .setSince("5.3")
       .setHandler(this)
       .setChangelog(
+        new Change("8.5", "The field 'periods' in the response is deprecated. Use 'period' instead"),
         new Change("7.7", "The parameters 'branch' and 'pullRequest' were added"),
-        new Change("7.6", "The field 'warning' is deprecated from the response"),
+        new Change("7.6", "The field 'warning' in the response is deprecated"),
         new Change("6.4", "The field 'ignoredConditions' is added to the response"));
 
     action.createParam(PARAM_ANALYSIS_ID)
index 391c97d91c3e7970e437c2d7cb1565ebad2987cd..1d756928d58d7862c48e918b780ee3adc11b9dd6 100644 (file)
@@ -29,6 +29,8 @@ import java.util.stream.StreamSupport;
 import javax.annotation.Nullable;
 import org.sonar.db.component.SnapshotDto;
 import org.sonarqube.ws.Qualitygates.ProjectStatusResponse;
+import org.sonarqube.ws.Qualitygates.ProjectStatusResponse.NewCodePeriod;
+import org.sonarqube.ws.Qualitygates.ProjectStatusResponse.Period;
 
 import static com.google.common.base.Strings.isNullOrEmpty;
 import static org.sonar.api.utils.DateUtils.formatDateTime;
@@ -75,25 +77,30 @@ public class QualityGateDetailsFormatter {
       return;
     }
 
-    ProjectStatusResponse.Period.Builder periodBuilder = ProjectStatusResponse.Period.newBuilder();
-    periodBuilder.clear();
+    Period.Builder periodsBuilder = Period.newBuilder();
+    NewCodePeriod.Builder periodBuilder = NewCodePeriod.newBuilder();
 
     SnapshotDto snapshot = this.optionalSnapshot.get();
 
     if (isNullOrEmpty(snapshot.getPeriodMode())) {
       return;
     }
-    periodBuilder.setIndex(1);
+    periodsBuilder.setIndex(1);
+    periodsBuilder.setMode(snapshot.getPeriodMode());
     periodBuilder.setMode(snapshot.getPeriodMode());
     Long periodDate = snapshot.getPeriodDate();
     if (periodDate != null) {
-      periodBuilder.setDate(formatDateTime(periodDate));
+      String formattedDateTime = formatDateTime(periodDate);
+      periodsBuilder.setDate(formattedDateTime);
+      periodBuilder.setDate(formattedDateTime);
     }
     String periodModeParameter = snapshot.getPeriodModeParameter();
     if (!isNullOrEmpty(periodModeParameter)) {
+      periodsBuilder.setParameter(periodModeParameter);
       periodBuilder.setParameter(periodModeParameter);
     }
-    projectStatusBuilder.addPeriods(periodBuilder);
+    projectStatusBuilder.addPeriods(periodsBuilder);
+    projectStatusBuilder.setPeriod(periodBuilder);
   }
 
   private void formatConditions(@Nullable JsonArray jsonConditions) {
index e5c5610b29dc275c8911706b2385a9018112d898..3ee1c35e54c00aa8f64d4754e16bce655e129d87 100644 (file)
         "date": "2000-04-27T00:45:23+0200",
         "parameter": "2015-12-07"
       }
-    ]
+    ],
+    "period": {
+        "mode": "last_version",
+        "date": "2000-04-27T00:45:23+0200",
+        "parameter": "2015-12-07"
+     }
   }
 }
index dec0b7937e0c194f2bd916f46136953f2f254eb5..d77aa95e4da038ba1ffa60f681d11c2cbc9e20c0 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.qualitygate.ws;
 
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import org.apache.commons.io.IOUtils;
 import org.junit.Rule;
 import org.junit.Test;
@@ -101,7 +102,7 @@ public class ProjectStatusActionTest {
       .setPeriodDate(956789123987L));
     dbClient.measureDao().insert(dbSession,
       newMeasureDto(gateDetailsMetric, project, snapshot)
-        .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json"))));
+        .setData(IOUtils.toString(getClass().getResource("ProjectStatusActionTest/measure_data.json"), StandardCharsets.UTF_8)));
     dbSession.commit();
 
     String response = ws.newRequest()
index 38c36070556117679715c6ca08ae36fcff2d800a..6cf88c57fcc677844a889d3e5b8dc97493bef036 100644 (file)
       "actual": "0",
       "level": "OK"
     }
-  ]
+  ],
+  "period": {
+    "mode": "last_version",
+    "date": "2000-04-27T00:45:23+0200",
+    "parameter": "2015-12-07"
+  }
 }
index ced73a135749d95b780620c199a748b34be60f0d..781e5b2c147d383203b822bde539b86b4ecfdec7 100644 (file)
@@ -35,6 +35,7 @@ message ProjectStatusResponse {
     repeated Condition conditions = 2;
     repeated Period periods = 3;
     optional bool ignoredConditions = 4;
+    optional NewCodePeriod period = 5;
   }
 
   message Condition {
@@ -47,6 +48,12 @@ message ProjectStatusResponse {
     optional string actualValue = 7;
   }
 
+    message NewCodePeriod {
+      optional string mode = 1;
+      optional string date = 2;
+      optional string parameter = 3;
+    }
+
   message Period {
     optional int32 index = 1;
     optional string mode = 2;