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); }
private async Task <HangoutCardSection[]> GetSections(Issue[] newIssues, Issue[] removedIssues, Issue[] currentIssues, InspectionsComparator comparer) { var total = currentIssues.Length; var hasNew = newIssues.Length > 0; var hasLess = removedIssues.Length > 0; var countOfErrors = newIssues.Count(i => i.Severity == Severity.ERROR); var countOfRemovedErrors = removedIssues.Count(i => i.Severity == Severity.ERROR); Console.WriteLine($"Creating section of message for all {total} violations"); var sections = new List <HangoutCardSection> { CardBuilderHelper.GetTextParagraphSection($"The total of violations in our code base is <b>{total}</b>.") }; if (!hasNew && !hasLess) { Console.WriteLine("No change in inspection"); sections.Add(CardBuilderHelper.GetTextParagraphSection("No change was found during the inspection")); } if (hasNew) { Console.WriteLine($"Adding section for the {newIssues.Length} new violations"); var message = $"+ <b>{newIssues.Length}</b> violation{(newIssues.Length == 1 ? " has" : "s have")} been introduced."; if (countOfErrors > 0) { message += $"\r\n<font color=\"#ff0000\">(of which <b>{countOfErrors}</b> {(countOfErrors > 1 ? "are errors" : "is an error")})</font>"; } sections.Add(CardBuilderHelper.GetTextParagraphSection(message)); } if (hasLess) { Console.WriteLine($"Adding section for the {removedIssues.Length} removed violations"); var message = $"- <b>{removedIssues.Length}</b> violation{(removedIssues.Length == 1 ? " has" : "s have")} been removed."; if (countOfRemovedErrors > 0) { message += $"\r\n<font color=\"#00ff00\">(of which <b>{countOfRemovedErrors}</b> {(countOfRemovedErrors > 1 ? "were errors" : "was an error")})</font>"; } sections.Add(CardBuilderHelper.GetTextParagraphSection(message)); } var(numberOfErrors, failedProjects) = comparer.EnforceNumberOfErrorsAndNumberOfViolationsByProject(currentIssues); if (numberOfErrors > 0) { sections.Add(CardBuilderHelper.GetKeyValueSection("Error(s)", $"{numberOfErrors} error{(numberOfErrors > 1 ? "s were" : " was")} detected by the inspection.", string.Empty, "https://icon-icons.com/icons2/1380/PNG/32/vcsconflicting_93497.png")); } foreach (var failedProject in failedProjects) { sections.Add(CardBuilderHelper.GetKeyValueSection("Threshold was reached by", failedProject.Project, $"{failedProject.Count} violations", "https://icon-icons.com/icons2/1024/PNG/32/warning_256_icon-icons.com_76006.png")); } var url = await _teamcityService.GetTeamCityBuildUrl(_buildId, "&tab=Inspection"); sections.Add(await CardBuilderHelper.GetLinkSectionToUrl(url, "Go to TeamCity build")); return(sections.ToArray()); }