public async Task <SemaphoreModel> FetchSemaphoreAsync( GitHubProject project, string @ref, string basePath, string semaphorePath) { string contents = await _github.GetGitHubFileContentsAsync( $"{basePath}/{semaphorePath}", project, @ref); return(SemaphoreModel.Parse(semaphorePath, contents)); }
private async Task AddUpdatedFile( List <GitObject> updatedFiles, IGitHubClient client, GitHubBranch branch, string repo, string filePath, string updatedContent) { string gitPath = string.Join('/', Options.GitOptions.Path, repo, filePath); string currentContent = await client.GetGitHubFileContentsAsync(gitPath, branch); if (currentContent == updatedContent) { Logger.WriteMessage($"File '{filePath}' has not changed."); } else { Logger.WriteMessage($"File '{filePath}' has changed."); updatedFiles.Add(new GitObject { Path = gitPath, Type = GitObject.TypeBlob, Mode = GitObject.ModeFile, Content = updatedContent }); } }
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 async Task <RepoData[]> GetImageInfoForSubscriptionAsync(Subscription subscription) { string imageDataJson; using (IGitHubClient gitHubClient = this.gitHubClientFactory.GetClient(Options.GitOptions.ToGitHubAuth(), Options.IsDryRun)) { GitHubProject project = new GitHubProject(Options.GitOptions.Repo, Options.GitOptions.Owner); GitHubBranch branch = new GitHubBranch(Options.GitOptions.Branch, project); GitRepo repo = subscription.RepoInfo; string imageInfoPath = $"{Options.GitOptions.Path}/image-info.{repo.Owner}-{repo.Name}-{repo.Branch}.json"; imageDataJson = await gitHubClient.GetGitHubFileContentsAsync(imageInfoPath, branch); } return(JsonConvert.DeserializeObject <RepoData[]>(imageDataJson)); }
private async Task <IEnumerable <GitObject> > FilterUpdatedGitObjectsAsync( IEnumerable <GitObject> gitObjects, IGitHubClient gitHubClient, GitHubBranch branch) { List <GitObject> updatedGitObjects = new(); foreach (GitObject gitObject in gitObjects) { string currentContent = await gitHubClient.GetGitHubFileContentsAsync(gitObject.Path, branch); if (currentContent == gitObject.Content) { _loggerService.WriteMessage($"File '{gitObject.Path}' has not changed."); } else { _loggerService.WriteMessage($"File '{gitObject.Path}' has changed."); updatedGitObjects.Add(gitObject); } } return(updatedGitObjects); }
public override async Task ExecuteAsync() { RepoData[] srcRepos = JsonConvert.DeserializeObject <RepoData[]>(File.ReadAllText(Options.ImageInfoPath)); using (IGitHubClient gitHubClient = this.gitHubClientFactory.GetClient(Options.GitOptions.ToGitHubAuth(), Options.IsDryRun)) { await GitHelper.ExecuteGitOperationsWithRetryAsync(async() => { bool hasChanges = false; GitReference gitRef = await GitHelper.PushChangesAsync(gitHubClient, Options, "Merging image info updates from build.", async branch => { string originalTargetImageInfoContents = await gitHubClient.GetGitHubFileContentsAsync(Options.GitOptions.Path, branch); IEnumerable <RepoData> newImageInfo; if (originalTargetImageInfoContents != null) { List <RepoData> targetRepos = JsonConvert.DeserializeObject <RepoData[]>(originalTargetImageInfoContents).ToList(); ImageInfoMergeOptions options = new ImageInfoMergeOptions { ReplaceTags = true }; ImageInfoHelper.MergeRepos(srcRepos, targetRepos, options); newImageInfo = targetRepos; } else { // If there is no existing file to update, there's nothing to merge with so the source data // becomes the target data. newImageInfo = srcRepos; } string newTargetImageInfoContents = JsonHelper.SerializeObject(newImageInfo.OrderBy(r => r.Repo).ToArray()) + Environment.NewLine; if (originalTargetImageInfoContents != newTargetImageInfoContents) { GitObject imageInfoGitObject = new GitObject { Path = Options.GitOptions.Path, Type = GitObject.TypeBlob, Mode = GitObject.ModeFile, Content = newTargetImageInfoContents }; hasChanges = true; return(new GitObject[] { imageInfoGitObject }); } else { return(Enumerable.Empty <GitObject>()); } }); Uri imageInfoPathIdentifier = GitHelper.GetBlobUrl(Options.GitOptions); if (hasChanges) { if (!Options.IsDryRun) { Uri commitUrl = GitHelper.GetCommitUrl(Options.GitOptions, gitRef.Object.Sha); Logger.WriteMessage($"The '{imageInfoPathIdentifier}' file was updated ({commitUrl})."); } else { Logger.WriteMessage($"The '{imageInfoPathIdentifier}' file would have been updated."); } } else { Logger.WriteMessage($"No changes to the '{imageInfoPathIdentifier}' file were needed."); } }); } }