diff options
author | Serhat Yenican <104850907+serhat-yenican-sonarsource@users.noreply.github.com> | 2024-11-18 15:56:00 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-11-19 20:02:53 +0000 |
commit | 045816274ba0f5a3ae1984ce06356caac8ff29df (patch) | |
tree | 206e89cc130085b6657aeca33b8a25453277ed0c /server | |
parent | e355b1927914aec7e22b4c3da98d9e75c48a57d5 (diff) | |
download | sonarqube-045816274ba0f5a3ae1984ce06356caac8ff29df.tar.gz sonarqube-045816274ba0f5a3ae1984ce06356caac8ff29df.zip |
CODEFIX-187 set isAiCodeFixEnabled field in SearchProjectsAction response (#12280)
Diffstat (limited to 'server')
3 files changed, 30 insertions, 10 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java index 835742ee1b8..161b5d2f7e7 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java @@ -37,7 +37,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import org.sonar.api.measures.Metric; -import org.sonar.db.component.ComponentQualifiers; import org.sonar.api.server.ws.WebService; import org.sonar.api.server.ws.WebService.Param; import org.sonar.api.utils.System2; @@ -48,6 +47,7 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; 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.db.entity.EntityDto; import org.sonar.db.measure.MeasureDto; @@ -1394,6 +1394,24 @@ public class SearchProjectsActionIT { } @Test + @DataProvider({"true", "false"}) + public void return_ai_codefix_enabled(Boolean isEnabled) { + userSession.logIn(); + ProjectDto project = db.components().insertPublicProject(componentDto -> componentDto.setName("proj_A"), + projectDto -> { + projectDto.setAiCodeFixEnabled(isEnabled); + }).getProjectDto(); + authorizationIndexerTester.allowOnlyAnyone(project); + index(); + + SearchProjectsWsResponse result = call(request); + + assertThat(result.getComponentsList()).extracting(Component::getKey, Component::getIsAiCodeFixEnabled) + .containsExactly( + tuple(project.getKey(), isEnabled)); + } + + @Test public void does_not_return_branches() { ProjectDto project = db.components().insertPublicProject().getProjectDto(); authorizationIndexerTester.allowOnlyAnyone(project); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java index 9afdc59ebeb..1dd787393eb 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java @@ -40,7 +40,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import org.sonar.db.component.ComponentQualifiers; import org.sonar.api.server.ws.Change; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; @@ -52,12 +51,13 @@ import org.sonar.core.platform.PlatformEditionProvider; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.BranchDto; +import org.sonar.db.component.ComponentQualifiers; import org.sonar.db.component.SnapshotDto; import org.sonar.db.project.ProjectDto; import org.sonar.db.property.PropertyDto; import org.sonar.db.property.PropertyQuery; -import org.sonar.server.ai.code.assurance.AiCodeAssuranceVerifier; import org.sonar.db.user.TokenType; +import org.sonar.server.ai.code.assurance.AiCodeAssuranceVerifier; import org.sonar.server.component.ws.FilterParser.Criterion; import org.sonar.server.component.ws.SearchProjectsAction.SearchResults.SearchResultsBuilder; import org.sonar.server.es.Facets; @@ -489,7 +489,8 @@ public class SearchProjectsAction implements ComponentsWsAction { .setName(dbProject.getName()) .setQualifier(dbProject.getQualifier()) .setVisibility(Visibility.getLabel(dbProject.isPrivate())) - .setIsAiCodeAssured(aiCodeAssuranceVerifier.isAiCodeAssured(dbProject)); + .setIsAiCodeAssured(aiCodeAssuranceVerifier.isAiCodeAssured(dbProject)) + .setIsAiCodeFixEnabled(dbProject.getAiCodeFixEnabled()); wsComponent.getTagsBuilder().addAllTags(dbProject.getTags()); SnapshotDto snapshotDto = analysisByProjectUuid.get(dbProject.getUuid()); @@ -513,7 +514,6 @@ public class SearchProjectsAction implements ComponentsWsAction { return wsComponent.build(); } - } public static class SearchResults { @@ -525,8 +525,7 @@ public class SearchProjectsAction implements ComponentsWsAction { private final ProjectMeasuresQuery query; private final int total; - private SearchResults(List<ProjectDto> projects, Set<String> favoriteProjectUuids, SearchIdResult<String> searchResults, Map<String, - SnapshotDto> analysisByProjectUuid, + private SearchResults(List<ProjectDto> projects, Set<String> favoriteProjectUuids, SearchIdResult<String> searchResults, Map<String, SnapshotDto> analysisByProjectUuid, Map<String, Long> applicationsLeakPeriods, ProjectMeasuresQuery query) { this.projects = projects; this.favoriteProjectUuids = favoriteProjectUuids; diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json index f888de5a702..1f87a9c776f 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json @@ -15,7 +15,8 @@ "java" ], "visibility": "public", - "isAiCodeAssured": false + "isAiCodeAssured": false, + "isAiCodeFixEnabled": false }, { "key": "another_project", @@ -24,7 +25,8 @@ "isFavorite": false, "tags": [], "visibility": "public", - "isAiCodeAssured": false + "isAiCodeAssured": false, + "isAiCodeFixEnabled": false }, { "key": "third_project", @@ -37,7 +39,8 @@ "java" ], "visibility": "public", - "isAiCodeAssured": false + "isAiCodeAssured": false, + "isAiCodeFixEnabled": false } ], "facets": [ |