using Adaptation.FileHandlers.json.WorkItems; using Adaptation.Shared; using Adaptation.Shared.Duplicator; using Adaptation.Shared.Methods; using log4net; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Text.Json; using System.Text.Json.Serialization; namespace Adaptation.FileHandlers.Markdown; public class ProcessData : IProcessData { private readonly List _Details; List Shared.Properties.IProcessData.Details => _Details; private readonly ILog _Log; public ProcessData(IFileRead fileRead, Logistics logistics, string targetFileLocation, string url, ReadOnlyCollection workItemTypes, List fileInfoCollection) { if (fileRead.IsEAFHosted) { } _Details = new List(); _Log = LogManager.GetLogger(typeof(ProcessData)); WriteFiles(fileRead, logistics, url, workItemTypes, targetFileLocation, fileInfoCollection); } string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary reactors) => throw new Exception(string.Concat("See ", nameof(WriteFiles))); Tuple> IProcessData.GetResults(IFileRead fileRead, Logistics logistics, List fileInfoCollection) => new(logistics.Logistics1[0], Array.Empty(), Array.Empty(), fileInfoCollection); #nullable enable internal static List GetDescriptions(JsonElement[] jsonElements) { List results = new(); Description? description; JsonSerializerOptions jsonSerializerOptions = new() { NumberHandling = JsonNumberHandling.AllowReadingFromString | JsonNumberHandling.WriteAsString }; foreach (JsonElement jsonElement in jsonElements) { if (jsonElement.ValueKind != JsonValueKind.Object) throw new Exception(); description = JsonSerializer.Deserialize(jsonElement.ToString(), jsonSerializerOptions); if (description is null) continue; results.Add(description); } return results; } private void WriteFiles(IFileRead fileRead, Logistics logistics, string url, ReadOnlyCollection workItemTypes, string destinationDirectory, List fileInfoCollection) { if (!Directory.Exists(destinationDirectory)) _ = Directory.CreateDirectory(destinationDirectory); string json = File.ReadAllText(logistics.ReportFullPath); // WorkItem[]? workItems = JsonSerializer.Deserialize(json); // if (workItems is null) // throw new Exception(nameof(workItems)); JsonElement[]? jsonElements = JsonSerializer.Deserialize(json); if (jsonElements is null) throw new Exception(nameof(jsonElements)); WorkItem? workItem; List workItems = new(); foreach (JsonElement jsonElement in jsonElements) { workItem = JsonSerializer.Deserialize(jsonElement.ToString()); if (workItem is null) continue; workItems.Add(workItem); } List spaces = new(); bool keepRelations = false; List lines = new(); List messages = new(); ReadOnlyCollection results; ReadOnlyDictionary keyValuePairs = GetWorkItems(workItems, keepRelations); ReadOnlyCollection records = new(keyValuePairs.Values.ToArray()); ReadOnlyCollection userStoryWorkItemTypes = new(new string[] { "User Story" }); ReadOnlyCollection bugFeatureWorkItemTypes = new(new string[] { "Bug", "Feature" }); ReadOnlyCollection bugUserStoryWorkItemTypes = new(new string[] { "Bug", "User Story" }); ReadOnlyCollection bugUserStoryTaskWorkItemTypes = new(new string[] { "Bug", "User Story", "Task" }); messages.AddRange(WriteFile(fileRead, destinationDirectory, fileInfoCollection, records, "records")); messages.AddRange(WriteWithPartentsFile(fileRead, destinationDirectory, fileInfoCollection, records, bugFeatureWorkItemTypes, "bugs-features-with-parents")); messages.AddRange(WriteWithPartentsFile(fileRead, destinationDirectory, fileInfoCollection, records, bugUserStoryWorkItemTypes, "bugs-user-stories-with-parents")); foreach (string workItemType in workItemTypes) { lines.Clear(); lines.Add($"# {workItemType}"); lines.Add(string.Empty); AppendLines(url, spaces, lines, records, workItemType); results = new(Array.Empty()); WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), results, workItemType); _Details.Add(results); } { lines.Clear(); string workItemType = "Feature"; lines.Add($"# {nameof(FeatureCheckIterationPath122508)}"); lines.Add(string.Empty); results = FeatureCheckIterationPath122508(url, lines, bugUserStoryTaskWorkItemTypes, keyValuePairs, workItemType); WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), results, "check-122508"); _Details.Add(results); } { lines.Clear(); string workItemType = "Feature"; lines.Add($"# {nameof(FeatureCheckTag122514)}"); lines.Add(string.Empty); results = FeatureCheckTag122514(url, lines, bugUserStoryWorkItemTypes, keyValuePairs, workItemType); WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), results, "check-122514"); _Details.Add(results); } { lines.Clear(); string workItemType = "Feature"; lines.Add($"# {nameof(FeatureCheckPriority126169)}"); lines.Add(string.Empty); results = FeatureCheckPriority126169(url, lines, bugUserStoryWorkItemTypes, keyValuePairs, workItemType); WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), results, "check-126169"); _Details.Add(results); } { lines.Clear(); string workItemType = "Feature"; lines.Add($"# {nameof(FeatureCheckState123066)}"); lines.Add(string.Empty); results = FeatureCheckState123066(url, lines, bugUserStoryTaskWorkItemTypes, keyValuePairs, workItemType); WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), results, "check-123066"); _Details.Add(results); } { lines.Clear(); string workItemType = "Feature"; lines.Add($"# {nameof(FeatureCheckState123067)}"); lines.Add(string.Empty); results = FeatureCheckState123067(url, lines, bugUserStoryTaskWorkItemTypes, keyValuePairs, workItemType); WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), results, "check-123067"); _Details.Add(results); } { lines.Clear(); string workItemType = "Feature"; lines.Add($"# {nameof(FeatureCheckStart122517)}"); lines.Add(string.Empty); results = FeatureCheckStart122517(url, lines, bugUserStoryTaskWorkItemTypes, keyValuePairs, workItemType); WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), results, "check-122517"); _Details.Add(results); } { lines.Clear(); string workItemType = "User Story"; lines.Add($"# {nameof(UserStoryCheckIterationPath228385)}"); lines.Add(string.Empty); results = UserStoryCheckIterationPath228385(url, lines, userStoryWorkItemTypes, keyValuePairs, workItemType); WriteFiles(fileRead, destinationDirectory, fileInfoCollection, new(lines), results, "check-228385"); _Details.Add(results); } if (messages.Count > 0) throw new Exception($"{messages.Count}{Environment.NewLine}{string.Join(Environment.NewLine, messages)}"); } private static void WriteFiles(IFileRead fileRead, string destinationDirectory, List fileInfoCollection, ReadOnlyCollection lines, ReadOnlyCollection records, string fileName) { string markdown = string.Join(Environment.NewLine, lines); string markdownFile = Path.Combine(destinationDirectory, $"{fileName}.md"); string markdownOld = !File.Exists(markdownFile) ? string.Empty : File.ReadAllText(markdownFile); if (markdown != markdownOld) File.WriteAllText(markdownFile, markdown); if (!fileRead.IsEAFHosted) fileInfoCollection.Add(new(markdownFile)); string html = CommonMark.CommonMarkConverter.Convert(markdown).Replace(" GetWorkItems(IEnumerable workItems, bool keepRelations) { ReadOnlyDictionary results; Dictionary keyValuePairs = new(); foreach (WorkItem workItem in workItems) keyValuePairs.Add(workItem.Id, workItem); results = GetKeyValuePairs(new(keyValuePairs), keepRelations); return results; } private static string? GetJson(IEnumerable records, List results) { string? result; try { result = JsonSerializer.Serialize(records.ToArray(), RecordCollectionSourceGenerationContext.Default.RecordArray); } catch (Exception) { result = null; foreach (Record record in records) { try { _ = JsonSerializer.Serialize(record, RecordSourceGenerationContext.Default.Record); } catch (Exception ex) { results.Add($"Record {record.WorkItem.Id} is not serializable!{Environment.NewLine}{ex.Message}"); } } } return result; } private static ReadOnlyCollection WriteFile(IFileRead fileRead, string destinationDirectory, List fileInfoCollection, ReadOnlyCollection records, string fileName) { List results = new(); string? json = GetJson(records, results); string jsonFile = Path.Combine(destinationDirectory, $"{fileName}.json"); string jsonOld = !File.Exists(jsonFile) ? string.Empty : File.ReadAllText(jsonFile); if (!string.IsNullOrEmpty(json) && json != jsonOld) File.WriteAllText(jsonFile, json); if (!fileRead.IsEAFHosted) fileInfoCollection.Add(new(jsonFile)); return new(results); } private static ReadOnlyCollection WriteWithPartentsFile(IFileRead fileRead, string destinationDirectory, List fileInfoCollection, ReadOnlyCollection records, ReadOnlyCollection workItemTypes, string fileName) { List results = new(); List filtered = new(); Record record; foreach (Record r in records) { if (r.WorkItem.State == "Removed" || !workItemTypes.Contains(r.WorkItem.WorkItemType)) continue; record = new(r.WorkItem, r.Parent, Array.Empty(), Array.Empty(), Array.Empty()); filtered.Add(record); } string? json = GetJson(filtered, results); string jsonFile = Path.Combine(destinationDirectory, $"{fileName}.json"); string jsonOld = !File.Exists(jsonFile) ? string.Empty : File.ReadAllText(jsonFile); if (!string.IsNullOrEmpty(json) && json != jsonOld) File.WriteAllText(jsonFile, json); if (!fileRead.IsEAFHosted) fileInfoCollection.Add(new(jsonFile)); return new(results); } private static void AppendLines(string url, List spaces, List lines, ReadOnlyCollection records, string workItemType) { List results = new(); string? maxIterationPath; List distinct = new(); foreach (Record record in records) { // if (record.WorkItem.Id != 109724) // continue; if (record.WorkItem.WorkItemType != workItemType) continue; results.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}"); results.Add(string.Empty); results.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})"); if (record.Children is null || record.Children.Length == 0) results.Add(string.Empty); else { AppendLines(spaces, results, record, condensed: true, sprintOnly: false); results.Add(string.Empty); distinct.Clear(); AppendLines(spaces, distinct, record, condensed: false, sprintOnly: true); if (distinct.Count > 1) { results.Add($"## Distinct Iteration Path(s) - {record.WorkItem.WorkItemType} - {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title} - {record.WorkItem.IterationPath}"); results.Add(string.Empty); results.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})"); distinct.Sort(); distinct = (from l in distinct select l.Trim()).Distinct().ToList(); results.AddRange(distinct); results.Add(string.Empty); maxIterationPath = distinct.Max(); if (!string.IsNullOrEmpty(maxIterationPath) && maxIterationPath.Contains("] ") && maxIterationPath.Split(']')[1].Trim() != record.WorkItem.IterationPath) { results.Add($"### Sync to Distinct Max Iteration Path => {maxIterationPath} - {record.WorkItem.Id} - {record.WorkItem.Title}"); results.Add(string.Empty); } } results.Add($"## Extended - {record.WorkItem.Id} - {record.WorkItem.Title}"); results.Add(string.Empty); AppendLines(spaces, results, record, condensed: false, sprintOnly: false); results.Add(string.Empty); } lines.AddRange(results); results.Clear(); } } private static void AppendLines(List spaces, List lines, Record record, bool condensed, bool sprintOnly) { string line; spaces.Add('\t'); WorkItem workItem; if (record.Children is not null) { foreach (Record child in record.Children) { workItem = child.WorkItem; line = GetLine(spaces, workItem, child, condensed, sprintOnly).TrimEnd(); lines.Add(line); AppendLines(spaces, lines, child, condensed, sprintOnly); } } spaces.RemoveAt(0); } private static ReadOnlyDictionary GetKeyValuePairs(ReadOnlyDictionary keyValuePairs, bool keepRelations) { Dictionary results = new(); Record record; List nests = new(); WorkItem? parentWorkItem; ReadOnlyCollection childRecords; ReadOnlyCollection relatedRecords; ReadOnlyCollection successorRecords; foreach (KeyValuePair keyValuePair in keyValuePairs) { nests.Clear(); if (keyValuePair.Value.Parent is null) parentWorkItem = null; else _ = keyValuePairs.TryGetValue(keyValuePair.Value.Parent.Value, out parentWorkItem); try { childRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Child", nests, keepRelations); // Forward relatedRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Related", nests, keepRelations); // Related successorRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Successor", nests, keepRelations); // Forward // predecessorRecords = Record.GetKeyValuePairs(keyValuePairs, keyValuePair.Value, "Predecessor", nests, keepRelations); // Reverse record = Record.Get(keyValuePair.Value, parentWorkItem, childRecords, relatedRecords, successorRecords, keepRelations); } catch (Exception) { record = new(keyValuePair.Value, parentWorkItem, Array.Empty(), Array.Empty(), Array.Empty()); } results.Add(keyValuePair.Key, record); } return new(results); } private static string GetLine(List spaces, WorkItem workItem, Record record, bool condensed, bool sprintOnly) { string result; string closed = GetClosed(workItem); result = sprintOnly ? $"\t- [ ] {workItem.IterationPath}" : condensed ? $"{new string(spaces.Skip(1).ToArray())}- {closed} {record.WorkItem.Id} - {workItem.Title}" : $"{new string(spaces.Skip(1).ToArray())}- {closed} {record.WorkItem.Id} - {workItem.Title} ~~~ {workItem.AssignedTo} - {workItem.IterationPath.Replace('\\', '-')} - {workItem.CreatedDate} --- {workItem.ClosedDate}"; return result; } private static string GetClosed(WorkItem workItem) => workItem.State != "Closed" ? "[ ]" : "[x]"; private static void FilterChildren(ReadOnlyCollection workItemTypes, Record record, List results) { if (record.Children is not null) { foreach (Record r in record.Children) { if (!workItemTypes.Contains(r.WorkItem.WorkItemType)) continue; results.Add(r); FilterChildren(workItemTypes, r, results); } } } private static ReadOnlyCollection FilterChildren(ReadOnlyCollection workItemTypes, Record record) { List results = new(); FilterChildren(workItemTypes, record, results); return new(results); } private static int GetState(WorkItem workItem) => workItem.State switch { "New" => 1, "Active" => 2, "Resolved" => 3, "Closed" => 4, "Removed" => 5, _ => 8 }; private static ReadOnlyCollection GetMaxIterationPaths122508(ReadOnlyCollection records) { List results; List? collection; Dictionary> keyValuePairs = new(); foreach (Record record in records) { if (!keyValuePairs.TryGetValue(record.WorkItem.IterationPath, out collection)) { keyValuePairs.Add(record.WorkItem.IterationPath, new()); if (!keyValuePairs.TryGetValue(record.WorkItem.IterationPath, out collection)) throw new Exception(); } collection.Add(record); } string? max = keyValuePairs.Keys.Max(); results = string.IsNullOrEmpty(max) ? new() : keyValuePairs[max]; return results.AsReadOnly(); } private static ReadOnlyCollection FeatureCheckIterationPath122508(string url, List lines, ReadOnlyCollection workItemTypes, ReadOnlyDictionary keyValuePairs, string workItemType) { List results = new(); Record record; List violations = new(); List collection = new(); ReadOnlyCollection records; ReadOnlyCollection maxIterationPaths; foreach (KeyValuePair keyValuePair in keyValuePairs) { record = keyValuePair.Value; if (record.WorkItem.State is "Removed") continue; if (!record.WorkItem.IterationPath.Contains('\\')) continue; if (record.WorkItem.WorkItemType != workItemType) continue; collection.Clear(); violations.Clear(); if (record.Children is null || record.Children.Length == 0) continue; records = FilterChildren(workItemTypes, record); maxIterationPaths = GetMaxIterationPaths122508(records); foreach (Record r in maxIterationPaths) { if (string.IsNullOrEmpty(r.WorkItem.IterationPath) || record.WorkItem.IterationPath == r.WorkItem.IterationPath) continue; violations.Add($"{r.WorkItem.Id}:{r.WorkItem.IterationPath};"); } if (violations.Count > 0) { collection.Insert(0, string.Empty); collection.Insert(0, $"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}"); lines.AddRange(collection); violations.Insert(0, $"IterationPath:{record.WorkItem.IterationPath};"); results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations))); } } return new(results); } private static ReadOnlyCollection GetWorkItemsNotMatching122514(Record record, ReadOnlyCollection records) { List results = new(); string[] segments; string[] parentTags = record.WorkItem.Tags.Split(';').Select(l => l.Trim()).ToArray(); foreach (Record r in records) { segments = string.IsNullOrEmpty(r.WorkItem.Tags) ? Array.Empty() : r.WorkItem.Tags.Split(';').Select(l => l.Trim()).ToArray(); if (segments.Length > 0 && parentTags.Any(l => segments.Contains(l))) continue; results.Add(r); } return new(results); } private static ReadOnlyCollection FeatureCheckTag122514(string url, List lines, ReadOnlyCollection workItemTypes, ReadOnlyDictionary keyValuePairs, string workItemType) { List results = new(); Record record; List collection = new(); List violations = new(); ReadOnlyCollection records; ReadOnlyCollection recordsNotMatching; foreach (KeyValuePair keyValuePair in keyValuePairs) { record = keyValuePair.Value; if (record.WorkItem.State is "Removed") continue; if (record.WorkItem.WorkItemType != workItemType) continue; collection.Clear(); violations.Clear(); if (record.Children is null || record.Children.Length == 0) continue; if (string.IsNullOrEmpty(record.WorkItem.Tags)) recordsNotMatching = new(new Record[] { record }); else { records = FilterChildren(workItemTypes, record); recordsNotMatching = GetWorkItemsNotMatching122514(record, records); if (!string.IsNullOrEmpty(record.WorkItem.Tags) && recordsNotMatching.Count == 0) continue; } collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}"); collection.Add(string.Empty); foreach (Record r in recordsNotMatching) collection.Add($"- [ ] [{r.WorkItem}]({url}{r.WorkItem}) {nameof(record.WorkItem.Tags)} != {record.WorkItem.Tags}"); collection.Add(string.Empty); lines.AddRange(collection); violations.Add($"Tag:{record.WorkItem.Tags};"); foreach (Record r in recordsNotMatching) violations.Add($"{r.WorkItem.Id}:{r.WorkItem.Tags};"); results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations))); } return new(results); } private static ReadOnlyCollection GetWorkItemsNotMatching126169(Record record, ReadOnlyCollection records) { List results = new(); foreach (Record r in records) { if (record.WorkItem.Priority is null) { results.Add(record); break; } if (r.WorkItem.Priority == record.WorkItem.Priority.Value) continue; results.Add(r); } return new(results); } private static ReadOnlyCollection FeatureCheckPriority126169(string url, List lines, ReadOnlyCollection workItemTypes, ReadOnlyDictionary keyValuePairs, string workItemType) { List results = new(); Record record; List collection = new(); List violations = new(); ReadOnlyCollection records; ReadOnlyCollection recordsNotMatching; foreach (KeyValuePair keyValuePair in keyValuePairs) { record = keyValuePair.Value; if (record.WorkItem.State is "Removed") continue; if (record.WorkItem.WorkItemType != workItemType) continue; collection.Clear(); violations.Clear(); if (record.Children is null || record.Children.Length == 0) continue; records = FilterChildren(workItemTypes, record); recordsNotMatching = GetWorkItemsNotMatching126169(record, records); if (recordsNotMatching.Count == 0) continue; collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}"); collection.Add(string.Empty); collection.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})"); foreach (Record r in recordsNotMatching) collection.Add($"- [ ] [{r.WorkItem.Id}]({url}{r.WorkItem.Id}) {nameof(record.WorkItem.Priority)} != {record.WorkItem.Priority}"); collection.Add(string.Empty); lines.AddRange(collection); violations.Add($"Priority:{record.WorkItem.Priority};"); foreach (Record r in recordsNotMatching) violations.Add($"{r.WorkItem.Id}:{r.WorkItem.Priority};"); results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations))); } return new(results); } private static ReadOnlyCollection GetWorkItemsNotMatching123066(Record record, ReadOnlyCollection records) { List results = new(); int check; int state = GetState(record.WorkItem); List> collection = new(); foreach (Record r in records) { if (r.WorkItem.State is "Removed") continue; check = GetState(r.WorkItem); if (check == state) continue; collection.Add(new(check, r)); } if (collection.Count > 0) { KeyValuePair[] notNewState = (from l in collection where l.Value.WorkItem.State != "New" select l).ToArray(); if (notNewState.Length == 0 && record.WorkItem.State is "New" or "Active") collection.Clear(); else if (notNewState.Length > 0) { int minimum = notNewState.Min(l => l.Key); if (minimum == state) collection.Clear(); else if (minimum == 1 && record.WorkItem.State == "New") collection.Clear(); else if (notNewState.Length > 0 && record.WorkItem.State == "Active") collection.Clear(); } } foreach (KeyValuePair keyValuePair in collection.OrderByDescending(l => l.Key)) results.Add(keyValuePair.Value); return new(results); } private static ReadOnlyCollection GetWorkItemsNotMatching123067(Record record, ReadOnlyCollection records) { List results = new(); int check; int state = GetState(record.WorkItem); List> collection = new(); foreach (Record r in records) { if (r.WorkItem.State is "Removed") continue; check = GetState(r.WorkItem); if (check == state) continue; collection.Add(new(check, r)); } if (collection.Count > 0) { KeyValuePair[] notNewState = (from l in collection where l.Value.WorkItem.State != "New" select l).ToArray(); if (notNewState.Length == 0 && record.WorkItem.State is "New" or "Active") collection.Clear(); else if (notNewState.Length > 0) { int minimum = notNewState.Min(l => l.Key); if (minimum == state) collection.Clear(); else if (minimum == 1 && record.WorkItem.State == "New") collection.Clear(); else if (notNewState.Length > 0 && record.WorkItem.State == "Active") collection.Clear(); } } foreach (KeyValuePair keyValuePair in collection.OrderByDescending(l => l.Key)) results.Add(keyValuePair.Value); return new(results); } private static ReadOnlyCollection GetWorkItemsNotMatching122517(Record record, ReadOnlyCollection records) { List results = new(); if (record.WorkItem.StartDate is null) throw new Exception(); DateTime dateTime = record.WorkItem.StartDate.Value; List> collection = new(); foreach (Record r in records) { if (r.WorkItem.State is "Removed") continue; if (r.WorkItem.ActivatedDate is null) continue; if (dateTime >= r.WorkItem.ActivatedDate.Value) continue; collection.Add(new(r.WorkItem.ActivatedDate.Value.Ticks, r)); } foreach (KeyValuePair keyValuePair in collection.OrderBy(l => l.Key)) results.Add(keyValuePair.Value); return new(results); } private static ReadOnlyCollection FeatureCheckState123066(string url, List lines, ReadOnlyCollection workItemTypes, ReadOnlyDictionary keyValuePairs, string workItemType) { List results = new(); Record record; List collection = new(); List violations = new(); ReadOnlyCollection records; ReadOnlyCollection recordsNotMatching; foreach (KeyValuePair keyValuePair in keyValuePairs) { record = keyValuePair.Value; if (record.WorkItem.State is "Removed") continue; if (record.WorkItem.WorkItemType != workItemType) continue; collection.Clear(); violations.Clear(); if (record.Children is null || record.Children.Length == 0) continue; records = FilterChildren(workItemTypes, record); recordsNotMatching = GetWorkItemsNotMatching123066(record, records); if (recordsNotMatching.Count == 0) continue; collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}"); collection.Add(string.Empty); collection.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})"); foreach (Record r in recordsNotMatching) collection.Add($"- [ ] [{r.WorkItem.Id}]({url}{r.WorkItem.Id}) {nameof(record.WorkItem.State)} != {record.WorkItem.State}"); collection.Add(string.Empty); lines.AddRange(collection); violations.Add($"State:{record.WorkItem.State};"); foreach (Record r in recordsNotMatching) violations.Add($"{r.WorkItem.Id}:{r.WorkItem.State};"); results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations))); } return new(results); } private static ReadOnlyCollection FeatureCheckState123067(string url, List lines, ReadOnlyCollection workItemTypes, ReadOnlyDictionary keyValuePairs, string workItemType) { List results = new(); Record record; List collection = new(); List violations = new(); ReadOnlyCollection records; ReadOnlyCollection recordsNotMatching; foreach (KeyValuePair keyValuePair in keyValuePairs) { record = keyValuePair.Value; if (record.WorkItem.State is "Removed") continue; if (record.WorkItem.WorkItemType != workItemType) continue; collection.Clear(); violations.Clear(); if (record.Children is null || record.Children.Length == 0) continue; records = FilterChildren(workItemTypes, record); recordsNotMatching = GetWorkItemsNotMatching123067(record, records); if (recordsNotMatching.Count == 0) continue; collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}"); collection.Add(string.Empty); collection.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})"); foreach (Record r in recordsNotMatching) collection.Add($"- [ ] [{r.WorkItem.Id}]({url}{r.WorkItem.Id}) {nameof(record.WorkItem.State)} != {record.WorkItem.State}"); collection.Add(string.Empty); lines.AddRange(collection); violations.Add($"State:{record.WorkItem.State};"); foreach (Record r in recordsNotMatching) violations.Add($"{r.WorkItem.Id}:{r.WorkItem.State};"); results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations))); } return new(results); } private static ReadOnlyCollection FeatureCheckStart122517(string url, List lines, ReadOnlyCollection workItemTypes, ReadOnlyDictionary keyValuePairs, string workItemType) { List results = new(); Record record; List collection = new(); List violations = new(); ReadOnlyCollection records; ReadOnlyCollection recordsNotMatching; foreach (KeyValuePair keyValuePair in keyValuePairs) { record = keyValuePair.Value; if (record.WorkItem.State is "Removed") continue; if (record.WorkItem.WorkItemType != workItemType) continue; collection.Clear(); violations.Clear(); if (record.Children is null || record.Children.Length == 0) continue; if (record.WorkItem.StartDate is null) continue; records = FilterChildren(workItemTypes, record); recordsNotMatching = GetWorkItemsNotMatching122517(record, records); if (recordsNotMatching.Count == 0) continue; collection.Add($"## {record.WorkItem.AssignedTo} - {record.WorkItem.Id} - {record.WorkItem.Title}"); collection.Add(string.Empty); collection.Add($"- [{record.WorkItem.Id}]({url}{record.WorkItem.Id})"); foreach (Record r in recordsNotMatching) collection.Add($"- [ ] [{r.WorkItem.Id}]({url}{r.WorkItem.Id}) {nameof(record.WorkItem.ActivatedDate)} != {record.WorkItem.ActivatedDate}"); collection.Add(string.Empty); lines.AddRange(collection); violations.Add($"StartDate:{record.WorkItem.StartDate};"); foreach (Record r in recordsNotMatching) violations.Add($"{r.WorkItem.Id}:{r.WorkItem.ActivatedDate};"); results.Add(Record.GetWithoutNesting(record, string.Join(" ", violations))); } return new(results); } private static ReadOnlyDictionary> GetWorkItemsMatching228385(ReadOnlyCollection records) { Dictionary> results = new(); string key; List? collection; foreach (Record record in records) { key = $"{record.WorkItem.IterationPath}-{record.WorkItem.AssignedTo}"; if (!results.TryGetValue(key, out collection)) { results.Add(key, new()); if (!results.TryGetValue(key, out collection)) throw new Exception(); } collection.Add(record); } return new(results); } private static ReadOnlyDictionary> GetWorkItemsMatching228385(ReadOnlyDictionary keyValuePairs, string workItemType) { ReadOnlyDictionary> results; Record record; List records = new(); foreach (KeyValuePair keyValuePair in keyValuePairs) { record = keyValuePair.Value; if (record.WorkItem.State is "Removed" or "Closed") continue; if (!record.WorkItem.IterationPath.Contains('\\')) continue; if (record.WorkItem.StoryPoints is null) continue; if (record.WorkItem.WorkItemType != workItemType) continue; records.Add(record); } Record[] sorted = records.OrderByDescending(l => l.WorkItem.IterationPath).ToArray(); results = GetWorkItemsMatching228385(new(sorted)); return results; } private static ReadOnlyCollection UserStoryCheckIterationPath228385(string url, List lines, ReadOnlyCollection _, ReadOnlyDictionary keyValuePairs, string workItemType) { List results = new(); long totalStoryPoints; ReadOnlyDictionary> records = GetWorkItemsMatching228385(keyValuePairs, workItemType); foreach (KeyValuePair> keyValuePair in records) { totalStoryPoints = 0; foreach (Record record in keyValuePair.Value) { if (record.WorkItem.StoryPoints is null) continue; totalStoryPoints += record.WorkItem.StoryPoints.Value; } lines.Add(string.Empty); lines.Add($"## {keyValuePair.Key} => {totalStoryPoints}"); lines.Add(string.Empty); foreach (Record record in keyValuePair.Value) lines.Add($"- [ ] [{record.WorkItem.Id}]({url}{record.WorkItem.Id}) - {record.WorkItem.Title}"); } return new(results); } }