Exemplo n.º 1
0
 public static Uri GetArchiveUrl(IGitBranchRef branchRef) =>
 new Uri($"https://github.com/{branchRef.Owner}/{branchRef.Repo}/archive/{branchRef.Branch}.zip");
Exemplo n.º 2
0
        public static async Task <string> DownloadAndExtractGitRepoArchiveAsync(HttpClient httpClient, IGitBranchRef branchRef)
        {
            string uniqueName      = $"{branchRef.Owner}-{branchRef.Repo}-{branchRef.Branch}";
            string extractPath     = Path.Combine(Path.GetTempPath(), uniqueName);
            Uri    repoContentsUrl = GitHelper.GetArchiveUrl(branchRef);
            string zipPath         = Path.Combine(Path.GetTempPath(), $"{uniqueName}.zip");

            File.WriteAllBytes(zipPath, await httpClient.GetByteArrayAsync(repoContentsUrl));

            try
            {
                ZipFile.ExtractToDirectory(zipPath, extractPath);
            }
            finally
            {
                File.Delete(zipPath);
            }

            return(Path.Combine(extractPath, $"{branchRef.Repo}-{branchRef.Branch}"));
        }