public EmailReportViewModel(AbstractReport emailReportDto, EmailReportConfiguration emailReportConfiguration) { var config = emailReportConfiguration.PipelineConfiguration; ProjectName = config.ProjectName; HasTaskFailures = emailReportDto.HasFailedTasks(); Release = emailReportDto.GetReleaseViewModel(config); Build = emailReportDto.GetBuildViewModel(config); Artifacts = emailReportDto.GetArtifactViewModels(config); HasCanceledPhases = emailReportDto.HasCanceledPhases(); InitializePhases(emailReportDto); var reportDataConfiguration = emailReportConfiguration.ReportDataConfiguration; EmailSubject = GetMailSubject(emailReportDto, reportDataConfiguration); HasFailedTests = emailReportDto.HasFailedTests(reportDataConfiguration.IncludeOthersInTotal); var summaryGroupDto = emailReportDto.TestSummaryGroups?.First(); if (emailReportDto.Summary != null) { AllTests = new TestResultSummaryViewModel(emailReportDto.Summary, config, reportDataConfiguration.IncludeOthersInTotal); } InitializeSummaryGroupViewModel(emailReportDto, emailReportConfiguration.ReportDataConfiguration, config); ShowAssociatedChanges = reportDataConfiguration.IncludeCommits; if (ShowAssociatedChanges) { InitializeAssociatedChanges(emailReportDto, config); } InitializeTestResultGroups(emailReportDto, emailReportConfiguration); TestTabLink = config.TestTabLink; DataMissing = emailReportDto.DataMissing; }
public async Task AddReportDataAsync(AbstractReport emailReportDto) { var mailConfigs = _emailReportConfiguration.MailConfigurations; var shouldSendMail = emailReportDto.DataMissing; MailConfiguration mailConfigurationToUse = null; if (!shouldSendMail) { // Evaluate each configuration and see what matches foreach (var mailConfig in mailConfigs) { if (mailConfig.SendMailCondition == SendMailCondition.Always) { mailConfigurationToUse = mailConfig; } else { if (!_testfailuresFlagsInitialized) { hasTestFailures = emailReportDto.HasFailedTests(_emailReportConfiguration.ReportDataConfiguration.IncludeOthersInTotal); hasFailedTasks = emailReportDto.HasFailedTasks(); hasCanceledPhases = emailReportDto.HasCanceledPhases(); _testfailuresFlagsInitialized = true; } var hasFailures = hasTestFailures || hasFailedTasks || hasCanceledPhases; if ((mailConfig.SendMailCondition == SendMailCondition.OnFailure && hasFailures) || (mailConfig.SendMailCondition == SendMailCondition.OnSuccess && !hasFailures)) { mailConfigurationToUse = mailConfig; } else if (mailConfig.SendMailCondition == SendMailCondition.OnNewFailuresOnly && hasFailures) { // Always treat phase cancellation issues as new failure as we cannot distinguish/compare phase level issues // Still compare failed tests and failed tasks where possible to reduce noise if (hasCanceledPhases && !hasTestFailures && !hasFailedTasks) { mailConfigurationToUse = mailConfig; _logger.LogInformation($"Has Phase cancellation(s) issues. Treating as new failure."); } else { _logger.LogInformation( $"Looking for new failures, as the user send mail condition is '{mailConfig.SendMailCondition}'."); if (hasPreviousReleaseGotSameFailures == null) { hasPreviousReleaseGotSameFailures = await HasPreviousReleaseGotSameFailuresAsync(emailReportDto, _emailReportConfiguration.PipelineConfiguration, hasTestFailures, hasFailedTasks); } shouldSendMail = !hasPreviousReleaseGotSameFailures.Value; mailConfigurationToUse = mailConfig; } } } if (mailConfigurationToUse != null) { break; } } } emailReportDto.MailConfiguration = mailConfigurationToUse; }