Skip to content

Commit

Permalink
Fixed wit relation migration. Added node filters. Fixed history migrate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Kanieski committed Dec 16, 2020
1 parent b6b74d4 commit 2566faa
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 31 deletions.
2 changes: 1 addition & 1 deletion AzureDevOpsMigrator.WPF/Pages/RunMigrationPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void Orchestrator_StatusChanged(object source, (int Increment, SyncState
{
CurrentCount += eventArgs.Increment;
Bar_Progress.Value = CurrentCount;
System.Diagnostics.Debug.WriteLine($"{CurrentCount}/{CurrentMax}");
Text_Progress.Text = ($"{CurrentCount}/{CurrentMax}");
Logs.Add(eventArgs);
});
}
Expand Down
9 changes: 9 additions & 0 deletions AzureDevOpsMigrator.WPF/Pages/WitPages/WitAreaPathsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>

<StackPanel Orientation="Horizontal" Margin="5" Grid.Row="0" Grid.Column="0">
Expand All @@ -25,5 +26,13 @@
</StackPanel>
<CheckBox Grid.Column="1" Grid.Row="0" VerticalAlignment="Center"
IsChecked="{Binding Model.Execution.AreaPathMigratorEnabled, Mode=TwoWay}" />

<StackPanel Orientation="Horizontal" Margin="5" Grid.Row="1" Grid.Column="0">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="Area Path Filter (Regex)" />
<Button Margin="20,0,0,0" Foreground="DodgerBlue" Background="Transparent" BorderThickness="0">
</Button>
</StackPanel>
<TextBox Grid.Column="1" Grid.Row="1" VerticalAlignment="Center"
Text="{Binding Model.AreaPathFilter, Mode=TwoWay}" />
</Grid>
</Page>
29 changes: 25 additions & 4 deletions AzureDevOpsMigrator.WPF/Pages/WitPages/WitGeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>


Expand All @@ -51,9 +54,11 @@
<Button Margin="20,0,0,0" Foreground="DodgerBlue" Background="Transparent" BorderThickness="0">
</Button>
</StackPanel>
<TextBox Grid.Column="1" Grid.Row="2" VerticalAlignment="Center"
Text="{Binding Model.MaxDegreeOfParallelism, Mode=TwoWay}" />

<StackPanel Orientation="Horizontal" Grid.Row="2" Grid.Column="1">
<Slider VerticalAlignment="Center" Width="200" Minimum="1" Maximum="20"
Value="{Binding Model.MaxDegreeOfParallelism, Mode=TwoWay}" />
<TextBlock Text="{Binding Model.MaxDegreeOfParallelism, Mode=OneWay}" VerticalAlignment="Center" Margin="20,0,0,0"/>
</StackPanel>

<StackPanel Orientation="Horizontal" Margin="5" Grid.Row="3" Grid.Column="0">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="Compare Fields" />
Expand Down Expand Up @@ -92,13 +97,29 @@
IsChecked="{Binding Model.MigrateAttachments, Mode=TwoWay}" />



<StackPanel Orientation="Horizontal" Margin="5" Grid.Row="7" Grid.Column="0">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="Migrate Relations" />
</StackPanel>
<CheckBox Grid.Column="1" Grid.Row="7" VerticalAlignment="Center"
IsChecked="{Binding Model.MigrateItemRelations, Mode=TwoWay}" />



<StackPanel Orientation="Horizontal" Margin="5" Grid.Row="8" Grid.Column="0">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="Migrate Artifact Links" />
</StackPanel>
<CheckBox Grid.Column="1" Grid.Row="8" VerticalAlignment="Center"
IsChecked="{Binding Model.MigrateArtifactLinks, Mode=TwoWay}" />


<StackPanel Orientation="Horizontal" Margin="5" Grid.Row="9" Grid.Column="0">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="Migration State Field" />
<Button Margin="20,0,0,0" Foreground="DodgerBlue" Background="Transparent" BorderThickness="0">

