]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20548 added clean code taxonomy data to /api/qualityprofiles/changelog
authorlukasz-jarocki-sonarsource <lukasz.jarocki@sonarsource.com>
Sun, 1 Oct 2023 09:51:02 +0000 (11:51 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 10 Oct 2023 20:02:44 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualityprofile/ws/ChangelogActionIT.java
server/sonar-webserver-webapi/src/it/resources/org/sonar/server/qualityprofile/ws/ChangelogActionIT/changelog_example.json
server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualityprofile/ws/ChangelogAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualityprofile/ws/changelog-example.json

index 7d282d04319ecba8e211c0f79df4b9fce87d50d7..48c1bf734f136cb054fe3867c41031a8b8a3c216 100644 (file)
@@ -96,6 +96,13 @@ public class ChangelogActionIT {
       "      \"action\": \"ACTIVATED\",\n" +
       "      \"ruleKey\": \"" + rule.getKey() + "\",\n" +
       "      \"ruleName\": \"" + rule.getName() + "\",\n" +
+      "      \"cleanCodeAttributeCategory\": \"INTENTIONAL\",\n" +
+      "      \"impacts\": [\n" +
+      "        {\n" +
+      "          \"softwareQuality\": \"MAINTAINABILITY\",\n" +
+      "          \"severity\": \"HIGH\"\n" +
+      "        }\n" +
+      "      ]," +
       "      \"params\": {\n" +
       "        \"severity\": \"MINOR\",\n" +
       "        \"bar\": \"bar_value\",\n" +
@@ -345,7 +352,7 @@ public class ChangelogActionIT {
     insertChange(c -> c.setRulesProfileUuid(profileUuid)
       .setUserUuid(user3.getUuid())
       .setChangeType(ActiveRuleChange.Type.ACTIVATED.name())
-      .setData(ImmutableMap.of("severity", "MAJOR", "param_format", "^[A-Z][a-zA-Z0-9]*$", "ruleUuid", rule3.getUuid())));
+      .setData(ImmutableMap.of("severity", "MAJOR", "param_format", "^[A-Z][a-zA-Z0-9]*", "ruleUuid", rule3.getUuid())));
 
     ws.newRequest()
       .setMethod("GET")
index c40c1bb7f3231910d1683513a87e515259e8fbd4..5dd8fcdd761e30c0ed0b9827186bf9085a49c2ee 100644 (file)
       "authorName" : "Anakin Skywalker",
       "ruleKey" : "java:S2438",
       "ruleName" : "\"Threads\" should not be used where \"Runnables\" are expected",
+      "cleanCodeAttributeCategory": "INTENTIONAL",
+      "impacts": [
+        {
+          "softwareQuality": "MAINTAINABILITY",
+          "severity": "HIGH"
+        }
+      ],
       "params" : {
         "severity" : "CRITICAL"
       }
       "authorLogin" : "padme.amidala",
       "authorName" : "Padme Amidala",
       "ruleKey" : "java:S2162",
-      "ruleName" : "\"equals\" methods should be symmetric and work for subclasses"
+      "ruleName" : "\"equals\" methods should be symmetric and work for subclasses",
+      "cleanCodeAttributeCategory": "INTENTIONAL",
+      "impacts": [
+        {
+          "softwareQuality": "MAINTAINABILITY",
+          "severity": "HIGH"
+        }
+      ],
+      "params" : {}
     },
     {
       "action" : "ACTIVATED",
       "ruleKey" : "java:S00101",
       "ruleName" : "Class names should comply with a naming convention",
       "date" : "2014-09-12T15:20:46+0200",
+      "cleanCodeAttributeCategory": "INTENTIONAL",
+      "impacts": [
+        {
+          "softwareQuality": "MAINTAINABILITY",
+          "severity": "HIGH"
+        }
+      ],
       "params" : {
         "severity" : "MAJOR",
-        "format" : "^[A-Z][a-zA-Z0-9]*$"
+        "format" : "^[A-Z][a-zA-Z0-9]*"
       }
     }
   ]
