Exemplo n.º 1
0
        public IEnumerable <IFileNode> GetFiles(string url, SearchOption searchOption)
        {
            IGitHubUrl gitHubUrl  = GitHubUrl.Parse(url);
            string     branchName = gitHubUrl.Tree ?? GitHubUtilities.DefaultBranchName;

            if (string.IsNullOrWhiteSpace(gitHubUrl.Tree))
            {
                branchName = GetRepository(url).DefaultBranchName;
            }

            using (IWebClient webClient = CreateWebClient()) {
                HtmlDocument htmlDocument = new HtmlDocument();

                string fileListUrl = GetFileListUrl(url, branchName);

                htmlDocument.LoadHtml(webClient.DownloadString(fileListUrl));

                IEnumerable <IFileNode> nextFiles = ParseFiles(htmlDocument.DocumentNode);

                foreach (IFileNode file in nextFiles)
                {
                    yield return(file);

                    if (searchOption == SearchOption.AllDirectories && file.IsDirectory)
                    {
                        foreach (IFileNode nestedFile in GetFiles(file.Url, searchOption))
                        {
                            yield return(nestedFile);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public Repository(string url)
        {
            IGitHubUrl gitHubUrl = GitHubUrl.Parse(url);

            Name  = gitHubUrl.RepositoryName;
            Owner = gitHubUrl.Owner;
            Tree  = gitHubUrl.Tree;
        }
Exemplo n.º 3
0
        private string GetFileListUrl(string url, string branchName)
        {
            IGitHubUrl gitHubUrl = GitHubUrl.Parse(url);

            StringBuilder sb = new StringBuilder();

            sb.Append(GitHubUtilities.GitHubRootUrl);
            sb.Append(Uri.EscapeUriString(gitHubUrl.Owner));
            sb.Append("/");
            sb.Append(Uri.EscapeUriString(gitHubUrl.RepositoryName));
            sb.Append("/file-list/");
            sb.Append(Uri.EscapeUriString(branchName ?? GitHubUtilities.DefaultBranchName));

            if (!string.IsNullOrWhiteSpace(gitHubUrl.Path))
            {
                sb.Append(Uri.EscapeUriString(gitHubUrl.Path));
            }

            return(sb.ToString());
        }