private static async Task <string> CheckAndPopulateFileContentAsync(GitHttpClient client, RepositoryReference repo, IEnumerable <GitTreeEntryRef> tree, string value, string folder = null) { if (string.IsNullOrEmpty(value) || !Uri.IsWellFormedUriString(value, UriKind.Relative)) { return(value); } var fileName = value.Split('/', StringSplitOptions.RemoveEmptyEntries).Last(); var filePath = string.IsNullOrEmpty(folder) ? fileName : $"{folder}/{fileName}"; var fileItem = tree.FirstOrDefault(i => i.RelativePath.Equals(filePath, StringComparison.Ordinal)); if (fileItem is null) { return(value); } var fileStream = await client .GetItemContentAsync(project : repo.Project, repo.Repository, fileItem.RelativePath, download : true, versionDescriptor : repo.VersionDescriptor()) .ConfigureAwait(false); using var streamReader = new StreamReader(fileStream); var file = await streamReader .ReadToEndAsync() .ConfigureAwait(false); return(string.IsNullOrEmpty(file) ? value : file); }
private static async Task <ComponentTemplate> ResolveComponentTemplateAsync(ProjectTemplate projectTemplate, RepositoryReference repository, GitHttpClient client, GitTreeRef tree, GitTreeEntryRef treeItem) { var componentYamlFile = await client .GetItemAsync(project : repository.Project, repository.Repository, treeItem.RelativePath, download : true, versionDescriptor : repository.VersionDescriptor()) .ConfigureAwait(false); var componentYaml = componentYamlFile.Content; var componentJson = new Deserializer().ToJson(componentYaml); var componentTemplate = TeamCloudSerialize.DeserializeObject <ComponentTemplate>(componentJson, new ComponentTemplateConverter(projectTemplate, componentYamlFile.Path)); var folder = treeItem.RelativePath.Split(Constants.ComponentYaml).First().TrimEnd('/'); componentTemplate.Description = await CheckAndPopulateFileContentAsync(client, repository, tree.TreeEntries, componentTemplate.Description, folder) .ConfigureAwait(false); return(componentTemplate); }