private async Task SendErrorsAndThresholdThroughMail(InspectionsComparator comparer) { if (!_mailNotifier.IsSetUp) { Console.WriteLine("The Software Quality mail notifier is not set up"); return; } var(newIssues, _, _) = comparer.GetComparison(); var newErrors = newIssues.Where(i => i.Severity == Severity.ERROR).ToArray(); var blamer = new GitBlamer(_gitPath); var(_, headCommit) = await _teamcityService.ComputeCommitRange(_buildId); var contributors = await blamer.GetNewContributors(headCommit, newErrors, newErrors.Length, ComputePathToRepo); foreach (var contributor in contributors) { try { Console.WriteLine($"Sending mail to {contributor.Name} for errors in inspection"); var body = await GetBody(contributor.Contributions, contributor.Name); await _mailNotifier.SendMail("Errors in daily inspection", contributor.Mail, contributor.Name, body); } catch (Exception e) { Console.WriteLine($"Failed to send mail to {contributor.Name}: {e.Message}"); } } }
private async Task <HangoutCard> GetLeaderBoardCard(DuplicateComparator comparator) { try { var(_, removedDuplicates, _) = comparator.GetComparison(); var blamer = new GitBlamer(_gitPath); var(baseCommit, headCommit) = await _teamcityService.ComputeCommitRange(_buildId); var contributors = await blamer.GetRemovalContributors(baseCommit, headCommit, removedDuplicates, 3, file => file); var sections = new List <HangoutCardSection>(); var rank = 1; foreach (var contributor in contributors) { sections.Add(CardBuilderHelper.GetKeyValueSection("Duplication has been removed by", contributor.Name, $"for a cost of {contributor.Contributions.Sum(f => f.Score)}", _ranks[rank])); rank++; } return(new HangoutCard { Header = CardBuilderHelper.GetCardHeader("Podium", "Who removed duplication", "https://icon-icons.com/icons2/9/PNG/128/podium_1511.png"), Sections = sections.ToArray() }); } catch (Exception) { Console.WriteLine("Failed to retrieve best contributors"); } return(null); }
public async Task RunAsync() { Console.WriteLine($"Current user is: {System.Security.Principal.WindowsIdentity.GetCurrent().Name}"); var(baseCommit, headCommit) = await _teamCityService.ComputeCommitRange(_buildId); var metadata = new MetadataReleaseNotes { BaseCommit = baseCommit, HeadCommit = headCommit }; var content = JsonConvert.SerializeObject(metadata); if (File.Exists(_path)) { File.Delete(_path); } using (var file = File.OpenWrite(_path)) using (var writer = new StreamWriter(file)) { await writer.WriteAsync(content); await writer.FlushAsync(); } using (var httpClient = new HttpClient()) { var message = await GetMessage(DateTime.UtcNow); Console.WriteLine($"Webhook: {_webhook}"); var response = await httpClient.PostAsync(_webhook, message); Console.WriteLine($"Response: {response.StatusCode.ToString()}"); if (!response.IsSuccessStatusCode) { Console.WriteLine(await response.Content.ReadAsStringAsync()); } } }