From 8db9514c8369155c64a707b9ceb41a43ef23b3ac Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Mon, 16 Sep 2024 14:41:33 -0700 Subject: [PATCH] CommonMark.NET --- .vscode/launch.json | 2 +- Day/Q32024/Helper-2024-09-11.cs | 46 +++++++++++++++++++++++++-------- File-Folder-Helper.csproj | 3 ++- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0a4305b..6fcb53c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,7 +13,7 @@ "args": [ "s", "X", - "D:/5-Other-Small/Kanban-messa010ec/Work-Items", + "D:/5-Other-Small/Kanban-messa010ec/Kanban/Work-Items", "Day-Helper-2024-09-11", "*.json", ".kanbn", diff --git a/Day/Q32024/Helper-2024-09-11.cs b/Day/Q32024/Helper-2024-09-11.cs index 4edd71c..06ae0ba 100644 --- a/Day/Q32024/Helper-2024-09-11.cs +++ b/Day/Q32024/Helper-2024-09-11.cs @@ -12,7 +12,7 @@ internal static partial class Helper20240911 public record Relation([property: JsonPropertyName("rel")] string Type, [property: JsonPropertyName("url")] string URL, - [property: JsonPropertyName("attributes")] Attribute Attribute); + [property: JsonPropertyName("attributes")] Attribute Attributes); public record Record(WorkItem WorkItem, ReadOnlyDictionary Children); @@ -74,7 +74,7 @@ internal static partial class Helper20240911 private static int? GetIdFromUrlIfChild(Relation relation) { int? result; - string[] segments = relation.Attribute.Name != "Child" ? [] : relation.URL.Split('/'); + string[] segments = relation?.Attributes is null || relation.Attributes.Name != "Child" ? [] : relation.URL.Split('/'); if (segments.Length < 2) result = null; else @@ -134,19 +134,20 @@ internal static partial class Helper20240911 return result; } - private static string GetLine(List spaces, WorkItem workItem, KeyValuePair keyValuePair, bool condensed) => - condensed ? $"{new string(spaces.Skip(1).ToArray())}- {GetClosed(workItem)} {keyValuePair.Key} - {workItem.Title}" : - $"{new string(spaces.Skip(1).ToArray())}- {GetClosed(workItem)} {keyValuePair.Key} - {workItem.Title} ~~~ {workItem.AssignedTo} - {workItem.IterationPath.Replace('\\', '-')} - {workItem.CreatedDate} --- {workItem.ClosedDate}"; + private static string GetLine(List spaces, WorkItem workItem, KeyValuePair keyValuePair, bool condensed, bool sprintOnly) => + sprintOnly ? $"\t- [ ] {workItem.IterationPath}" : + condensed ? $"{new string(spaces.Skip(1).ToArray())}- {GetClosed(workItem)} {keyValuePair.Key} - {workItem.Title}" : + $"{new string(spaces.Skip(1).ToArray())}- {GetClosed(workItem)} {keyValuePair.Key} - {workItem.Title} ~~~ {workItem.AssignedTo} - {workItem.IterationPath.Replace('\\', '-')} - {workItem.CreatedDate} --- {workItem.ClosedDate}"; - private static void AppendLines(List spaces, List lines, Record record, bool condensed) + private static void AppendLines(List spaces, List lines, Record record, bool condensed, bool sprintOnly) { spaces.Add('\t'); WorkItem workItem; foreach (KeyValuePair keyValuePair in record.Children) { workItem = keyValuePair.Value.WorkItem; - lines.Add(GetLine(spaces, workItem, keyValuePair, condensed)); - AppendLines(spaces, lines, keyValuePair.Value, condensed); + lines.Add(GetLine(spaces, workItem, keyValuePair, condensed, sprintOnly)); + AppendLines(spaces, lines, keyValuePair.Value, condensed, sprintOnly); } spaces.RemoveAt(0); } @@ -154,6 +155,7 @@ internal static partial class Helper20240911 private static void AppendLines(List spaces, List lines, ReadOnlyDictionary workItemAndChildren, string workItemType) { WorkItem workItem; + List distinct = []; foreach (KeyValuePair keyValuePair in workItemAndChildren) { workItem = keyValuePair.Value.WorkItem; @@ -165,11 +167,20 @@ internal static partial class Helper20240911 lines.Add(string.Empty); if (keyValuePair.Value.Children.Count > 0) { - AppendLines(spaces, lines, keyValuePair.Value, condensed: true); + AppendLines(spaces, lines, keyValuePair.Value, condensed: true, sprintOnly: false); + lines.Add(string.Empty); + distinct.Clear(); + lines.Add($"## Distinct Iteration Path(s) - {workItem.WorkItemType} - {workItem.AssignedTo} - {workItem.Id} - {workItem.Title} - {workItem.IterationPath}"); + lines.Add(string.Empty); + lines.Add($"- [{workItem.Id}](https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/{workItem.Id})"); + lines.Add(string.Empty); + AppendLines(spaces, distinct, keyValuePair.Value, condensed: false, sprintOnly: true); + distinct.Sort(); + lines.AddRange(distinct.Distinct()); lines.Add(string.Empty); lines.Add($"## Extended - {workItem.Id} - {workItem.Title}"); lines.Add(string.Empty); - AppendLines(spaces, lines, keyValuePair.Value, condensed: false); + AppendLines(spaces, lines, keyValuePair.Value, condensed: false, sprintOnly: false); lines.Add(string.Empty); } } @@ -177,6 +188,10 @@ internal static partial class Helper20240911 internal static void WriteMarkdown(ILogger logger, List args) { + string old; + string html; + string text; + string checkFile; List spaces = []; string searchPattern = args[2]; string filterDirectory = args[3]; @@ -200,7 +215,16 @@ internal static partial class Helper20240911 foreach (string workItemType in workItemTypes) { AppendLines(spaces, lines, workItemAndChildren, workItemType); - File.WriteAllText(Path.Combine(destinationDirectory, $"{workItemType}.md"), string.Join(Environment.NewLine, lines)); + checkFile = Path.Combine(destinationDirectory, $"{workItemType}.md"); + text = string.Join(Environment.NewLine, lines); + old = !File.Exists(checkFile) ? string.Empty : File.ReadAllText(checkFile); + if (text != old) + File.WriteAllText(checkFile, text); + checkFile = Path.Combine(destinationDirectory, $"{workItemType}.html"); + html = CommonMark.CommonMarkConverter.Convert(text); + old = !File.Exists(checkFile) ? string.Empty : File.ReadAllText(checkFile); + if (html != old) + File.WriteAllText(checkFile, html); } } diff --git a/File-Folder-Helper.csproj b/File-Folder-Helper.csproj index 52bffee..aef7326 100644 --- a/File-Folder-Helper.csproj +++ b/File-Folder-Helper.csproj @@ -1,4 +1,4 @@ - + enable Exe @@ -13,6 +13,7 @@ +