Search in sources :

Example 1 with QualityGate

use of org.sonar.api.ce.posttask.QualityGate in project sonarqube by SonarSource.

the class PostProjectAnalysisTaskImpl method finished.

@Override
public void finished(ProjectAnalysis analysis) {
    CeTask ceTask = analysis.getCeTask();
    Project project = analysis.getProject();
    QualityGate qualityGate = analysis.getQualityGate();
    LOG.info("POSTASKPLUGIN: finished() CeTask[{}][{}] Project[{}] Date[{}] QualityGate[{}]", ceTask.getStatus(), ceTask.getId(), project.getKey(), analysis.getDate().getTime(), qualityGate == null ? null : qualityGate.getStatus());
}
Also used : Project(org.sonar.api.ce.posttask.Project) CeTask(org.sonar.api.ce.posttask.CeTask) QualityGate(org.sonar.api.ce.posttask.QualityGate)

Example 2 with QualityGate

use of org.sonar.api.ce.posttask.QualityGate in project sonarqube by SonarSource.

the class WebhookPayloadFactoryImplTest method create_payload_for_successful_analysis.

@Test
public void create_payload_for_successful_analysis() {
    CeTask task = newCeTaskBuilder().setStatus(CeTask.Status.SUCCESS).setId("#1").build();
    QualityGate gate = newQualityGateBuilder().setId("G1").setName("Gate One").setStatus(QualityGate.Status.WARN).add(newConditionBuilder().setMetricKey("coverage").setOperator(QualityGate.Operator.GREATER_THAN).setOnLeakPeriod(true).setWarningThreshold("75.0").setErrorThreshold("70.0").build(QualityGate.EvaluationStatus.WARN, "74.0")).build();
    PostProjectAnalysisTask.ProjectAnalysis analysis = newAnalysis(task, gate, emptyMap());
    WebhookPayload payload = underTest.create(analysis);
    assertThat(payload.getProjectKey()).isEqualTo(PROJECT_KEY);
    assertJson(payload.getJson()).isSimilarTo(getClass().getResource("WebhookPayloadTest/success.json"));
}
Also used : CeTask(org.sonar.api.ce.posttask.CeTask) PostProjectAnalysisTask(org.sonar.api.ce.posttask.PostProjectAnalysisTask) QualityGate(org.sonar.api.ce.posttask.QualityGate) Test(org.junit.Test)

Example 3 with QualityGate

use of org.sonar.api.ce.posttask.QualityGate in project sonarqube by SonarSource.

the class WebhookPayloadFactoryImplTest method create_payload_with_gate_conditions_without_value.

@Test
public void create_payload_with_gate_conditions_without_value() {
    CeTask task = newCeTaskBuilder().setStatus(CeTask.Status.SUCCESS).setId("#1").build();
    QualityGate gate = newQualityGateBuilder().setId("G1").setName("Gate One").setStatus(QualityGate.Status.WARN).add(newConditionBuilder().setMetricKey("coverage").setOperator(QualityGate.Operator.GREATER_THAN).setWarningThreshold("75.0").setErrorThreshold("70.0").buildNoValue()).build();
    PostProjectAnalysisTask.ProjectAnalysis analysis = newAnalysis(task, gate, emptyMap());
    WebhookPayload payload = underTest.create(analysis);
    assertThat(payload.getProjectKey()).isEqualTo(PROJECT_KEY);
    assertJson(payload.getJson()).isSimilarTo(getClass().getResource("WebhookPayloadTest/gate_condition_without_value.json"));
}
Also used : CeTask(org.sonar.api.ce.posttask.CeTask) PostProjectAnalysisTask(org.sonar.api.ce.posttask.PostProjectAnalysisTask) QualityGate(org.sonar.api.ce.posttask.QualityGate) Test(org.junit.Test)

Example 4 with QualityGate

use of org.sonar.api.ce.posttask.QualityGate in project sonarqube by SonarSource.

the class WebhookPayloadFactoryImplTest method create_payload_with_analysis_properties.

@Test
public void create_payload_with_analysis_properties() {
    CeTask task = newCeTaskBuilder().setStatus(CeTask.Status.SUCCESS).setId("#1").build();
    QualityGate gate = newQualityGateBuilder().setId("G1").setName("Gate One").setStatus(QualityGate.Status.WARN).build();
    Map<String, String> scannerProperties = ImmutableMap.of("sonar.analysis.revision", "ab45d24", "sonar.analysis.buildNumber", "B123", "not.prefixed.with.sonar.analysis", "should be ignored", "ignored", "should be ignored too");
    PostProjectAnalysisTask.ProjectAnalysis analysis = newAnalysis(task, gate, scannerProperties);
    WebhookPayload payload = underTest.create(analysis);
    assertJson(payload.getJson()).isSimilarTo(getClass().getResource("WebhookPayloadTest/with_analysis_properties.json"));
    assertThat(payload.getJson()).doesNotContain("not.prefixed.with.sonar.analysis").doesNotContain("ignored");
}
Also used : CeTask(org.sonar.api.ce.posttask.CeTask) PostProjectAnalysisTask(org.sonar.api.ce.posttask.PostProjectAnalysisTask) QualityGate(org.sonar.api.ce.posttask.QualityGate) Test(org.junit.Test)

Aggregations

CeTask (org.sonar.api.ce.posttask.CeTask)4 QualityGate (org.sonar.api.ce.posttask.QualityGate)4 Test (org.junit.Test)3 PostProjectAnalysisTask (org.sonar.api.ce.posttask.PostProjectAnalysisTask)3 Project (org.sonar.api.ce.posttask.Project)1