private FetchedRepo(WritableRepositoryInformation repoInfo, RepoUtils repoUtils, ILogger <FetchedRepo> logger) { _repoInfo = repoInfo ?? throw new ArgumentNullException(nameof(repoInfo)); _repoUtils = repoUtils ?? throw new ArgumentNullException(nameof(repoUtils)); _repoFolder = Path.Combine(ReposIndexer.RepositoriesDirectory, repoInfo.Id); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
public static FetchedRepo GetInstance(WritableRepositoryInformation repo, RepoUtils repoUtils, ILogger <FetchedRepo> logger) { var fetchedRepo = new FetchedRepo(repo, repoUtils, logger); fetchedRepo.Init(); return(fetchedRepo); }
/// <summary> /// Tries to read the cache file of a repository. /// </summary> /// <param name="repo">Repo to read the cache file for</param> /// <param name="cached">The read cached version or null if none has been created.</param> /// <returns>true if a cache file has been found and loaded.</returns> public bool TryGetCachedVersion(WritableRepositoryInformation repo, out RepositoryInformation cached) { var repoCacheFile = GetCachePath(repo.Id); _logger.LogInformation("Cache lookup for repo {RepoId}", repo.Id); if (!File.Exists(repoCacheFile)) { cached = null; return(false); } _logger.LogInformation("Cache hit for repo {RepoId} on file {FileName}", repo.Id, repoCacheFile); repo.AddDependencies(JsonConvert.DeserializeObject <IReadOnlyList <string> >(File.ReadAllText(repoCacheFile))); cached = repo.ToRepositoryInformation(); return(true); }
private RepositoryInformation ProcessSingleRepo(WritableRepositoryInformation repo) { if (_repoCache.TryGetCachedVersion(repo, out var cachedVersion)) { return(cachedVersion); } using (_telemetry.TrackIndexRepositoryDuration(repo.Id)) using (_logger.BeginScope("Starting indexing for repo {Name}", repo.Id)) using (var fetchedRepo = _repoFetcher.FetchRepo(repo)) { IReadOnlyList <GitFileInfo> files; using (_telemetry.TrackListFilesDuration(repo.Id)) { _logger.LogInformation("Finding files in repo {Name}...", repo.Id); files = fetchedRepo.GetFileInfos(); } var filePaths = files.Where(ShouldCheckOutFile).Select(x => x.Path).ToList(); IReadOnlyList <ICheckedOutFile> checkedOutFiles; using (_telemetry.TrackCheckOutFilesDuration(repo.Id)) { _logger.LogInformation( "Checking out {FileCount} files from repo {Name}", filePaths.Count, repo.Id); checkedOutFiles = fetchedRepo.CheckoutFiles(filePaths); } foreach (var cfgFile in checkedOutFiles) { var dependencies = _configFileParser.Parse(cfgFile); repo.AddDependencies(dependencies); } _logger.LogInformation("Finished indexing repo {Name}", repo.Id); } var result = repo.ToRepositoryInformation(); _repoCache.Persist(result); return(result); }
public IFetchedRepo FetchRepo(WritableRepositoryInformation repo) { return(FetchedRepo.GetInstance(repo, _repoUtils, _loggerFactory.CreateLogger <FetchedRepo>())); }