Explorar el Código

SONAR-20665 add response field qualityProfile to projectanalysis/search response

tags/10.3.0.82913
Matteo Mara hace 7 meses
padre
commit
8f82ee4239

+ 4
- 0
server/sonar-webserver-webapi/src/it/java/org/sonar/server/projectanalysis/ws/SearchActionIT.java Ver fichero

.setName("6.3").setCategory(VERSION.getLabel())); .setName("6.3").setCategory(VERSION.getLabel()));
db.events().insertEvent(newEvent(a2).setUuid("E21") db.events().insertEvent(newEvent(a2).setUuid("E21")
.setName("Quality Profile changed to Sonar Way") .setName("Quality Profile changed to Sonar Way")
.setData("key=Profile Key;languageKey=The Key of the Language;name=Profile Name")
.setCategory(EventCategory.QUALITY_PROFILE.getLabel())); .setCategory(EventCategory.QUALITY_PROFILE.getLabel()));
db.events().insertEvent(newEvent(a2).setUuid("E22") db.events().insertEvent(newEvent(a2).setUuid("E22")
.setName("6.3").setCategory(OTHER.getLabel())); .setName("6.3").setCategory(OTHER.getLabel()));
db.events().insertEvent(newEvent(a2).setUuid("E23")
.setName("Use 'Sonar Way update profile' (JavaScript)")
.setCategory(EventCategory.QUALITY_PROFILE.getLabel()));


EventDto eventDto = db.events().insertEvent(newEvent(a3) EventDto eventDto = db.events().insertEvent(newEvent(a3)
.setUuid("E31") .setUuid("E31")

+ 2
- 1
server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/SearchAction.java Ver fichero

.setSince("6.3") .setSince("6.3")
.setResponseExample(getClass().getResource("search-example.json")) .setResponseExample(getClass().getResource("search-example.json"))
.setChangelog( .setChangelog(
new Change("9.0", "Add field response 'detectedCI'"),
new Change("10.3", "Add response field 'qualityProfile' for events related to quality profile changes"),
new Change("9.0", "Add response field 'detectedCI'"),
new Change("7.5", "Add QualityGate information on Applications")) new Change("7.5", "Add QualityGate information on Applications"))
.setHandler(this); .setHandler(this);



+ 29
- 13
server/sonar-webserver-webapi/src/main/java/org/sonar/server/projectanalysis/ws/SearchResponseBuilder.java Ver fichero

import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.db.component.SnapshotDto; import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventComponentChangeDto; import org.sonar.db.event.EventComponentChangeDto;
import org.sonar.db.event.EventDto; import org.sonar.db.event.EventDto;
import org.sonarqube.ws.ProjectAnalyses.Analysis; import org.sonarqube.ws.ProjectAnalyses.Analysis;
import org.sonarqube.ws.ProjectAnalyses.Event; import org.sonarqube.ws.ProjectAnalyses.Event;
import org.sonarqube.ws.ProjectAnalyses.QualityGate; import org.sonarqube.ws.ProjectAnalyses.QualityGate;
import org.sonarqube.ws.ProjectAnalyses.QualityProfile;
import org.sonarqube.ws.ProjectAnalyses.SearchResponse; import org.sonarqube.ws.ProjectAnalyses.SearchResponse;


import static java.lang.String.format; import static java.lang.String.format;
private final Event.Builder wsEvent; private final Event.Builder wsEvent;
private final SearchData searchData; private final SearchData searchData;
private final QualityGate.Builder wsQualityGate; private final QualityGate.Builder wsQualityGate;
private final QualityProfile.Builder wsQualityProfile;
private final ProjectAnalyses.DefinitionChange.Builder wsDefinitionChange; private final ProjectAnalyses.DefinitionChange.Builder wsDefinitionChange;


SearchResponseBuilder(SearchData searchData) { SearchResponseBuilder(SearchData searchData) {
this.wsAnalysis = Analysis.newBuilder(); this.wsAnalysis = Analysis.newBuilder();
this.wsEvent = Event.newBuilder(); this.wsEvent = Event.newBuilder();
this.wsQualityGate = QualityGate.newBuilder(); this.wsQualityGate = QualityGate.newBuilder();
this.wsQualityProfile = QualityProfile.newBuilder();
this.wsDefinitionChange = ProjectAnalyses.DefinitionChange.newBuilder(); this.wsDefinitionChange = ProjectAnalyses.DefinitionChange.newBuilder();
this.searchData = searchData; this.searchData = searchData;
} }
wsEvent.clear().setKey(dbEvent.getUuid()); wsEvent.clear().setKey(dbEvent.getUuid());
ofNullable(dbEvent.getName()).ifPresent(wsEvent::setName); ofNullable(dbEvent.getName()).ifPresent(wsEvent::setName);
ofNullable(dbEvent.getDescription()).ifPresent(wsEvent::setDescription); ofNullable(dbEvent.getDescription()).ifPresent(wsEvent::setDescription);
ofNullable(dbEvent.getCategory()).ifPresent(cat -> wsEvent.setCategory(fromLabel(cat).name()));
if (dbEvent.getCategory() != null) {
switch (EventCategory.fromLabel(dbEvent.getCategory())) {
case DEFINITION_CHANGE:
addDefinitionChange(dbEvent);
break;
case QUALITY_GATE:
addQualityGateInformation(dbEvent);
break;
default:
break;
}
}
ofNullable(dbEvent.getCategory())
.ifPresent(cat -> {
wsEvent.setCategory(fromLabel(cat).name());
switch (fromLabel(cat)) {
case DEFINITION_CHANGE -> addDefinitionChange(dbEvent);
case QUALITY_GATE -> addQualityGateInformation(dbEvent);
case QUALITY_PROFILE -> addQualityProfileInformation(dbEvent);
default -> {
//Nothing to do if not one of the previous cases
}
}
});
return wsEvent; return wsEvent;
} }


