Skip to content

Commit 06db817

Browse files
authored
Fixed the issue with target query when PrefixProjectToNodes is enabled (#1188)
1 parent 0a7aacc commit 06db817

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/VstsSyncMigrator.Core.Tests/WorkItemMigrationTests.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,58 @@ namespace VstsSyncMigrator.Core.Tests
55
{
66
[TestClass]
77
public class WorkItemMigrationTests
8-
{
8+
{
99
[TestMethod]
1010
public void TestFixAreaPath_WhenNoAreaPathOrIterationPath_DoesntChangeQuery()
1111
{
1212
string WIQLQueryBit = @"AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
1313

14-
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", null);
14+
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", false, null);
1515

1616
Assert.AreEqual(WIQLQueryBit, targetWIQLQueryBit);
1717
}
1818

19-
19+
2020
[TestMethod]
2121
public void TestFixAreaPath_WhenAreaPathInQuery_ChangesQuery()
2222
{
23-
string WIQLQueryBit = @"AND [System.AreaPath] = 'SourceServer\Area\Path1' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
23+
string WIQLQueryBit = @"AND [System.AreaPath] = 'SourceServer\Area\Path1' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
2424
string expectTargetQueryBit = @"AND [System.AreaPath] = 'TargetServer\Area\Path1' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
2525

26-
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", null);
26+
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", false, null);
27+
28+
Assert.AreEqual(expectTargetQueryBit, targetWIQLQueryBit);
29+
}
30+
31+
[TestMethod]
32+
public void TestFixAreaPath_WhenAreaPathInQuery_WithPrefixProjectToNodesEnabled_ChangesQuery()
33+
{
34+
string WIQLQueryBit = @"AND [System.AreaPath] = 'SourceServer\Area\Path1' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
35+
string expectTargetQueryBit = @"AND [System.AreaPath] = 'TargetServer\SourceServer\Area\Path1' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
36+
37+
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", true, null);
2738

2839
Assert.AreEqual(expectTargetQueryBit, targetWIQLQueryBit);
2940
}
3041

3142
[TestMethod]
3243
public void TestFixAreaPath_WhenMultipleAreaPathInQuery_ChangesQuery()
3344
{
34-
string WIQLQueryBit = @"AND [System.AreaPath] = 'SourceServer\Area\Path1' OR [System.AreaPath] = 'SourceServer\Area\Path2' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
45+
string WIQLQueryBit = @"AND [System.AreaPath] = 'SourceServer\Area\Path1' OR [System.AreaPath] = 'SourceServer\Area\Path2' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
3546
string expectTargetQueryBit = @"AND [System.AreaPath] = 'TargetServer\Area\Path1' OR [System.AreaPath] = 'TargetServer\Area\Path2' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
3647

37-
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", null);
48+
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", false, null);
3849

3950
Assert.AreEqual(expectTargetQueryBit, targetWIQLQueryBit);
4051
}
4152

4253
[TestMethod]
4354
public void TestFixAreaPath_WhenAreaPathAtEndOfQuery_ChangesQuery()
4455
{
45-
string WIQLQueryBit = @"AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan') AND [System.AreaPath] = 'SourceServer\Area\Path1'";
56+
string WIQLQueryBit = @"AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan') AND [System.AreaPath] = 'SourceServer\Area\Path1'";
4657
string expectTargetQueryBit = @"AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan') AND [System.AreaPath] = 'TargetServer\Area\Path1'";
4758

48-
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", null);
59+
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", false, null);
4960

5061
Assert.AreEqual(expectTargetQueryBit, targetWIQLQueryBit);
5162
}
@@ -56,7 +67,7 @@ public void TestFixIterationPath_WhenInQuery_ChangesQuery()
5667
string WIQLQueryBit = @"AND [System.IterationPath] = 'SourceServer\Iteration\Path1' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
5768
string expectTargetQueryBit = @"AND [System.IterationPath] = 'TargetServer\Iteration\Path1' AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
5869

59-
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", null);
70+
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", false, null);
6071

6172
Assert.AreEqual(expectTargetQueryBit, targetWIQLQueryBit);
6273
}
@@ -67,7 +78,7 @@ public void TestFixAreaPathAndIteration_WhenMultipleOccuranceInQuery_ChangesQuer
6778
string WIQLQueryBit = @"AND ([System.AreaPath] = 'SourceServer\Area\Path1' OR [System.AreaPath] = 'SourceServer\Area\Path2') AND ([System.IterationPath] = 'SourceServer\Iteration\Path1' OR [System.IterationPath] = 'SourceServer\Iteration\Path2') AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
6879
string expectTargetQueryBit = @"AND ([System.AreaPath] = 'TargetServer\Area\Path1' OR [System.AreaPath] = 'TargetServer\Area\Path2') AND ([System.IterationPath] = 'TargetServer\Iteration\Path1' OR [System.IterationPath] = 'TargetServer\Iteration\Path2') AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
6980

70-
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", null);
81+
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", false, null);
7182

7283
Assert.AreEqual(expectTargetQueryBit, targetWIQLQueryBit);
7384
}
@@ -78,7 +89,7 @@ public void TestFixAreaPathAndIteration_WhenMultipleOccuranceWithMixtureOrEqualA
7889
string WIQLQueryBit = @"AND ([System.AreaPath] = 'SourceServer\Area\Path1' OR [System.AreaPath] UNDER 'SourceServer\Area\Path2') AND ([System.IterationPath] UNDER 'SourceServer\Iteration\Path1' OR [System.IterationPath] = 'SourceServer\Iteration\Path2') AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
7990
string expectTargetQueryBit = @"AND ([System.AreaPath] = 'TargetServer\Area\Path1' OR [System.AreaPath] UNDER 'TargetServer\Area\Path2') AND ([System.IterationPath] UNDER 'TargetServer\Iteration\Path1' OR [System.IterationPath] = 'TargetServer\Iteration\Path2') AND [Microsoft.VSTS.Common.ClosedDate] = '' AND [System.WorkItemType] NOT IN ('Test Suite', 'Test Plan')";
8091

81-
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", null);
92+
string targetWIQLQueryBit = WorkItemMigrationContext.FixAreaPathAndIterationPathForTargetQuery(WIQLQueryBit, "SourceServer", "TargetServer", false, null);
8293

8394
Assert.AreEqual(expectTargetQueryBit, targetWIQLQueryBit);
8495
}

src/VstsSyncMigrator.Core/Execution/MigrationContext/WorkItemMigrationContext.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected override void InternalExecute()
122122
{
123123
contextLog.Information("[FilterWorkItemsThatAlreadyExistInTarget] is enabled. Searching for work items that have already been migrated to the target...", sourceWorkItems.Count());
124124

125-
string targetWIQLQueryBit = FixAreaPathAndIterationPathForTargetQuery(_config.WIQLQueryBit, Engine.Source.WorkItems.Project.Name, Engine.Target.WorkItems.Project.Name, contextLog);
125+
string targetWIQLQueryBit = FixAreaPathAndIterationPathForTargetQuery(_config.WIQLQueryBit, Engine.Source.WorkItems.Project.Name, Engine.Target.WorkItems.Project.Name, _config.PrefixProjectToNodes, contextLog);
126126
sourceWorkItems = ((TfsWorkItemMigrationClient)Engine.Target.WorkItems).FilterExistingWorkItems(sourceWorkItems, new TfsWiqlDefinition() { OrderBit = _config.WIQLOrderBit, QueryBit = targetWIQLQueryBit }, (TfsWorkItemMigrationClient)Engine.Source.WorkItems);
127127
contextLog.Information("!! After removing all found work items there are {SourceWorkItemCount} remaining to be migrated.", sourceWorkItems.Count());
128128
}
@@ -176,7 +176,7 @@ protected override void InternalExecute()
176176
}
177177
}
178178

