From f4733cb9ef274b0b990b0459b3c523eb756ce5cb Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Thu, 13 Aug 2020 14:23:09 -0500 Subject: [PATCH] SONAR-13471 Deprecate periods in api/qualitygates/project_status --- .../qualitygate/ws/ProjectStatusAction.java | 3 ++- .../ws/QualityGateDetailsFormatter.java | 17 ++++++++++++----- .../qualitygate/ws/project_status-example.json | 7 ++++++- .../qualitygate/ws/ProjectStatusActionTest.java | 3 ++- .../ProjectStatusActionTest/measure_data.json | 7 ++++++- .../src/main/protobuf/ws-qualitygates.proto | 7 +++++++ 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java index 5b31a34239c..bdf3567d1b2 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ProjectStatusAction.java @@ -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) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatter.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatter.java index 391c97d91c3..1d756928d58 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatter.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatter.java @@ -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) { diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/project_status-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/project_status-example.json index e5c5610b29d..3ee1c35e54c 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/project_status-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/project_status-example.json @@ -64,6 +64,11 @@ "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" + } } } diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java index dec0b7937e0..d77aa95e4da 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/ProjectStatusActionTest.java @@ -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() diff --git a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/qualitygate/ws/ProjectStatusActionTest/measure_data.json b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/qualitygate/ws/ProjectStatusActionTest/measure_data.json index 38c36070556..6cf88c57fcc 100644 --- a/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/qualitygate/ws/ProjectStatusActionTest/measure_data.json +++ b/server/sonar-webserver-webapi/src/test/resources/org/sonar/server/qualitygate/ws/ProjectStatusActionTest/measure_data.json @@ -56,5 +56,10 @@ "actual": "0", "level": "OK" } - ] + ], + "period": { + "mode": "last_version", + "date": "2000-04-27T00:45:23+0200", + "parameter": "2015-12-07" + } } diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto index ced73a13574..781e5b2c147 100644 --- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto +++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto @@ -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; -- 2.39.5