use of org.sonar.server.qualitygate.Condition in project sonarqube by SonarSource.
the class LiveQualityGateComputerImpl method loadQualityGate.
@Override
public QualityGate loadQualityGate(DbSession dbSession, ProjectDto project, BranchDto branch) {
QualityGateDto gateDto = qGateFinder.getQualityGate(dbSession, project).getQualityGate();
Collection<QualityGateConditionDto> conditionDtos = dbClient.gateConditionDao().selectForQualityGate(dbSession, gateDto.getUuid());
Set<String> metricUuids = conditionDtos.stream().map(QualityGateConditionDto::getMetricUuid).collect(toHashSet(conditionDtos.size()));
Map<String, MetricDto> metricsByUuid = dbClient.metricDao().selectByUuids(dbSession, metricUuids).stream().collect(uniqueIndex(MetricDto::getUuid));
Stream<Condition> conditions = conditionDtos.stream().map(conditionDto -> {
String metricKey = metricsByUuid.get(conditionDto.getMetricUuid()).getKey();
Condition.Operator operator = Condition.Operator.fromDbValue(conditionDto.getOperator());
return new Condition(metricKey, operator, conditionDto.getErrorThreshold());
});
if (branch.getBranchType() == BranchType.PULL_REQUEST) {
conditions = conditions.filter(Condition::isOnLeakPeriod);
}
return new QualityGate(String.valueOf(gateDto.getUuid()), gateDto.getName(), conditions.collect(toHashSet(conditionDtos.size())));
}
use of org.sonar.server.qualitygate.Condition in project sonarqube by SonarSource.
the class WebhookPayloadFactoryImpl method writeQualityGate.
private static void writeQualityGate(JsonWriter writer, EvaluatedQualityGate gate) {
writer.name("qualityGate").beginObject().prop("name", gate.getQualityGate().getName()).prop(PROPERTY_STATUS, gate.getStatus().toString()).name("conditions").beginArray();
for (EvaluatedCondition evaluatedCondition : gate.getEvaluatedConditions()) {
Condition condition = evaluatedCondition.getCondition();
writer.beginObject().prop("metric", condition.getMetricKey()).prop("operator", condition.getOperator().name());
evaluatedCondition.getValue().ifPresent(t -> writer.prop("value", t));
writer.prop(PROPERTY_STATUS, evaluatedCondition.getStatus().name()).prop("errorThreshold", condition.getErrorThreshold()).endObject();
}
writer.endArray().endObject();
}
use of org.sonar.server.qualitygate.Condition in project sonarqube by SonarSource.
the class QGToEvaluatedQG method apply.
@Override
public EvaluatedQualityGate apply(QualityGate qg) {
EvaluatedQualityGate.Builder builder = EvaluatedQualityGate.newBuilder();
Set<Condition> conditions = qg.getConditions().stream().map(q -> {
Condition condition = new Condition(q.getMetricKey(), Condition.Operator.valueOf(q.getOperator().name()), q.getErrorThreshold());
builder.addEvaluatedCondition(condition, EvaluatedCondition.EvaluationStatus.valueOf(q.getStatus().name()), q.getStatus() == EvaluationStatus.NO_VALUE ? null : q.getValue());
return condition;
}).collect(MoreCollectors.toSet());
return builder.setQualityGate(new org.sonar.server.qualitygate.QualityGate(qg.getId(), qg.getName(), conditions)).setStatus(Metric.Level.valueOf(qg.getStatus().name())).build();
}
Aggregations