From 79cbc21d702958479b1fb1946620a52577a5ba37 Mon Sep 17 00:00:00 2001 From: Matteo Mara Date: Tue, 28 Mar 2023 17:31:37 +0200 Subject: [PATCH] SONAR-18746 Remove the field periods from the response of api/qualitygates/project_status --- .../server/qualitygate/ws/ProjectStatusAction.java | 1 + .../ws/QualityGateDetailsFormatter.java | 10 +++------- .../qualitygate/ws/project_status-example.json | 8 -------- .../ws/QualityGateDetailsFormatterTest.java | 14 ++++++-------- sonar-ws/src/main/protobuf/ws-qualitygates.proto | 9 +-------- 5 files changed, 11 insertions(+), 31 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 54fc1d9db32..456ae51975c 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 @@ -96,6 +96,7 @@ public class ProjectStatusAction implements QualityGatesWsAction { .setSince("5.3") .setHandler(this) .setChangelog( + new Change("10.0", "The field 'periods' in the response is removed"), new Change("9.9", "'caycStatus' field is added to the response"), new Change("9.5", "The 'Execute Analysis' permission also allows to access the endpoint"), new Change("8.5", "The field 'periods' in the response is deprecated. Use 'period' instead"), 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 e32b433b482..b8715debe22 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 @@ -31,7 +31,6 @@ import org.sonar.db.component.SnapshotDto; import org.sonar.server.qualitygate.QualityGateCaycStatus; 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; @@ -81,7 +80,6 @@ public class QualityGateDetailsFormatter { return; } - Period.Builder periodsBuilder = Period.newBuilder(); NewCodePeriod.Builder periodBuilder = NewCodePeriod.newBuilder(); SnapshotDto snapshot = this.optionalSnapshot.get(); @@ -89,21 +87,19 @@ public class QualityGateDetailsFormatter { if (isNullOrEmpty(snapshot.getPeriodMode())) { return; } - periodsBuilder.setIndex(1); - periodsBuilder.setMode(snapshot.getPeriodMode()); + periodBuilder.setMode(snapshot.getPeriodMode()); Long periodDate = snapshot.getPeriodDate(); if (periodDate != null) { 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(periodsBuilder); + projectStatusBuilder.setPeriod(periodBuilder); } 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 b17e84c2c76..686493327cf 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 @@ -58,14 +58,6 @@ "actualValue": "0" } ], - "periods": [ - { - "index": 1, - "mode": "last_version", - "date": "2000-04-27T00:45:23+0200", - "parameter": "2015-12-07" - } - ], "period": { "mode": "last_version", "date": "2000-04-27T00:45:23+0200", diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java index ebf394c06d3..ca7fec90ce6 100644 --- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java +++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/qualitygate/ws/QualityGateDetailsFormatterTest.java @@ -39,7 +39,7 @@ public class QualityGateDetailsFormatterTest { private QualityGateDetailsFormatter underTest; @Test - public void map_level_conditions_and_periods() throws IOException { + public void map_level_conditions_and_period() throws IOException { String measureData = IOUtils.toString(getClass().getResource("QualityGateDetailsFormatterTest/quality_gate_details.json")); SnapshotDto snapshot = new SnapshotDto() .setPeriodMode("last_version") @@ -68,13 +68,11 @@ public class QualityGateDetailsFormatterTest { assertThat(conditions).extracting("errorThreshold").containsOnly("85", "0", "0"); assertThat(conditions).extracting("actualValue").containsExactly("82.2985024398452", "1", "0"); - // check periods - assertThat(result.getPeriodsCount()).isOne(); - List periods = result.getPeriodsList(); - assertThat(periods).extracting("index").containsExactly(1); - assertThat(periods).extracting("mode").containsExactly("last_version"); - assertThat(periods).extracting("parameter").containsExactly("2015-12-07"); - assertThat(periods.get(0).getDate()).isEqualTo(formatDateTime(snapshot.getPeriodDate())); + // check period + ProjectStatusResponse.NewCodePeriod period = result.getPeriod(); + assertThat(period).extracting("mode").isEqualTo("last_version"); + assertThat(period).extracting("parameter").isEqualTo("2015-12-07"); + assertThat(period.getDate()).isEqualTo(formatDateTime(snapshot.getPeriodDate())); } @Test diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto index 8d137726d1c..8c9d4fbf962 100644 --- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto +++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto @@ -33,7 +33,7 @@ message ProjectStatusResponse { message ProjectStatus { optional Status status = 1; repeated Condition conditions = 2; - repeated Period periods = 3; + reserved 3; //drop periods optional bool ignoredConditions = 4; optional NewCodePeriod period = 5; optional string caycStatus = 6; @@ -55,13 +55,6 @@ message ProjectStatusResponse { optional string parameter = 3; } - message Period { - optional int32 index = 1; - optional string mode = 2; - optional string date = 3; - optional string parameter = 4; - } - enum Status { OK = 1; WARN = 2; -- 2.39.5