Beispiel #1
0
        public IEnumerable <ManifestInfo> GetManifestsFromRepository(Uri bucketUri, CancellationToken cancellationToken)
        {
            var results = new List <ManifestInfo>();

            var repositoryRoot = _gitRepository.DownloadRepository(bucketUri, cancellationToken);

            if (repositoryRoot != null)
            {
                using (var repository = new Repository(repositoryRoot))
                {
                    var repositoryRemote = repository.Network.Remotes.Single().Url;
                    var branchName       = repository.Head.FriendlyName;

                    var manifestsSubPath = repository.Index.Any(x => x.Path.StartsWith("bucket/"))
                        ? "bucket"
                        : string.Empty;
                    var manifests = repository.Index.Where(x => IsManifestFile(x.Path, manifestsSubPath));
                    bool IsManifestPredicate(string filePath) => IsManifestFile(filePath, manifestsSubPath);

                    var commitCache = _gitRepository.GetCommitsCache(repository, IsManifestPredicate, cancellationToken);

                    foreach (var entry in manifests.TakeWhile(x => !cancellationToken.IsCancellationRequested))
                    {
                        var commit = commitCache[entry.Path].First();

                        var manifestMetadata = new ManifestMetadata(
                            repositoryRemote,
                            branchName,
                            entry.Path,
                            commit.Author.Name,
                            commit.Author.Email,
                            commit.Author.When,
                            commit.Sha);

                        var blob     = (Blob)commit[entry.Path].Target;
                        var manifest = CreateManifest(blob.GetContentText(), manifestMetadata);
                        if (manifest != null)
                        {
                            results.Add(manifest);
                        }
                    }
                }

                _gitRepository.DeleteRepository(repositoryRoot);
            }

            return(results);
        }