This commit is contained in:
2024-09-13 14:41:34 -07:00
parent ba9b7d8d64
commit 6bda42fe67
4 changed files with 42 additions and 2529 deletions

View File

@ -92,16 +92,23 @@ internal static partial class Helper20240911
Dictionary<int, Record> results = [];
int? childId;
WorkItem? childWorkItem;
List<WorkItem> collection = [];
Dictionary<int, Record> keyValuePairs;
if (workItem.Relations is not null && workItem.Relations.Length > 0)
{
collection.Clear();
foreach (Relation relation in workItem.Relations)
{
childId = GetIdFromUrlIfChild(relation);
if (childId is null || !workItems.TryGetValue(childId.Value, out childWorkItem))
continue;
keyValuePairs = GetKeyValuePairs(workItems, childWorkItem);
results.Add(childId.Value, new(childWorkItem, new(keyValuePairs)));
collection.Add(childWorkItem);
}
collection = (from l in collection orderby l.State != "Closed", l.Id select l).ToList();
foreach (WorkItem item in collection)
{
keyValuePairs = GetKeyValuePairs(workItems, item);
results.Add(item.Id, new(item, new(keyValuePairs)));
}
}
return results;
@ -123,34 +130,48 @@ internal static partial class Helper20240911
private static string GetClosed(WorkItem workItem)
{
string result = workItem.ClosedDate is null ? "[ ]" : "[x]";
string result = workItem.State != "Closed" ? "[ ]" : "[x]";
return result;
}
private static void AppendLines(List<char> spaces, List<string> lines, Record record)
private static string GetLine(List<char> spaces, WorkItem workItem, KeyValuePair<int, Record> 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 void AppendLines(List<char> spaces, List<string> lines, Record record, bool condensed)
{
spaces.Add('\t');
WorkItem workItem;
foreach (KeyValuePair<int, Record> keyValuePair in record.Children)
{
workItem = keyValuePair.Value.WorkItem;
lines.Add($"{new string(spaces.ToArray())}- {GetClosed(workItem)} {keyValuePair.Key} - {workItem.Title} - {workItem.ClosedDate}");
AppendLines(spaces, lines, keyValuePair.Value);
lines.Add(GetLine(spaces, workItem, keyValuePair, condensed));
AppendLines(spaces, lines, keyValuePair.Value, condensed);
}
spaces.RemoveAt(0);
}
private static void AppendLines(List<char> spaces, List<string> lines, ReadOnlyDictionary<int, Record> workItemAndChildren)
private static void AppendLines(List<char> spaces, List<string> lines, ReadOnlyDictionary<int, Record> workItemAndChildren, string workItemType)
{
WorkItem workItem;
foreach (KeyValuePair<int, Record> keyValuePair in workItemAndChildren)
{
workItem = keyValuePair.Value.WorkItem;
lines.Add($"## {keyValuePair.Key} - {workItem.Title}");
if (workItem.WorkItemType != workItemType)
continue;
lines.Add($"## {workItem.AssignedTo} - {workItem.Id} - {workItem.Title}");
lines.Add(string.Empty);
lines.Add($"{new string(spaces.ToArray())}- {GetClosed(workItem)} {keyValuePair.Key} - {workItem.Title} - {workItem.ClosedDate}");
AppendLines(spaces, lines, keyValuePair.Value);
lines.Add($"- [{workItem.Id}](https://tfs.intra.infineon.com/tfs/FactoryIntegration/ART%20SPS/_workitems/edit/{workItem.Id})");
lines.Add(string.Empty);
if (keyValuePair.Value.Children.Count > 0)
{
AppendLines(spaces, lines, keyValuePair.Value, condensed: true);
lines.Add(string.Empty);
lines.Add($"## Extended - {workItem.Id} - {workItem.Title}");
lines.Add(string.Empty);
AppendLines(spaces, lines, keyValuePair.Value, condensed: false);
lines.Add(string.Empty);
}
}
}
@ -159,8 +180,12 @@ internal static partial class Helper20240911
List<char> spaces = [];
string searchPattern = args[2];
string filterDirectory = args[3];
string[] workItemTypes = args[4].Split('|');
List<string> lines = ["# WorkItems", string.Empty];
string sourceDirectory = Path.GetFullPath(args[0]);
string destinationDirectory = Path.GetFullPath(args[5]);
if (!Directory.Exists(destinationDirectory))
_ = Directory.CreateDirectory(destinationDirectory);
string[] files = Directory.GetFiles(sourceDirectory, searchPattern, SearchOption.AllDirectories);
logger.LogInformation("With search pattern '{SearchPattern}' found {files} file(s)", searchPattern, files.Length);
ReadOnlyDictionary<int, WorkItem> workItems = GetWorkItems(filterDirectory, files);
@ -172,8 +197,11 @@ internal static partial class Helper20240911
string json = JsonSerializer.Serialize(workItemAndChildren, new JsonSerializerOptions() { WriteIndented = true });
File.WriteAllText(".json", json);
}
AppendLines(spaces, lines, workItemAndChildren);
File.WriteAllText(".md", string.Join(Environment.NewLine, lines));
foreach (string workItemType in workItemTypes)
{
AppendLines(spaces, lines, workItemAndChildren, workItemType);
File.WriteAllText(Path.Combine(destinationDirectory, $"{workItemType}.md"), string.Join(Environment.NewLine, lines));
}
}
}