index 57b3a8b902b30fc6cb3a112e51fa906f24fd110f..b349bcaa2e594ef820a435948974123012c92a86 100644 (file)
@@ -39,6 +39,7 @@ import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.text.JsonWriter;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
+import org.sonar.db.issue.ImpactDto;
 import org.sonar.db.qualityprofile.QProfileChangeDto;
 import org.sonar.db.qualityprofile.QProfileChangeQuery;
 import org.sonar.db.qualityprofile.QProfileDto;
@@ -71,7 +72,8 @@ public class ChangelogAction implements QProfileWsAction {
         "Events are ordered by date in descending order (most recent first).")
       .setChangelog(
         new org.sonar.api.server.ws.Change("9.8", "response fields 'total', 's', 'ps' have been deprecated, please use 'paging' object instead"),
-        new org.sonar.api.server.ws.Change("9.8", "The field 'paging' has been added to the response"))
+        new org.sonar.api.server.ws.Change("9.8", "The field 'paging' has been added to the response"),
+        new org.sonar.api.server.ws.Change("10.3", "Added fields 'cleanCodeAttributeCategory' and 'impacts' to response"))
       .setHandler(this)
       .setResponseExample(getClass().getResource("changelog-example.json"));
 
@@ -166,6 +168,23 @@ public class ChangelogAction implements QProfileWsAction {
         changeWriter
           .prop("ruleKey", rule.getKey().toString())
           .prop("ruleName", rule.getName());
+
+        if (rule.getCleanCodeAttribute() != null) {
+          changeWriter
+            .prop("cleanCodeAttributeCategory", rule.getCleanCodeAttribute().getAttributeCategory().toString());
+        }
+        changeWriter
+          .name("impacts")
+          .beginArray();
+        for (ImpactDto impact : rule.getDefaultImpacts()) {
+          changeWriter
+            .beginObject()
+            .prop("softwareQuality", impact.getSoftwareQuality().toString())
+            .prop("severity", impact.getSeverity().toString())
+            .endObject();
+        }
+
+        changeWriter.endArray();
       }
       writeParameters(json, change);
       json.endObject();
index 0bf3a77442edc5c77019e5a29dd8bf74a07a1bdc..057563b29444739eb89f92ceb59f673d0776e719 100644 (file)
       "authorName" : "Anakin Skywalker",
       "ruleKey" : "java:S2438",
       "ruleName" : "\"Threads\" should not be used where \"Runnables\" are expected",
+      "cleanCodeAttributeCategory": "INTENTIONAL",
+      "impacts": [
+        {
+          "softwareQuality": "RELIABILITY",
+          "severity": "LOW"
+        },
+        {
+          "softwareQuality": "SECURITY",
+          "severity": "HIGH"
+        }
+      ],
       "params" : {
         "severity" : "CRITICAL"
       }
       "authorLogin" : "padme.amidala",
       "authorName" : "Padme Amidala",
       "ruleKey" : "java:S2162",
-      "ruleName" : "\"equals\" methods should be symmetric and work for subclasses"
+      "ruleName" : "\"equals\" methods should be symmetric and work for subclasses",
+      "cleanCodeAttributeCategory": "INTENTIONAL",
+      "impacts": [
+        {
+          "softwareQuality": "RELIABILITY",
+          "severity": "LOW"
+        },
+        {
+          "softwareQuality": "SECURITY",
+          "severity": "HIGH"
+        }
+      ]
     },
     {
       "action" : "ACTIVATED",
       "authorName" : "Obiwan Kenobi",
       "ruleKey" : "java:S00101",
       "ruleName" : "Class names should comply with a naming convention",
+      "cleanCodeAttributeCategory": "INTENTIONAL",
+      "impacts": [
+        {
+          "softwareQuality": "RELIABILITY",
+          "severity": "LOW"
+        },
+        {
+          "softwareQuality": "SECURITY",
+          "severity": "HIGH"
+        }
+      ],
       "date" : "2014-09-12T15:20:46+0200",
       "params" : {
         "severity" : "MAJOR",