private async Task CommitFilesForPullRequest(string repoUri, string branch, string assetsProducedInCommit, IEnumerable <DependencyDetail> itemsToUpdate, string pullRequestBaseBranch = null, string pullRequestTitle = null, string pullRequestDescription = null) { DependencyFileContentContainer fileContainer = await _fileManager.UpdateDependencyFiles(itemsToUpdate, repoUri, branch); Dictionary <string, GitCommit> dependencyFilesToCommit = fileContainer.GetFilesToCommitMap(pullRequestBaseBranch); await _gitClient.PushFilesAsync(dependencyFilesToCommit, repoUri, pullRequestBaseBranch); // If there is an arcade asset that we need to update we try to update the script files as well DependencyDetail arcadeItem = itemsToUpdate.Where(i => i.Name.ToLower().Contains("arcade")).FirstOrDefault(); if (arcadeItem != null) { await _gitClient.PushFilesAsync(await GetScriptCommitsAsync(repoUri, branch, assetsProducedInCommit, pullRequestBaseBranch), repoUri, pullRequestBaseBranch); } }
public async Task <DependencyFileContentContainer> UpdateDependencyFiles(IEnumerable <DependencyDetail> itemsToUpdate, string repoUri, string branch) { XmlDocument versionDetails = await ReadVersionDetailsXmlAsync(repoUri, branch); XmlDocument versionProps = await ReadVersionPropsAsync(repoUri, branch); JObject globalJson = await ReadGlobalJsonAsync(repoUri, branch); foreach (DependencyDetail itemToUpdate in itemsToUpdate) { XmlNodeList versionList = versionDetails.SelectNodes($"//Dependency[@Name='{itemToUpdate.Name}']"); if (versionList.Count == 0 || versionList.Count > 1) { if (versionList.Count == 0) { _logger.LogError($"No dependencies named '{itemToUpdate.Name}' found."); } else { _logger.LogError("The use of the same asset, even with a different version, is currently not supported."); } return(null); } XmlNode parentNode = itemToUpdate.Type == DependencyType.Product ? versionDetails.DocumentElement.SelectSingleNode("ProductDependencies") : versionDetails.DocumentElement.SelectSingleNode("ToolsetDependencies"); XmlNodeList nodesToUpdate = parentNode.SelectNodes($"//Dependency[@Name='{itemToUpdate.Name}']"); foreach (XmlNode dependencyToUpdate in nodesToUpdate) { dependencyToUpdate.Attributes["Version"].Value = itemToUpdate.Version; dependencyToUpdate.SelectSingleNode("Sha").InnerText = itemToUpdate.Commit; // If the dependency is of Product type we also have to update version.props // If the dependency is of Toolset type and it has no <Expression> defined or not set to VersionProps we also update global.json // if not, we update version.props if (itemToUpdate.Type == DependencyType.Product) { UpdateVersionPropsDoc(versionProps, itemToUpdate); } else { if (dependencyToUpdate.SelectSingleNode("Expression") != null && dependencyToUpdate.SelectSingleNode("Expression").InnerText == VersionPropsExpression) { UpdateVersionPropsDoc(versionProps, itemToUpdate); } else { UpdateVersionGlobalJson(itemToUpdate.Name, itemToUpdate.Version, globalJson); } } } } DependencyFileContentContainer fileContainer = new DependencyFileContentContainer { GlobalJson = new DependencyFileContent(DependencyFilePath.GlobalJson, globalJson), VersionDetailsXml = new DependencyFileContent(DependencyFilePath.VersionDetailsXml, versionDetails), VersionProps = new DependencyFileContent(DependencyFilePath.VersionProps, versionProps) }; return(fileContainer); }