]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23363 Add impacts to issues/pull endpoint
authorLéo Geoffroy <leo.geoffroy@sonarsource.com>
Wed, 6 Nov 2024 17:03:07 +0000 (18:03 +0100)
committersonartech <sonartech@sonarsource.com>
Mon, 11 Nov 2024 20:02:44 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/issue/ws/pull-example.proto
sonar-ws/src/main/protobuf/ws-issues.proto

index f7a292c13395602ab335f7b9cc74260417a0ec17..2529829b316222d4b22c488cea6cc7cd7c5f80b7 100644 (file)
@@ -24,16 +24,19 @@ import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
+import org.assertj.core.groups.Tuple;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.issue.Issue;
-import org.sonar.db.component.ComponentQualifiers;
+import org.sonar.api.issue.impact.Severity;
+import org.sonar.api.issue.impact.SoftwareQuality;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
+import org.sonar.db.component.ComponentQualifiers;
 import org.sonar.db.component.ProjectData;
-import org.sonar.server.component.ComponentTypesRule;
+import org.sonar.db.issue.ImpactDto;
 import org.sonar.db.issue.IssueDbTester;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.project.ProjectDto;
@@ -42,6 +45,7 @@ import org.sonar.db.protobuf.DbIssues;
 import org.sonar.db.rule.RuleDto;
 import org.sonar.db.user.UserDto;
 import org.sonar.server.component.ComponentFinder;
+import org.sonar.server.component.ComponentTypesRule;
 import org.sonar.server.exceptions.ForbiddenException;
 import org.sonar.server.exceptions.NotFoundException;
 import org.sonar.server.issue.TaintChecker;
@@ -204,7 +208,8 @@ public class PullActionIT {
       .setIssueCreationTime(NOW)
       .setStatus(Issue.STATUS_RESOLVED)
       .setLocations(mainLocation.build())
-      .setType(Common.RuleType.BUG.getNumber()));
+      .setType(Common.RuleType.BUG.getNumber())
+      .replaceAllImpacts(List.of(new ImpactDto().setSoftwareQuality(SoftwareQuality.MAINTAINABILITY).setSeverity(Severity.MEDIUM))));
     loginWithBrowsePermission(issueDto);
 
     TestRequest request = tester.newRequest()
@@ -223,6 +228,8 @@ public class PullActionIT {
     assertThat(issueLite.getResolved()).isTrue();
     assertThat(issueLite.getRuleKey()).isEqualTo("java:S1000");
     assertThat(issueLite.getType()).isEqualTo(Common.RuleType.forNumber(issueDto.getType()));
+    assertThat(issueLite.getImpactsList()).extracting(Common.Impact::getSoftwareQuality, Common.Impact::getSeverity)
+      .containsExactly(Tuple.tuple(Common.SoftwareQuality.MAINTAINABILITY, Common.ImpactSeverity.MEDIUM));
 
     Issues.Location location = issueLite.getMainLocation();
     assertThat(location.getMessage()).isEqualTo(issueDto.getMessage());
@@ -419,7 +426,7 @@ public class PullActionIT {
       .setComponent(correctFile)
       .setType(2));
 
-    //this one should not be returned - it is a different rule repository
+    // this one should not be returned - it is a different rule repository
     issueDbTester.insertIssue(p -> p.setSeverity("MINOR")
       .setManualSeverity(true)
       .setMessage("openIssue")
index 6a0bd2c77747ac09793da4f0bb93734f979a186c..c7d6379cb118ac3471a1d580515a9c390968ac36 100644 (file)
@@ -20,6 +20,7 @@
 package org.sonar.server.issue.ws.pull;
 
 import org.sonar.api.server.ServerSide;
+import org.sonar.core.rule.ImpactFormatter;
 import org.sonar.db.issue.IssueDto;
 import org.sonar.db.protobuf.DbIssues;
 import org.sonar.db.rule.RuleDto;
@@ -70,6 +71,12 @@ public class PullActionProtobufObjectGenerator implements ProtobufObjectGenerato
     issueBuilder.setType(Common.RuleType.forNumber(issueDto.getType()));
     issueBuilder.setClosed(false);
     issueBuilder.setMainLocation(location);
+    issueBuilder.addAllImpacts(issueDto.getEffectiveImpacts().entrySet()
+      .stream().map(entry -> Common.Impact.newBuilder()
+        .setSoftwareQuality(Common.SoftwareQuality.valueOf(entry.getKey().name()))
+        .setSeverity(ImpactFormatter.mapImpactSeverity(entry.getValue()))
+        .build())
+      .toList());
 
     return issueBuilder.build();
   }
index 62358e1afb569eccd20027aa3c1803e31b445e40..e655d31e28d3200423489ff4d77dca64b2ee1d8c 100644 (file)
@@ -12,6 +12,7 @@ message IssueLite {
   optional string type = 6;
   optional Location mainLocation = 7;
   optional bool closed = 8;
+  repeated sonarqube.ws.commons.Impact impacts = 9;
 }
 
 message Location {
@@ -26,4 +27,4 @@ message TextRange {
   optional int32 endLine = 3;
   optional int32 endLineOffset = 4;
   optional string hash = 5;
-}
\ No newline at end of file
+}
index 647d461b2b8ad908e92f9b87926211f0b060d7c9..d7cd1d46f0c61c6999e9d161eb3a1befd8137e39 100644 (file)
@@ -29,9 +29,9 @@ option optimize_for = SPEED;
 // Response of GET api/issues/search
 message SearchWsResponse {
   reserved 5;
-  optional int64 total = 1 [deprecated=true];
-  optional int64 p = 2 [deprecated=true];
-  optional int32 ps = 3 [deprecated=true];
+  optional int64 total = 1 [deprecated = true];
+  optional int64 p = 2 [deprecated = true];
+  optional int32 ps = 3 [deprecated = true];
   optional sonarqube.ws.commons.Paging paging = 4;
 
   // Total amount of effort, only when the facet "total" is enabled
@@ -275,6 +275,7 @@ message IssueLite {
   optional sonarqube.ws.commons.RuleType type = 6;
   optional Location mainLocation = 7;
   optional bool closed = 8;
+  repeated sonarqube.ws.commons.Impact impacts = 9;
 }