/// <summary>
        /// Gets a Tree Response for a given SHA.
        /// </summary>
        /// <remarks>
        /// https://developer.github.com/v3/git/trees/#get-a-tree-recursively
        /// </remarks>
        /// <param name="owner">The owner of the repository</param>
        /// <param name="name">The name of the repository</param>
        /// <param name="reference">The SHA that references the tree</param>
        public IObservable <TreeResponse> GetRecursive(string owner, string name, string reference)
        {
            Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
            Ensure.ArgumentNotNullOrEmptyString(name, "name");
            Ensure.ArgumentNotNullOrEmptyString(reference, "reference");

            return(_client.GetRecursive(owner, name, reference).ToObservable());
        }
Beispiel #2
0
        // The GraphQL Api does not support the recursive reading of files so using the V3 API
        public async Task <List <RepositoryFile> > ReadFilesAsync(string owner, string name, string gitRef)
        {
            var repoFiles = new List <RepositoryFile>();

            TreeResponse treeResponse = null;

            try
            {
                treeResponse = await treesClient.GetRecursive(owner, name, gitRef).ConfigureAwait(false);
            }
            catch (Octokit.ApiException ex) when(ex.Message == "Git Repository is empty.")
            {
                return(repoFiles);
            }

            var treeItems = treeResponse.Tree;

            if (treeItems != null && treeItems.Any())
            {
                var fileTreeItems = treeItems.Where(treeItem => treeItem.Type == TreeType.Blob);

                foreach (var fileTreeItem in fileTreeItems)
                {
                    var codeRepoFile = new RepositoryFile();
                    codeRepoFile.FullPath = fileTreeItem.Path;
                    codeRepoFile.Name     = Path.GetFileName(codeRepoFile.FullPath);

                    repoFiles.Add(codeRepoFile);
                }
            }

            return(repoFiles);
        }