Infineon.EAF.Runtime 2.52.0

Infineon.EAF.Runtime 2.49.3
IDescription.GetDescriptions with body
This commit is contained in:
2023-10-07 10:56:15 -07:00
parent 172f45aa67
commit b943a882cb
37 changed files with 710 additions and 199 deletions

View File

@ -4,10 +4,13 @@ using Adaptation.Shared;
using Adaptation.Shared.Duplicator;
using Adaptation.Shared.Methods;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
using Microsoft.VisualStudio.Services.WebApi.Patch;
using Microsoft.VisualStudio.Services.WebApi.Patch.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net.Http;
@ -24,11 +27,11 @@ public class ProcessData : IProcessData
List<object> Shared.Properties.IProcessData.Details => _Details;
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, HttpClient httpClient, string basePage, string api, string query, WorkItemTrackingHttpClient workItemTrackingHttpClient, string project, string json)
public ProcessData(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, HttpClient httpClient, string basePage, string api, string query, WorkItemTrackingHttpClient workItemTrackingHttpClient, string project, ReadOnlyDictionary<string, string> assignedToNameToUser, ReadOnlyDictionary<string, string> requestorNameToUser, string json)
{
fileInfoCollection.Clear();
_Details = new List<object>();
Parse(fileRead, logistics, fileInfoCollection, httpClient, basePage, api, query, workItemTrackingHttpClient, project, json);
Parse(fileRead, logistics, fileInfoCollection, httpClient, basePage, api, query, workItemTrackingHttpClient, project, assignedToNameToUser, requestorNameToUser, json);
}
string IProcessData.GetCurrentReactor(IFileRead fileRead, Logistics logistics, Dictionary<string, string> reactors)
@ -43,7 +46,7 @@ public class ProcessData : IProcessData
private static void AddPatch(JsonPatchDocument document, string path, object value) => document.Add(new JsonPatchOperation { From = null, Operation = Operation.Add, Path = path, Value = value });
private static Dictionary<string, FIBacklogMesa> GetFIBacklogMesaCollection(string json, string keySection)
private static Dictionary<string, FIBacklogMesa> GetFIBacklogMesaCollection(string json)
{
Dictionary<string, FIBacklogMesa> results = new();
string key;
@ -59,7 +62,7 @@ public class ProcessData : IProcessData
continue;
if (string.IsNullOrEmpty(fIBacklogMesa.Requestor))
continue;
key = $"{fIBacklogMesa.Requestor.Split(' ').First()}{keySection}{fIBacklogMesa.Req}";
key = $"{fIBacklogMesa.Req} - ";
if (results.ContainsKey(key))
continue;
results.Add(key, fIBacklogMesa);
@ -109,12 +112,12 @@ public class ProcessData : IProcessData
return results;
}
private static Value[] GetExtra(string keySection, IReadOnlyList<Value> workItems, Dictionary<string, FIBacklogMesa> keyToFIBacklogMesa)
private static Value[] GetExtra(IReadOnlyList<Value> workItems, Dictionary<string, FIBacklogMesa> keyToFIBacklogMesa)
{
List<Value> results = new();
foreach (Value value in workItems)
{
if (!value.Fields.SystemTitle.Contains(keySection))
if (!value.Fields.SystemTitle.Contains(" - "))
continue;
if (keyToFIBacklogMesa.Remove(value.Fields.SystemTitle))
continue;
@ -180,7 +183,188 @@ public class ProcessData : IProcessData
}
}
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, HttpClient httpClient, string basePage, string api, string query, WorkItemTrackingHttpClient workItemTrackingHttpClient, string project, string json)
private static JsonPatchDocument GetUATDocument(string project, ReadOnlyDictionary<string, string> requestorNameToUser, DateTime dateTime, string key, FIBacklogMesa fiBacklogMesa)
{
JsonPatchDocument result = new();
AddPatch(result, "/fields/System.AreaPath", project);
string description = GetDescription(fiBacklogMesa, dateTime);
AddPatch(result, "/fields/System.IterationPath", project);
AddPatch(result, "/fields/System.Title", key);
AddPatch(result, "/fields/System.Description", description);
if (requestorNameToUser.TryGetValue(fiBacklogMesa.AssignedTo, out string? requestorUser))
AddPatch(result, "/fields/System.AssignedTo", requestorUser);
return result;
}
private static JsonPatchDocument GetBugDocument(string project, ReadOnlyDictionary<string, string> assignedToNameToUser, Task<WorkItem> uatWorkItemTask, FIBacklogMesa fiBacklogMesa)
{
JsonPatchDocument result = new();
if (uatWorkItemTask.Result.Id is null)
throw new NotSupportedException();
AddPatch(result, "/relations/-", new WorkItemRelation() { Rel = "System.LinkTypes.Hierarchy-Forward", Url = uatWorkItemTask.Result.Url });
AddPatch(result, "/fields/System.AreaPath", project);
AddPatch(result, "/fields/System.IterationPath", project);
AddPatch(result, "/fields/System.Title", $"{fiBacklogMesa.Req} - {fiBacklogMesa.Subject}");
if (!string.IsNullOrEmpty(fiBacklogMesa.Definition))
AddPatch(result, "/fields/System.Description", fiBacklogMesa.Definition);
if (assignedToNameToUser.TryGetValue(fiBacklogMesa.Requestor, out string? requestorUser))
AddPatch(result, "/fields/System.AssignedTo", requestorUser);
return result;
}
private static JsonPatchDocument GetDeveloperTaskDocument(string project, ReadOnlyDictionary<string, string> assignedToNameToUser, FIBacklogMesa fiBacklogMesa)
{
JsonPatchDocument result = new();
AddPatch(result, "/fields/System.AreaPath", project);
AddPatch(result, "/fields/System.IterationPath", project);
AddPatch(result, "/fields/System.Title", $"{fiBacklogMesa.Req} - Developer Task");
if (assignedToNameToUser.TryGetValue(fiBacklogMesa.AssignedTo, out string? assignedToUser))
AddPatch(result, "/fields/System.AssignedTo", assignedToUser);
return result;
}
private static JsonPatchDocument GetSecondDeveloperTaskDocument(string project, ReadOnlyDictionary<string, string> assignedToNameToUser, FIBacklogMesa fiBacklogMesa)
{
JsonPatchDocument result = new();
AddPatch(result, "/fields/System.AreaPath", project);
AddPatch(result, "/fields/System.IterationPath", project);
AddPatch(result, "/fields/System.Title", $"{fiBacklogMesa.Req} - Developer Task");
if (assignedToNameToUser.TryGetValue(fiBacklogMesa.SecondResource, out string? assignedToUser))
AddPatch(result, "/fields/System.AssignedTo", assignedToUser);
return result;
}
private static JsonPatchDocument GetUserStoryDocument(string project, ReadOnlyDictionary<string, string> requestorNameToUser, Task<WorkItem> uatWorkItemTask, FIBacklogMesa fiBacklogMesa)
{
JsonPatchDocument result = new();
if (uatWorkItemTask?.Result.Id is null)
throw new NotSupportedException();
AddPatch(result, "/relations/-", new WorkItemRelation() { Rel = "System.LinkTypes.Hierarchy-Forward", Url = uatWorkItemTask.Result.Url });
AddPatch(result, "/fields/System.AreaPath", project);
AddPatch(result, "/fields/System.IterationPath", project);
AddPatch(result, "/fields/System.Title", $"{fiBacklogMesa.Req} - User Story");
if (requestorNameToUser.TryGetValue(fiBacklogMesa.Requestor, out string? requestorUser))
AddPatch(result, "/fields/System.AssignedTo", requestorUser);
return result;
}
private static JsonPatchDocument GetAssignedToRelationDocument(Task<WorkItem> assignedToWorkItemTask)
{
JsonPatchDocument result = new();
if (assignedToWorkItemTask.Result.Id is null)
throw new NotSupportedException();
AddPatch(result, "/relations/-", new WorkItemRelation() { Rel = "System.LinkTypes.Hierarchy-Forward", Url = assignedToWorkItemTask.Result.Url });
return result;
}
private static JsonPatchDocument GetSecondResourceDocument(Task<WorkItem> secondResourceWorkItemTask)
{
JsonPatchDocument result = new();
if (secondResourceWorkItemTask?.Result.Id is null)
throw new NotSupportedException();
AddPatch(result, "/relations/-", new WorkItemRelation() { Rel = "System.LinkTypes.Hierarchy-Forward", Url = secondResourceWorkItemTask.Result.Url });
return result;
}
private static JsonPatchDocument GetFeatureDocument(string project, ReadOnlyDictionary<string, string> requestorNameToUser, List<string> tags, Task<WorkItem>? userStoryWorkItemTask, FIBacklogMesa fiBacklogMesa)
{
JsonPatchDocument result = new();
if (userStoryWorkItemTask?.Result.Id is null)
throw new NotSupportedException();
AddPatch(result, "/relations/-", new WorkItemRelation() { Rel = "System.LinkTypes.Hierarchy-Forward", Url = userStoryWorkItemTask.Result.Url });
AddPatch(result, "/fields/System.AreaPath", project);
if (tags.Count > 0)
{
AddPatch(result, "/fields/System.Tags", tags.Last());
tags.RemoveAt(tags.Count - 1);
}
AddPatch(result, "/fields/System.IterationPath", project);
if (!string.IsNullOrEmpty(fiBacklogMesa.Definition))
AddPatch(result, "/fields/System.Description", fiBacklogMesa.Definition);
if (int.TryParse(fiBacklogMesa.Priority.Substring(0, 1), out int priority) && priority != 0)
AddPatch(result, "/fields/Microsoft.VSTS.Common.Priority", priority);
if (!string.IsNullOrEmpty(fiBacklogMesa.EstEffortDays) && int.TryParse(fiBacklogMesa.EstEffortDays, out int estEffortDays) && estEffortDays != 0)
AddPatch(result, "/fields/Microsoft.VSTS.Scheduling.Effort", estEffortDays);
if (!string.IsNullOrEmpty(fiBacklogMesa.CommitDate) && DateTime.TryParseExact(fiBacklogMesa.CommitDate.Split(' ').First(), "MM/dd/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime commitDate) && commitDate != DateTime.MinValue)
AddPatch(result, "/fields/Microsoft.VSTS.Scheduling.TargetDate", commitDate.AddHours(12).ToUniversalTime());
if (!string.IsNullOrEmpty(fiBacklogMesa.Updates))
AddPatch(result, "/fields/System.History", fiBacklogMesa.Updates);
AddPatch(result, "/fields/System.Title", $"{fiBacklogMesa.Req} - {fiBacklogMesa.Subject}");
if (requestorNameToUser.TryGetValue(fiBacklogMesa.Requestor, out string? requestorUser))
AddPatch(result, "/fields/System.AssignedTo", requestorUser);
// https://tfs.intra.infineon.com/tfs/ManufacturingIT/Mesa_FI/_apis/wit/workitemtypes/feature/fields?api-version=7.0
return result;
}
private static void DoWork(WorkItemTrackingHttpClient workItemTrackingHttpClient, string project, ReadOnlyDictionary<string, string> assignedToNameToUser, ReadOnlyDictionary<string, string> requestorNameToUser, string key, FIBacklogMesa fiBacklogMesa)
{
DateTime dateTime;
List<string> tags = new();
JsonPatchDocument tagDocument;
Task<WorkItem>? secondResourceWorkItemTask = null;
bool isBugFix = fiBacklogMesa.Priority == "0 - BugFix";
if (!DateTime.TryParse(fiBacklogMesa.Submitted, out dateTime))
dateTime = DateTime.MinValue;
foreach (string tag in fiBacklogMesa.SystemS.Split('/'))
{
if (string.IsNullOrEmpty(tag.Trim()))
continue;
tags.Add(tag.Trim());
}
tags.Reverse();
JsonPatchDocument uatDocument = GetUATDocument(project, requestorNameToUser, dateTime, key, fiBacklogMesa);
Task<WorkItem> uatWorkItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(uatDocument, project, "Task");
uatWorkItemTask.Wait();
if (isBugFix)
{
JsonPatchDocument bugDocument = GetBugDocument(project, assignedToNameToUser, uatWorkItemTask, fiBacklogMesa);
Task<WorkItem> bugWorkItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(bugDocument, project, "Bug");
bugWorkItemTask.Wait();
}
if (!isBugFix)
{
JsonPatchDocument developerTaskDocument = GetDeveloperTaskDocument(project, assignedToNameToUser, fiBacklogMesa);
Task<WorkItem> assignedToWorkItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(developerTaskDocument, project, "Task");
assignedToWorkItemTask.Wait();
if (!string.IsNullOrEmpty(fiBacklogMesa.SecondResource))
{
JsonPatchDocument secondDeveloperTaskDocument = GetSecondDeveloperTaskDocument(project, assignedToNameToUser, fiBacklogMesa);
secondResourceWorkItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(secondDeveloperTaskDocument, project, "Task");
secondResourceWorkItemTask.Wait();
}
JsonPatchDocument userStoryDocument = GetUserStoryDocument(project, requestorNameToUser, uatWorkItemTask, fiBacklogMesa);
Task<WorkItem> userStoryWorkItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(userStoryDocument, project, "User Story");
userStoryWorkItemTask.Wait();
if (userStoryWorkItemTask?.Result.Id is null)
throw new NotSupportedException();
JsonPatchDocument assignedToRelationDocument = GetAssignedToRelationDocument(assignedToWorkItemTask);
userStoryWorkItemTask = workItemTrackingHttpClient.UpdateWorkItemAsync(assignedToRelationDocument, userStoryWorkItemTask.Result.Id.Value);
userStoryWorkItemTask.Wait();
if (secondResourceWorkItemTask is not null)
{
if (userStoryWorkItemTask.Result.Id is null)
throw new NotSupportedException();
JsonPatchDocument secondResourceDocument = GetSecondResourceDocument(secondResourceWorkItemTask);
userStoryWorkItemTask = workItemTrackingHttpClient.UpdateWorkItemAsync(secondResourceDocument, userStoryWorkItemTask.Result.Id.Value);
userStoryWorkItemTask.Wait();
}
JsonPatchDocument featureDocument = GetFeatureDocument(project, requestorNameToUser, tags, userStoryWorkItemTask, fiBacklogMesa);
Task<WorkItem> featureWorkItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(featureDocument, project, "Feature");
featureWorkItemTask.Wait();
for (int i = tags.Count - 1; i > -1; i--)
{
if (featureWorkItemTask.Result.Id is null)
throw new NotSupportedException();
tagDocument = new();
AddPatch(tagDocument, "/fields/System.Tags", tags[i]);
tags.RemoveAt(i);
featureWorkItemTask = workItemTrackingHttpClient.UpdateWorkItemAsync(tagDocument, featureWorkItemTask.Result.Id.Value);
featureWorkItemTask.Wait();
}
}
}
private void Parse(IFileRead fileRead, Logistics logistics, List<FileInfo> fileInfoCollection, HttpClient httpClient, string basePage, string api, string query, WorkItemTrackingHttpClient workItemTrackingHttpClient, string project, ReadOnlyDictionary<string, string> assignedToNameToUser, ReadOnlyDictionary<string, string> requestorNameToUser, string json)
{
if (fileRead is null)
throw new NullReferenceException();
@ -189,24 +373,17 @@ public class ProcessData : IProcessData
if (fileInfoCollection is null)
throw new NullReferenceException();
int counter = 0;
DateTime dateTime;
string description;
string keySection = " UAT for ";
string? directory = Path.GetDirectoryName(fileRead.ReportFullPath);
if (directory is null)
throw new Exception();
string? directory = Path.GetDirectoryName(fileRead.ReportFullPath) ?? throw new Exception();
string[] checkFiles = Directory.GetFiles(directory, "*.csv", SearchOption.TopDirectoryOnly);
if (checkFiles.Any())
UpdateIds(httpClient, basePage, api, checkFiles);
else
{
JsonPatchDocument document;
string ids = GetIds(httpClient, basePage, api, query);
Value[] workItems = GetWorkItems(httpClient, basePage, api, ids);
Task<Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem> workItemTask;
Dictionary<string, FIBacklogMesa> keyToFIBacklogMesa = GetFIBacklogMesaCollection(json, keySection);
Dictionary<string, FIBacklogMesa> keyToFIBacklogMesa = GetFIBacklogMesaCollection(json);
Value[] workItems = string.IsNullOrEmpty(ids) ? Array.Empty<Value>() : GetWorkItems(httpClient, basePage, api, ids);
int count = keyToFIBacklogMesa.Count;
Value[] extra = GetExtra(keySection, workItems, keyToFIBacklogMesa);
Value[] extra = GetExtra(workItems, keyToFIBacklogMesa);
if (count != extra.Length)
{ }
if (count != keyToFIBacklogMesa.Count)
@ -216,33 +393,10 @@ public class ProcessData : IProcessData
{
if (counter > 5)
break;
document = new();
if (!DateTime.TryParse(keyValuePair.Value.Submitted, out dateTime))
dateTime = DateTime.MinValue;
AddPatch(document, "/fields/System.AreaPath", project);
description = GetDescription(keyValuePair.Value, dateTime);
AddPatch(document, "/fields/System.IterationPath", project);
AddPatch(document, "/fields/System.Title", keyValuePair.Key);
AddPatch(document, "/fields/System.Description", description);
// AddPatch(document, "/fields/System.AssignedTo", "Mike.Phares@infineon.com");
if (!fileRead.IsEAFHosted)
continue;
workItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(document, project, "Task");
workItemTask.Wait();
DoWork(workItemTrackingHttpClient, project, assignedToNameToUser, requestorNameToUser, keyValuePair.Key, keyValuePair.Value);
counter++;
if (workItemTask.Result is null)
continue;
if (keyValuePair.Value.Priority == "0 - BugFix")
{
document = new();
AddPatch(document, "/fields/System.AreaPath", project);
AddPatch(document, "/fields/System.IterationPath", project);
AddPatch(document, "/fields/System.Title", keyValuePair.Value.Subject);
AddPatch(document, "/fields/System.Description", $"{description}<br />{keyValuePair.Value.Definition}");
// AddPatch(document, "/fields/System.AssignedTo", "Mike.Phares@infineon.com");
workItemTask = workItemTrackingHttpClient.CreateWorkItemAsync(document, project, "Bug");
workItemTask.Wait();
}
}
}
}