示例#1
0
        public IEnumerable <INotification> ProduceNotifications(IBuildTreeBuildsDelta fromDelta)
        {
            if (NothingChanged(fromDelta))
            {
                return(Enumerable.Empty <INotification>());
            }

            return(CreateNotifications(fromDelta));
        }
示例#2
0
        private IEnumerable <INotification> CreateNotifications(IBuildTreeBuildsDelta fromDelta)
        {
            var succeeded = FilterSucceeded(fromDelta).ToList();
            var failed    = FilterFailed(fromDelta).ToList();
            var cancelled = FilterCancelled(fromDelta).ToList();

            var allGroups = new List <List <IBuildNode> > {
                succeeded, failed, cancelled
            };

            foreach (var buildNodes in allGroups.Where(x => x.Count > 0))
            {
                var status = buildNodes.Max(x => ParseStatus(x.Status));

                // try to group by definition/branch etc.
                var groupedByDefinitionAndBranch = GroupByDefinitionAndBranch(buildNodes).ToList();
                var groupedByDefinition          = GroupByDefinition(buildNodes).ToList();
                var groupedByBranch = GroupByBranch(buildNodes).ToList();

                // only display groups with a size of up to 3 elements
                var allGroupings = new List <IEnumerable <object> > {
                    groupedByDefinitionAndBranch, groupedByDefinition, groupedByBranch
                };
                var smallestCount = allGroupings.Min(x => x.Count());

                // for a single build, also display the build notification
                if (smallestCount > 3 || allGroups.SelectMany(x => x).Count() == 1)
                {
                    yield return(BuildsNotifications(buildNodes, status));

                    continue;
                }

                // only give this message if it's exactly the same definition and branch for every build
                // otherwise there would be two many messages
                if (groupedByDefinitionAndBranch.Count == 1)
                {
                    var(definition, branch) = groupedByDefinitionAndBranch.First().Key;
                    yield return(DefinitionAndBranchNotification(buildNodes, status, definition, branch));

                    continue;
                }

                if (groupedByDefinition.Count == smallestCount)
                {
                    yield return(DefinitionNotification(buildNodes, status, groupedByDefinition.Select(x => x.Key)));

                    continue;
                }

                yield return(BranchNotification(buildNodes, status, groupedByBranch.Select(x => x.Key)));
            }
        }
示例#3
0
        public async Task Update(UpdateModes mode = UpdateModes.DeltaBuilds)
        {
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            Log.Info().Message("Starting update.").Write();
            var treeResult = await Task.Run(async() =>
            {
                var previousBuildStatus = _buildCache.CachedValues().ToDictionary(p => p.Key, p => p.Value.Status);
                var branchTask          = FetchBranches();
                var definitionsTask     = FetchDefinitions();
                var buildsTask          = FetchBuilds(mode);

                await Task.WhenAll(branchTask, definitionsTask, buildsTask);

                Log.Debug().Message("Everything is fetched.").Write();

                await UpdateBuilds();

                CleanupBuilds();

                var tree = BuildTree();

                var currentBuildNodes = tree.AllChildren().OfType <IBuildNode>();

                Log.Debug().Message("BuildTree is done. Producing notifications.").Write();
                // don't show any notifications for the initial fetch
                IBuildTreeBuildsDelta delta = _oldTree == null
                    ? new BuildTreeBuildsDelta()
                    : new BuildTreeBuildsDelta(currentBuildNodes, previousBuildStatus, _configuration.PartialSucceededTreatmentMode);

                var notifications = _notificationFactory.ProduceNotifications(delta).ToList();
                return(BuildTree : tree, Notifications : notifications);
            });

            Log.Debug().Message("Calling notify.").Write();
            _pipelineNotifier.Notify(treeResult.BuildTree, treeResult.Notifications);

            _oldTree = treeResult.BuildTree;
            stopWatch.Stop();
            Log.Info().Message($"Update done in {stopWatch.ElapsedMilliseconds} ms.").Write();
        }