diff --git a/AzureDevOps.WorkItemClone.ConsoleUI/Commands/WorkItemCloneCommand.cs b/AzureDevOps.WorkItemClone.ConsoleUI/Commands/WorkItemCloneCommand.cs index ec856b9..d484092 100644 --- a/AzureDevOps.WorkItemClone.ConsoleUI/Commands/WorkItemCloneCommand.cs +++ b/AzureDevOps.WorkItemClone.ConsoleUI/Commands/WorkItemCloneCommand.cs @@ -73,7 +73,7 @@ await AnsiConsole.Progress() var task5 = ctx.AddTask("[bold]Stage 5[/]: Create Output Plan Relations ", false); var task6 = ctx.AddTask("[bold]Stage 6[/]: Create Work Items", false); - string cacheTemplateWorkItemsFile = $"{config.CachePath}\\templateCache-{config.templateOrganization}-{config.templateProject}.json"; + string cacheTemplateWorkItemsFile = $"{config.CachePath}\\templateCache-{config.templateOrganization}-{config.templateProject}-{config.templateParentId}.json"; if (config.ClearCache && System.IO.File.Exists(cacheTemplateWorkItemsFile)) { @@ -81,11 +81,26 @@ await AnsiConsole.Progress() } task1.MaxValue = 1; - List templateWorkItems; + List templateWorkItems = null; + + + + task1.StartTask(); + task2.StartTask(); + if (System.IO.File.Exists(cacheTemplateWorkItemsFile)) { + + var changedDate = System.IO.File.GetLastWriteTime(cacheTemplateWorkItemsFile).AddDays(1).Date; + //Test Cache + QueryResults fakeItemsFromTemplateQuery; + fakeItemsFromTemplateQuery = await templateApi.GetWiqlQueryResults("Select [System.Id] From WorkItems Where [System.TeamProject] = '@project' AND [System.Parent] = @id AND [System.ChangedDate] > '@changeddate' order by [System.CreatedDate] desc", new Dictionary() { { "@id", config.templateParentId.ToString() }, { "@changeddate", changedDate.ToString("yyyy-MM-dd") } }); + if (fakeItemsFromTemplateQuery.workItems.Length == 0) + { + AnsiConsole.WriteLine($"Stage 1: Checked template for changes. None Detected. Loading Cache"); + // Load from Cache - task1.StartTask(); + task1.Increment(1); task1.Description = task1.Description + " (cache)"; await Task.Delay(250); @@ -95,8 +110,10 @@ await AnsiConsole.Progress() task2.Increment(templateWorkItems.Count); task2.Description = task2.Description + " (cache)"; AnsiConsole.WriteLine($"Stage 2: Loaded {templateWorkItems.Count()} work items from cache."); + } } - else + + if (templateWorkItems == null) { // Get From Server // -------------------------------------------------------------- @@ -105,7 +122,7 @@ await AnsiConsole.Progress() //AnsiConsole.WriteLine("Stage 1: Executing items from Query"); QueryResults fakeItemsFromTemplateQuery; - fakeItemsFromTemplateQuery = await templateApi.GetWiqlQueryResults(); + fakeItemsFromTemplateQuery = await templateApi.GetWiqlQueryResults("Select [System.Id] From WorkItems Where [System.TeamProject] = '@project' AND [System.Parent] = @id order by [System.CreatedDate] desc", new Dictionary() { { "@id", config.templateParentId.ToString() } }); AnsiConsole.WriteLine($"Stage 1: Query returned {fakeItemsFromTemplateQuery.workItems.Count()} items id's from the template."); task1.Increment(1); task1.StopTask(); diff --git a/AzureDevOps.WorkItemClone.ConsoleUI/Commands/WorkItemCommandBase.cs b/AzureDevOps.WorkItemClone.ConsoleUI/Commands/WorkItemCommandBase.cs index 055d27c..b55aab6 100644 --- a/AzureDevOps.WorkItemClone.ConsoleUI/Commands/WorkItemCommandBase.cs +++ b/AzureDevOps.WorkItemClone.ConsoleUI/Commands/WorkItemCommandBase.cs @@ -18,6 +18,8 @@ internal abstract class WorkItemCommandBase : AsyncCommand internal void CombineValuesFromConfigAndSettings(WorkItemCloneCommandSettings settings, WorkItemCloneCommandSettings config) { + config.NonInteractive = settings.NonInteractive; + config.ClearCache = settings.ClearCache; config.RunName = settings.RunName != null ? settings.RunName : DateTime.Now.ToString("yyyyyMMddHHmmss"); config.configFile = EnsureConfigFileAskIfMissing(config.configFile = settings.configFile != null ? settings.configFile : config.configFile); config.inputJsonFile = EnsureJsonFileAskIfMissing(config.inputJsonFile = settings.inputJsonFile != null ? settings.inputJsonFile : config.inputJsonFile); diff --git a/AzureDevOps.WorkItemClone.ConsoleUI/Properties/launchSettings.json b/AzureDevOps.WorkItemClone.ConsoleUI/Properties/launchSettings.json index 303fb04..ed8a14a 100644 --- a/AzureDevOps.WorkItemClone.ConsoleUI/Properties/launchSettings.json +++ b/AzureDevOps.WorkItemClone.ConsoleUI/Properties/launchSettings.json @@ -6,7 +6,7 @@ }, "Clone": { "commandName": "Project", - "commandLineArgs": "clone --RunName Allessandro2 --cachePath ..\\..\\..\\..\\..\\.cache\\ --configFile ..\\..\\..\\..\\..\\.cache\\configuration.json --jsonFile ..\\..\\..\\..\\..\\TestData\\new.json " + "commandLineArgs": "clone --cachePath ..\\..\\..\\..\\..\\.cache\\ --configFile ..\\..\\..\\..\\..\\.cache\\configuration-test.json --jsonFile ..\\..\\..\\..\\..\\TestData\\new.json --NonInteractive" }, "empty": { "commandName": "Project" diff --git a/AzureDevOps.WorkItemClone/AzureDevOpsApi.cs b/AzureDevOps.WorkItemClone/AzureDevOpsApi.cs index 2dfdcfe..1b6cd22 100644 --- a/AzureDevOps.WorkItemClone/AzureDevOpsApi.cs +++ b/AzureDevOps.WorkItemClone/AzureDevOpsApi.cs @@ -46,6 +46,31 @@ public async IAsyncEnumerable GetWorkItemsFullAsync(Workitem[] ite } } + public async Task GetWiqlQueryResults(string wiqlQuery, Dictionary parameters) + { + if (parameters == null) + { + parameters = new Dictionary(); + } + if (!parameters.ContainsKey("@project")) + { + parameters.Add("@project", _project); + } + if (string.IsNullOrEmpty(wiqlQuery)) + { + wiqlQuery = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.TeamProject] = '@project' order by [System.CreatedDate] desc"; + } + foreach (var param in parameters) + { + wiqlQuery = wiqlQuery.Replace(param.Key, param.Value); + } + string post = JsonConvert.SerializeObject(new + { + query = wiqlQuery + }); + string apiCallUrl = $"https://dev.azure.com/{_account}/_apis/wit/wiql?api-version=7.2-preview.2"; + return await GetObjectResult(apiCallUrl, post); + } public async Task GetWiqlQueryResults() {