ADO Comment update
This commit is contained in:
parent
d8bf4b3ab6
commit
f87c5a9aa6
22
.vscode/launch.json
vendored
22
.vscode/launch.json
vendored
@ -13,16 +13,18 @@
|
|||||||
"args": [
|
"args": [
|
||||||
"s",
|
"s",
|
||||||
"X",
|
"X",
|
||||||
"\\\\mesfs.infineon.com\\EC_SPC_Si\\PDSF\\MET08RESIHGCV\\Error",
|
"T:/MESAFIBACKLOG/06_SourceCode/MESAFIBACKLOG/Adaptation/.vscode/helper",
|
||||||
"Day-Helper-2024-08-20",
|
"Day-Helper-2024-08-09",
|
||||||
"\\\\mesfs.infineon.com\\EC_SPC_Si\\PDSF\\MET08RESIHGCV\\Source",
|
"MES",
|
||||||
"*.pdsf",
|
"https://tfs.intra.infineon.com",
|
||||||
"5000",
|
"/tfs/FactoryIntegration",
|
||||||
"555",
|
"ART SPS",
|
||||||
"666",
|
"/0d06e969-e1f5-4835-a359-620d557c7595/_apis/wit",
|
||||||
"777",
|
"/wiql/3373b300-8de3-4301-9795-e990c3b226f9",
|
||||||
"888",
|
"4n7d2jcql6bkq32f66tohddonfxajkypq66lm5y3zqemtlohawsa",
|
||||||
"999"
|
"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"
|
||||||
],
|
],
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}",
|
||||||
"console": "integratedTerminal",
|
"console": "integratedTerminal",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using File_Folder_Helper.Day.Q32024.ConvertExcelToJson;
|
using File_Folder_Helper.Day.Q32024.ConvertExcelToJson;
|
||||||
using File_Folder_Helper.Day.Q32024.WorkItems;
|
using File_Folder_Helper.Day.Q32024.WorkItems;
|
||||||
|
using File_Folder_Helper.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
|
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
|
||||||
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
|
using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models;
|
||||||
@ -68,7 +69,7 @@ internal static partial class Helper20240809
|
|||||||
return result.ToString();
|
return result.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ReadOnlyCollection<ValueWithReq> GetWorkItems(HttpClient httpClient, string sourceDirectory, string basePage, string api, string ids)
|
private static ReadOnlyCollection<ValueWithReq> GetWorkItems(HttpClient httpClient, string basePage, string api, string sourceDirectory, string ids)
|
||||||
{
|
{
|
||||||
List<ValueWithReq> results = [];
|
List<ValueWithReq> results = [];
|
||||||
int req;
|
int req;
|
||||||
@ -76,6 +77,7 @@ internal static partial class Helper20240809
|
|||||||
string file;
|
string file;
|
||||||
Value? value;
|
Value? value;
|
||||||
string[] segments;
|
string[] segments;
|
||||||
|
JsonElement[] jsonElements;
|
||||||
Task<HttpResponseMessage> httpResponseMessageTask = httpClient.GetAsync(string.Concat(basePage, api, $"/workitems?ids={ids}"));
|
Task<HttpResponseMessage> httpResponseMessageTask = httpClient.GetAsync(string.Concat(basePage, api, $"/workitems?ids={ids}"));
|
||||||
httpResponseMessageTask.Wait();
|
httpResponseMessageTask.Wait();
|
||||||
if (!httpResponseMessageTask.Result.IsSuccessStatusCode)
|
if (!httpResponseMessageTask.Result.IsSuccessStatusCode)
|
||||||
@ -87,21 +89,27 @@ internal static partial class Helper20240809
|
|||||||
JsonElement? result = JsonSerializer.Deserialize<JsonElement>(streamTask.Result);
|
JsonElement? result = JsonSerializer.Deserialize<JsonElement>(streamTask.Result);
|
||||||
if (result is null || result.Value.ValueKind != JsonValueKind.Object)
|
if (result is null || result.Value.ValueKind != JsonValueKind.Object)
|
||||||
throw new NullReferenceException(nameof(result));
|
throw new NullReferenceException(nameof(result));
|
||||||
JsonElement[] jsonElements = result.Value.EnumerateObject().Last().Value.EnumerateArray().ToArray();
|
JsonProperty[] jsonProperties = result.Value.EnumerateObject().ToArray();
|
||||||
foreach (JsonElement jsonElement in jsonElements)
|
foreach (JsonProperty jsonProperty in jsonProperties)
|
||||||
{
|
{
|
||||||
json = jsonElement.GetRawText();
|
if (jsonProperty.Value.ValueKind != JsonValueKind.Array)
|
||||||
value = JsonSerializer.Deserialize(json, ValueSourceGenerationContext.Default.Value);
|
|
||||||
if (value is null)
|
|
||||||
continue;
|
continue;
|
||||||
segments = value.Fields.SystemTitle.Split('-');
|
jsonElements = jsonProperty.Value.EnumerateArray().ToArray();
|
||||||
if (segments.Length < 2)
|
foreach (JsonElement jsonElement in jsonElements)
|
||||||
continue;
|
{
|
||||||
if (!int.TryParse(segments[0], out req) || req == 0)
|
json = jsonElement.GetRawText();
|
||||||
continue;
|
value = JsonSerializer.Deserialize(json, ValueSourceGenerationContext.Default.Value);
|
||||||
file = Path.Combine(sourceDirectory, $"{req}.json");
|
if (value is null)
|
||||||
File.WriteAllText(file, json);
|
continue;
|
||||||
results.Add(new(value, req, json));
|
segments = value.Fields.SystemTitle.Split('-');
|
||||||
|
if (segments.Length < 2)
|
||||||
|
continue;
|
||||||
|
if (!int.TryParse(segments[0], out req) || req == 0)
|
||||||
|
continue;
|
||||||
|
file = Path.Combine(sourceDirectory, $"{req}-{value.Id}.json");
|
||||||
|
File.WriteAllText(file, json);
|
||||||
|
results.Add(new(value, req, json));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new(results);
|
return new(results);
|
||||||
}
|
}
|
||||||
@ -118,6 +126,98 @@ internal static partial class Helper20240809
|
|||||||
return new(results);
|
return new(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ReadOnlyCollection<Models.Comment> GetComments(HttpClient httpClient, string basePage, string api, string sourceDirectory, int req, int id)
|
||||||
|
{
|
||||||
|
List<Models.Comment> results = [];
|
||||||
|
string json;
|
||||||
|
string file;
|
||||||
|
Models.Comment? comment;
|
||||||
|
JsonElement[] jsonElements;
|
||||||
|
Task<HttpResponseMessage> httpResponseMessageTask = httpClient.GetAsync(string.Concat(basePage, api, $"/workitems/{id}/comments?api-version=7.0-preview.3"));
|
||||||
|
httpResponseMessageTask.Wait();
|
||||||
|
if (!httpResponseMessageTask.Result.IsSuccessStatusCode)
|
||||||
|
throw new Exception(httpResponseMessageTask.Result.StatusCode.ToString());
|
||||||
|
Task<Stream> streamTask = httpResponseMessageTask.Result.Content.ReadAsStreamAsync();
|
||||||
|
streamTask.Wait();
|
||||||
|
if (!streamTask.Result.CanRead)
|
||||||
|
throw new NullReferenceException(nameof(streamTask));
|
||||||
|
JsonElement? result = JsonSerializer.Deserialize<JsonElement>(streamTask.Result);
|
||||||
|
if (result is null || result.Value.ValueKind != JsonValueKind.Object)
|
||||||
|
throw new NullReferenceException(nameof(result));
|
||||||
|
JsonProperty[] jsonProperties = result.Value.EnumerateObject().ToArray();
|
||||||
|
foreach (JsonProperty jsonProperty in jsonProperties)
|
||||||
|
{
|
||||||
|
if (jsonProperty.Value.ValueKind != JsonValueKind.Array)
|
||||||
|
continue;
|
||||||
|
jsonElements = jsonProperty.Value.EnumerateArray().ToArray();
|
||||||
|
foreach (JsonElement jsonElement in jsonElements)
|
||||||
|
{
|
||||||
|
json = jsonElement.GetRawText();
|
||||||
|
comment = JsonSerializer.Deserialize(jsonElement, CommentSourceGenerationContext.Default.Comment);
|
||||||
|
if (comment is null || comment.WorkItemId is null || comment.Id is null)
|
||||||
|
continue;
|
||||||
|
file = Path.Combine(sourceDirectory, $"{req}-{id}-{comment.Id}-comments.json");
|
||||||
|
File.WriteAllText(file, json);
|
||||||
|
results.Add(comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new(results);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdateComment(HttpClient httpClient,
|
||||||
|
string basePage,
|
||||||
|
string api,
|
||||||
|
int id,
|
||||||
|
FIBacklogMesa fiBacklogMesa,
|
||||||
|
Models.Comment comment)
|
||||||
|
{
|
||||||
|
DateTime submittedDateTime;
|
||||||
|
if (!DateTime.TryParse(fiBacklogMesa.Submitted, out submittedDateTime))
|
||||||
|
submittedDateTime = DateTime.MinValue;
|
||||||
|
string updatesWithSubmitted = $"{fiBacklogMesa.Updates}<br> <br>{submittedDateTime:MM/dd/yyyy} - Submitted by {fiBacklogMesa.Requestor}";
|
||||||
|
string json = JsonSerializer.Serialize(new { text = updatesWithSubmitted });
|
||||||
|
StringContent stringContent = new(json, Encoding.UTF8, "application/json");
|
||||||
|
string requestUri = string.Concat(basePage, api, $"/workitems/{id}/comments/{comment.Id}?api-version=7.0-preview.3");
|
||||||
|
Task<HttpResponseMessage> httpResponseMessageTask = httpClient.PatchAsync(requestUri, stringContent);
|
||||||
|
httpResponseMessageTask.Wait();
|
||||||
|
if (!httpResponseMessageTask.Result.IsSuccessStatusCode)
|
||||||
|
throw new Exception(httpResponseMessageTask.Result.StatusCode.ToString());
|
||||||
|
Task<Stream> streamTask = httpResponseMessageTask.Result.Content.ReadAsStreamAsync();
|
||||||
|
streamTask.Wait();
|
||||||
|
if (!streamTask.Result.CanRead)
|
||||||
|
throw new NullReferenceException(nameof(streamTask));
|
||||||
|
JsonElement? result = JsonSerializer.Deserialize<JsonElement>(streamTask.Result);
|
||||||
|
if (result is null || result.Value.ValueKind != JsonValueKind.Object)
|
||||||
|
throw new NullReferenceException(nameof(result));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdateAllWorkItemsPharesComment(HttpClient httpClient,
|
||||||
|
string basePage,
|
||||||
|
string api,
|
||||||
|
string sourceDirectory,
|
||||||
|
Dictionary<string, FIBacklogMesa> keyToFIBacklogMesa,
|
||||||
|
ReadOnlyCollection<ValueWithReq> valueWithReqCollection)
|
||||||
|
{
|
||||||
|
string key;
|
||||||
|
FIBacklogMesa? fIBacklogMesa;
|
||||||
|
ReadOnlyCollection<Models.Comment> comments;
|
||||||
|
foreach (ValueWithReq valueWithReq in valueWithReqCollection)
|
||||||
|
{
|
||||||
|
if (valueWithReq.Value.Fields.SystemCommentCount == 0)
|
||||||
|
continue;
|
||||||
|
key = $"{valueWithReq.Req} - ";
|
||||||
|
if (!keyToFIBacklogMesa.TryGetValue(key, out fIBacklogMesa))
|
||||||
|
continue;
|
||||||
|
comments = GetComments(httpClient, basePage, api, sourceDirectory, valueWithReq.Req, valueWithReq.Value.Id);
|
||||||
|
foreach (Models.Comment comment in comments)
|
||||||
|
{
|
||||||
|
if (comment.CreatedBy?.UniqueName is null || !comment.CreatedBy.UniqueName.Contains("Phares", StringComparison.CurrentCultureIgnoreCase))
|
||||||
|
continue;
|
||||||
|
UpdateComment(httpClient, basePage, api, valueWithReq.Value.Id, fIBacklogMesa, comment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static DateTime? GetCommitDate(FIBacklogMesa fiBacklogMesa)
|
private static DateTime? GetCommitDate(FIBacklogMesa fiBacklogMesa)
|
||||||
{
|
{
|
||||||
DateTime? result;
|
DateTime? result;
|
||||||
@ -358,13 +458,13 @@ internal static partial class Helper20240809
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static int SetSyncTag(HttpClient httpClient,
|
private static int SetSyncTag(HttpClient httpClient,
|
||||||
string basePage,
|
string basePage,
|
||||||
string api,
|
string api,
|
||||||
WorkItemTrackingHttpClient workItemTrackingHttpClient,
|
WorkItemTrackingHttpClient workItemTrackingHttpClient,
|
||||||
ReadOnlyDictionary<string, string> assignedToNameToUser,
|
ReadOnlyDictionary<string, string> assignedToNameToUser,
|
||||||
ReadOnlyDictionary<string, string> requestorNameToUser,
|
ReadOnlyDictionary<string, string> requestorNameToUser,
|
||||||
Dictionary<string, FIBacklogMesa> keyToFIBacklogMesa,
|
Dictionary<string, FIBacklogMesa> keyToFIBacklogMesa,
|
||||||
ReadOnlyCollection<ValueWithReq> valueWithReqCollection)
|
ReadOnlyCollection<ValueWithReq> valueWithReqCollection)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int result = 0;
|
||||||
string key;
|
string key;
|
||||||
@ -381,6 +481,8 @@ internal static partial class Helper20240809
|
|||||||
foreach (ValueWithReq valueWithReq in valueWithReqCollection)
|
foreach (ValueWithReq valueWithReq in valueWithReqCollection)
|
||||||
{
|
{
|
||||||
key = $"{valueWithReq.Req} - ";
|
key = $"{valueWithReq.Req} - ";
|
||||||
|
if (!string.IsNullOrEmpty(key)) // Forced to skip logic
|
||||||
|
continue;
|
||||||
compareTags = GetTags(valueWithReq.Value.Fields);
|
compareTags = GetTags(valueWithReq.Value.Fields);
|
||||||
if (compareTags.Contains(sync))
|
if (compareTags.Contains(sync))
|
||||||
continue;
|
continue;
|
||||||
@ -481,10 +583,11 @@ internal static partial class Helper20240809
|
|||||||
int counter = 0;
|
int counter = 0;
|
||||||
string ids = GetIds(httpClient, basePage, api, query);
|
string ids = GetIds(httpClient, basePage, api, query);
|
||||||
Dictionary<string, FIBacklogMesa> keyToFIBacklogMesa = GetFIBacklogMesaCollection(json);
|
Dictionary<string, FIBacklogMesa> keyToFIBacklogMesa = GetFIBacklogMesaCollection(json);
|
||||||
ReadOnlyCollection<ValueWithReq> valueWithReqCollection = string.IsNullOrEmpty(ids) ? new([]) : GetWorkItems(httpClient, sourceDirectory, basePage, api, ids);
|
ReadOnlyCollection<ValueWithReq> valueWithReqCollection = string.IsNullOrEmpty(ids) ? new([]) : GetWorkItems(httpClient, basePage, api, sourceDirectory, ids);
|
||||||
int updated = SetSyncTag(httpClient, basePage, api, workItemTrackingHttpClient, assignedToNameToUser, requestorNameToUser, keyToFIBacklogMesa, valueWithReqCollection);
|
int updated = SetSyncTag(httpClient, basePage, api, workItemTrackingHttpClient, assignedToNameToUser, requestorNameToUser, keyToFIBacklogMesa, valueWithReqCollection);
|
||||||
if (updated == 0)
|
if (updated == 0)
|
||||||
{
|
{
|
||||||
|
UpdateAllWorkItemsPharesComment(httpClient, basePage, api, sourceDirectory, keyToFIBacklogMesa, valueWithReqCollection);
|
||||||
ReadOnlyCollection<ValueWithReq> extra = RemoveFrom(keyToFIBacklogMesa, valueWithReqCollection);
|
ReadOnlyCollection<ValueWithReq> extra = RemoveFrom(keyToFIBacklogMesa, valueWithReqCollection);
|
||||||
foreach (KeyValuePair<string, FIBacklogMesa> keyValuePair in keyToFIBacklogMesa)
|
foreach (KeyValuePair<string, FIBacklogMesa> keyValuePair in keyToFIBacklogMesa)
|
||||||
{
|
{
|
||||||
|
19
Models/Comment.cs
Normal file
19
Models/Comment.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
|
public record Comment([property: JsonPropertyName("workItemId")] int? WorkItemId,
|
||||||
|
[property: JsonPropertyName("id")] int? Id,
|
||||||
|
[property: JsonPropertyName("version")] int? Version,
|
||||||
|
[property: JsonPropertyName("text")] string? Text,
|
||||||
|
[property: JsonPropertyName("createdBy")] CreatedBy CreatedBy,
|
||||||
|
[property: JsonPropertyName("createdDate")] DateTime CreatedDate,
|
||||||
|
[property: JsonPropertyName("modifiedBy")] ModifiedBy ModifiedBy,
|
||||||
|
[property: JsonPropertyName("modifiedDate")] DateTime ModifiedDate,
|
||||||
|
[property: JsonPropertyName("url")] string? Url);
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(Comment))]
|
||||||
|
internal partial class CommentSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
18
Models/CreatedBy.cs
Normal file
18
Models/CreatedBy.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using File_Folder_Helper.Day.Q32024.WorkItems;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
|
public record CreatedBy([property: JsonPropertyName("displayName")] string? DisplayName,
|
||||||
|
[property: JsonPropertyName("url")] string? Url,
|
||||||
|
[property: JsonPropertyName("_links")] Links Links,
|
||||||
|
[property: JsonPropertyName("id")] string? Id,
|
||||||
|
[property: JsonPropertyName("uniqueName")] string? UniqueName,
|
||||||
|
[property: JsonPropertyName("imageUrl")] string? ImageUrl,
|
||||||
|
[property: JsonPropertyName("descriptor")] string? Descriptor);
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(CreatedBy))]
|
||||||
|
internal partial class CreatedBySourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
18
Models/ModifiedBy.cs
Normal file
18
Models/ModifiedBy.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using File_Folder_Helper.Day.Q32024.WorkItems;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
|
public record ModifiedBy([property: JsonPropertyName("displayName")] string? DisplayName,
|
||||||
|
[property: JsonPropertyName("url")] string? Url,
|
||||||
|
[property: JsonPropertyName("_links")] Links Links,
|
||||||
|
[property: JsonPropertyName("id")] string? Id,
|
||||||
|
[property: JsonPropertyName("uniqueName")] string? UniqueName,
|
||||||
|
[property: JsonPropertyName("imageUrl")] string? ImageUrl,
|
||||||
|
[property: JsonPropertyName("descriptor")] string? Descriptor);
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(ModifiedBy))]
|
||||||
|
internal partial class ModifiedBySourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user