Skip to content

Commit d267d6c

Browse files
committed
🐛 (WorkItemCloneCommand.cs): fix field access to use dictionary indexing
♻️ (WorkItemCloneCommand.cs): rename variables for clarity and consistency The changes fix the way fields are accessed in the `projectItem` object by using dictionary indexing (e.g., `projectItem.fields["System.Title"]`) instead of direct property access. This ensures compatibility with the data structure. Additionally, variable names are updated for better clarity and consistency, such as renaming `item` to `controlItem` in the `generateWorkItemsToBuildList` method. This improves code readability and maintainability. 📝 (Resources): add tst_jsonj_export_v20.json to Resources Introduce a new JSON file, `tst_jsonj_export_v20.json`, to the Resources directory. This file contains a list of work items with various fields such as `System.AreaPath`, `System.Tags`, `System.Title`, `Custom.Product`, `Microsoft.VSTS.Scheduling.Effort`, and `Custom.TRA_Milestone`. The addition of this file is intended to provide a sample dataset for testing and development purposes, ensuring that the application can handle and process work item data correctly. ✨ (data.json): add new tasks and milestones for engineering group New tasks and milestones are added to the data.json file to reflect the latest project requirements and scheduling efforts. This update ensures that all relevant tasks are tracked and managed effectively, improving project oversight and resource allocation. ♻️ (WorkItem.cs): change fields property type to Dictionary<string, object> for flexibility The fields property is changed from a custom Fields type to a Dictionary<string, object>. This change allows for more flexibility in handling various field types and structures that may be encountered in different work items.
1 parent ca4ac09 commit d267d6c

File tree

3 files changed

+433
-16
lines changed

3 files changed

+433
-16
lines changed

AzureDevOps.WorkItemClone.ConsoleUI/Commands/WorkItemCloneCommand.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ await AnsiConsole.Progress()
230230
Dictionary<string, string> queryParameters = new Dictionary<string, string>()
231231
{
232232
{ "@projectID", projectItem.id.ToString() },
233-
{ "@projectTitle", projectItem.fields.SystemTitle },
234-
{ "@projectTags", projectItem.fields.SystemTags },
233+
{ "@projectTitle", projectItem.fields["System.Title"].ToString() },
234+
{ "@projectTags", projectItem.fields["System.Tags"].ToString() },
235235
{ "@RunName", config.RunName }
236236
};
237237
var query = await targetApi.CreateProjectQuery(config.targetQueryTitle, config.targetQueryFolder, config.targetQuery, queryParameters);
@@ -250,29 +250,24 @@ await AnsiConsole.Progress()
250250
return 0;
251251
}
252252

253+
253254
private async IAsyncEnumerable<WorkItemToBuild> generateWorkItemsToBuildList(JArray jsonWorkItems, List<WorkItemFull> templateWorkItems, WorkItemFull projectItem, string targetTeamProject)
254255
{
255-
foreach (var item in jsonWorkItems)
256+
foreach (var controlItem in jsonWorkItems)
256257
{
257258
WorkItemFull templateWorkItem = null;
258259
int jsonItemTemplateId = 0;
259-
if (int.TryParse(item["id"].Value<string>(), out jsonItemTemplateId))
260+
if (int.TryParse(controlItem["id"].Value<string>(), out jsonItemTemplateId))
260261
{
261262
templateWorkItem = templateWorkItems.Find(x => x.id == jsonItemTemplateId);
262263
}
263264
WorkItemToBuild newItem = new WorkItemToBuild();
264265
newItem.guid = Guid.NewGuid();
265266
newItem.hasComplexRelation = false;
266267
newItem.templateId = jsonItemTemplateId;
267-
newItem.workItemType = templateWorkItem != null ? templateWorkItem.fields.SystemWorkItemType : "Deliverable";
268+
newItem.workItemType = templateWorkItem != null ? templateWorkItem.fields["System.WorkItemType"].ToString() : "Deliverable";
268269
newItem.fields = new Dictionary<string, string>();
269-
newItem.fields.Add("System.Description", templateWorkItem != null ? templateWorkItem.fields.SystemDescription : "");
270-
newItem.fields.Add("Microsoft.VSTS.Common.AcceptanceCriteria", templateWorkItem != null ? templateWorkItem.fields.MicrosoftVSTSCommonAcceptanceCriteria : "");
271-
//{
272-
// { "System.Tags", string.Join(";" , item.tags, item.area, item.fields.product, templateWorkItem != null? templateWorkItem.fields.SystemTags : "") },
273-
// { "System.AreaPath", string.Join("\\", targetTeamProject, item.area)},
274-
//};
275-
var fields = item["fields"].ToObject<Dictionary<string, string>>();
270+
var fields = controlItem["fields"].ToObject<Dictionary<string, string>>();
276271
foreach (var field in fields)
277272
{
278273
switch (field.Key)
@@ -281,14 +276,15 @@ private async IAsyncEnumerable<WorkItemToBuild> generateWorkItemsToBuildList(JAr
281276
newItem.fields.Add(field.Key, string.Join("\\", targetTeamProject, field.Value));
282277
break;
283278
default:
284-
if (newItem.fields.ContainsKey(field.Key))
279+
if (templateWorkItem != null && templateWorkItem.fields.ContainsKey(field.Key) && (field.Value.Contains("${valuefromtemplate}") || field.Value.Contains("${fromtemplate}")))
285280
{
286-
newItem.fields[field.Key] = field.Value;
281+
/// Add the value from the template
282+
newItem.fields.Add(field.Key, templateWorkItem.fields[field.Key].ToString());
287283
}
288284
else
289285
{
286+
/// add value from control file
290287
newItem.fields.Add(field.Key, field.Value);
291-
292288
}
293289
break;
294290
}

0 commit comments

Comments
 (0)