Search in sources :

Example 1 with QGChangeNotification

use of org.sonar.server.qualitygate.notification.QGChangeNotification in project sonarqube by SonarSource.

the class QualityGateEventsStep method notifyUsers.

/**
 * @param rawStatus OK or ERROR + optional text
 */
private void notifyUsers(Component project, QualityGateStatus rawStatus, boolean isNewAlert) {
    QGChangeNotification notification = new QGChangeNotification();
    notification.setDefaultMessage(String.format("Alert on %s: %s", project.getName(), rawStatus.getStatus().getLabel())).setFieldValue("projectName", project.getName()).setFieldValue("projectKey", project.getKey()).setFieldValue("projectVersion", project.getProjectAttributes().getProjectVersion()).setFieldValue("alertName", rawStatus.getStatus().getLabel()).setFieldValue("alertText", rawStatus.getText()).setFieldValue("alertLevel", rawStatus.getStatus().toString()).setFieldValue("isNewAlert", Boolean.toString(isNewAlert));
    Branch branch = analysisMetadataHolder.getBranch();
    if (!branch.isMain()) {
        notification.setFieldValue("branch", branch.getName());
    }
    List<Metric> ratingMetrics = metricRepository.getMetricsByType(MetricType.RATING);
    String ratingMetricsInOneString = ratingMetrics.stream().map(Metric::getName).collect(Collectors.joining(","));
    notification.setFieldValue("ratingMetrics", ratingMetricsInOneString);
    notificationService.deliverEmails(singleton(notification));
    // compatibility with old API
    notificationService.deliver(notification);
}
Also used : Branch(org.sonar.ce.task.projectanalysis.analysis.Branch) QGChangeNotification(org.sonar.server.qualitygate.notification.QGChangeNotification) Metric(org.sonar.ce.task.projectanalysis.metric.Metric)

Aggregations

Branch (org.sonar.ce.task.projectanalysis.analysis.Branch)1 Metric (org.sonar.ce.task.projectanalysis.metric.Metric)1 QGChangeNotification (org.sonar.server.qualitygate.notification.QGChangeNotification)1