コード例 #1
0
        private async Task <HangoutCard> GetReportCard(DateTime utcNow)
        {
            var url = await _teamCityService.GetTeamCityBuildUrl(_buildId, "&tab=report_project117_Release_Note");

            var section = await CardBuilderHelper.GetLinkSectionToUrl(url, "Release notes");

            var sections = new [] { section };

            return(new HangoutCard
            {
                Header = CardBuilderHelper.GetCardHeader("<b>Daily release note</b>", utcNow, "https://icon-icons.com/icons2/560/PNG/128/Dynamic-Content_icon-icons.com_53724.png"),
                Sections = sections
            });
        }
コード例 #2
0
        private async Task <HangoutCardSection[]> GetSections(DuplicateComparator comparator)
        {
            var(newDuplicates, removedDuplicates, currentDuplicates) = comparator.GetComparison();

            var hasNew  = newDuplicates.Length > 0;
            var hasLess = removedDuplicates.Length > 0;

            Console.WriteLine($"Creating section of message for all {currentDuplicates.Length} duplications");
            var sections = new List <HangoutCardSection>
            {
                CardBuilderHelper.GetTextParagraphSection($"The total of duplications in our code base is <b>{currentDuplicates.Length}</b>.")
            };

            if (!hasNew && !hasLess)
            {
                Console.WriteLine("No change in duplications");
                sections.Add(CardBuilderHelper.GetTextParagraphSection("No change was found during the inspection"));
            }

            if (hasNew)
            {
                Console.WriteLine($"Adding section for the {newDuplicates.Length} new duplicates");
                sections.Add(CardBuilderHelper.GetTextParagraphSection(
                                 $"+ <b>{newDuplicates.Length}</b> duplication{(newDuplicates.Length == 1 ? "has" : "s have")} been introduced."));
            }

            if (hasLess)
            {
                Console.WriteLine($"Adding section for the {removedDuplicates.Length} removed duplicates");
                sections.Add(CardBuilderHelper.GetTextParagraphSection(
                                 $"- <b>{removedDuplicates.Length}</b> duplication{(removedDuplicates.Length == 1 ? "has" : "s have")} been removed."));
            }

            var url = await _teamcityService.GetTeamCityBuildUrl(_buildId, "&tab=Duplicator");

            sections.Add(await CardBuilderHelper.GetLinkSectionToUrl(url, "Go to TeamCity build"));

            return(sections.ToArray());
        }
        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());
        }