private static async Task <ManifestInfo?> GetSubscriptionManifestAsync(Subscription subscription, ManifestFilterOptions filterOptions, HttpClient httpClient, ILoggerService loggerService, Action <ManifestOptions>?configureOptions) { // If the command is filtered with an OS type that does not match the OsType filter of the subscription, // then there are no images that need to be inspected. string osTypeRegexPattern = ManifestFilter.GetFilterRegexPattern(filterOptions.OsType); if (!string.IsNullOrEmpty(subscription.OsType) && !Regex.IsMatch(subscription.OsType, osTypeRegexPattern, RegexOptions.IgnoreCase)) { return(null); } string repoPath = await GitHelper.DownloadAndExtractGitRepoArchiveAsync(httpClient, subscription.Manifest, loggerService); try { TempManifestOptions manifestOptions = new(filterOptions) { Manifest = Path.Combine(repoPath, subscription.Manifest.Path), Variables = subscription.Manifest.Variables }; configureOptions?.Invoke(manifestOptions); return(ManifestInfo.Load(manifestOptions)); } finally { // The path to the repo is stored inside a zip extraction folder so be sure to delete that // zip extraction folder, not just the inner repo folder. Directory.Delete(new DirectoryInfo(repoPath).Parent !.FullName, true); } }
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}")); }
public string GetCommitSha(string filePath, bool useFullHash = false) { return(GitHelper.GetCommitSha(filePath, useFullHash)); }