179-
internal static string FixAreaPathAndIterationPathForTargetQuery(string sourceWIQLQueryBit, string sourceProject, string targetProject, ILogger? contextLog)
179+
internal static string FixAreaPathAndIterationPathForTargetQuery(string sourceWIQLQueryBit, string sourceProject, string targetProject, bool isPrefixProjectToNode, ILogger? contextLog)
180180
{
181181
string targetWIQLQueryBit = sourceWIQLQueryBit;
182182

@@ -188,6 +188,8 @@ internal static string FixAreaPathAndIterationPathForTargetQuery(string sourceWI
188188
return targetWIQLQueryBit;
189189
}
190190

191+
var prefixProject = isPrefixProjectToNode ? "\\" + sourceProject : string.Empty;
192+
191193
var matches = Regex.Matches(targetWIQLQueryBit, RegexPatterForAreaAndIterationPathsFix);
192194
foreach (Match match in matches)
193195
{
@@ -204,7 +206,7 @@ internal static string FixAreaPathAndIterationPathForTargetQuery(string sourceWI
204206
var subValue = value.Substring(0, slashIndex);
205207
if (subValue == sourceProject)
206208
{
207-
var targetValue = targetProject + value.Substring(slashIndex);
209+
var targetValue = targetProject + prefixProject + value.Substring(slashIndex);
208210
var targetMatchValue = match.Value.Replace(value, targetValue);
209211
targetWIQLQueryBit = targetWIQLQueryBit.Replace(match.Value, targetMatchValue);
210212
}

0 commit comments

Comments
 (0)