Browse Source

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

tags/10.3.0.82913
Matteo Mara 7 months ago
parent
commit
8f82ee4239

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

@@ -160,9 +160,13 @@ public class SearchActionIT {
.setName("6.3").setCategory(VERSION.getLabel()));
db.events().insertEvent(newEvent(a2).setUuid("E21")
.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()));
db.events().insertEvent(newEvent(a2).setUuid("E22")
.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)
.setUuid("E31")

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

@@ -83,7 +83,8 @@ public class SearchAction implements ProjectAnalysesWsAction {
.setSince("6.3")
.setResponseExample(getClass().getResource("search-example.json"))
.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"))
.setHandler(this);


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

@@ -25,11 +25,13 @@ import com.google.gson.JsonSyntaxException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.utils.KeyValueFormat;
import org.sonar.db.component.SnapshotDto;
import org.sonar.db.event.EventComponentChangeDto;
import org.sonar.db.event.EventDto;
@@ -37,6 +39,7 @@ import org.sonarqube.ws.ProjectAnalyses;
import org.sonarqube.ws.ProjectAnalyses.Analysis;
import org.sonarqube.ws.ProjectAnalyses.Event;
import org.sonarqube.ws.ProjectAnalyses.QualityGate;
import org.sonarqube.ws.ProjectAnalyses.QualityProfile;
import org.sonarqube.ws.ProjectAnalyses.SearchResponse;

import static java.lang.String.format;
@@ -52,12 +55,14 @@ class SearchResponseBuilder {
private final Event.Builder wsEvent;
private final SearchData searchData;
private final QualityGate.Builder wsQualityGate;
private final QualityProfile.Builder wsQualityProfile;
private final ProjectAnalyses.DefinitionChange.Builder wsDefinitionChange;

SearchResponseBuilder(SearchData searchData) {
this.wsAnalysis = Analysis.newBuilder();
this.wsEvent = Event.newBuilder();
this.wsQualityGate = QualityGate.newBuilder();
this.wsQualityProfile = QualityProfile.newBuilder();
this.wsDefinitionChange = ProjectAnalyses.DefinitionChange.newBuilder();
this.searchData = searchData;
}
@@ -102,22 +107,33 @@ class SearchResponseBuilder {
wsEvent.clear().setKey(dbEvent.getUuid());
ofNullable(dbEvent.getName()).ifPresent(wsEvent::setName);
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;
}

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) {
wsQualityGate.clear();
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 View File

@@ -16,12 +16,22 @@
{
"key": "E21",
"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",
"category": "OTHER",
"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 View File

@@ -50,6 +50,7 @@ message Event {
optional string description = 5;
optional QualityGate qualityGate = 6;
optional DefinitionChange definitionChange = 7;
optional QualityProfile qualityProfile = 8;
}

message Analysis {
@@ -69,6 +70,12 @@ message QualityGate {
repeated Failing failing = 3;
}

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

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

Loading…
Cancel
Save