Beispiel #1
0
        public async Task <DependencyFlowGraph> GetDependencyFlowGraphAsync(
            int channelId,
            int days,
            bool includeArcade,
            bool includeBuildTimes,
            bool includeDisabledSubscriptions,
            IReadOnlyList <string> includedFrequencies)
        {
            var engLatestChannel = await GetChannelAsync(EngLatestChannelId);

            var eng3Channel = await GetChannelAsync(Eng3ChannelId);

            var defaultChannels = (await GetDefaultChannelsAsync()).ToList();

            if (includeArcade)
            {
                if (engLatestChannel != null)
                {
                    defaultChannels.Add(
                        new DefaultChannel(0, "https://github.com/dotnet/arcade", true)
                    {
                        Branch  = "master",
                        Channel = engLatestChannel
                    }
                        );
                }

                if (eng3Channel != null)
                {
                    defaultChannels.Add(
                        new DefaultChannel(0, "https://github.com/dotnet/arcade", true)
                    {
                        Branch  = "release/3.x",
                        Channel = eng3Channel
                    }
                        );
                }
            }

            var subscriptions = (await GetSubscriptionsAsync()).ToList();

            // Build, then prune out what we don't want to see if the user specified
            // channels.
            DependencyFlowGraph flowGraph = await DependencyFlowGraph.BuildAsync(
                defaultChannels,
                subscriptions,
                this,
                days);

            IEnumerable <string> frequencies
                = includedFrequencies == default || includedFrequencies.Count() == 0
                ? new string[] { "everyWeek", "twiceDaily", "everyDay", "everyBuild", "none", }
                : includedFrequencies;

            Channel targetChannel = null;

            if (channelId != 0)
            {
                targetChannel = await GetChannelAsync(channelId);
            }

            if (targetChannel != null)
            {
                flowGraph.PruneGraph(
                    node => DependencyFlowGraph.IsInterestingNode(targetChannel.Name, node),
                    edge => DependencyFlowGraph.IsInterestingEdge(edge, includeDisabledSubscriptions, frequencies));
            }

            if (includeBuildTimes)
            {
                var edgesWithLastBuild = flowGraph.Edges
                                         .Where(e => e.Subscription.LastAppliedBuild != null);

                foreach (var edge in edgesWithLastBuild)
                {
                    edge.IsToolingOnly = !_context.IsProductDependency(
                        edge.From.Repository,
                        edge.From.Branch,
                        edge.To.Repository,
                        edge.To.Branch);
                }

                flowGraph.MarkBackEdges();
                flowGraph.CalculateLongestBuildPaths();
                flowGraph.MarkLongestBuildPath();
            }

            return(flowGraph);
        }
Beispiel #2
0
        public async Task <IActionResult> GetFlowGraphAsync(
            int channelId = 0,
            bool includeDisabledSubscriptions = false,
#pragma warning disable API0001 // Versioned API methods should not expose non-versioned types.
            IEnumerable <string> includedFrequencies = default,
#pragma warning restore API0001 // Versioned API methods should not expose non-versioned types.
            bool includeBuildTimes = false,
            int days           = 7,
            bool includeArcade = true)
        {
            var barOnlyRemote = await _remoteFactory.GetBarOnlyRemoteAsync(Logger);

            Microsoft.DotNet.Maestro.Client.Models.Channel engLatestChannel = await barOnlyRemote.GetChannelAsync(EngLatestChannelId);

            Microsoft.DotNet.Maestro.Client.Models.Channel eng3Channel = await barOnlyRemote.GetChannelAsync(Eng3ChannelId);

            List <Microsoft.DotNet.Maestro.Client.Models.DefaultChannel> defaultChannels = (await barOnlyRemote.GetDefaultChannelsAsync()).ToList();

            if (includeArcade)
            {
                if (engLatestChannel != null)
                {
                    defaultChannels.Add(
                        new Microsoft.DotNet.Maestro.Client.Models.DefaultChannel(0, "https://github.com/dotnet/arcade", true)
                    {
                        Branch  = "master",
                        Channel = engLatestChannel
                    }
                        );
                }

                if (eng3Channel != null)
                {
                    defaultChannels.Add(
                        new Microsoft.DotNet.Maestro.Client.Models.DefaultChannel(0, "https://github.com/dotnet/arcade", true)
                    {
                        Branch  = "release/3.x",
                        Channel = eng3Channel
                    }
                        );
                }
            }

            List <Microsoft.DotNet.Maestro.Client.Models.Subscription> subscriptions = (await barOnlyRemote.GetSubscriptionsAsync()).ToList();

            // Build, then prune out what we don't want to see if the user specified
            // channels.
            DependencyFlowGraph flowGraph = await DependencyFlowGraph.BuildAsync(defaultChannels, subscriptions, barOnlyRemote, days);

            IEnumerable <string> frequencies = includedFrequencies == default || includedFrequencies.Count() == 0 ?
                                               new string[] { "everyWeek", "twiceDaily", "everyDay", "everyBuild", "none", } :
            includedFrequencies;

            Microsoft.DotNet.Maestro.Client.Models.Channel targetChannel = null;

            if (channelId != 0)
            {
                targetChannel = await barOnlyRemote.GetChannelAsync((int)channelId);
            }

            if (targetChannel != null)
            {
                flowGraph.PruneGraph(
                    node => DependencyFlowGraph.IsInterestingNode(targetChannel.Name, node),
                    edge => DependencyFlowGraph.IsInterestingEdge(edge, includeDisabledSubscriptions, frequencies));
            }

            if (includeBuildTimes)
            {
                var edgesWithLastBuild = flowGraph.Edges
                                         .Where(e => e.Subscription.LastAppliedBuild != null);

                foreach (var edge in edgesWithLastBuild)
                {
                    edge.IsToolingOnly = !_context.IsProductDependency(
                        edge.Subscription.LastAppliedBuild.Id,
                        edge.To.Repository,
                        edge.To.Branch);
                }

                flowGraph.MarkBackEdges();
                flowGraph.CalculateLongestBuildPaths();
                flowGraph.MarkLongestBuildPath();
            }

            // Convert flow graph to correct return type
            return(Ok(FlowGraph.Create(flowGraph)));
        }