コード例 #1
0
        public static async Task <DependencyFlowGraph> BuildAsync(
            List <DefaultChannel> defaultChannels,
            List <Subscription> subscriptions,
            IBarClient barClient,
            int days)
        {
            // Dictionary of nodes. Key is the repo+branch
            Dictionary <string, DependencyFlowNode> nodes = new Dictionary <string, DependencyFlowNode>(
                StringComparer.OrdinalIgnoreCase);
            List <DependencyFlowEdge> edges = new List <DependencyFlowEdge>();

            // First create all the channel nodes. There may be disconnected
            // nodes in the graph, so we must process all channels and all subscriptions
            foreach (DefaultChannel channel in defaultChannels)
            {
                DependencyFlowNode flowNode = GetOrCreateNode(channel.Repository, channel.Branch, nodes);

                // Add the build times
                if (channel.Id != default(int))
                {
                    BuildTime buildTime = await barClient.GetBuildTimeAsync(channel.Id, days);

                    flowNode.OfficialBuildTime = buildTime.OfficialBuildTime ?? 0;
                    flowNode.PrBuildTime       = buildTime.PrBuildTime ?? 0;
                    flowNode.GoalTimeInMinutes = buildTime.GoalTimeInMinutes ?? 0;
                }
                else
                {
                    flowNode.OfficialBuildTime = 0;
                    flowNode.PrBuildTime       = 0;
                }

                // Add a the output mapping.
                flowNode.OutputChannels.Add(channel.Channel.Name);
            }

            // Process all subscriptions (edges)
            foreach (Subscription subscription in subscriptions)
            {
                // Get the target of the subscription
                DependencyFlowNode destinationNode = GetOrCreateNode(subscription.TargetRepository, subscription.TargetBranch, nodes);
                // Add the input channel for the node
                destinationNode.InputChannels.Add(subscription.Channel.Name);
                // Find all input nodes by looking up the default channels of the subscription input channel and repository.
                // This may return no nodes if there is no default channel for the inputs.
                IEnumerable <DefaultChannel> inputDefaultChannels = defaultChannels.Where(d => d.Channel.Name == subscription.Channel.Name &&
                                                                                          d.Repository.Equals(subscription.SourceRepository, StringComparison.OrdinalIgnoreCase));
                foreach (DefaultChannel defaultChannel in inputDefaultChannels)
                {
                    DependencyFlowNode sourceNode = GetOrCreateNode(defaultChannel.Repository, defaultChannel.Branch, nodes);

                    DependencyFlowEdge newEdge = new DependencyFlowEdge(sourceNode, destinationNode, subscription);
                    destinationNode.IncomingEdges.Add(newEdge);
                    sourceNode.OutgoingEdges.Add(newEdge);
                    edges.Add(newEdge);
                }
            }

            return(new DependencyFlowGraph(nodes.Select(kv => kv.Value).ToList(), edges));
        }
コード例 #2
0
ファイル: Remote.cs プロジェクト: theaoqi/arcade-services
        public Remote(IGitRepo gitClient, IBarClient barClient, ILogger logger)
        {
            _logger    = logger;
            _barClient = barClient;
            _gitClient = gitClient;

            if (_gitClient != null)
            {
                _fileManager = new GitFileManager(_gitClient, _logger);
            }
        }
コード例 #3
0
        /// <summary>
        ///     Get a remote for a specific repo.
        /// </summary>
        /// <param name="options">Command line options</param>
        /// <param name="repoUrl">Repository url</param>
        /// <param name="logger">Logger</param>
        /// <returns>New remote</returns>
        public static IRemote GetRemote(CommandLineOptions options, string repoUrl, ILogger logger)
        {
            DarcSettings darcSettings = LocalSettings.GetDarcSettings(options, logger, repoUrl);

            if (darcSettings.GitType != GitRepoType.None &&
                string.IsNullOrEmpty(darcSettings.GitRepoPersonalAccessToken))
            {
                throw new DarcException($"No personal access token was provided for repo type '{darcSettings.GitType}'");
            }

            // If a temporary repository root was not provided, use the environment
            // provided temp directory.
            string temporaryRepositoryRoot = darcSettings.TemporaryRepositoryRoot;

            if (string.IsNullOrEmpty(temporaryRepositoryRoot))
            {
                temporaryRepositoryRoot = Path.GetTempPath();
            }

            IGitRepo gitClient = null;

            if (darcSettings.GitType == GitRepoType.GitHub)
            {
                gitClient = new GitHubClient(options.GitLocation, darcSettings.GitRepoPersonalAccessToken,
                                             logger,
                                             temporaryRepositoryRoot,
                                             // Caching not in use for Darc local client.
                                             null);
            }
            else if (darcSettings.GitType == GitRepoType.AzureDevOps)
            {
                gitClient = new AzureDevOpsClient(options.GitLocation, darcSettings.GitRepoPersonalAccessToken,
                                                  logger,
                                                  temporaryRepositoryRoot);
            }

            IBarClient barClient = null;

            if (!string.IsNullOrEmpty(darcSettings.BuildAssetRegistryPassword))
            {
                barClient = new MaestroApiBarClient(darcSettings.BuildAssetRegistryPassword,
                                                    darcSettings.BuildAssetRegistryBaseUri);
            }
            return(new Remote(gitClient, barClient, logger));
        }