From f35493bcd4deaec5002fc8b68eb8bdd9e223caeb Mon Sep 17 00:00:00 2001 From: Daniel Hunegnaw Date: Wed, 8 Mar 2023 14:06:48 -0800 Subject: [PATCH] Updating the tool to support updating specific components given a component path --- NugetUpdate/Repositories/AzureDevOps.cs | 12 +++++++++--- NugetUpdate/Repositories/Github.cs | 2 +- NugetUpdate/Repositories/IRepositorySource.cs | 2 +- NugetUpdate/RepositorySourceExtensions.cs | 4 ++-- NugetUpdate/UpdateManager.cs | 9 +++++---- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/NugetUpdate/Repositories/AzureDevOps.cs b/NugetUpdate/Repositories/AzureDevOps.cs index b02dfee..8747421 100644 --- a/NugetUpdate/Repositories/AzureDevOps.cs +++ b/NugetUpdate/Repositories/AzureDevOps.cs @@ -31,7 +31,7 @@ public AzureDevOps(string token, string organization, string project, string rep _workItemService = new WorkItemService(organization, project, token); } - public async Task> FindProjectFiles() + public async Task> FindProjectFiles(string componentDirectory = null) { var response = await _client.GetAsync($"{_apiBase}/items?api-version=2.0-preview&versionType=branch&Version={_defaultBranch}&recursionLevel=Full"); @@ -43,9 +43,15 @@ public async Task> FindProjectFiles() foreach (dynamic item in content.value) { - if (((string)item.path).EndsWith("csproj")) + string path = (string)item.path ; + + Func isValidCsProj = p =>!string.IsNullOrEmpty(p) + && (string.IsNullOrWhiteSpace(componentDirectory) || !string.IsNullOrWhiteSpace(componentDirectory) && p.ToLower().Contains(componentDirectory.ToLower())) + && p.EndsWith("csproj"); + + if (isValidCsProj(path)) { - results.Add((string)item.path); + results.Add(path); } } diff --git a/NugetUpdate/Repositories/Github.cs b/NugetUpdate/Repositories/Github.cs index bfa067e..7e07d00 100644 --- a/NugetUpdate/Repositories/Github.cs +++ b/NugetUpdate/Repositories/Github.cs @@ -162,7 +162,7 @@ public async Task GetTextFile(string path) return new TextFile(path, fromBase64String, true); } - public async Task> FindProjectFiles() + public async Task> FindProjectFiles(string componentDirectory = null) { var results = new List(); diff --git a/NugetUpdate/Repositories/IRepositorySource.cs b/NugetUpdate/Repositories/IRepositorySource.cs index 887c5ac..d652727 100644 --- a/NugetUpdate/Repositories/IRepositorySource.cs +++ b/NugetUpdate/Repositories/IRepositorySource.cs @@ -11,6 +11,6 @@ public interface IRepositorySource Task GetTextFile(string path); - Task> FindProjectFiles(); + Task> FindProjectFiles(string componentDirectory = null); } } \ No newline at end of file diff --git a/NugetUpdate/RepositorySourceExtensions.cs b/NugetUpdate/RepositorySourceExtensions.cs index 7b2732e..9a5e907 100644 --- a/NugetUpdate/RepositorySourceExtensions.cs +++ b/NugetUpdate/RepositorySourceExtensions.cs @@ -5,11 +5,11 @@ namespace NugetPackageUpdates { public static class RepositorySourceExtensions { - public static async Task> GetProjectFiles(this IRepositorySource repository) + public static async Task> GetProjectFiles(this IRepositorySource repository, string componentDirectory = null) { var files = new List(); - foreach (var path in await repository.FindProjectFiles()) + foreach (var path in await repository.FindProjectFiles(componentDirectory)) { files.Add(await repository.GetProjectFile(path)); } diff --git a/NugetUpdate/UpdateManager.cs b/NugetUpdate/UpdateManager.cs index 24b895f..6072d06 100644 --- a/NugetUpdate/UpdateManager.cs +++ b/NugetUpdate/UpdateManager.cs @@ -46,9 +46,10 @@ public async Task CreatePullRequestsAsync( IRepositorySource ops, string[] reviewers, int? prLimit = null, - bool associatWithWorkItem = false) + bool associatWithWorkItem = false, + string componentDirectory = null) { - var changeSets = await GetChangeSets(ops); + var changeSets = await GetChangeSets(ops, componentDirectory: componentDirectory); _log.WriteLine("Opening PRs"); @@ -65,10 +66,10 @@ public async Task CreatePullRequestsAsync( } } - public async Task> GetChangeSets(IRepositorySource ops) + public async Task> GetChangeSets(IRepositorySource ops, string componentDirectory = null) { _log.WriteLine("Fetching project files"); - var projectFiles = await ops.GetProjectFiles(); + var projectFiles = await ops.GetProjectFiles(componentDirectory); if (projectFiles == null || !projectFiles.Any()) {