From 04d38e931b0aa44cfb3d228205b9d907bd0cf194 Mon Sep 17 00:00:00 2001 From: =?utf8?q?L=C3=A9o=20Geoffroy?= Date: Wed, 13 Nov 2024 15:13:51 +0100 Subject: [PATCH] SONAR-23537 Add MQR mode metric to project badges --- .../sonar/server/badge/ws/MeasureAction.java | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java index e9f3b337c94..e796b444de8 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/badge/ws/MeasureAction.java @@ -51,9 +51,16 @@ import static org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY; import static org.sonar.api.measures.CoreMetrics.TECHNICAL_DEBT_KEY; import static org.sonar.api.measures.CoreMetrics.VULNERABILITIES_KEY; import static org.sonar.api.measures.Metric.Level; +import static org.sonar.api.measures.Metric.ValueType; import static org.sonar.api.measures.Metric.Level.ERROR; import static org.sonar.api.measures.Metric.Level.OK; -import static org.sonar.api.measures.Metric.ValueType; +import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_ISSUES_KEY; +import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY; +import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_MAINTAINABILITY_REMEDIATION_EFFORT_KEY; +import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_RELIABILITY_ISSUES_KEY; +import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_RELIABILITY_RATING_KEY; +import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_ISSUES_KEY; +import static org.sonar.core.metric.SoftwareQualitiesMetrics.SOFTWARE_QUALITY_SECURITY_RATING_KEY; import static org.sonar.server.badge.ws.SvgFormatter.formatDuration; import static org.sonar.server.badge.ws.SvgFormatter.formatNumeric; import static org.sonar.server.badge.ws.SvgFormatter.formatPercent; @@ -68,21 +75,32 @@ public class MeasureAction extends AbstractProjectBadgesWsAction { private static final String PARAM_METRIC = "metric"; private static final Map METRIC_NAME_BY_KEY = ImmutableMap.builder() - .put(BUGS_KEY, "bugs") - .put(CODE_SMELLS_KEY, "code smells") .put(COVERAGE_KEY, "coverage") .put(DUPLICATED_LINES_DENSITY_KEY, "duplicated lines") .put(NCLOC_KEY, "lines of code") - .put(SQALE_RATING_KEY, "maintainability") .put(ALERT_STATUS_KEY, "quality gate") - .put(RELIABILITY_RATING_KEY, "reliability") .put(SECURITY_HOTSPOTS_KEY, "security hotspots") + + // Standard mode + .put(BUGS_KEY, "bugs") + .put(CODE_SMELLS_KEY, "code smells") + .put(VULNERABILITIES_KEY, "vulnerabilities") + .put(SQALE_RATING_KEY, "maintainability") + .put(RELIABILITY_RATING_KEY, "reliability") .put(SECURITY_RATING_KEY, "security") .put(TECHNICAL_DEBT_KEY, "technical debt") - .put(VULNERABILITIES_KEY, "vulnerabilities") + + // MQR mode + .put(SOFTWARE_QUALITY_RELIABILITY_ISSUES_KEY, "reliability issues") + .put(SOFTWARE_QUALITY_MAINTAINABILITY_ISSUES_KEY, "maintainability issues") + .put(SOFTWARE_QUALITY_SECURITY_ISSUES_KEY, "security issues") + .put(SOFTWARE_QUALITY_MAINTAINABILITY_RATING_KEY, "maintainability") + .put(SOFTWARE_QUALITY_RELIABILITY_RATING_KEY, "reliability") + .put(SOFTWARE_QUALITY_SECURITY_RATING_KEY, "security") + .put(SOFTWARE_QUALITY_MAINTAINABILITY_REMEDIATION_EFFORT_KEY, "technical debt") .build(); - private static final String[] DEPRECATED_METRIC_KEYS = {BUGS_KEY, CODE_SMELLS_KEY, SECURITY_HOTSPOTS_KEY, VULNERABILITIES_KEY}; + private static final String[] UNDEPRECATED_METRIC_KEYS = {BUGS_KEY, CODE_SMELLS_KEY, SECURITY_HOTSPOTS_KEY, VULNERABILITIES_KEY}; private static final Map QUALITY_GATE_MESSAGE_BY_STATUS = new EnumMap<>(Map.of( OK, "passed", @@ -113,8 +131,10 @@ public class MeasureAction extends AbstractProjectBadgesWsAction { .setDescription("Generate badge for project's measure as an SVG.
" + "Requires 'Browse' permission on the specified project.") .setSince("7.1") + .setChangelog(new Change("10.8", format("The following metric keys are not deprecated anymore: %s", String.join(", ", + UNDEPRECATED_METRIC_KEYS)))) .setChangelog(new Change("10.4", format("The following metric keys are now deprecated: %s", String.join(", ", - DEPRECATED_METRIC_KEYS)))) + UNDEPRECATED_METRIC_KEYS)))) .setResponseExample(Resources.getResource(getClass(), "measure-example.svg")); support.addProjectAndBranchParams(action); action.createParam(PARAM_METRIC) -- 2.39.5