package org.sonar.server.qualitygate.ws;
import com.google.common.io.Resources;
+import org.sonar.api.server.ws.Change;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.db.qualitygate.QualityGateDto;
import org.sonar.server.qualitygate.QualityGates;
+import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_ID;
+import static org.sonarqube.ws.client.qualitygate.QualityGatesWsParameters.PARAM_NAME;
+
public class ListAction implements QualityGatesWsAction {
private final QualityGates qualityGates;
.setDescription("Get a list of quality gates")
.setSince("4.3")
.setResponseExample(Resources.getResource(this.getClass(), "example-list.json"))
+ .setChangelog(
+ new Change("7.0", "'isDefault' field is added on quality gate level"),
+ new Change("7.0", "'default' field on root level is deprecated"))
.setHandler(this);
}
@Override
public void handle(Request request, Response response) {
try (JsonWriter writer = response.newJsonWriter()) {
+ QualityGateDto defaultQgate = qualityGates.getDefault();
+ Long defaultQgateId = defaultQgate == null ? null : defaultQgate.getId();
writer.beginObject().name("qualitygates").beginArray();
- for (QualityGateDto qgate : qualityGates.list()) {
- QualityGatesWs.writeQualityGate(qgate, writer);
+ for (QualityGateDto qualityGate : qualityGates.list()) {
+ writer.beginObject()
+ .prop(PARAM_ID, qualityGate.getId())
+ .prop(PARAM_NAME, qualityGate.getName())
+ .prop("isDefault", qualityGate.getId().equals(defaultQgateId))
+ .endObject();
}
writer.endArray();
- QualityGateDto defaultQgate = qualityGates.getDefault();
- if (defaultQgate != null) {
- writer.prop("default", defaultQgate.getId());
+ if (defaultQgateId != null) {
+ writer.prop("default", defaultQgateId);
}
writer.endObject().close();
}
new QualityGateDto().setId(666L).setName("Ninth")));
when(qGates.getDefault()).thenReturn(defaultQgate);
tester.newGetRequest("api/qualitygates", "list").execute().assertJson(
- "{\"qualitygates\":[{\"id\":42,\"name\":\"Golden\"},{\"id\":43,\"name\":\"Star\"},{\"id\":666,\"name\":\"Ninth\"}],\"default\":42}");
+ "{\"qualitygates\":[{\"id\":42,\"name\":\"Golden\",\"isDefault\":true},{\"id\":43,\"name\":\"Star\",\"isDefault\":false},{\"id\":666,\"name\":\"Ninth\",\"isDefault\":false}],\"default\":42}");
}
@Test