use of org.sonar.server.qualitygate.QualityGate in project sonarqube by SonarSource.
the class LiveQualityGateComputerImpl method refreshGateStatus.
@Override
public EvaluatedQualityGate refreshGateStatus(ComponentDto project, QualityGate gate, MeasureMatrix measureMatrix, Configuration configuration) {
QualityGateEvaluator.Measures measures = metricKey -> {
Optional<LiveMeasureDto> liveMeasureDto = measureMatrix.getMeasure(project, metricKey);
if (!liveMeasureDto.isPresent()) {
return Optional.empty();
}
MetricDto metric = measureMatrix.getMetricByUuid(liveMeasureDto.get().getMetricUuid());
return Optional.of(new LiveMeasure(liveMeasureDto.get(), metric));
};
EvaluatedQualityGate evaluatedGate = evaluator.evaluate(gate, measures, configuration);
measureMatrix.setValue(project, CoreMetrics.ALERT_STATUS_KEY, evaluatedGate.getStatus().name());
measureMatrix.setValue(project, CoreMetrics.QUALITY_GATE_DETAILS_KEY, QualityGateConverter.toJson(evaluatedGate));
return evaluatedGate;
}
use of org.sonar.server.qualitygate.QualityGate in project sonarqube by SonarSource.
the class LiveQualityGateComputerImplTest method loadQualityGate_on_branch_returns_default_gate.
@Test
public void loadQualityGate_on_branch_returns_default_gate() {
ProjectDto project = db.components().insertPublicProjectDto();
BranchDto branch = db.components().insertProjectBranch(project).setBranchType(BranchType.BRANCH);
MetricDto metric = db.measures().insertMetric();
QualityGateDto gate = db.qualityGates().insertQualityGate();
db.qualityGates().setDefaultQualityGate(gate);
QualityGateConditionDto condition = db.qualityGates().addCondition(gate, metric);
QualityGate result = underTest.loadQualityGate(db.getSession(), project, branch);
assertThat(result.getId()).isEqualTo("" + gate.getUuid());
assertThat(result.getConditions()).extracting(Condition::getMetricKey, Condition::getOperator, Condition::getErrorThreshold).containsExactlyInAnyOrder(tuple(metric.getKey(), Condition.Operator.fromDbValue(condition.getOperator()), condition.getErrorThreshold()));
}
use of org.sonar.server.qualitygate.QualityGate in project sonarqube by SonarSource.
the class LiveQualityGateComputerImplTest method loadQualityGate_returns_hardcoded_gate_for_pull_requests.
@Test
public void loadQualityGate_returns_hardcoded_gate_for_pull_requests() {
ProjectDto project = db.components().insertPublicProjectDto();
BranchDto branch = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
MetricDto metric1 = db.measures().insertMetric(m -> m.setKey("new_metric"));
MetricDto metric2 = db.measures().insertMetric(m -> m.setKey("metric"));
QualityGateDto gate = db.qualityGates().insertQualityGate();
db.qualityGates().setDefaultQualityGate(gate);
db.qualityGates().addCondition(gate, metric1);
db.qualityGates().addCondition(gate, metric2);
QualityGate result = underTest.loadQualityGate(db.getSession(), project, branch);
assertThat(result.getConditions()).extracting(Condition::getMetricKey).containsExactly("new_metric");
}
use of org.sonar.server.qualitygate.QualityGate in project sonarqube by SonarSource.
the class LiveMeasureComputerImplTest method event_contains_newQualityGate_computed_by_LiveQualityGateComputer.
@Test
public void event_contains_newQualityGate_computed_by_LiveQualityGateComputer() {
markProjectAsAnalyzed(project);
db.measures().insertLiveMeasure(project, alertStatusMetric, m -> m.setData(Metric.Level.ERROR.name()));
db.measures().insertLiveMeasure(project, intMetric, m -> m.setVariation(42.0).setValue(null));
BranchDto branch = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), project.projectUuid(), "master").orElseThrow(() -> new IllegalStateException("Can't find master branch"));
List<QGChangeEvent> result = run(file1, newQualifierBasedIntLeakFormula());
assertThat(result).extracting(QGChangeEvent::getQualityGateSupplier).extracting(Supplier::get).containsExactly(Optional.of(newQualityGate));
verify(qGateComputer).loadQualityGate(any(DbSession.class), argThat(p -> p.getUuid().equals(projectDto.getUuid())), eq(branch));
verify(qGateComputer).getMetricsRelatedTo(qualityGate);
verify(qGateComputer).refreshGateStatus(eq(project), same(qualityGate), any(MeasureMatrix.class), any(Configuration.class));
}
Aggregations