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) });
        }
        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(InspectionsComparator comparator)
        {
            try
            {
                var(_, removedIssues, _) = comparator.GetComparison();

                var blamer = new GitBlamer(_gitPath);

                var(baseCommit, headCommit) = await _teamcityService.ComputeCommitRange(_buildId);

                var contributors = await blamer.GetRemovalContributors(baseCommit, headCommit, removedIssues, 3, ComputePathToRepo);

                var sections = new List <HangoutCardSection>();
                var rank     = 1;
                foreach (var contributor in contributors)
                {
                    sections.Add(CardBuilderHelper.GetKeyValueSection("Violations have 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 violations", "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);
        }
コード例 #4
0
        public async Task RunAsync()
        {
            var comparer = new InspectionsComparator(_old, _new, null);

            var(newIssues, removedIssues, _) = comparer.GetComparison();

            var blamer = new GitBlamer(_gitPath);

            var contributorsForNewViolations = await blamer.GetNewContributors(_headCommit, newIssues, 10, ComputePathToRepo);

            var contributorsForRemovalViolations = await blamer.GetRemovalContributors(_baseCommit, _headCommit, removedIssues, 10, ComputePathToRepo);

            Console.WriteLine("The top ten collaborators who added violations are:");
            var rank = 1;

            foreach (var collaborator in contributorsForNewViolations)
            {
                Console.WriteLine($"{rank}# {collaborator.Name} with {collaborator.Contributions.Count} fragments");
                rank++;
            }
            Console.WriteLine("");
            Console.WriteLine("The top ten collaborators who removed violations are:");
            var goodRank = 1;

            foreach (var collaborator in contributorsForRemovalViolations)
            {
                Console.WriteLine($"{goodRank}# {collaborator.Name} with {collaborator.Contributions.Count} fragments");
                goodRank++;
            }
        }