diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2024-12-10 15:09:12 +0100 |
---|---|---|
committer | Steve Marion <steve.marion@sonarsource.com> | 2024-12-18 11:13:24 +0100 |
commit | 75aac2d1e297a1e2d409507b56912ffcdd533964 (patch) | |
tree | 6faf091cacb299836cb8f6d27b1e199e26a739b3 /server/sonar-webserver-webapi | |
parent | 370b64459c4b6bcd1a1fd615cf370ff24cb00e37 (diff) | |
download | sonarqube-75aac2d1e297a1e2d409507b56912ffcdd533964.tar.gz sonarqube-75aac2d1e297a1e2d409507b56912ffcdd533964.zip |
SONAR-23893 Update quality gate search endpoint to return containsAiCode field
Diffstat (limited to 'server/sonar-webserver-webapi')
2 files changed, 10 insertions, 23 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SearchActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SearchActionIT.java index ab7887753b7..a6af513679b 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SearchActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/SearchActionIT.java @@ -19,13 +19,11 @@ */ package org.sonar.server.qualitygate.ws; -import java.util.stream.Stream; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; import org.sonar.api.server.ws.WebService; import org.sonar.db.DbClient; import org.sonar.db.DbTester; @@ -300,13 +298,12 @@ class SearchActionIT { } @ParameterizedTest - @MethodSource("aiCodeAssuranceParams") - void return_ai_code_assurance(boolean containsAiCode, boolean aiCodeSupportedByQg, AiCodeAssurance expected) { - QualityGateDto qualityGate = db.qualityGates().insertQualityGate(qg -> qg.setAiCodeSupported(aiCodeSupportedByQg)); + @ValueSource(booleans = {true, false}) + void return_ai_code_assurance(boolean containsAiCode) { + QualityGateDto qualityGate = db.qualityGates().insertQualityGate(); ProjectDto project = db.components().insertPublicProject(componentDto -> componentDto.setName("proj1"), projectDto -> projectDto.setContainsAiCode(containsAiCode)).getProjectDto(); db.qualityGates().associateProjectToQualityGate(project, qualityGate); - when(aiCodeAssuranceVerifier.getAiCodeAssurance(project.getContainsAiCode(), qualityGate.isAiCodeSupported())).thenReturn(expected); SearchResponse response = ws.newRequest() .setParam(PARAM_GATE_NAME, valueOf(qualityGate.getName())) @@ -314,18 +311,9 @@ class SearchActionIT { .executeProtobuf(SearchResponse.class); assertThat(response.getResultsList()) - .extracting(Result::getName, Result::getKey, result -> result.getAiCodeAssurance().name()) + .extracting(Result::getName, Result::getKey, Result::getContainsAiCode) .containsExactlyInAnyOrder( - tuple(project.getName(), project.getKey(), expected.name())); - } - - private static Stream<Arguments> aiCodeAssuranceParams() { - return Stream.of( - Arguments.of(false, false, AiCodeAssurance.NONE), - Arguments.of(false, true, AiCodeAssurance.NONE), - Arguments.of(true, false, AiCodeAssurance.CONTAINS_AI_CODE), - Arguments.of(true, true, AiCodeAssurance.AI_CODE_ASSURED) - ); + tuple(project.getName(), project.getKey(), containsAiCode)); } @Test diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java index ec000ac70f5..eae38d6b605 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/SearchAction.java @@ -36,7 +36,6 @@ import org.sonar.db.qualitygate.QualityGateDto; import org.sonar.server.ai.code.assurance.AiCodeAssuranceVerifier; import org.sonar.server.user.UserSession; import org.sonarqube.ws.Qualitygates; -import org.sonarqube.ws.Qualitygates.SearchResponse.AiCodeAssurance; import static org.sonar.api.server.ws.WebService.Param.SELECTED; import static org.sonar.api.utils.Paging.forPageIndex; @@ -70,6 +69,9 @@ public class SearchAction implements QualityGatesWsAction { .setSince("4.3") .setResponseExample(Resources.getResource(this.getClass(), "search-example.json")) .setChangelog( + new Change("2025.1", "Field 'containsAiCode' response field has added."), + new Change("2025.1", "Field 'isAiCodeAssured' response field has been removed."), + new Change("2025.1", "Field 'aiCodeAssurance' response field has been removed."), new Change("10.8", "Field 'isAiCodeAssured' response field has been deprecated. Use 'aiCodeAssurance' instead."), new Change("10.8", "New field 'aiCodeAssurance' in the response."), new Change("10.0", "deprecated 'more' response field has been removed"), @@ -137,14 +139,11 @@ public class SearchAction implements QualityGatesWsAction { .build(); for (ProjectQgateAssociationDto project : paginatedProjects) { - AiCodeAssurance aiCodeAssurance = AiCodeAssurance.valueOf(aiCodeAssuranceVerifier.getAiCodeAssurance(project.getContainsAiCode(), - project.isAiCodeSupportedByQg()).name()); createResponse.addResultsBuilder() .setName(project.getName()) .setKey(project.getKey()) .setSelected(project.getGateUuid() != null) - .setIsAiCodeAssured(AiCodeAssurance.AI_CODE_ASSURED.equals(aiCodeAssurance)) - .setAiCodeAssurance(aiCodeAssurance); + .setContainsAiCode(project.getContainsAiCode()); } writeProtobuf(createResponse.build(), request, response); |