diff options
9 files changed, 66 insertions, 10 deletions
diff --git a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java index a953a97d098..86a7694729f 100644 --- a/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java +++ b/server/sonar-db-dao/src/it/java/org/sonar/db/qualitygate/QualityGateDaoIT.java @@ -78,6 +78,15 @@ class QualityGateDaoIT { } @Test + void insert_ai_code_supported() { + underTest.insert(db.getSession(), new QualityGateDto().setName("test").setAiCodeSupported(true)); + + QualityGateDto reloaded = underTest.selectByName(db.getSession(), "test"); + + assertThat(reloaded.isAiCodeSupported()).isTrue(); + } + + @Test void select_all() { QualityGateDto qualityGate1 = qualityGateDbTester.insertQualityGate(); QualityGateDto qualityGate2 = qualityGateDbTester.insertQualityGate(); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml index 2036ff7ac4d..a91ed6cb8d3 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/qualitygate/QualityGateMapper.xml @@ -14,8 +14,9 @@ </sql> <insert id="insertQualityGate" parameterType="QualityGate" useGeneratedKeys="false"> - insert into quality_gates (uuid, name, is_built_in, created_at, updated_at) - values (#{uuid, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{isBuiltIn, jdbcType=BOOLEAN}, #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}) + insert into quality_gates (uuid, name, is_built_in, ai_code_supported, created_at, updated_at) + values (#{uuid, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{isBuiltIn, jdbcType=BOOLEAN}, #{aiCodeSupported, jdbcType=BOOLEAN}, + #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}) </insert> <select id="selectAll" resultType="QualityGate"> @@ -89,6 +90,7 @@ update quality_gates set name=#{name}, is_built_in=#{isBuiltIn, jdbcType=BOOLEAN}, + ai_code_supported=#{aiCodeSupported, jdbcType=BOOLEAN}, updated_at=#{updatedAt, jdbcType=TIMESTAMP} where uuid=#{uuid, jdbcType=VARCHAR} </update> 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 } diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto index e7de5d25138..3895e02c57d 100644 --- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto +++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto @@ -128,6 +128,7 @@ message ShowWsResponse { required bool isDefault = 7; optional bool hasStandardConditions = 8; optional bool hasMQRConditions = 9; + optional bool isAiCodeSupported = 10; message Condition { required string id = 1; @@ -167,6 +168,7 @@ message ListWsResponse { optional string caycStatus = 6; optional bool hasStandardConditions = 7; optional bool hasMQRConditions = 8; + optional bool isAiCodeSupported = 9; } message RootActions { |