From 9c6740becb0076094f98e9de196a0c8988d2f5c4 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Fri, 6 Sep 2024 16:23:27 -0700 Subject: [PATCH] WorkItem more --- .vscode/launch.json | 8 +- .vscode/settings.json | 4 +- Day/Q32024/Helper-2024-08-09.cs | 4 +- Day/Q32024/Helper-2024-08-30.cs | 90 ++++++++++-- Day/Q32024/WorkItems/CustomRequester.cs | 47 +++---- Day/Q32024/WorkItems/Fields.cs | 175 ++++++++++-------------- 6 files changed, 180 insertions(+), 148 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index cbdf429..13cccf3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -13,8 +13,8 @@ "args": [ "s", "X", - "T:/MESAFIBACKLOG/06_SourceCode/MESAFIBACKLOG/Adaptation/.vscode/helper", - "Day-Helper-2024-08-09", + "L:/DevOps/Mesa_FI/File-Folder-Helper/.vscode/helper/tfs", + "Day-Helper-2024-08-30", "MES", "https://tfs.intra.infineon.com", "/tfs/FactoryIntegration", @@ -22,9 +22,7 @@ "/0d06e969-e1f5-4835-a359-620d557c7595/_apis/wit", "/wiql/3373b300-8de3-4301-9795-e990c3b226f9", "4n7d2jcql6bkq32f66tohddonfxajkypq66lm5y3zqemtlohawsa", - "FI Backlog Mesa - Request List.json", - "Chase|infineon\\TuckerC,Dakota(SRP)|infineon\\Mitchem,Daniel|infineon\\StieberD,Jonathan|infineon\\Ouellette,Mike|infineon\\Phares", - "Chad B|infineon\\cbecker1,Debra Q|infineon\\Quinones,Jeanne M|infineon\\jmcinty2,Jessica F|infineon\\jfuente1,Jonathon S|infineon\\jsperli1,Justin H|infineon\\jhollan2,Kelly C|infineon\\kclark1,Mark C|infineon\\mcouste1,Marti J|infineon\\mjarsey1,Nik C|infineon\\nclark1,Peyton M|infineon\\McChesne,Ron O|infineon\\HendersS,Susan H|infineon\\HendersS,Tiffany M|infineon\\tmunoz1,Todd C|infineon\\tcarrie1" + "FI Backlog Mesa - Request List.json" ], "cwd": "${workspaceFolder}", "console": "integratedTerminal", diff --git a/.vscode/settings.json b/.vscode/settings.json index 0861f9e..4c7725f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -37,6 +37,8 @@ "SUBM", "SURN", "SYSLIB", - "WIQL" + "VSTS", + "WIQL", + "WSJF" ] } \ No newline at end of file diff --git a/Day/Q32024/Helper-2024-08-09.cs b/Day/Q32024/Helper-2024-08-09.cs index 61f8e7b..d57e986 100644 --- a/Day/Q32024/Helper-2024-08-09.cs +++ b/Day/Q32024/Helper-2024-08-09.cs @@ -582,7 +582,7 @@ internal static partial class Helper20240809 Update(httpClient, basePage, api, workItemTrackingHttpClient, sync, valueWithReq); continue; } - if (!isBugFix && int.TryParse(fiBacklogMesa.EstEffortDays, out int estEffortDays) && valueWithReq.Value.Fields.Effort != estEffortDays) + if (!isBugFix && int.TryParse(fiBacklogMesa.EstEffortDays, out int estEffortDays) && valueWithReq.Value.Fields.MicrosoftVSTSSchedulingEffort != estEffortDays) { result += 1; Update(httpClient, basePage, api, workItemTrackingHttpClient, sync, valueWithReq); @@ -591,7 +591,7 @@ internal static partial class Helper20240809 dateTime = GetCommitDate(fiBacklogMesa); if (dateTime is not null) { - timeSpan = new(valueWithReq.Value.Fields.TargetDate.Ticks - dateTime.Value.Ticks); + timeSpan = new(valueWithReq.Value.Fields.MicrosoftVSTSSchedulingTargetDate.Ticks - dateTime.Value.Ticks); if (timeSpan.Hours is > 32 or < -32) { result += 1; diff --git a/Day/Q32024/Helper-2024-08-30.cs b/Day/Q32024/Helper-2024-08-30.cs index f889214..b575bbd 100644 --- a/Day/Q32024/Helper-2024-08-30.cs +++ b/Day/Q32024/Helper-2024-08-30.cs @@ -14,8 +14,30 @@ namespace File_Folder_Helper.Day.Q32024; internal static partial class Helper20240830 { + public record WorkItem(string? AssignedTo, + int? BusinessValue, + DateTime ChangedDate, + int CommentCount, + DateTime CreatedDate, + string Description, + float? Effort, + int Id, + int? Priority, + string? Requester, + int Revision, + int? RiskReductionMinusOpportunityEnablement, + DateTime? StartDate, + string State, + string Tags, + DateTime? TargetDate, + float? TimeCriticality, + string Title, + string WorkItemType, + float? WeightedShortestJobFirst); + private static string GetIds(HttpClient httpClient, string basePage, string api, string query) { + List results = []; StringBuilder result = new(); Task httpResponseMessageTask = httpClient.GetAsync(string.Concat(basePage, api, query)); httpResponseMessageTask.Wait(); @@ -30,13 +52,19 @@ internal static partial class Helper20240830 if (root is null || root.WorkItems is null) throw new NullReferenceException(nameof(root)); foreach (WIQL.WorkItem workItem in root.WorkItems) - _ = result.Append(workItem.Id).Append(','); + { + results.Add(workItem.Id); + if (results.Count > 199) + break; + } + foreach (int id in results) + _ = result.Append(id).Append(','); if (result.Length > 0) _ = result.Remove(result.Length - 1, 1); return result.ToString(); } - private static ReadOnlyCollection GetWorkItems(HttpClient httpClient, string basePage, string api, string sourceDirectory, string ids) + private static ReadOnlyCollection GetWorkItems(HttpClient httpClient, string basePage, string api, string targetFileLocation, string ids) { List results = []; string json; @@ -66,7 +94,7 @@ internal static partial class Helper20240830 value = JsonSerializer.Deserialize(json, ValueSourceGenerationContext.Default.Value); if (value is null) continue; - file = Path.Combine(sourceDirectory, $"{-1}-{value.Id}.json"); + file = Path.Combine(targetFileLocation, $"{-1}-{value.Id}.json"); File.WriteAllText(file, json); results.Add(new(value, -1, json)); } @@ -74,7 +102,41 @@ internal static partial class Helper20240830 return new(results); } + private static ReadOnlyCollection GetWorkItems(ReadOnlyCollection valueWithReqCollection) + { + List results = []; + Fields fields; + WorkItem workItem; + foreach (ValueWithReq valueWithReq in valueWithReqCollection) + { + fields = valueWithReq.Value.Fields; + workItem = new(fields.SystemAssignedTo?.DisplayName, + fields.MicrosoftVSTSCommonBusinessValue == 0 ? null : fields.MicrosoftVSTSCommonBusinessValue, + fields.SystemChangedDate, + fields.SystemCommentCount, + fields.SystemCreatedDate, + fields.SystemDescription, + fields.MicrosoftVSTSSchedulingEffort == 0 ? null : fields.MicrosoftVSTSSchedulingEffort, + valueWithReq.Value.Id, + fields.MicrosoftVSTSCommonPriority == 0 ? null : fields.MicrosoftVSTSCommonPriority, + fields.CustomRequester?.DisplayName, + valueWithReq.Value.Rev, + fields.CustomRRminusOE == 0 ? null : fields.CustomRRminusOE, + fields.MicrosoftVSTSSchedulingStartDate == DateTime.MinValue ? null : fields.MicrosoftVSTSSchedulingStartDate, + fields.SystemState, + fields.SystemTags, + fields.MicrosoftVSTSSchedulingTargetDate == DateTime.MinValue ? null : fields.MicrosoftVSTSSchedulingTargetDate, + fields.MicrosoftVSTSCommonTimeCriticality == 0 ? null : fields.MicrosoftVSTSCommonTimeCriticality, + fields.SystemTitle, + fields.SystemWorkItemType, + fields.CustomWSJF == 0 ? null : fields.CustomWSJF); + results.Add(workItem); + } + return new(results); + } + private static void CompareWorkItems(WorkItemTrackingHttpClient workItemTrackingHttpClient, + string sourceDirectory, string project, string site, ReadOnlyCollection valueWithReqCollection) @@ -82,14 +144,24 @@ internal static partial class Helper20240830 ArgumentNullException.ThrowIfNull(workItemTrackingHttpClient); if (string.IsNullOrEmpty(project)) throw new ArgumentException($"'{nameof(project)}' cannot be null or empty.", nameof(project)); + if (string.IsNullOrEmpty(sourceDirectory)) + throw new ArgumentException($"'{nameof(sourceDirectory)}' cannot be null or empty.", nameof(site)); if (string.IsNullOrEmpty(site)) throw new ArgumentException($"'{nameof(site)}' cannot be null or empty.", nameof(site)); - ArgumentNullException.ThrowIfNull(valueWithReqCollection); + ReadOnlyCollection workItems = GetWorkItems(valueWithReqCollection); + string file = Path.Combine(sourceDirectory, $"_.json"); + string json = JsonSerializer.Serialize(workItems); + File.WriteAllText(file, json); + foreach (WorkItem workItem in workItems) + { + if (workItem is null) + { } + } // https://stackoverflow.com/questions/18153998/how-do-i-remove-all-html-tags-from-a-string-without-knowing-which-tags-are-in-it } private static void CompareWorkItems(HttpClient httpClient, - string sourceDirectory, + string targetFileLocation, string basePage, string api, string query, @@ -98,11 +170,11 @@ internal static partial class Helper20240830 string site) { string ids = GetIds(httpClient, basePage, api, query); - ReadOnlyCollection valueWithReqCollection = string.IsNullOrEmpty(ids) ? new([]) : GetWorkItems(httpClient, basePage, api, sourceDirectory, ids); - CompareWorkItems(workItemTrackingHttpClient, project, site, valueWithReqCollection); + ReadOnlyCollection valueWithReqCollection = string.IsNullOrEmpty(ids) ? new([]) : GetWorkItems(httpClient, basePage, api, targetFileLocation, ids); + CompareWorkItems(workItemTrackingHttpClient, targetFileLocation, project, site, valueWithReqCollection); } - private static void CreateWorkItems(ILogger logger, string sourceDirectory, string api, string site, string query, string project, string basePage, string baseAddress, byte[] bytes, MediaTypeWithQualityHeaderValue mediaTypeWithQualityHeaderValue, WorkItemTrackingHttpClient workItemTrackingHttpClient, HttpClient httpClient) + private static void CompareWorkItems(ILogger logger, string sourceDirectory, string api, string site, string query, string project, string basePage, string baseAddress, byte[] bytes, MediaTypeWithQualityHeaderValue mediaTypeWithQualityHeaderValue, WorkItemTrackingHttpClient workItemTrackingHttpClient, HttpClient httpClient) { string base64 = Convert.ToBase64String(bytes); httpClient.DefaultRequestHeaders.Authorization = new("Basic", base64); @@ -127,7 +199,7 @@ internal static partial class Helper20240830 MediaTypeWithQualityHeaderValue mediaTypeWithQualityHeaderValue = new("application/json"); WorkItemTrackingHttpClient workItemTrackingHttpClient = connection.GetClient(); HttpClient httpClient = new(new HttpClientHandler() { UseDefaultCredentials = true }) { BaseAddress = new(baseAddress) }; - CreateWorkItems(logger, sourceDirectory, api, site, query, project, basePage, baseAddress, bytes, mediaTypeWithQualityHeaderValue, workItemTrackingHttpClient, httpClient); + CompareWorkItems(logger, sourceDirectory, api, site, query, project, basePage, baseAddress, bytes, mediaTypeWithQualityHeaderValue, workItemTrackingHttpClient, httpClient); } } \ No newline at end of file diff --git a/Day/Q32024/WorkItems/CustomRequester.cs b/Day/Q32024/WorkItems/CustomRequester.cs index e83597d..bb66dc9 100644 --- a/Day/Q32024/WorkItems/CustomRequester.cs +++ b/Day/Q32024/WorkItems/CustomRequester.cs @@ -6,42 +6,29 @@ public class CustomRequester { [JsonConstructor] public CustomRequester( + string descriptor, string displayName, - string url, - Links links, string id, - string uniqueName, string imageUrl, - string descriptor + Links links, + string uniqueName, + string url ) { - DisplayName = displayName; - Url = url; - Links = links; - Id = id; - UniqueName = uniqueName; - ImageUrl = imageUrl; Descriptor = descriptor; + DisplayName = displayName; + Id = id; + ImageUrl = imageUrl; + Links = links; + UniqueName = uniqueName; + Url = url; } - [JsonPropertyName("displayName")] - public string DisplayName { get; } - - [JsonPropertyName("url")] - public string Url { get; } - - [JsonPropertyName("_links")] - public Links Links { get; } - - [JsonPropertyName("id")] - public string Id { get; } - - [JsonPropertyName("uniqueName")] - public string UniqueName { get; } - - [JsonPropertyName("imageUrl")] - public string ImageUrl { get; } - - [JsonPropertyName("descriptor")] - public string Descriptor { get; } + [JsonPropertyName("descriptor")] public string Descriptor { get; } + [JsonPropertyName("displayName")] public string DisplayName { get; } + [JsonPropertyName("id")] public string Id { get; } + [JsonPropertyName("imageUrl")] public string ImageUrl { get; } + [JsonPropertyName("_links")] public Links Links { get; } + [JsonPropertyName("uniqueName")] public string UniqueName { get; } + [JsonPropertyName("url")] public string Url { get; } } \ No newline at end of file diff --git a/Day/Q32024/WorkItems/Fields.cs b/Day/Q32024/WorkItems/Fields.cs index 17b2974..8d25362 100644 --- a/Day/Q32024/WorkItems/Fields.cs +++ b/Day/Q32024/WorkItems/Fields.cs @@ -5,113 +5,86 @@ namespace File_Folder_Helper.Day.Q32024.WorkItems; public class Fields { [JsonConstructor] - public Fields( - string systemAreaPath, - string systemTeamProject, - string systemIterationPath, - string systemWorkItemType, - string systemState, - string systemReason, - CustomRequester customRequester, - SystemAssignedTo systemAssignedTo, - DateTime systemCreatedDate, - SystemCreatedBy systemCreatedBy, - DateTime systemChangedDate, - SystemChangedBy systemChangedBy, - int systemCommentCount, - string systemTitle, - DateTime microsoftVSTSCommonStateChangeDate, - int microsoftVSTSCommonPriority, - string systemDescription, - string systemTags, - string systemHistory, - float? effort, - DateTime targetDate - ) + public Fields(int customRRminusOE, + CustomRequester? customRequester, + float customWSJF, + float? microsoftVSTSSchedulingEffort, + int microsoftVSTSCommonBusinessValue, + int microsoftVSTSCommonPriority, + DateTime microsoftVSTSCommonStateChangeDate, + float microsoftVSTSCommonTimeCriticality, + DateTime microsoftVSTSSchedulingStartDate, + string systemAreaPath, + SystemAssignedTo systemAssignedTo, + SystemChangedBy systemChangedBy, + DateTime systemChangedDate, + int systemCommentCount, + SystemCreatedBy systemCreatedBy, + DateTime systemCreatedDate, + string systemDescription, + string systemHistory, + string systemIterationPath, + string systemReason, + string systemState, + string systemTags, + string systemTeamProject, + string systemTitle, + string systemWorkItemType, + DateTime microsoftVSTSSchedulingTargetDate) { - SystemAreaPath = systemAreaPath; - SystemTeamProject = systemTeamProject; - SystemIterationPath = systemIterationPath; - SystemWorkItemType = systemWorkItemType; - SystemState = systemState; - SystemReason = systemReason; + CustomRRminusOE = customRRminusOE; CustomRequester = customRequester; - SystemAssignedTo = systemAssignedTo; - SystemCreatedDate = systemCreatedDate; - SystemCreatedBy = systemCreatedBy; - SystemChangedDate = systemChangedDate; - SystemChangedBy = systemChangedBy; - SystemCommentCount = systemCommentCount; - SystemTitle = systemTitle; - MicrosoftVSTSCommonStateChangeDate = microsoftVSTSCommonStateChangeDate; + CustomWSJF = customWSJF; + MicrosoftVSTSSchedulingEffort = microsoftVSTSSchedulingEffort; + MicrosoftVSTSCommonBusinessValue = microsoftVSTSCommonBusinessValue; MicrosoftVSTSCommonPriority = microsoftVSTSCommonPriority; + MicrosoftVSTSCommonStateChangeDate = microsoftVSTSCommonStateChangeDate; + MicrosoftVSTSCommonTimeCriticality = microsoftVSTSCommonTimeCriticality; + MicrosoftVSTSSchedulingStartDate = microsoftVSTSSchedulingStartDate; + SystemAreaPath = systemAreaPath; + SystemAssignedTo = systemAssignedTo; + SystemChangedBy = systemChangedBy; + SystemChangedDate = systemChangedDate; + SystemCommentCount = systemCommentCount; + SystemCreatedBy = systemCreatedBy; + SystemCreatedDate = systemCreatedDate; SystemDescription = systemDescription; - SystemTags = systemTags; SystemHistory = systemHistory; - Effort = effort; - TargetDate = targetDate; + SystemIterationPath = systemIterationPath; + SystemReason = systemReason; + SystemState = systemState; + SystemTags = systemTags; + SystemTeamProject = systemTeamProject; + SystemTitle = systemTitle; + SystemWorkItemType = systemWorkItemType; + MicrosoftVSTSSchedulingTargetDate = microsoftVSTSSchedulingTargetDate; } - [JsonPropertyName("System.AreaPath")] - public string SystemAreaPath { get; } // { init; get; } + [JsonPropertyName("Custom.RRminusOE")] public int CustomRRminusOE { get; } // { init; get; } + [JsonPropertyName("Custom.Requester")] public CustomRequester? CustomRequester { get; } // { init; get; } + [JsonPropertyName("Custom.WSJF")] public float CustomWSJF { get; } // { init; get; } + [JsonPropertyName("Microsoft.VSTS.Scheduling.Effort")] public float? MicrosoftVSTSSchedulingEffort { get; } // { init; get; } + [JsonPropertyName("Microsoft.VSTS.Common.BusinessValue")] public int MicrosoftVSTSCommonBusinessValue { get; } // { init; get; } + [JsonPropertyName("Microsoft.VSTS.Common.Priority")] public int MicrosoftVSTSCommonPriority { get; } // { init; get; } + [JsonPropertyName("Microsoft.VSTS.Common.StateChangeDate")] public DateTime MicrosoftVSTSCommonStateChangeDate { get; } // { init; get; } + [JsonPropertyName("Microsoft.VSTS.Common.TimeCriticality")] public float MicrosoftVSTSCommonTimeCriticality { get; } // { init; get; } + [JsonPropertyName("Microsoft.VSTS.Scheduling.StartDate")] public DateTime MicrosoftVSTSSchedulingStartDate { get; } // { init; get; } + [JsonPropertyName("System.AreaPath")] public string SystemAreaPath { get; } // { init; get; } + [JsonPropertyName("System.AssignedTo")] public SystemAssignedTo? SystemAssignedTo { get; } // { init; get; } + [JsonPropertyName("System.ChangedBy")] public SystemChangedBy SystemChangedBy { get; } // { init; get; } + [JsonPropertyName("System.ChangedDate")] public DateTime SystemChangedDate { get; } // { init; get; } + [JsonPropertyName("System.CommentCount")] public int SystemCommentCount { get; } // { init; get; } + [JsonPropertyName("System.CreatedBy")] public SystemCreatedBy SystemCreatedBy { get; } // { init; get; } + [JsonPropertyName("System.CreatedDate")] public DateTime SystemCreatedDate { get; } // { init; get; } + [JsonPropertyName("System.Description")] public string SystemDescription { get; } // { init; get; } + [JsonPropertyName("System.History")] public string SystemHistory { get; } // { init; get; } + [JsonPropertyName("System.IterationPath")] public string SystemIterationPath { get; } // { init; get; } + [JsonPropertyName("System.Reason")] public string SystemReason { get; } // { init; get; } + [JsonPropertyName("System.State")] public string SystemState { get; } // { init; get; } + [JsonPropertyName("System.Tags")] public string SystemTags { get; } // { init; get; } + [JsonPropertyName("System.TeamProject")] public string SystemTeamProject { get; } // { init; get; } + [JsonPropertyName("System.Title")] public string SystemTitle { get; } // { init; get; } + [JsonPropertyName("System.WorkItemType")] public string SystemWorkItemType { get; } // { init; get; } + [JsonPropertyName("Microsoft.VSTS.Scheduling.TargetDate")] public DateTime MicrosoftVSTSSchedulingTargetDate { get; } // { init; get; } - [JsonPropertyName("System.TeamProject")] - public string SystemTeamProject { get; } // { init; get; } - - [JsonPropertyName("System.IterationPath")] - public string SystemIterationPath { get; } // { init; get; } - - [JsonPropertyName("System.WorkItemType")] - public string SystemWorkItemType { get; } // { init; get; } - - [JsonPropertyName("System.State")] - public string SystemState { get; } // { init; get; } - - [JsonPropertyName("System.Reason")] - public string SystemReason { get; } // { init; get; } - - [JsonPropertyName("Custom.Requester")] - public CustomRequester CustomRequester { get; } // { init; get; } - - [JsonPropertyName("System.AssignedTo")] - public SystemAssignedTo SystemAssignedTo { get; } // { init; get; } - - [JsonPropertyName("System.CreatedDate")] - public DateTime SystemCreatedDate { get; } // { init; get; } - - [JsonPropertyName("System.CreatedBy")] - public SystemCreatedBy SystemCreatedBy { get; } // { init; get; } - - [JsonPropertyName("System.ChangedDate")] - public DateTime SystemChangedDate { get; } // { init; get; } - - [JsonPropertyName("System.ChangedBy")] - public SystemChangedBy SystemChangedBy { get; } // { init; get; } - - [JsonPropertyName("System.CommentCount")] - public int SystemCommentCount { get; } // { init; get; } - - [JsonPropertyName("System.Title")] - public string SystemTitle { get; } // { init; get; } - - [JsonPropertyName("Microsoft.VSTS.Common.StateChangeDate")] - public DateTime MicrosoftVSTSCommonStateChangeDate { get; } // { init; get; } - - [JsonPropertyName("Microsoft.VSTS.Common.Priority")] - public int MicrosoftVSTSCommonPriority { get; } // { init; get; } - - [JsonPropertyName("System.Description")] - public string SystemDescription { get; } // { init; get; } - - [JsonPropertyName("System.Tags")] - public string SystemTags { get; } // { init; get; } - - [JsonPropertyName("System.History")] - public string SystemHistory { get; } // { init; get; } - - [JsonPropertyName("Microsoft.VSTS.Scheduling.Effort")] - public float? Effort { get; } // { init; get; } - - [JsonPropertyName("Microsoft.VSTS.Scheduling.TargetDate")] - public DateTime TargetDate { get; } // { init; get; } } \ No newline at end of file