776 lines
35 KiB
C#
776 lines
35 KiB
C#
using Microsoft.Extensions.Logging;
|
|
#if CommonMark
|
|
using System.Collections.ObjectModel;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
#endif
|
|
|
|
namespace File_Folder_Helper.ADO2024.PI3;
|
|
|
|
internal static partial class Helper20240911
|
|
{
|
|
|
|
#if CommonMark
|
|
|
|
private record Attribute([property: JsonPropertyName("isLocked")] bool IsLocked,
|
|
[property: JsonPropertyName("name")] string Name);
|
|
|
|
private record Relation([property: JsonPropertyName("rel")] string Type,
|
|
[property: JsonPropertyName("url")] string URL,
|
|
[property: JsonPropertyName("attributes")] Attribute Attributes);
|
|
|
|
private record WorkItem(string AreaPath,
|
|
string? AssignedTo,
|
|
int? BusinessValue,
|
|
DateTime ChangedDate,
|
|
DateTime? ClosedDate,
|
|
int CommentCount,
|
|
DateTime CreatedDate,
|
|
string Description,
|
|
float? Effort,
|
|
int Id,
|
|
string IterationPath,
|
|
int? Parent,
|
|
int? Priority,
|
|
Relation[] Relations,
|
|
string? Requester,
|
|
DateTime? ResolvedDate,
|
|
int Revision,
|
|
int? RiskReductionMinusOpportunityEnablement,
|
|
DateTime? StartDate,
|
|
string State,
|
|
string Tags,
|
|
DateTime? TargetDate,
|
|
float? TimeCriticality,
|
|
string Title,
|
|
string? Violation,
|
|
float? WeightedShortestJobFirst,
|
|
string WorkItemType)
|
|
{
|
|
|
|
public override string ToString() => $"{Id} - {WorkItemType} - {Title}";
|
|
|
|
public static WorkItem Get(WorkItem workItem, string? violation) =>
|
|
new(workItem.AreaPath,
|
|
workItem.AssignedTo,
|
|
workItem.BusinessValue,
|
|
workItem.ChangedDate,
|
|
workItem.ClosedDate,
|
|
workItem.CommentCount,
|
|
workItem.CreatedDate,
|
|
workItem.Description,
|
|
workItem.Effort,
|
|
workItem.Id,
|
|
workItem.IterationPath,
|
|
workItem.Parent,
|
|
workItem.Priority,
|
|
workItem.Relations,
|
|
workItem.Requester,
|
|
workItem.ResolvedDate,
|
|
workItem.Revision,
|
|
workItem.RiskReductionMinusOpportunityEnablement,
|
|
workItem.StartDate,
|
|
workItem.State,
|
|
workItem.Tags,
|
|
workItem.TargetDate,
|
|
workItem.TimeCriticality,
|
|
workItem.Title,
|
|
workItem.Violation is null ? violation : workItem.Violation,
|
|
workItem.WeightedShortestJobFirst,
|
|
workItem.WorkItemType);
|
|
|
|
}
|
|
|
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
|
[JsonSerializable(typeof(WorkItem[]))]
|
|
private partial class WorkItemCollectionSourceGenerationContext : JsonSerializerContext
|
|
{
|
|
}
|
|
|
|
private record Record(WorkItem WorkItem,
|
|
WorkItem? Parent,
|
|
ReadOnlyCollection<Record> Children);
|
|
|
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
|
[JsonSerializable(typeof(Record[]))]
|
|
private partial class RecordCollectionCommonSourceGenerationContext : JsonSerializerContext
|
|
{
|
|
}
|
|
|
|
private static int? GetIdFromUrlIfChild(Relation relation)
|
|
{
|
|
int? result;
|
|
string[] segments = relation?.Attributes is null || relation.Attributes.Name != "Child" ? [] : relation.URL.Split('/');
|
|
if (segments.Length < 2)
|
|
result = null;
|
|
else
|
|
{
|
|
if (!int.TryParse(segments[^1], out int id))
|
|
result = null;
|
|
else
|
|
result = id;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private static ReadOnlyCollection<Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs, WorkItem workItem, List<bool> nests)
|
|
{
|
|
List<Record> results = [];
|
|
int? childId;
|
|
Record record;
|
|
nests.Add(true);
|
|
WorkItem? childWorkItem;
|
|
WorkItem? parentWorkItem;
|
|
List<WorkItem> collection = [];
|
|
ReadOnlyCollection<Record> records;
|
|
if (workItem.Relations is not null && workItem.Relations.Length > 0)
|
|
{
|
|
collection.Clear();
|
|
foreach (Relation relation in workItem.Relations)
|
|
{
|
|
childId = GetIdFromUrlIfChild(relation);
|
|
if (childId is not null && workItem.Parent is not null && relation?.URL is not null && relation.URL.Contains(workItem.Parent.Value.ToString()))
|
|
continue;
|
|
if (childId is null || !keyValuePairs.TryGetValue(childId.Value, out childWorkItem))
|
|
continue;
|
|
collection.Add(childWorkItem);
|
|
}
|
|
collection = (from l in collection orderby l.State != "Closed", l.Id select l).ToList();
|
|
foreach (WorkItem w in collection)
|
|
{
|
|
if (nests.Count > 99)
|
|
break;
|
|
if (w.Parent is null)
|
|
parentWorkItem = null;
|
|
else
|
|
_ = keyValuePairs.TryGetValue(w.Parent.Value, out parentWorkItem);
|
|
records = GetKeyValuePairs(keyValuePairs, w, nests);
|
|
record = new(w, parentWorkItem, records);
|
|
results.Add(record);
|
|
}
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
private static void AppendLines(List<char> spaces, List<string> lines, Record record, bool condensed, bool sprintOnly)
|
|
{
|
|
string line;
|
|
spaces.Add('\t');
|
|
WorkItem workItem;
|
|
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 void AppendLines(string url, List<char> spaces, List<string> lines, ReadOnlyCollection<Record> records, string workItemType)
|
|
{
|
|
List<string> results = [];
|
|
string? maxIterationPath;
|
|
List<string> distinct = [];
|
|
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.Count == 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 string GetClosed(WorkItem workItem) =>
|
|
workItem.State != "Closed" ? "[ ]" : "[x]";
|
|
|
|
private static string GetLine(List<char> 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 ReadOnlyCollection<string> GetChildrenDirectories(ReadOnlyDictionary<int, Record> keyValuePairs, List<bool> nests, string parentDirectory, Record record)
|
|
{
|
|
List<string> results = [];
|
|
nests.Add(true);
|
|
string directory;
|
|
Record? childRecord;
|
|
ReadOnlyCollection<string> childrenDirectories;
|
|
foreach (Record r in record.Children)
|
|
{
|
|
// if (record.WorkItem.Id == 110730)
|
|
// continue;
|
|
// if (record.WorkItem.Id == 110732)
|
|
// continue;
|
|
directory = Path.Combine(parentDirectory, $"{r.WorkItem.WorkItemType[..1]}-{r.WorkItem.Id}-{r.WorkItem.Title.Trim()[..1]}");
|
|
results.Add(directory);
|
|
if (!keyValuePairs.TryGetValue(r.WorkItem.Id, out childRecord))
|
|
continue;
|
|
if (nests.Count > 99)
|
|
break;
|
|
childrenDirectories = GetChildrenDirectories(keyValuePairs, nests, directory, childRecord);
|
|
results.AddRange(childrenDirectories);
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
private static void FilterChildren(ReadOnlyCollection<string> workItemTypes, Record record, List<WorkItem> results)
|
|
{
|
|
foreach (Record r in record.Children)
|
|
{
|
|
if (!workItemTypes.Contains(r.WorkItem.WorkItemType))
|
|
continue;
|
|
results.Add(r.WorkItem);
|
|
FilterChildren(workItemTypes, r, results);
|
|
}
|
|
}
|
|
|
|
private static ReadOnlyDictionary<int, Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs)
|
|
{
|
|
Dictionary<int, Record> results = [];
|
|
Record record;
|
|
List<bool> nests = [];
|
|
WorkItem? parentWorkItem;
|
|
ReadOnlyCollection<Record> records;
|
|
foreach (KeyValuePair<int, WorkItem> keyValuePair in keyValuePairs)
|
|
{
|
|
nests.Clear();
|
|
if (keyValuePair.Value.Parent is null)
|
|
parentWorkItem = null;
|
|
else
|
|
_ = keyValuePairs.TryGetValue(keyValuePair.Value.Parent.Value, out parentWorkItem);
|
|
try
|
|
{
|
|
records = GetKeyValuePairs(keyValuePairs, keyValuePair.Value, nests);
|
|
record = new(keyValuePair.Value, parentWorkItem, records);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
record = new(keyValuePair.Value, parentWorkItem, new([]));
|
|
}
|
|
results.Add(keyValuePair.Key, record);
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
private static ReadOnlyCollection<string> GetDirectories(string destinationDirectory, ReadOnlyDictionary<int, Record> keyValuePairs)
|
|
{
|
|
List<string> results = [];
|
|
Record record;
|
|
string directory;
|
|
List<bool> nests = [];
|
|
ReadOnlyCollection<string> childrenDirectories;
|
|
string ticksDirectory = Path.Combine(destinationDirectory, "_", DateTime.Now.Ticks.ToString());
|
|
foreach (KeyValuePair<int, Record> keyValuePair in keyValuePairs)
|
|
{
|
|
record = keyValuePair.Value;
|
|
if (record.Parent is not null && (record.WorkItem.Parent is null || record.Parent.Id != record.WorkItem.Parent.Value))
|
|
continue;
|
|
if (record.Parent is not null)
|
|
continue;
|
|
// if (record.WorkItem.Id == 110730)
|
|
// continue;
|
|
// if (record.WorkItem.Id == 110732)
|
|
// continue;
|
|
nests.Clear();
|
|
directory = Path.Combine(ticksDirectory, $"{record.WorkItem.WorkItemType[..1]}-{record.WorkItem.Id}-{record.WorkItem.Title.Trim()[..1]}");
|
|
childrenDirectories = GetChildrenDirectories(keyValuePairs, nests, directory, record);
|
|
results.AddRange(childrenDirectories);
|
|
}
|
|
return new(results.Distinct().ToArray());
|
|
}
|
|
|
|
private static int GetState(WorkItem workItem) =>
|
|
workItem.State switch
|
|
{
|
|
"New" => 1,
|
|
"Active" => 2,
|
|
"Resolved" => 3,
|
|
"Closed" => 4,
|
|
"Removed" => 5,
|
|
_ => 8
|
|
};
|
|
|
|
private static ReadOnlyCollection<WorkItem> FilterChildren(ReadOnlyCollection<string> workItemTypes, Record record)
|
|
{
|
|
List<WorkItem> results = [];
|
|
FilterChildren(workItemTypes, record, results);
|
|
return new(results);
|
|
}
|
|
|
|
private static ReadOnlyDictionary<int, Record> GetWorkItems(ILogger<Worker> logger, string developmentURL, string productionURL)
|
|
{
|
|
ReadOnlyDictionary<int, Record> results;
|
|
Dictionary<int, WorkItem> keyValuePairs = [];
|
|
Task<HttpResponseMessage> httpResponseMessage;
|
|
HttpClient httpClient = new(new HttpClientHandler { UseCookies = false });
|
|
httpResponseMessage = httpClient.GetAsync(developmentURL);
|
|
httpResponseMessage.Wait();
|
|
if (!httpResponseMessage.Result.IsSuccessStatusCode)
|
|
logger.LogWarning("{StatusCode} for {url}", httpResponseMessage.Result.StatusCode, developmentURL);
|
|
Task<string> developmentJSON = httpResponseMessage.Result.Content.ReadAsStringAsync();
|
|
developmentJSON.Wait();
|
|
if (!string.IsNullOrEmpty(productionURL))
|
|
{
|
|
httpResponseMessage = httpClient.GetAsync(productionURL);
|
|
httpResponseMessage.Wait();
|
|
if (!httpResponseMessage.Result.IsSuccessStatusCode)
|
|
logger.LogWarning("{StatusCode} for {url}", httpResponseMessage.Result.StatusCode, productionURL);
|
|
Task<string> productionJSON = httpResponseMessage.Result.Content.ReadAsStringAsync();
|
|
productionJSON.Wait();
|
|
if (productionJSON.Result != developmentJSON.Result)
|
|
logger.LogWarning("productionJSON doesn't match developmentJSON");
|
|
}
|
|
WorkItem[]? workItems = JsonSerializer.Deserialize(developmentJSON.Result, WorkItemCollectionSourceGenerationContext.Default.WorkItemArray);
|
|
if (workItems is null)
|
|
logger.LogWarning("workItems is null");
|
|
else
|
|
{
|
|
foreach (WorkItem workItem in workItems)
|
|
keyValuePairs.Add(workItem.Id, workItem);
|
|
}
|
|
results = GetKeyValuePairs(new(keyValuePairs));
|
|
return results;
|
|
}
|
|
|
|
private static void WriteFileStructure(string destinationDirectory, ReadOnlyDictionary<int, Record> keyValuePairs)
|
|
{
|
|
ReadOnlyCollection<string> collection = GetDirectories(destinationDirectory, keyValuePairs);
|
|
foreach (string directory in collection)
|
|
{
|
|
if (directory.Length > 222)
|
|
continue;
|
|
if (!Directory.Exists(directory))
|
|
_ = Directory.CreateDirectory(directory);
|
|
}
|
|
}
|
|
|
|
private static void WriteFiles(string destinationDirectory, ReadOnlyCollection<Record> records, string fileName)
|
|
{
|
|
string json = JsonSerializer.Serialize(records.ToArray(), RecordCollectionCommonSourceGenerationContext.Default.RecordArray);
|
|
string jsonFile = Path.Combine(destinationDirectory, $"{fileName}.json");
|
|
string jsonOld = !File.Exists(jsonFile) ? string.Empty : File.ReadAllText(jsonFile);
|
|
if (json != jsonOld)
|
|
File.WriteAllText(jsonFile, json);
|
|
}
|
|
|
|
private static void WriteFiles(string destinationDirectory, ReadOnlyCollection<string> lines, ReadOnlyCollection<WorkItem> workItems, string fileName)
|
|
{
|
|
string text = string.Join(Environment.NewLine, lines);
|
|
string markdownFile = Path.Combine(destinationDirectory, $"{fileName}.md");
|
|
string textOld = !File.Exists(markdownFile) ? string.Empty : File.ReadAllText(markdownFile);
|
|
if (text != textOld)
|
|
File.WriteAllText(markdownFile, text);
|
|
string html = CommonMark.CommonMarkConverter.Convert(text).Replace("<a href", "<a target='_blank' href");
|
|
string htmlFile = Path.Combine(destinationDirectory, $"{fileName}.html");
|
|
string htmlOld = !File.Exists(htmlFile) ? string.Empty : File.ReadAllText(htmlFile);
|
|
if (html != htmlOld)
|
|
File.WriteAllText(htmlFile, html);
|
|
string json = JsonSerializer.Serialize(workItems.ToArray(), WorkItemCollectionSourceGenerationContext.Default.WorkItemArray);
|
|
string jsonFile = Path.Combine(destinationDirectory, $"{fileName}.json");
|
|
string jsonOld = !File.Exists(jsonFile) ? string.Empty : File.ReadAllText(jsonFile);
|
|
if (json != jsonOld)
|
|
File.WriteAllText(jsonFile, json);
|
|
}
|
|
|
|
private static ReadOnlyCollection<WorkItem> GetWorkItemsNotMatching122514(Record record, ReadOnlyCollection<WorkItem> workItems)
|
|
{
|
|
List<WorkItem> results = [];
|
|
string[] segments;
|
|
string[] parentTags = record.WorkItem.Tags.Split(';').Select(l => l.Trim()).ToArray();
|
|
foreach (WorkItem workItem in workItems)
|
|
{
|
|
segments = string.IsNullOrEmpty(workItem.Tags) ? [] : workItem.Tags.Split(';').Select(l => l.Trim()).ToArray();
|
|
if (segments.Length > 0 && parentTags.Any(l => segments.Contains(l)))
|
|
continue;
|
|
results.Add(workItem);
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
private static ReadOnlyCollection<WorkItem> GetWorkItemsNotMatching126169(Record record, ReadOnlyCollection<WorkItem> workItems)
|
|
{
|
|
List<WorkItem> results = [];
|
|
foreach (WorkItem workItem in workItems)
|
|
{
|
|
if (record.WorkItem.Priority is null)
|
|
{
|
|
results.Add(record.WorkItem);
|
|
break;
|
|
}
|
|
if (workItem.Priority == record.WorkItem.Priority.Value)
|
|
continue;
|
|
results.Add(workItem);
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
private static ReadOnlyCollection<WorkItem> GetWorkItemsNotMatching123066(Record record, ReadOnlyCollection<WorkItem> workItems)
|
|
{
|
|
List<WorkItem> results = [];
|
|
int check;
|
|
int state = GetState(record.WorkItem);
|
|
List<KeyValuePair<int, WorkItem>> collection = [];
|
|
foreach (WorkItem workItem in workItems)
|
|
{
|
|
if (workItem.State is "Removed")
|
|
continue;
|
|
check = GetState(workItem);
|
|
if (check == state)
|
|
continue;
|
|
collection.Add(new(check, workItem));
|
|
}
|
|
if (collection.Count > 0)
|
|
{
|
|
KeyValuePair<int, WorkItem>[] notNewState = (from l in collection where l.Value.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<int, WorkItem> keyValuePair in collection.OrderByDescending(l => l.Key))
|
|
results.Add(keyValuePair.Value);
|
|
return new(results);
|
|
}
|
|
|
|
private static ReadOnlyCollection<WorkItem> GetWorkItemsNotMatching123067(Record record, ReadOnlyCollection<WorkItem> workItems)
|
|
{
|
|
List<WorkItem> results = [];
|
|
int check;
|
|
int state = GetState(record.WorkItem);
|
|
List<KeyValuePair<int, WorkItem>> collection = [];
|
|
foreach (WorkItem workItem in workItems)
|
|
{
|
|
if (record.WorkItem.State is "Removed" or "Resolved" or "Closed")
|
|
continue;
|
|
check = GetState(workItem);
|
|
if (check == state)
|
|
continue;
|
|
collection.Add(new(check, workItem));
|
|
}
|
|
foreach (KeyValuePair<int, WorkItem> keyValuePair in collection.OrderByDescending(l => l.Key))
|
|
results.Add(keyValuePair.Value);
|
|
return new(results);
|
|
}
|
|
|
|
private static string? GetMaxIterationPath122508(ReadOnlyCollection<WorkItem> workItems)
|
|
{
|
|
string? result;
|
|
List<string> results = [];
|
|
foreach (WorkItem workItem in workItems)
|
|
{
|
|
if (results.Contains(workItem.IterationPath))
|
|
continue;
|
|
results.Add(workItem.IterationPath);
|
|
}
|
|
result = results.Count == 0 ? null : results.Max();
|
|
return result;
|
|
}
|
|
|
|
private static ReadOnlyCollection<WorkItem> FeatureCheckIterationPath122508(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyCollection<Record> records, string workItemType)
|
|
{
|
|
List<WorkItem> results = [];
|
|
string? maxIterationPath;
|
|
List<string> collection = [];
|
|
List<string> violations = [];
|
|
ReadOnlyCollection<WorkItem> childrenWorkItems;
|
|
foreach (Record record in records)
|
|
{
|
|
if (record.WorkItem.State is "Removed")
|
|
continue;
|
|
if (record.WorkItem.WorkItemType != workItemType)
|
|
continue;
|
|
collection.Clear();
|
|
violations.Clear();
|
|
if (record.Children.Count == 0)
|
|
continue;
|
|
childrenWorkItems = FilterChildren(workItemTypes, record);
|
|
maxIterationPath = GetMaxIterationPath122508(childrenWorkItems);
|
|
if (string.IsNullOrEmpty(maxIterationPath) || record.WorkItem.IterationPath == maxIterationPath)
|
|
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})");
|
|
collection.Add($"- [ ] {record.WorkItem.Id} => {record.WorkItem.IterationPath} != {maxIterationPath}");
|
|
collection.Add(string.Empty);
|
|
lines.AddRange(collection);
|
|
results.Add(WorkItem.Get(record.WorkItem, $"IterationPath:<a target='_blank' href=' {url}{record.WorkItem.Id} '>{record.WorkItem.Id}</a>;{record.WorkItem.IterationPath} != {maxIterationPath}"));
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
private static ReadOnlyCollection<WorkItem> FeatureCheckTag122514(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyCollection<Record> records, string workItemType)
|
|
{
|
|
List<WorkItem> results = [];
|
|
List<string> collection = [];
|
|
List<string> violations = [];
|
|
ReadOnlyCollection<WorkItem> childrenWorkItems;
|
|
ReadOnlyCollection<WorkItem> workItemsNotMatching;
|
|
foreach (Record record in records)
|
|
{
|
|
if (record.WorkItem.State is "Removed")
|
|
continue;
|
|
if (record.WorkItem.WorkItemType != workItemType)
|
|
continue;
|
|
collection.Clear();
|
|
violations.Clear();
|
|
if (record.Children.Count == 0)
|
|
continue;
|
|
if (string.IsNullOrEmpty(record.WorkItem.Tags))
|
|
workItemsNotMatching = new([record.WorkItem]);
|
|
else
|
|
{
|
|
childrenWorkItems = FilterChildren(workItemTypes, record);
|
|
workItemsNotMatching = GetWorkItemsNotMatching122514(record, childrenWorkItems);
|
|
if (!string.IsNullOrEmpty(record.WorkItem.Tags) && workItemsNotMatching.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 (WorkItem workItem in workItemsNotMatching)
|
|
collection.Add($"- [ ] {workItem} {nameof(record.WorkItem.Tags)} != {record.WorkItem.Tags}");
|
|
collection.Add(string.Empty);
|
|
lines.AddRange(collection);
|
|
violations.Add($"Tag:{record.WorkItem.Tags};");
|
|
foreach (WorkItem workItem in workItemsNotMatching)
|
|
violations.Add($"<a target='_blank' href=' {url}{workItem.Id} '>{workItem.Id}</a>:{workItem.Tags};");
|
|
results.Add(WorkItem.Get(record.WorkItem, string.Join(' ', violations)));
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
private static ReadOnlyCollection<WorkItem> FeatureCheckPriority126169(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyCollection<Record> records, string workItemType)
|
|
{
|
|
List<WorkItem> results = [];
|
|
List<string> collection = [];
|
|
List<string> violations = [];
|
|
ReadOnlyCollection<WorkItem> childrenWorkItems;
|
|
ReadOnlyCollection<WorkItem> workItemsNotMatching;
|
|
foreach (Record record in records)
|
|
{
|
|
if (record.WorkItem.State is "Removed")
|
|
continue;
|
|
if (record.WorkItem.WorkItemType != workItemType)
|
|
continue;
|
|
collection.Clear();
|
|
violations.Clear();
|
|
if (record.Children.Count == 0)
|
|
continue;
|
|
childrenWorkItems = FilterChildren(workItemTypes, record);
|
|
workItemsNotMatching = GetWorkItemsNotMatching126169(record, childrenWorkItems);
|
|
if (workItemsNotMatching.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 (WorkItem workItem in workItemsNotMatching)
|
|
collection.Add($"- [ ] [{workItem.Id}]({url}{workItem.Id}) {nameof(record.WorkItem.Priority)} != {record.WorkItem.Priority}");
|
|
collection.Add(string.Empty);
|
|
lines.AddRange(collection);
|
|
violations.Add($"Priority:{record.WorkItem.Priority};");
|
|
foreach (WorkItem workItem in workItemsNotMatching)
|
|
violations.Add($"<a target='_blank' href=' {url}{workItem.Id} '>{workItem.Id}</a>:{workItem.Priority};");
|
|
results.Add(WorkItem.Get(record.WorkItem, string.Join(' ', violations)));
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
private static ReadOnlyCollection<WorkItem> FeatureCheckState123066(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyCollection<Record> records, string workItemType)
|
|
{
|
|
List<WorkItem> results = [];
|
|
List<string> collection = [];
|
|
List<string> violations = [];
|
|
ReadOnlyCollection<WorkItem> childrenWorkItems;
|
|
ReadOnlyCollection<WorkItem> workItemsNotMatching;
|
|
foreach (Record record in records)
|
|
{
|
|
if (record.WorkItem.State is "Removed")
|
|
continue;
|
|
if (record.WorkItem.WorkItemType != workItemType)
|
|
continue;
|
|
collection.Clear();
|
|
violations.Clear();
|
|
if (record.Children.Count == 0)
|
|
continue;
|
|
childrenWorkItems = FilterChildren(workItemTypes, record);
|
|
workItemsNotMatching = GetWorkItemsNotMatching123066(record, childrenWorkItems);
|
|
if (workItemsNotMatching.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 (WorkItem workItem in workItemsNotMatching)
|
|
collection.Add($"- [ ] [{workItem.Id}]({url}{workItem.Id}) {nameof(record.WorkItem.State)} != {record.WorkItem.State}");
|
|
collection.Add(string.Empty);
|
|
lines.AddRange(collection);
|
|
violations.Add($"State:{record.WorkItem.State};");
|
|
foreach (WorkItem workItem in workItemsNotMatching)
|
|
violations.Add($"<a target='_blank' href=' {url}{workItem.Id} '>{workItem.Id}</a>:{workItem.State};");
|
|
results.Add(WorkItem.Get(record.WorkItem, string.Join(' ', violations)));
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
private static ReadOnlyCollection<WorkItem> FeatureCheckState123067(string url, List<string> lines, ReadOnlyCollection<string> workItemTypes, ReadOnlyCollection<Record> records, string workItemType)
|
|
{
|
|
List<WorkItem> results = [];
|
|
List<string> collection = [];
|
|
List<string> violations = [];
|
|
ReadOnlyCollection<WorkItem> childrenWorkItems;
|
|
ReadOnlyCollection<WorkItem> workItemsNotMatching;
|
|
foreach (Record record in records)
|
|
{
|
|
if (record.WorkItem.State is "Removed" or "New" or "Active")
|
|
continue;
|
|
if (record.WorkItem.WorkItemType != workItemType)
|
|
continue;
|
|
collection.Clear();
|
|
violations.Clear();
|
|
if (record.Children.Count == 0)
|
|
continue;
|
|
childrenWorkItems = FilterChildren(workItemTypes, record);
|
|
workItemsNotMatching = GetWorkItemsNotMatching123067(record, childrenWorkItems);
|
|
if (workItemsNotMatching.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 (WorkItem workItem in workItemsNotMatching)
|
|
collection.Add($"- [ ] [{workItem.Id}]({url}{workItem.Id}) {nameof(record.WorkItem.State)} != {record.WorkItem.State}");
|
|
collection.Add(string.Empty);
|
|
lines.AddRange(collection);
|
|
violations.Add($"State:{record.WorkItem.State};");
|
|
foreach (WorkItem workItem in workItemsNotMatching)
|
|
violations.Add($"<a target='_blank' href=' {url}{workItem.Id} '>{workItem.Id}</a>:{workItem.State};");
|
|
results.Add(WorkItem.Get(record.WorkItem, string.Join(' ', violations)));
|
|
}
|
|
return new(results);
|
|
}
|
|
|
|
internal static void WriteMarkdown(ILogger<Worker> logger, List<string> args)
|
|
{
|
|
string url = args[5];
|
|
List<char> spaces = [];
|
|
List<string> lines = [];
|
|
ReadOnlyCollection<WorkItem> results;
|
|
string[] workItemTypes = args[4].Split('~');
|
|
string sourceDirectory = Path.GetFullPath(args[0]);
|
|
string destinationDirectory = Path.GetFullPath(args[6]);
|
|
if (!Directory.Exists(destinationDirectory))
|
|
_ = Directory.CreateDirectory(destinationDirectory);
|
|
ReadOnlyDictionary<int, Record> keyValuePairs = GetWorkItems(logger, args[2], args[3]);
|
|
WriteFileStructure(destinationDirectory, keyValuePairs);
|
|
ReadOnlyCollection<Record> records = new(keyValuePairs.Values.ToArray());
|
|
ReadOnlyCollection<string> bugUserStoryWorkItemTypes = new(new string[] { "Bug", "User Story" });
|
|
ReadOnlyCollection<string> bugUserStoryTaskWorkItemTypes = new(new string[] { "Bug", "User Story", "Task" });
|
|
WriteFiles(destinationDirectory, records, "with-parents");
|
|
foreach (string workItemType in workItemTypes)
|
|
{
|
|
lines.Clear();
|
|
lines.Add($"# {workItemType}");
|
|
lines.Add(string.Empty);
|
|
AppendLines(url, spaces, lines, records, workItemType);
|
|
results = new([]);
|
|
WriteFiles(destinationDirectory, new(lines), results, workItemType);
|
|
}
|
|
{
|
|
lines.Clear();
|
|
string workItemType = "Feature";
|
|
lines.Add($"# {nameof(FeatureCheckIterationPath122508)}");
|
|
lines.Add(string.Empty);
|
|
results = FeatureCheckIterationPath122508(url, lines, bugUserStoryTaskWorkItemTypes, records, workItemType);
|
|
WriteFiles(destinationDirectory, new(lines), results, "check-122508");
|
|
}
|
|
{
|
|
lines.Clear();
|
|
string workItemType = "Feature";
|
|
lines.Add($"# {nameof(FeatureCheckTag122514)}");
|
|
lines.Add(string.Empty);
|
|
results = FeatureCheckTag122514(url, lines, bugUserStoryWorkItemTypes, records, workItemType);
|
|
WriteFiles(destinationDirectory, new(lines), results, "check-122514");
|
|
}
|
|
{
|
|
lines.Clear();
|
|
string workItemType = "Feature";
|
|
lines.Add($"# {nameof(FeatureCheckPriority126169)}");
|
|
lines.Add(string.Empty);
|
|
results = FeatureCheckPriority126169(url, lines, bugUserStoryWorkItemTypes, records, workItemType);
|
|
WriteFiles(destinationDirectory, new(lines), results, "check-126169");
|
|
}
|
|
{
|
|
lines.Clear();
|
|
string workItemType = "Feature";
|
|
lines.Add($"# {nameof(FeatureCheckState123066)}");
|
|
lines.Add(string.Empty);
|
|
results = FeatureCheckState123066(url, lines, bugUserStoryTaskWorkItemTypes, records, workItemType);
|
|
WriteFiles(destinationDirectory, new(lines), results, "check-123066");
|
|
}
|
|
{
|
|
lines.Clear();
|
|
string workItemType = "Feature";
|
|
lines.Add($"# {nameof(FeatureCheckState123067)}");
|
|
lines.Add(string.Empty);
|
|
results = FeatureCheckState123067(url, lines, bugUserStoryTaskWorkItemTypes, records, workItemType);
|
|
WriteFiles(destinationDirectory, new(lines), results, "check-123067");
|
|
}
|
|
}
|
|
|
|
#else
|
|
|
|
internal static void WriteMarkdown(ILogger<Worker> logger, List<string> args)
|
|
{
|
|
logger.LogError("WriteMarkdown is not available in CommonMark {args[0]}", args[0]);
|
|
logger.LogError("WriteMarkdown is not available in CommonMark {args[1]}", args[1]);
|
|
}
|
|
|
|
#endif
|
|
|
|
} |