</Button>
</StackPanel>
<TextBox Grid.Column="1" Grid.Row="7" VerticalAlignment="Center"
<TextBox Grid.Column="1" Grid.Row="9" VerticalAlignment="Center"
Text="{Binding Model.MigrationStateField, Mode=TwoWay}" />
</Grid>
</Grid>
Expand Down
9 changes: 9 additions & 0 deletions AzureDevOpsMigrator.WPF/Pages/WitPages/WitIterationsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>

<StackPanel Orientation="Horizontal" Margin="5" Grid.Row="0" Grid.Column="0">
Expand All @@ -26,5 +27,13 @@
</StackPanel>
<CheckBox Grid.Column="1" Grid.Row="0" VerticalAlignment="Center"
IsChecked="{Binding Model.Execution.IterationsMigratorEnabled, Mode=TwoWay}" />

<StackPanel Orientation="Horizontal" Margin="5" Grid.Row="1" Grid.Column="0">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="Iteration Filter (Regex)" />
<Button Margin="20,0,0,0" Foreground="DodgerBlue" Background="Transparent" BorderThickness="0">
</Button>
</StackPanel>
<TextBox Grid.Column="1" Grid.Row="1" VerticalAlignment="Center"
Text="{Binding Model.IterationFilter, Mode=TwoWay}" />
</Grid>
</Page>
4 changes: 4 additions & 0 deletions AzureDevOpsMigrator/Models/Migration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ public class MigrationConfig
public string MigrationStateField { get; set; } = "MigrationState";
public bool MigrateHistory { get; set; } = true;
public bool MigrateAttachments { get; set; } = true;
public string AreaPathFilter { get; set; } = "";
public string IterationFilter { get; set; } = "";

