diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2023-10-05 15:02:23 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-10-12 20:02:51 +0000 |
commit | f450cceab1272d465c8e2e7ddf9ccb0cd869e695 (patch) | |
tree | b1947473153ff45293afe5567d4225519f2c19ca | |
parent | 0d4bba4a5af9f4944446ed7bb847671e068a5201 (diff) | |
download | sonarqube-f450cceab1272d465c8e2e7ddf9ccb0cd869e695.tar.gz sonarqube-f450cceab1272d465c8e2e7ddf9ccb0cd869e695.zip |
SONAR-20607 New isDefault flag on api/qualitygates/show endpoint
4 files changed, 29 insertions, 3 deletions
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 f77091cebf2..3f7fccc0312 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 @@ -44,6 +44,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.AssertionsForClassTypes.tuple; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -258,6 +260,26 @@ public class ShowActionIT { } @Test + public void reponse_should_show_isDefault() { + QualityGateDto defaultQualityGate = db.qualityGates().insertQualityGate(); + db.qualityGates().setDefaultQualityGate(defaultQualityGate); + + ShowWsResponse response = ws.newRequest() + .setParam("name", defaultQualityGate.getName()) + .executeProtobuf(ShowWsResponse.class); + + assertTrue(response.getIsDefault()); + + QualityGateDto nonDefaultQualityGate = db.qualityGates().insertQualityGate(); + + response = ws.newRequest() + .setParam("name", nonDefaultQualityGate.getName()) + .executeProtobuf(ShowWsResponse.class); + + assertFalse(response.getIsDefault()); + } + + @Test public void fail_when_no_name() { QualityGateDto qualityGate = db.qualityGates().insertQualityGate(); 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 8eae80f9445..ddc9e03e4ba 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 @@ -66,6 +66,7 @@ public class ShowAction implements QualityGatesWsAction { .setSince("4.3") .setResponseExample(Resources.getResource(this.getClass(), "show-example.json")) .setChangelog( + new Change("10.3", "'isDefault' field is added to the response"), new Change("10.0", "Field 'id' in the response has been removed"), new Change("10.0", "Parameter 'id' is removed. Use 'name' instead."), new Change("9.9", "'caycStatus' field is added to the response"), @@ -110,6 +111,7 @@ public class ShowAction implements QualityGatesWsAction { return ShowWsResponse.newBuilder() .setName(qualityGate.getName()) .setIsBuiltIn(qualityGate.isBuiltIn()) + .setIsDefault(qualityGate.getUuid().equals(defaultQualityGate.getUuid())) .setCaycStatus(caycStatus.toString()) .addAllConditions(conditions.stream() .map(toWsCondition(metricsByUuid)) 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 c960640c619..1275a4bbe13 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 @@ -15,6 +15,7 @@ } ], "isBuiltIn": false, + "isDefault": false, "actions": { "rename": true, "setAsDefault": true, diff --git a/sonar-ws/src/main/protobuf/ws-qualitygates.proto b/sonar-ws/src/main/protobuf/ws-qualitygates.proto index 261f82f1b79..4da1680ba7a 100644 --- a/sonar-ws/src/main/protobuf/ws-qualitygates.proto +++ b/sonar-ws/src/main/protobuf/ws-qualitygates.proto @@ -120,11 +120,12 @@ message UpdateConditionResponse { // GET api/qualitygates/show message ShowWsResponse { optional string id = 1; - optional string name = 2; + required string name = 2; repeated Condition conditions = 3; - optional bool isBuiltIn = 4; + required bool isBuiltIn = 4; optional Actions actions = 5; - optional string caycStatus = 6; + required string caycStatus = 6; + required bool isDefault = 7; message Condition { required string id = 1; |