private void addQualityProfileInformation(EventDto event) {
wsQualityProfile.clear();

Map<String, String> data = KeyValueFormat.parse(event.getData());

Optional.ofNullable(data.get("key")).ifPresent(wsQualityProfile::setKey);
Optional.ofNullable(data.get("name")).ifPresent(wsQualityProfile::setName);
Optional.ofNullable(data.get("languageKey")).ifPresent(wsQualityProfile::setLanguageKey);

wsEvent.setQualityProfile(wsQualityProfile.build());
}

private void addQualityGateInformation(EventDto event) { private void addQualityGateInformation(EventDto event) {
wsQualityGate.clear(); wsQualityGate.clear();
List<EventComponentChangeDto> eventComponentChangeDtos = searchData.componentChangesByEventUuid.get(event.getUuid()); List<EventComponentChangeDto> eventComponentChangeDtos = searchData.componentChangesByEventUuid.get(event.getUuid());

+ 11
- 1
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/projectanalysis/ws/search-example.json Ver fichero

{ {
"key": "E21", "key": "E21",
"category": "QUALITY_PROFILE", "category": "QUALITY_PROFILE",
"name": "Quality Profile changed to Sonar Way"
"name": "Quality Profile changed to Sonar Way",
"qualityProfile": {
"key": "Profile Key",
"name": "Profile Name",
"languageKey": "The Key of the Language"
}
}, },
{ {
"key": "E22", "key": "E22",
"category": "OTHER", "category": "OTHER",
"name": "6.3" "name": "6.3"
},
{
"key": "E23",
"category": "QUALITY_PROFILE",
"name": "Use 'Sonar Way update profile' (JavaScript)"
} }
] ]
}, },

+ 7
- 0
sonar-ws/src/main/protobuf/ws-projectanalyses.proto Ver fichero

optional string description = 5; optional string description = 5;
optional QualityGate qualityGate = 6; optional QualityGate qualityGate = 6;
optional DefinitionChange definitionChange = 7; optional DefinitionChange definitionChange = 7;
optional QualityProfile qualityProfile = 8;
} }


message Analysis { message Analysis {
repeated Failing failing = 3; repeated Failing failing = 3;
} }


message QualityProfile {
optional string key = 1;
optional string name = 2;
optional string languageKey = 3;
}

message Failing { message Failing {
optional string key = 1; optional string key = 1;
optional string name = 2; optional string name = 2;

Cargando…
Cancelar
Guardar