private void ValidateSettings(DarcSettings settings) { if (string.IsNullOrEmpty(settings.PersonalAccessToken)) { throw new ArgumentException("The personal access token is missing..."); } }
public Remote(DarcSettings settings, ILogger logger) { ValidateSettings(settings); _logger = logger; if (settings.GitType == GitRepoType.GitHub) { _gitClient = new GitHubClient(settings.PersonalAccessToken, _logger); } else if (settings.GitType == GitRepoType.AzureDevOps) { _gitClient = new AzureDevOpsClient(settings.PersonalAccessToken, _logger); } // Only initialize the file manager if we have a git client, which excludes "None" if (_gitClient != null) { _fileManager = new GitFileManager(_gitClient, _logger); } // Initialize the bar client if there is a password if (!string.IsNullOrEmpty(settings.BuildAssetRegistryPassword)) { if (!string.IsNullOrEmpty(settings.BuildAssetRegistryBaseUri)) { _barClient = ApiFactory.GetAuthenticated(settings.BuildAssetRegistryBaseUri, settings.BuildAssetRegistryPassword); } else { _barClient = ApiFactory.GetAuthenticated(settings.BuildAssetRegistryPassword); } } }
public static async Task <DependencyGraph> GetDependencyGraphAsync( DarcSettings darcSettings, DependencyDetail dependency, bool remote, ILogger logger, string reposFolder = null, IEnumerable <string> remotesMap = null, string testPath = null) { // Fail fast if darcSettings is null in a remote scenario if (remote && darcSettings == null) { throw new DarcException("In a remote scenario 'DarcSettings' have to be set."); } HashSet <DependencyDetail> uniqueDependencyDetails = new HashSet <DependencyDetail>( new DependencyDetailComparer()); DependencyGraphNode graphNode = new DependencyGraphNode(dependency); Stack <DependencyGraphNode> nodesToVisit = new Stack <DependencyGraphNode>(); nodesToVisit.Push(graphNode); uniqueDependencyDetails.Add(graphNode.DependencyDetail); while (nodesToVisit.Count > 0) { DependencyGraphNode node = nodesToVisit.Pop(); IEnumerable <DependencyDetail> dependencies = await GetDependenciesAsync( darcSettings, remote, logger, node, remotesMap, reposFolder, testPath); if (dependencies != null) { foreach (DependencyDetail dependencyDetail in dependencies) { DependencyGraphNode dependencyGraphNode = new DependencyGraphNode( dependencyDetail, node.VisitedNodes); dependencyGraphNode.VisitedNodes.Add(node.DependencyDetail.RepoUri); if (!graphNode.VisitedNodes.Contains(dependencyDetail.RepoUri) && dependencyDetail.RepoUri != node.DependencyDetail.RepoUri) { node.ChildNodes.Add(dependencyGraphNode); nodesToVisit.Push(dependencyGraphNode); uniqueDependencyDetails.Add(dependencyGraphNode.DependencyDetail); } } } } return(new DependencyGraph(graphNode, uniqueDependencyDetails)); }
private void ValidateSettings(DarcSettings settings) { // Should have a git repo type of AzureDevOps, GitHub, or None. if (settings.GitType == GitRepoType.GitHub || settings.GitType == GitRepoType.AzureDevOps) { // PAT is required for these types. if (string.IsNullOrEmpty(settings.PersonalAccessToken)) { throw new ArgumentException("The personal access token is missing..."); } } else if (settings.GitType != GitRepoType.None) { throw new ArgumentException($"Unexpected git repo type: {settings.GitType}"); } }
public Remote(DarcSettings settings, ILogger logger) { ValidateSettings(settings); _logger = logger; if (settings.GitType == GitRepoType.GitHub) { _gitClient = new GitHubClient(settings.PersonalAccessToken, _logger); } else { _gitClient = new VstsClient(settings.PersonalAccessToken, _logger); } _fileManager = new DependencyFileManager(_gitClient, _logger); _barClient = new BuildAssetRegistryClient(settings.BuildAssetRegistryBaseUri, _logger); }
private static async Task <IEnumerable <DependencyDetail> > GetDependenciesAsync( DarcSettings darcSettings, bool remote, ILogger logger, DependencyGraphNode node, IEnumerable <string> remotesMap, string reposFolder, string testPath = null) { try { IEnumerable <DependencyDetail> dependencies = null; if (!string.IsNullOrEmpty(testPath)) { testPath = Path.Combine( testPath, node.DependencyDetail.RepoUri, node.DependencyDetail.Commit); if (!string.IsNullOrEmpty(node.DependencyDetail.Commit) && Directory.Exists(testPath)) { Local local = new Local( Path.Combine( testPath, ".git"), logger); dependencies = await local.GetDependenciesAsync(); } } else if (remote) { Remote remoteClient = new Remote(darcSettings, logger); dependencies = await remoteClient.GetDependenciesAsync( node.DependencyDetail.RepoUri, node.DependencyDetail.Commit); } else { string repoPath = GetRepoPath(node.DependencyDetail, remotesMap, reposFolder, logger); if (!string.IsNullOrEmpty(repoPath)) { // Local's constructor expects the repo's .git folder to be passed in. In this // particular case we could pass any folder under 'repoPath' or even a fake one // but we use .git to keep things consistent to what Local expects Local local = new Local($"{repoPath}/.git", logger); string fileContents = LocalHelpers.GitShow( repoPath, node.DependencyDetail.Commit, VersionFiles.VersionDetailsXml, logger); dependencies = local.GetDependenciesFromFileContents(fileContents); } } return(dependencies); } catch (Exception exc) { logger.LogError(exc, $"Something failed while trying the fetch the " + $"dependencies of repo '{node.DependencyDetail.RepoUri}' at sha " + $"'{node.DependencyDetail.Commit}'"); throw; } }
public Local(DarcSettings settings, ILogger logger) { }