Skip to content

Commit

Permalink
Change templateCache to a single file with org and project...
Browse files Browse the repository at this point in the history
Create a RunID and have all other cache end up thre.
  • Loading branch information
MrHinsh committed Jul 2, 2024
1 parent 400ca01 commit 5c05bbb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class WorkItemCloneCommand : WorkItemCommandBase<WorkItemCloneCommandSe
{
public override async Task<int> ExecuteAsync(CommandContext context, WorkItemCloneCommandSettings settingsFromCmd)
{
string runID = DateTime.Now.ToString("yyyyy-MM-dd-HH-mm-ss");
WorkItemCloneCommandSettings config = null;
if (File.Exists(settingsFromCmd.configFile))
{
Expand All @@ -27,6 +28,9 @@ public override async Task<int> ExecuteAsync(CommandContext context, WorkItemClo
AzureDevOpsApi templateApi = CreateAzureDevOpsConnection(config.templateAccessToken, config.templateOrganization, config.templateProject);
List<jsonWorkItem> jsonWorkItems = LoadJsonFile(config.inputJsonFile);


string runCache = $"{config.CachePath}\\{runID}";

// --------------------------------------------------------------
WriteOutSettings(config);
if (!config.NonInteractive)
Expand Down Expand Up @@ -87,7 +91,6 @@ await AnsiConsole.Progress()
{
fakeItemsFromTemplateQuery = await templateApi.GetWiqlQueryResults();
AnsiConsole.WriteLine($"Stage 1: Query returned {fakeItemsFromTemplateQuery.workItems.Count()} items id's from the template.");
System.IO.File.WriteAllText($"{config.CachePath}\\Step1-TemplateQuery.json", JsonConvert.SerializeObject(fakeItemsFromTemplateQuery, Formatting.Indented));
}
task1.Increment(1);
task1.StopTask();
Expand All @@ -96,8 +99,8 @@ await AnsiConsole.Progress()
task2.MaxValue = fakeItemsFromTemplateQuery.workItems.Count();
task2.StartTask();
//AnsiConsole.WriteLine($"Stage 2: Starting process of {task2.MaxValue} work items to get their full data ");
string cachetemplateWorkItemsFile = $"{config.CachePath}\\Step2-TemplateItems.json";
if (config.ClearCache)
string cachetemplateWorkItemsFile = $"{config.CachePath}\\templateCache-{config.templateOrganization}-{config.templateProject}.json";
if (config.ClearCache && System.IO.File.Exists(cachetemplateWorkItemsFile))
{
System.IO.File.Delete(cachetemplateWorkItemsFile);
}
Expand All @@ -119,7 +122,7 @@ await AnsiConsole.Progress()
templateWorkItems.Add(workItem);
task2.Increment(1);
}
System.IO.File.WriteAllText($"{config.CachePath}\\Step2-TemplateItems.json", JsonConvert.SerializeObject(templateWorkItems, Formatting.Indented));
System.IO.File.WriteAllText($"{runCache}\\Step2-TemplateItems.json", JsonConvert.SerializeObject(templateWorkItems, Formatting.Indented));
}

//AnsiConsole.WriteLine($"Stage 2: All {task2.MaxValue} work items loaded");
Expand All @@ -131,7 +134,7 @@ await AnsiConsole.Progress()
//AnsiConsole.WriteLine($"Stage 3: Load the Project work item with ID {config.targetParentId} from {config.targetOrganization} ");
AzureDevOpsApi targetApi = CreateAzureDevOpsConnection(config.targetAccessToken, config.targetOrganization, config.targetProject);
WorkItemFull projectItem = await targetApi.GetWorkItem((int)config.targetParentId);
System.IO.File.WriteAllText($"{config.CachePath}\\Step3-Project.json", JsonConvert.SerializeObject(projectItem, Formatting.Indented));
System.IO.File.WriteAllText($"{runCache}\\Step3-Project.json", JsonConvert.SerializeObject(projectItem, Formatting.Indented));
//AnsiConsole.WriteLine($"Stage 3: Project `{projectItem.fields.SystemTitle}` loaded ");
task3.Increment(1);
task3.StopTask();
Expand All @@ -147,7 +150,7 @@ await AnsiConsole.Progress()
buildItems.Add(witb);
task4.Increment(1);
}
System.IO.File.WriteAllText($"{config.CachePath}\\Step4-WorkItemsToBuild.json", JsonConvert.SerializeObject(buildItems, Formatting.Indented));
System.IO.File.WriteAllText($"{runCache}\\Step4-WorkItemsToBuild.json", JsonConvert.SerializeObject(buildItems, Formatting.Indented));
task4.StopTask();
//AnsiConsole.WriteLine($"Stage 4: Completed first pass.");
// --------------------------------------------------------------
Expand All @@ -160,7 +163,7 @@ await AnsiConsole.Progress()
//AnsiConsole.WriteLine($"Stage 5: processing {witb.guid} for output of {witb.relations.Count-1} relations");
task5.Increment(1);
}
System.IO.File.WriteAllText($"{config.CachePath}\\Step5-WorkItemsToBuild.json", JsonConvert.SerializeObject(buildItems, Formatting.Indented));
System.IO.File.WriteAllText($"{runCache}\\Step5-WorkItemsToBuild.json", JsonConvert.SerializeObject(buildItems, Formatting.Indented));
task5.StopTask();
//AnsiConsole.WriteLine($"Stage 5: Completed second pass.");

Expand All @@ -174,7 +177,7 @@ await AnsiConsole.Progress()
//AnsiConsole.WriteLine($"Stage 6: Processing {witb.guid} for output of {witb.relations.Count - 1} relations");
task6.Increment(1);
}
System.IO.File.WriteAllText($"{config.CachePath}\\Step6-WorkItemsToBuild.json", JsonConvert.SerializeObject(buildItems, Formatting.Indented));
System.IO.File.WriteAllText($"{runCache}\\Step6-WorkItemsToBuild.json", JsonConvert.SerializeObject(buildItems, Formatting.Indented));
task6.StopTask();
//AnsiConsole.WriteLine($"Stage 6: All Work Items Created.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ internal class WorkItemCloneCommandSettings : BaseCommandSettings
[CommandOption("--ClearCache")]
[JsonIgnore]
public bool ClearCache { get; set; }
[Description("Rerun with the same data. Usually because the previus run failed half way through. Overrides ClearCache.")]
[CommandOption("--rerun")]
[JsonIgnore]
public bool rerun { get; set; }
//------------------------------------------------
[CommandOption("--outputPath|--cachePath")]
[DefaultValue("./cache")]
Expand Down

0 comments on commit 5c05bbb

Please sign in to comment.