public ObservableCollection<GitRepo> GitRepoMappings { get; set; } = new ObservableCollection<GitRepo>();
public bool MigrateItemRelations { get; set; }
public bool MigrateArtifactLinks { get; set; }
}
public class GitRepo
{
Expand Down
13 changes: 13 additions & 0 deletions AzureDevOpsMigrator/Services/Migrators/AreaPathMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,18 @@ public AreaPathMigrator(MigrationConfig config, ILogger<IAreaPathMigrator> log,
{ }
protected override TreeStructureGroup _nodesType => TreeStructureGroup.Areas;
protected override TreeNodeStructureType _nodeType => TreeNodeStructureType.Area;

protected override bool IsFilterMatch(string path)
{
if (_areaFilter != _config.AreaPathFilter)
{
_areaFilter = _config.AreaPathFilter;
_areaFilterMatcher = new System.Text.RegularExpressions.Regex(_config.AreaPathFilter);
}
return string.IsNullOrEmpty(_config.AreaPathFilter) ? true : _areaFilterMatcher.IsMatch(path);
}

private string _areaFilter = "";
private System.Text.RegularExpressions.Regex _areaFilterMatcher;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ public async Task ExecuteAsync(System.Threading.CancellationToken token)

var flattenedSourcePaths = new List<(string Path, WorkItemClassificationNode Node)>();
FlattenNodes(sourcePaths, ref flattenedSourcePaths);
flattenedSourcePaths = flattenedSourcePaths.OrderBy(s => s.Path).Select(p => (string.Join('\\', p.Path.Split(@"\").Skip(3)), p.Node)).ToList();
flattenedSourcePaths = flattenedSourcePaths.OrderBy(s => s.Path)
.Where(x => IsFilterMatch(x.Path))
.Select(p => (string.Join('\\', p.Path.Split(@"\").Skip(3)), p.Node))
.ToList();

var flattenedTargetPaths = new List<(string Path, WorkItemClassificationNode Node)>();
FlattenNodes(targetPaths, ref flattenedTargetPaths);
flattenedTargetPaths = flattenedTargetPaths.OrderBy(s => s.Path).Select(p => (string.Join('\\', p.Path.Split(@"\").Skip(3)), p.Node)).ToList();
flattenedTargetPaths = flattenedTargetPaths.OrderBy(s => s.Path).Select(p => (string.Join('\\', p.Path.Split(@"\").Skip(3)), p.Node))
.ToList();

_log.LogInformation($"{flattenedSourcePaths.Count} source nodes flattened");
_log.LogInformation($"{flattenedTargetPaths.Count} target nodes flattened");
Expand All @@ -54,11 +58,11 @@ public async Task ExecuteAsync(System.Threading.CancellationToken token)
{
token.ThrowIfCancellationRequested();


// look up modified path in target
var existing = flattenedTargetPaths
.Select(x => new { Path = x.Path, Node = x.Node})
.Select(x => new { Path = x.Path, Node = x.Node })
.FirstOrDefault(p => p.Path.Equals(sourceNode.Path, System.StringComparison.OrdinalIgnoreCase));

if (existing == null)
{
// Create a new area path in target
Expand All @@ -71,7 +75,7 @@ public async Task ExecuteAsync(System.Threading.CancellationToken token)
Attributes = sourceNode.Node.Attributes,
HasChildren = sourceNode.Node.HasChildren
}));
}
}
else
{
bool changes = false;
Expand Down Expand Up @@ -124,6 +128,11 @@ public async Task ExecuteAsync(System.Threading.CancellationToken token)

}

protected virtual bool IsFilterMatch(string path)
{
throw new NotImplementedException("Filter match is not implemented");
}

private void FlattenNodes(IEnumerable<WorkItemClassificationNode> nodes, ref List<(string Path, WorkItemClassificationNode Node)> paths)
{
foreach (var node in nodes)
Expand All @@ -146,7 +155,7 @@ private void FlattenNodes(IEnumerable<WorkItemClassificationNode> nodes, ref Lis
FlattenNodes(
await _sourceEndpoint.GetClassificationNodes(_config.SourceEndpointConfig.ProjectName, _nodesType, token),
ref paths);
return paths.Count;
return paths.Where(node => IsFilterMatch(node.Path)).Count();
}
}
}
13 changes: 13 additions & 0 deletions AzureDevOpsMigrator/Services/Migrators/IterationMigrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,18 @@ public IterationMigrator(MigrationConfig config, ILogger<IIterationMigrator> log
{ }
protected override TreeStructureGroup _nodesType => TreeStructureGroup.Iterations;
protected override TreeNodeStructureType _nodeType => TreeNodeStructureType.Iteration;

protected override bool IsFilterMatch(string path)
{
if (_iterationFilter != _config.IterationFilter)
{
_iterationFilter = _config.IterationFilter;
_iterationFilterMatcher = new System.Text.RegularExpressions.Regex(_config.IterationFilter);
}
return string.IsNullOrEmpty(_config.IterationFilter) ? true : _iterationFilterMatcher.IsMatch(path);
}

private string _iterationFilter = "";
private System.Text.RegularExpressions.Regex _iterationFilterMatcher;
}
}
15 changes: 11 additions & 4 deletions AzureDevOpsMigrator/Services/Migrators/OrchestratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ await Task.WhenAll(
{
try
{
return plan.IterationsCount = await _iterationMigrator.GetPlannedCount(token);
return plan.IterationsCount = _config.Execution.IterationsMigratorEnabled ? await _iterationMigrator.GetPlannedCount(token) : 0;
}
catch (Exception ex)
{
Expand All @@ -94,7 +94,7 @@ await Task.WhenAll(
{
try
{
return plan.AreaPathsCount = await _areaPathMigrator.GetPlannedCount(token);
return plan.AreaPathsCount = _config.Execution.AreaPathMigratorEnabled ? await _areaPathMigrator.GetPlannedCount(token) : 0;
}
catch (Exception ex)
{
Expand All @@ -106,7 +106,7 @@ await Task.WhenAll(
{
try
{
return plan.WorkItemsCount = await _workItemMigrator.GetPlannedCount(token);
return plan.WorkItemsCount = _config.Execution.WorkItemsMigratorEnabled ? await _workItemMigrator.GetPlannedCount(token) : 0;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -188,7 +188,14 @@ public async Task ExecuteAsync(MigrationPlan plan, CancellationToken token)
}


await _workItemMigrator.ExecuteAsync(token);
if (_config.Execution.WorkItemsMigratorEnabled)
{
await _workItemMigrator.ExecuteAsync(token);
}
else
{
_log.LogInformation("Skipping work item migrations..");
}
}
catch (OperationCanceledException opCanceledEx)
{
Expand Down
Loading

0 comments on commit 2566faa

Please sign in to comment.