]> source.dussan.org Git - sonarqube.git/commitdiff
CODEFIX-187 set isAiCodeFixEnabled field in SearchProjectsAction response (#12280)
authorSerhat Yenican <104850907+serhat-yenican-sonarsource@users.noreply.github.com>
Mon, 18 Nov 2024 14:56:00 +0000 (15:56 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 19 Nov 2024 20:02:53 +0000 (20:02 +0000)
server/sonar-webserver-webapi/src/it/java/org/sonar/server/component/ws/SearchProjectsActionIT.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ws/SearchProjectsAction.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/component/ws/search_projects-example.json

index 835742ee1b879d97555cceaaa9e2cb3dc980e304..161b5d2f7e7bde2c4f47979c98d09389df3a708b 100644 (file)
@@ -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;
@@ -1393,6 +1393,24 @@ public class SearchProjectsActionIT {
         tuple(project.getKey(), aiCodeAssured));
   }
 
+  @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();
index 9afdc59ebeb47878f7e54895a46ada87e5afdafe..1dd787393eb2dfe165128dc50f888da5c86a523c 100644 (file)
@@ -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;
index f888de5a7025c450db04c4b10726a680c5fc2226..1f87a9c776f65eb383c93365f115a235634627bc 100644 (file)
@@ -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": [