コード例 #1
0
        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 <HttpContent[]> GetMessages(InspectionsComparator comparer, DateTime nowUtc)
        {
            var(newIssues, removedIssues, currentIssues) = comparer.GetComparison();
            var sections = await GetSections(newIssues, removedIssues, currentIssues, comparer);

            Console.WriteLine("Creating header section of message");
            var card = new HangoutCard
            {
                Header   = CardBuilderHelper.GetCardHeader("<b>Inspection daily report</b>", nowUtc, "https://icon-icons.com/icons2/624/PNG/128/Inspection-80_icon-icons.com_57310.png"),
                Sections = sections
            };

            var card2 = await GetLeaderBoardCard(comparer);

            var cards = new List <HangoutCard> {
                card
            };

            if (card2 != null)
            {
                cards.Add(card2);
            }

            var content = JsonConvert.SerializeObject(new HangoutCardMessage
            {
                Cards = cards.ToArray()
            });

            Console.WriteLine($"Sending message to Hangout:\r\n{content}");
            return(new HttpContent[] { new StringContent(content) });
        }
コード例 #3
0
        private async Task <HangoutCard> GetReportCard(DuplicateComparator comparator, DateTime nowUtc)
        {
            var sections = await GetSections(comparator);

            return(new HangoutCard
            {
                Header = CardBuilderHelper.GetCardHeader("<b>Duplicate daily report</b>", nowUtc, "https://icon-icons.com/icons2/1278/PNG/128/1497562286-gemini-zodiac-sign_85087.png"),
                Sections = sections
            });
        }
コード例 #4
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
            });
        }
コード例 #5
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());
        }