From e930060f740d74573323d7baed1bce5937bf4ac6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?L=C3=A9o=20Geoffroy?= Date: Wed, 6 Nov 2024 18:03:07 +0100 Subject: [PATCH] SONAR-23363 Add impacts to issues/pull endpoint --- .../org/sonar/server/issue/ws/PullActionIT.java | 15 +++++++++++---- .../pull/PullActionProtobufObjectGenerator.java | 7 +++++++ .../org/sonar/server/issue/ws/pull-example.proto | 3 ++- sonar-ws/src/main/protobuf/ws-issues.proto | 7 ++++--- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java index f7a292c1339..2529829b316 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/issue/ws/PullActionIT.java @@ -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") diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java index 6a0bd2c7774..c7d6379cb11 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/issue/ws/pull/PullActionProtobufObjectGenerator.java @@ -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(); } diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/issue/ws/pull-example.proto b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/issue/ws/pull-example.proto index 62358e1afb5..e655d31e28d 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/issue/ws/pull-example.proto +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/issue/ws/pull-example.proto @@ -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 +} diff --git a/sonar-ws/src/main/protobuf/ws-issues.proto b/sonar-ws/src/main/protobuf/ws-issues.proto index 647d461b2b8..d7cd1d46f0c 100644 --- a/sonar-ws/src/main/protobuf/ws-issues.proto +++ b/sonar-ws/src/main/protobuf/ws-issues.proto @@ -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; } -- 2.39.5