Skip to content

Commit 406e7fa

Browse files
committed
PR 28: Updated reflected WIT to test for URL format +semver: minor
- Updated reflected WIT to test for URL format +semver: minor
1 parent e15b8b0 commit 406e7fa

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

TfsWitMigrator.Core/ComponentContext/WorkItemStoreContext.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using Microsoft.TeamFoundation.WorkItemTracking.Client;
44
using System.Collections.Generic;
5+
using System.Text.RegularExpressions;
56

67
namespace VSTS.DataBulkEditor.Engine
78
{
@@ -34,9 +35,15 @@ public string CreateReflectedWorkItemId(WorkItem wi)
3435
public int GetReflectedWorkItemId(WorkItem wi, string reflectedWotkItemIdField)
3536
{
3637
string rwiid = wi.Fields[reflectedWotkItemIdField].Value.ToString();
37-
return int.Parse(rwiid.Substring(rwiid.LastIndexOf(@"/") + 1));
38+
if (Regex.IsMatch(rwiid, @"(http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?"))
39+
{
40+
return int.Parse(rwiid.Substring(rwiid.LastIndexOf(@"/") + 1));
41+
}
42+
return 0;
3843
}
3944

45+
46+
4047
public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedWotkItemIdField)
4148
{
4249
string ReflectedWorkItemId = CreateReflectedWorkItemId(workItemToFind);
@@ -49,11 +56,18 @@ public WorkItem FindReflectedWorkItem(WorkItem workItemToFind, string reflectedW
4956
{
5057
string rwiid = workItemToFind.Fields[reflectedWotkItemIdField].Value.ToString();
5158
int idToFind = GetReflectedWorkItemId(workItemToFind, reflectedWotkItemIdField);
52-
found = Store.GetWorkItem(idToFind);
53-
if (!(found.Fields[reflectedWotkItemIdField].Value.ToString() == rwiid))
59+
if (idToFind == 0)
5460
{
5561
found = null;
5662
}
63+
else
64+
{
65+
found = Store.GetWorkItem(idToFind);
66+
if (!(found.Fields[reflectedWotkItemIdField].Value.ToString() == rwiid))
67+
{
68+
found = null;
69+
}
70+
}
5771
}
5872
if (found == null) { found = FindReflectedWorkItemByReflectedWorkItemId(ReflectedWorkItemId, reflectedWotkItemIdField); }
5973
if (found == null) { found = FindReflectedWorkItemByMigrationRef(ReflectedWorkItemId); }

0 commit comments

Comments
 (0)