Example #1
0
        private async Task <GitObject> GetUpdatedImageInfoGitObjectAsync()
        {
            ImageArtifactDetails srcImageArtifactDetails = ImageInfoHelper.LoadFromFile(Options.ImageInfoPath, Manifest);

            string repoPath = await GitHelper.DownloadAndExtractGitRepoArchiveAsync(httpClient, Options.GitOptions);

            try
            {
                string repoImageInfoPath = Path.Combine(repoPath, Options.GitOptions.Path);
                string originalTargetImageInfoContents = File.ReadAllText(repoImageInfoPath);

                ImageArtifactDetails newImageArtifactDetails;

                if (originalTargetImageInfoContents != null)
                {
                    ImageArtifactDetails targetImageArtifactDetails = ImageInfoHelper.LoadFromContent(
                        originalTargetImageInfoContents, Manifest, skipManifestValidation: true);

                    RemoveOutOfDateContent(targetImageArtifactDetails);

                    ImageInfoMergeOptions options = new ImageInfoMergeOptions
                    {
                        ReplaceTags = true
                    };

                    ImageInfoHelper.MergeImageArtifactDetails(srcImageArtifactDetails, targetImageArtifactDetails, options);

                    newImageArtifactDetails = targetImageArtifactDetails;
                }
                else
                {
                    // If there is no existing file to update, there's nothing to merge with so the source data
                    // becomes the target data.
                    newImageArtifactDetails = srcImageArtifactDetails;
                }

                string newTargetImageInfoContents =
                    JsonHelper.SerializeObject(newImageArtifactDetails) + Environment.NewLine;

                if (originalTargetImageInfoContents != newTargetImageInfoContents)
                {
                    return(new GitObject
                    {
                        Path = Options.GitOptions.Path,
                        Type = GitObject.TypeBlob,
                        Mode = GitObject.ModeFile,
                        Content = newTargetImageInfoContents
                    });
                }
                else
                {
                    return(null);
                }
            }
            finally
            {
                Directory.Delete(repoPath, recursive: true);
            }
        }
Example #2
0
        private async Task <ImageArtifactDetails> GetImageInfoForSubscriptionAsync(Subscription subscription, ManifestInfo manifest)
        {
            string imageDataJson;

            using (IGitHubClient gitHubClient = _gitHubClientFactory.GetClient(Options.GitOptions.ToGitHubAuth(), Options.IsDryRun))
            {
                GitHubProject project = new GitHubProject(subscription.ImageInfo.Repo, subscription.ImageInfo.Owner);
                GitHubBranch  branch  = new GitHubBranch(subscription.ImageInfo.Branch, project);

                GitFile repo = subscription.Manifest;
                imageDataJson = await gitHubClient.GetGitHubFileContentsAsync(subscription.ImageInfo.Path, branch);
            }

            return(ImageInfoHelper.LoadFromContent(imageDataJson, manifest, skipManifestValidation: true));
        }
        private string?GetUpdatedImageInfo(string repoPath)
        {
            ImageArtifactDetails srcImageArtifactDetails = ImageInfoHelper.LoadFromFile(Options.ImageInfoPath, Manifest);

            string repoImageInfoPath = Path.Combine(repoPath, Options.GitOptions.Path);
            string originalTargetImageInfoContents = File.ReadAllText(repoImageInfoPath);

            ImageArtifactDetails newImageArtifactDetails;

            if (originalTargetImageInfoContents != null)
            {
                ImageArtifactDetails targetImageArtifactDetails = ImageInfoHelper.LoadFromContent(
                    originalTargetImageInfoContents, Manifest, skipManifestValidation: true);

                RemoveOutOfDateContent(targetImageArtifactDetails);

                ImageInfoMergeOptions options = new ImageInfoMergeOptions
                {
                    IsPublish = true
                };

                ImageInfoHelper.MergeImageArtifactDetails(srcImageArtifactDetails, targetImageArtifactDetails, options);

                newImageArtifactDetails = targetImageArtifactDetails;
            }
            else
            {
                // If there is no existing file to update, there's nothing to merge with so the source data
                // becomes the target data.
                newImageArtifactDetails = srcImageArtifactDetails;
            }

            string newTargetImageInfoContents =
                JsonHelper.SerializeObject(newImageArtifactDetails) + Environment.NewLine;

            if (originalTargetImageInfoContents != newTargetImageInfoContents)
            {
                return(newTargetImageInfoContents);
            }
            else
            {
                return(null);
            }
        }