private void checkQualityGateStatusChange( Component project, Metric metric, QualityGateStatus rawStatus) { Optional<Measure> baseMeasure = measureRepository.getBaseMeasure(project, metric); if (!baseMeasure.isPresent()) { checkNewQualityGate(project, rawStatus); return; } if (!baseMeasure.get().hasQualityGateStatus()) { LOGGER.warn( String.format( "Previous alterStatus for project %s is not a supported value. Can not compute Quality Gate event", project.getKey())); checkNewQualityGate(project, rawStatus); return; } QualityGateStatus baseStatus = baseMeasure.get().getQualityGateStatus(); if (baseStatus.getStatus() != rawStatus.getStatus()) { // The QualityGate status has changed String label = String.format( "%s (was %s)", rawStatus.getStatus().getColorName(), baseStatus.getStatus().getColorName()); createEvent(project, label, rawStatus.getText()); boolean isNewKo = rawStatus.getStatus() == Measure.Level.OK; notifyUsers(project, label, rawStatus, isNewKo); } }
private void executeForProject(Component project) { Metric metric = metricRepository.getByKey(CoreMetrics.ALERT_STATUS_KEY); Optional<Measure> rawStatus = measureRepository.getRawMeasure(project, metric); if (!rawStatus.isPresent() || !rawStatus.get().hasQualityGateStatus()) { return; } checkQualityGateStatusChange(project, metric, rawStatus.get().getQualityGateStatus()); }
@Override public void visitProjectView(Component projectView, Path<LastCommit> path) { Optional<Measure> rawMeasure = measureRepository.getRawMeasure(projectView, lastCommitDateMetric); if (rawMeasure.isPresent()) { // path.parent() should never fail as a project view must never be a root component path.parent().addDate(rawMeasure.get().getLongValue()); } }
private void saveAndAggregate(Component component, Path<LastCommit> path) { long maxDate = path.current().getDate(); if (maxDate > 0L) { measureRepository.add( component, lastCommitDateMetric, Measure.newMeasureBuilder().create(maxDate)); if (!path.isRoot()) { path.parent().addDate(maxDate); } } }
private void addNewMeasure( Component component, String metricKey, Formula formula, Counter counter) { // no new measure can be created by formulas for PROJECT_VIEW components, their measures are the // copy if (component.getType() == Component.Type.PROJECT_VIEW) { return; } Metric metric = metricRepository.getByKey(metricKey); Optional<Measure> measure = formula.createMeasure(counter, new CreateMeasureContextImpl(component, metric)); if (measure.isPresent()) { measureRepository.add(component, metric, measure.get()); } }
@Override public void visitFile(Component file, Path<LastCommit> path) { // load SCM blame information from report. It can be absent when the file was not touched // since previous analysis (optimization to decrease execution of blame commands). In this case // the date is loaded from database, as it did not change from previous analysis. BatchReport.Changesets changesets = reportReader.readChangesets(file.getReportAttributes().getRef()); if (changesets == null) { Optional<Measure> baseMeasure = measureRepository.getBaseMeasure(file, lastCommitDateMetric); if (baseMeasure.isPresent()) { path.current().addDate(baseMeasure.get().getLongValue()); } } else { for (BatchReport.Changesets.Changeset changeset : changesets.getChangesetList()) { if (changeset.hasDate()) { path.current().addDate(changeset.getDate()); } } } saveAndAggregate(file, path); }