public static async Task <string> DownloadAndExtractGitRepoArchiveAsync( HttpClient httpClient, IGitHubBranchRef branchRef, ILoggerService loggerService) { string uniqueName = $"{branchRef.Owner}-{branchRef.Repo}-{branchRef.Branch}"; string extractPath = Path.Combine(Path.GetTempPath(), uniqueName); Uri repoContentsUrl = GetArchiveUrl(branchRef); string zipPath = Path.Combine(Path.GetTempPath(), $"{uniqueName}.zip"); byte[] bytes = await RetryHelper.GetWaitAndRetryPolicy <Exception>(loggerService) .ExecuteAsync(() => httpClient.GetByteArrayAsync(repoContentsUrl)); File.WriteAllBytes(zipPath, bytes); try { ZipFile.ExtractToDirectory(zipPath, extractPath); } finally { File.Delete(zipPath); } return(Path.Combine(extractPath, $"{branchRef.Repo}-{branchRef.Branch}")); }
public static Uri GetArchiveUrl(IGitHubBranchRef branchRef) => new Uri($"https://github.com/{branchRef.Owner}/{branchRef.Repo}/archive/{branchRef.Branch}.zip");
public static async Task <string> DownloadAndExtractGitRepoArchiveAsync(HttpClient httpClient, IGitHubBranchRef 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}")); }