aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>2024-08-13 11:34:16 +0200
committersonartech <sonartech@sonarsource.com>2024-08-26 20:03:06 +0000
commite697fb5a3d3c531f82993912cb5f5a870144a5a2 (patch)
tree5712e6e380bb71d2c66527881f2716f5ecd67f35
parent428ec45595e130c7702d4a2555ed67c6141cfbc3 (diff)
downloadsonarqube-e697fb5a3d3c531f82993912cb5f5a870144a5a2.tar.gz
sonarqube-e697fb5a3d3c531f82993912cb5f5a870144a5a2.zip
SONAR-22727 Add new metric to changelog in webapi
-rw-r--r--server/sonar-web/src/main/js/apps/quality-gates/components/Conditions.tsx43
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java30
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java1
-rw-r--r--server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java10
-rw-r--r--server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/MeasuresWsModuleTest.java13
8 files changed, 82 insertions, 18 deletions
diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/Conditions.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/Conditions.tsx
index 42546938009..d4271a980b5 100644
--- a/server/sonar-web/src/main/js/apps/quality-gates/components/Conditions.tsx
+++ b/server/sonar-web/src/main/js/apps/quality-gates/components/Conditions.tsx
@@ -31,25 +31,25 @@ import {
Spinner,
SubHeading,
} from 'design-system';
-import { differenceWith, map, uniqBy } from 'lodash';
+import {differenceWith, map, uniqBy} from 'lodash';
import * as React from 'react';
-import { FormattedMessage } from 'react-intl';
+import {FormattedMessage} from 'react-intl';
import DocHelpTooltip from '~sonar-aligned/components/controls/DocHelpTooltip';
-import { MetricKey } from '~sonar-aligned/types/metrics';
-import { useAvailableFeatures } from '../../../app/components/available-features/withAvailableFeatures';
-import { useMetrics } from '../../../app/components/metrics/withMetricsContext';
+import {MetricKey} from '~sonar-aligned/types/metrics';
+import {useAvailableFeatures} from '../../../app/components/available-features/withAvailableFeatures';
+import {useMetrics} from '../../../app/components/metrics/withMetricsContext';
import DocumentationLink from '../../../components/common/DocumentationLink';
-import ModalButton, { ModalProps } from '../../../components/controls/ModalButton';
-import { DocLink } from '../../../helpers/doc-links';
-import { useDocUrl } from '../../../helpers/docs';
-import { getLocalizedMetricName, translate } from '../../../helpers/l10n';
-import { Feature } from '../../../types/features';
-import { CaycStatus, Condition as ConditionType, QualityGate } from '../../../types/types';
-import { groupAndSortByPriorityConditions, isQualityGateOptimized } from '../utils';
+import ModalButton, {ModalProps} from '../../../components/controls/ModalButton';
+import {DocLink} from '../../../helpers/doc-links';
+import {useDocUrl} from '../../../helpers/docs';
+import {getLocalizedMetricName, translate} from '../../../helpers/l10n';
+import {Feature} from '../../../types/features';
+import {CaycStatus, Condition as ConditionType, QualityGate} from '../../../types/types';
+import {groupAndSortByPriorityConditions, isQualityGateOptimized} from '../utils';
import AddConditionModal from './AddConditionModal';
-import CaYCConditionsSimplificationGuide from './CaYCConditionsSimplificationGuide';
import CaycCompliantBanner from './CaycCompliantBanner';
import CaycCondition from './CaycCondition';
+import CaYCConditionsSimplificationGuide from './CaYCConditionsSimplificationGuide';
import CaycFixOptimizeBanner from './CaycFixOptimizeBanner';
import CaycReviewUpdateConditionsModal from './ConditionReviewAndUpdateModal';
import ConditionsTable from './ConditionsTable';
@@ -66,6 +66,23 @@ const FORBIDDEN_METRICS: string[] = [
MetricKey.releasability_rating,
MetricKey.security_hotspots,
MetricKey.new_security_hotspots,
+ MetricKey.software_quality_maintainability_rating,
+ MetricKey.new_software_quality_maintainability_rating,
+ MetricKey.software_quality_reliability_rating,
+ MetricKey.new_software_quality_reliability_rating,
+ MetricKey.software_quality_security_rating,
+ MetricKey.new_software_quality_security_rating,
+ MetricKey.software_quality_security_review_rating,
+ MetricKey.new_software_quality_security_review_rating,
+ MetricKey.effort_to_reach_software_quality_maintainability_rating_a,
+ MetricKey.software_quality_maintainability_remediation_effort,
+ MetricKey.new_software_quality_maintainability_remediation_effort,
+ MetricKey.software_quality_security_remediation_effort,
+ MetricKey.new_software_quality_security_remediation_effort,
+ MetricKey.software_quality_reliability_remediation_effort,
+ MetricKey.new_software_quality_reliability_remediation_effort,
+ MetricKey.software_quality_maintainability_debt_ratio,
+ MetricKey.new_software_quality_maintainability_debt_ratio,
];
export default function Conditions({ qualityGate, isFetching }: Readonly<Props>) {
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
index 98f87ca1bfb..c5b775936c5 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
@@ -96,6 +96,7 @@ public class ComponentAction implements MeasuresWsAction {
.setResponseExample(getClass().getResource("component-example.json"))
.setSince("5.4")
.setChangelog(
+ new Change("10.7", "Added new accepted values for the 'metricKeys' param: %s".formatted(MeasuresWsModule.getNewMetricsInSonarQube107())),
new Change("10.5", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
index 7eb02739fe1..67d8d3409f3 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/ComponentTreeAction.java
@@ -181,6 +181,7 @@ public class ComponentTreeAction implements MeasuresWsAction {
.setHandler(this)
.addPagingParams(100, MAX_SIZE)
.setChangelog(
+ new Change("10.7", "Added new accepted values for the 'metricKeys' param: %s".formatted(MeasuresWsModule.getNewMetricsInSonarQube107())),
new Change("10.5", "Added new accepted values for the 'metricKeys' param: 'new_maintainability_issues', 'new_reliability_issues', 'new_security_issues'"),
new Change("10.5", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java
index 710f7479379..e72cd6362b8 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/MeasuresWsModule.java
@@ -19,6 +19,9 @@
*/
package org.sonar.server.measure.ws;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.sonar.core.metric.SoftwareQualitiesMetrics;
import org.sonar.core.platform.Module;
public class MeasuresWsModule extends Module {
@@ -32,7 +35,6 @@ public class MeasuresWsModule extends Module {
SearchHistoryAction.class);
}
-
public static String getDeprecatedMetricsInSonarQube93() {
return "'" + String.join("', '", "releasability_effort", "security_rating_effort", "reliability_rating_effort", "security_review_rating_effort",
"maintainability_rating_effort", "last_change_on_maintainability_rating", "last_change_on_releasability_rating", "last_change_on_reliability_rating",
@@ -40,7 +42,7 @@ public class MeasuresWsModule extends Module {
}
public static String getDeprecatedMetricsInSonarQube104() {
- return "'" + String.join("', '","bugs", "new_bugs", "vulnerabilities", "new_vulnerabilities",
+ return "'" + String.join("', '", "bugs", "new_bugs", "vulnerabilities", "new_vulnerabilities",
"code_smells", "new_code_smells", "high_impact_accepted_issues") + "'";
}
@@ -48,4 +50,28 @@ public class MeasuresWsModule extends Module {
return "'" + String.join("', '", "new_blocker_violations", "new_critical_violations", "new_major_violations", "new_minor_violations",
"new_info_violations", "blocker_violations", "critical_violations", "major_violations", "minor_violations", "info_violations") + "'";
}
+
+ public static String getNewMetricsInSonarQube107() {
+ return Stream.of(
+ SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_DEBT_RATIO,
+ SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_RATING,
+ SoftwareQualitiesMetrics.SOFTWARE_QUALITY_RELIABILITY_RATING,
+ SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_RATING,
+ SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_REVIEW_RATING,
+ SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_REMEDIATION_EFFORT,
+ SoftwareQualitiesMetrics.SOFTWARE_QUALITY_RELIABILITY_REMEDIATION_EFFORT,
+ SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_REMEDIATION_EFFORT,
+ SoftwareQualitiesMetrics.EFFORT_TO_REACH_SOFTWARE_QUALITY_MAINTAINABILITY_RATING_A,
+
+ SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MAINTAINABILITY_DEBT_RATIO,
+ SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MAINTAINABILITY_RATING,
+ SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_RELIABILITY_RATING,
+ SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_RATING,
+ SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_REVIEW_RATING,
+ SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_MAINTAINABILITY_REMEDIATION_EFFORT,
+ SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_RELIABILITY_REMEDIATION_EFFORT,
+ SoftwareQualitiesMetrics.NEW_SOFTWARE_QUALITY_SECURITY_REMEDIATION_EFFORT)
+ .map(e -> "'" + e.getKey() + "'")
+ .collect(Collectors.joining(", "));
+ }
}
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
index 6acd198f964..52594af49db 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchAction.java
@@ -87,6 +87,7 @@ public class SearchAction implements MeasuresWsAction {
.setResponseExample(getClass().getResource("search-example.json"))
.setHandler(this)
.setChangelog(
+ new Change("10.7", "Added new accepted values for the 'metricKeys' param: %s".formatted(MeasuresWsModule.getNewMetricsInSonarQube107())),
new Change("10.5", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
index 2f47507fd31..d8822093948 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/measure/ws/SearchHistoryAction.java
@@ -95,6 +95,7 @@ public class SearchHistoryAction implements MeasuresWsAction {
.setResponseExample(getClass().getResource("search_history-example.json"))
.setSince("6.3")
.setChangelog(
+ new Change("10.7", "Added new accepted values for the 'metricKeys' param: %s".formatted(MeasuresWsModule.getNewMetricsInSonarQube107())),
new Change("10.5", String.format("The metrics %s are now deprecated " +
"without exact replacement. Use 'maintainability_issues', 'reliability_issues' and 'security_issues' instead.",
MeasuresWsModule.getDeprecatedMetricsInSonarQube105())),
diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java
index da04ff265b3..f55d0cba08c 100644
--- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java
+++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/QualityGateConditionsUpdater.java
@@ -26,8 +26,12 @@ import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import javax.annotation.Nullable;
+import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metric.ValueType;
+import org.sonar.core.metric.SoftwareQualitiesMetrics;
import org.sonar.core.util.Uuids;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
@@ -58,7 +62,9 @@ import static org.sonar.server.qualitygate.Condition.Operator.LESS_THAN;
import static org.sonar.server.qualitygate.ValidRatingMetrics.isCoreRatingMetric;
public class QualityGateConditionsUpdater {
- public static final Set<String> INVALID_METRIC_KEYS = Set.of(ALERT_STATUS_KEY, SECURITY_HOTSPOTS_KEY, NEW_SECURITY_HOTSPOTS_KEY);
+ public static final Set<String> INVALID_METRIC_KEYS = Stream.concat(Stream.of(ALERT_STATUS_KEY, SECURITY_HOTSPOTS_KEY, NEW_SECURITY_HOTSPOTS_KEY),
+ new SoftwareQualitiesMetrics().getMetrics().stream().map(Metric::getKey))
+ .collect(Collectors.toUnmodifiableSet());
private static final Map<Integer, Set<Condition.Operator>> VALID_OPERATORS_BY_DIRECTION = Map.of(
DIRECTION_NONE, Set.of(GREATER_THAN, LESS_THAN),
@@ -213,7 +219,7 @@ public class QualityGateConditionsUpdater {
}
private static void checkRatingGreaterThanOperator(@Nullable String value, List<String> errors) {
- check(isNullOrEmpty(value) || !Objects.equals(toRating(value), E), errors, "There's no worse rating than E (%s)" , value);
+ check(isNullOrEmpty(value) || !Objects.equals(toRating(value), E), errors, "There's no worse rating than E (%s)", value);
}
private static Rating toRating(String value) {
diff --git a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/MeasuresWsModuleTest.java b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/MeasuresWsModuleTest.java
index ff9c933a0bf..51d90e14b61 100644
--- a/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/MeasuresWsModuleTest.java
+++ b/server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/MeasuresWsModuleTest.java
@@ -45,6 +45,17 @@ public class MeasuresWsModuleTest {
String actual = MeasuresWsModule.getDeprecatedMetricsInSonarQube105();
assertThat(actual).isEqualTo("'new_blocker_violations', 'new_critical_violations', 'new_major_violations', 'new_minor_violations', " +
- "'new_info_violations', 'blocker_violations', 'critical_violations', 'major_violations', 'minor_violations', 'info_violations'");
+ "'new_info_violations', 'blocker_violations', 'critical_violations', 'major_violations', 'minor_violations', 'info_violations'");
+ }
+
+ @Test
+ public void getNewMetricsInSonarQube107_shouldReturnExactString() {
+ String actual = MeasuresWsModule.getNewMetricsInSonarQube107();
+ assertThat(actual).isEqualTo("'software_quality_maintainability_debt_ratio', 'software_quality_maintainability_rating', 'software_quality_reliability_rating', " +
+ "'software_quality_security_rating', 'software_quality_security_review_rating', 'software_quality_maintainability_remediation_effort', " +
+ "'software_quality_reliability_remediation_effort', 'software_quality_security_remediation_effort', 'effort_to_reach_software_quality_maintainability_rating_a', " +
+ "'new_software_quality_maintainability_debt_ratio', 'new_software_quality_maintainability_rating', 'new_software_quality_reliability_rating', " +
+ "'new_software_quality_security_rating', 'new_software_quality_security_review_rating', 'new_software_quality_maintainability_remediation_effort'," +
+ " 'new_software_quality_reliability_remediation_effort', 'new_software_quality_security_remediation_effort'");
}
}