Skip to content

Commit

Permalink
🐛 (WorkItemCloneCommand.cs): handle missing 'System.Tags' field to pr…
Browse files Browse the repository at this point in the history
…event errors

🔧 (launchSettings.json): update commandLineArgs to use a lighter test JSON file
✨ (Resources): add a new lightweight test JSON file for faster testing
♻️ (WorkItem.cs): remove unused Fields class to clean up the codebase
📝 (README.md): update targetQuery example and add clarification on `${fromtemplate}` usage

Handling the missing 'System.Tags' field prevents potential runtime errors when the field is not present. Updating the commandLineArgs to use a lighter test JSON file improves testing efficiency. Adding a new lightweight test JSON file provides a more efficient testing resource. Removing the unused Fields class cleans up the codebase, making it more maintainable. Updating the README.md provides clearer documentation on how to use the `${fromtemplate}` placeholder and updates the targetQuery example to reflect the latest query structure.
  • Loading branch information
MrHinsh committed Jul 25, 2024
1 parent bb957b5 commit b339983
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ await AnsiConsole.Progress()
{
{ "@projectID", projectItem.id.ToString() },
{ "@projectTitle", projectItem.fields["System.Title"].ToString() },
{ "@projectTags", projectItem.fields["System.Tags"].ToString() },
{ "@projectTags", projectItem.fields.ContainsKey("System.Tags") ? projectItem.fields["System.Tags"].ToString() : "" },
{ "@RunName", config.RunName }
};
var query = await targetApi.CreateProjectQuery(config.targetQueryTitle, config.targetQueryFolder, config.targetQuery, queryParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"Clone": {
"commandName": "Project",
"commandLineArgs": "clone --cachePath ..\\..\\..\\..\\..\\.cache\\ --configFile ..\\..\\..\\..\\..\\.cache\\configuration-test.json --jsonFile ..\\..\\..\\..\\..\\TestData\\tst_jsonj_export_v20.json --NonInteractive"
"commandLineArgs": "clone --cachePath ..\\..\\..\\..\\..\\.cache\\ --configFile ..\\..\\..\\..\\..\\.cache\\configuration-test.json --jsonFile ..\\..\\..\\..\\..\\TestData\\tst_jsonj_export_v20-lite.json --NonInteractive"
},
"empty": {
"commandName": "Project"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"id": 213928,
"fields": {
"System.AreaPath": "Engineering Group\\ECH Group\\ECH TPL 1",
"System.Tags": "Customer Document",
"System.Title": "Technical specification",
"Custom.Product": "CC",
"Microsoft.VSTS.Scheduling.Effort": 12,
"Custom.TRA_Milestone": "E0.1",
"System.Description": "${fromtemplate}",
"Microsoft.VSTS.Common.AcceptanceCriteria": "${fromtemplate}"
}
}
]
19 changes: 0 additions & 19 deletions AzureDevOps.WorkItemClone/DataContracts/WorkItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,6 @@ public class WorkItemFull
public string url { get; set; }
}

public class Fields
{
[JsonProperty("System.Id")]
public int SystemId { get; set; }
[JsonProperty("System.WorkItemType")]
public string SystemWorkItemType { get; set; }

[JsonProperty("System.Title")]
public string SystemTitle { get; set; }
[JsonProperty("System.Description")]
public string SystemDescription { get; set; }
[JsonProperty("Microsoft.VSTS.Common.AcceptanceCriteria")]
public string MicrosoftVSTSCommonAcceptanceCriteria { get; set; }
[JsonProperty("System.Tags")]
public string SystemTags { get; set; }
[JsonProperty("System.Parent")]
public int SystemParent { get; set; }
}

public class SystemCreatedby
{
public string displayName { get; set; }
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Clones work items from a template project to a target project incorproating a JS
"templateOrganization": "orgname",
"templateProject": "template Project",
"templateParentId": 212315,
"targetQuery": "SELECT [System.Id], [System.WorkItemType], [System.Title], [System.AreaPath],[System.AssignedTo],[System.State] FROM workitems WHERE [System.Parent] = @projectID",
"targetQuery": "SELECT [Custom.Product], [System.Title], [System.Description], [Custom.DeadlineDate], [System.AreaPath], [System.AssignedTo], [System.State], [Custom.Notes], [System.WorkItemType], [Custom.TRA_Milestone] FROM WorkItemLinks WHERE (Source.[System.Id] = @projectID or Source.[System.Parent] = @projectID) and ([System.Links.LinkType] = 'System.LinkTypes.Hierarchy-Forward') and (Target.[System.Parent] = @projectID) ORDER BY [Custom.DeadlineDate] mode(Recursive)",
"targetQueryTitle": "Project-@RunName - @projectTitle",
"targetQueryFolder": "Shared Queries"
}
Expand All @@ -117,6 +117,8 @@ The `id` is the ID of the template item. This will be used to specifiy Descripti

The `fields` are the fields that will be used to create the work item. You can use any field ientifyer from Azure DevOps.

Use the `${fromtemplate}` to specify that the value should be taken from the template. This is used here for the Description and Acceptance Criteria, but can be used to pull data from any field.

```json
[
{
Expand Down
15 changes: 15 additions & 0 deletions TestData/tst_jsonj_export_v20-lite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[
{
"id": 213928,
"fields": {
"System.AreaPath": "Engineering Group\\ECH Group\\ECH TPL 1",
"System.Tags": "Customer Document",
"System.Title": "Technical specification",
"Custom.Product": "CC",
"Microsoft.VSTS.Scheduling.Effort": 12,
"Custom.TRA_Milestone": "E0.1",
"System.Description": "${fromtemplate}",
"Microsoft.VSTS.Common.AcceptanceCriteria": "${fromtemplate}"
}
}
]

0 comments on commit b339983

Please sign in to comment.