diff options
author | Jacek Poreda <jacek.poreda@sonarsource.com> | 2024-11-21 11:24:55 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-11-29 20:03:06 +0000 |
commit | ef4ed37bdfa1b2591a6d1b1df259384bf0270713 (patch) | |
tree | fae26e1427a924b2367338308b3a79e2eb9fbeb4 /server/sonar-webserver-webapi | |
parent | 9fd8ce023c13cca6b645a8af40683da66cae43aa (diff) | |
download | sonarqube-ef4ed37bdfa1b2591a6d1b1df259384bf0270713.tar.gz sonarqube-ef4ed37bdfa1b2591a6d1b1df259384bf0270713.zip |
SONAR-23619 Add 'isAiCodeSupported' flag to show and list endpoints of Quality Gates
Diffstat (limited to 'server/sonar-webserver-webapi')
6 files changed, 51 insertions, 8 deletions
diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ListActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ListActionIT.java index c832973660b..8628a153f26 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ListActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ListActionIT.java @@ -113,6 +113,22 @@ public class ListActionIT { } @Test + public void test_ai_code_supported_flag() { + QualityGateDto qualityGateWithAiCodeSupported = db.qualityGates().insertQualityGate(qg -> qg.setAiCodeSupported(true)); + QualityGateDto qualityGateWithoutAiCodeSupported = db.qualityGates().insertQualityGate(qg -> qg.setAiCodeSupported(false)); + db.qualityGates().setDefaultQualityGate(qualityGateWithAiCodeSupported); + + ListWsResponse response = ws.newRequest() + .executeProtobuf(ListWsResponse.class); + + assertThat(response.getQualitygatesList()) + .extracting(QualityGate::getName, QualityGate::getIsAiCodeSupported) + .containsExactlyInAnyOrder( + tuple(qualityGateWithAiCodeSupported.getName(), true), + tuple(qualityGateWithoutAiCodeSupported.getName(), false)); + } + + @Test public void test_caycStatus_flag() { QualityGateDto qualityGate1 = db.qualityGates().insertQualityGate(); QualityGateConditionDto condition1 = db.qualityGates().addCondition(qualityGate1, db.measures().insertMetric()); @@ -177,7 +193,7 @@ public class ListActionIT { assertThatThrownBy(() -> ws.newRequest() .executeProtobuf(ListWsResponse.class)) - .isInstanceOf(IllegalStateException.class); + .isInstanceOf(IllegalStateException.class); } diff --git a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ShowActionIT.java b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ShowActionIT.java index 4393492c7fd..37d5b0f5d91 100644 --- a/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ShowActionIT.java +++ b/server/sonar-webserver-webapi/src/it/java/org/sonar/server/qualitygate/ws/ShowActionIT.java @@ -115,6 +115,26 @@ public class ShowActionIT { } @Test + public void show_ai_code_supported() { + QualityGateDto qualityGate = db.qualityGates().insertQualityGate(); + db.qualityGates().setDefaultQualityGate(qualityGate); + + QualityGateDto qualityGateWithAiCodeSupported = db.qualityGates().insertQualityGate(qg -> qg.setAiCodeSupported(true)); + QualityGateDto qualityGateWithoutAiCodeSupported = db.qualityGates().insertQualityGate(qg -> qg.setAiCodeSupported(false)); + + ShowWsResponse responseWithAiCodeAssurance = ws.newRequest() + .setParam("name", qualityGateWithAiCodeSupported.getName()) + .executeProtobuf(ShowWsResponse.class); + + ShowWsResponse responseWithoutAiCodeAssurance = ws.newRequest() + .setParam("name", qualityGateWithoutAiCodeSupported.getName()) + .executeProtobuf(ShowWsResponse.class); + + assertThat(responseWithAiCodeAssurance.getIsAiCodeSupported()).isTrue(); + assertThat(responseWithoutAiCodeAssurance.getIsAiCodeSupported()).isFalse(); + } + + @Test public void show_isCaycCompliant() { QualityGateDto qualityGate = db.qualityGates().insertQualityGate(); when(qualityGateCaycChecker.checkCaycCompliant(any(DbSession.class), eq(qualityGate.getUuid()))).thenReturn(COMPLIANT); @@ -320,8 +340,8 @@ public class ShowActionIT { assertThatThrownBy(() -> ws.newRequest() .setParam("name", qualityGate.getName()) .execute()) - .isInstanceOf(IllegalStateException.class) - .hasMessageContaining(format("Could not find metric with id %s", metric.getUuid())); + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining(format("Could not find metric with id %s", metric.getUuid())); } @Test @@ -331,8 +351,8 @@ public class ShowActionIT { assertThatThrownBy(() -> ws.newRequest() .setParam("name", "UNKNOWN") .execute()) - .isInstanceOf(NotFoundException.class) - .hasMessageContaining("No quality gate has been found for name UNKNOWN"); + .isInstanceOf(NotFoundException.class) + .hasMessageContaining("No quality gate has been found for name UNKNOWN"); } @Test diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java index e9cebcf1ef3..860ecb5163f 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ListAction.java @@ -66,6 +66,7 @@ public class ListAction implements QualityGatesWsAction { .setSince("4.3") .setResponseExample(Resources.getResource(this.getClass(), "list-example.json")) .setChangelog( + new Change("10.8", "'isAiCodeSupported' field is added on quality gate"), new Change("10.8", "'hasMQRConditions' and 'hasStandardConditions' fields are added on quality gate"), new Change("10.0", "Field 'default' in the response has been removed"), new Change("10.0", "Field 'id' in the response has been removed"), @@ -101,6 +102,7 @@ public class ListAction implements QualityGatesWsAction { .setName(qualityGate.getName()) .setIsDefault(qualityGate.getUuid().equals(defaultUuid)) .setIsBuiltIn(qualityGate.isBuiltIn()) + .setIsAiCodeSupported(qualityGate.isAiCodeSupported()) .setCaycStatus(qualityGateCaycChecker.checkCaycCompliant(conditions, metrics).toString()) .setHasMQRConditions(qualityModeResult.hasMQRConditions()) .setHasStandardConditions(qualityModeResult.hasStandardConditions()) diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java index 915c6fde52f..14ea0695d4b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/qualitygate/ws/ShowAction.java @@ -70,6 +70,7 @@ public class ShowAction implements QualityGatesWsAction { .setSince("4.3") .setResponseExample(Resources.getResource(this.getClass(), "show-example.json")) .setChangelog( + new Change("10.8", "'isAiCodeSupported' field is added on quality gate"), new Change("10.8", "'hasMQRConditions' and 'hasStandardConditions' fields are added on quality gate"), new Change("10.3", "'isDefault' field is added to the response"), new Change("10.0", "Field 'id' in the response has been removed"), @@ -118,6 +119,7 @@ public class ShowAction implements QualityGatesWsAction { return ShowWsResponse.newBuilder() .setName(qualityGate.getName()) .setIsBuiltIn(qualityGate.isBuiltIn()) + .setIsAiCodeSupported(qualityGate.isAiCodeSupported()) .setIsDefault(qualityGate.getUuid().equals(defaultQualityGate.getUuid())) .setCaycStatus(caycStatus.toString()) .setHasMQRConditions(qualityModeResult.hasMQRConditions()) diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json index c21ffa6327c..62345af6717 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/list-example.json @@ -15,7 +15,8 @@ }, "caycStatus": "compliant", "hasStandardConditions": false, - "hasMQRConditions": false + "hasMQRConditions": false, + "isAiCodeSupported": false }, { "name": "Sonar way - Without Coverage", @@ -32,7 +33,8 @@ }, "caycStatus": "non-compliant", "hasStandardConditions": false, - "hasMQRConditions": false + "hasMQRConditions": false, + "isAiCodeSupported": false } ], "actions": { diff --git a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/show-example.json b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/show-example.json index 1275a4bbe13..67a1cf3455d 100644 --- a/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/show-example.json +++ b/server/sonar-webserver-webapi/src/main/resources/org/sonar/server/qualitygate/ws/show-example.json @@ -25,5 +25,6 @@ "manageConditions": true, "delegate": true }, - "caycStatus": "non-compliant" + "caycStatus": "non-compliant", + "isAiCodeSupported": false } |