Skip to content

Commit

Permalink
🔧 (configuration.json): refactor MigrationTools configuration structure
Browse files Browse the repository at this point in the history
♻️ (TfsNodeStructureTool): rename NodeBasePaths to Filters for clarity
⬆️ (csproj): add DotNet.Glob package for node filtering
📝 (docs): update documentation to reflect configuration changes

Refactor the configuration structure to improve clarity and maintainability. Rename `NodeBasePaths` to `Filters` to better describe its purpose. Add the `DotNet.Glob` package to support the new filtering mechanism. Update the documentation to reflect these changes and ensure consistency.
  • Loading branch information
MrHinsh committed Aug 23, 2024
1 parent f15a37c commit d7b8c38
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 30 deletions.
15 changes: 7 additions & 8 deletions configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
},
"MigrationTools": {
"Version": "16.0",
"Source": [
{
"Source": {
"TfsTeamProject": {
"EndpointType": "TfsTeamProject",
"Collection": "https://dev.azure.com/nkdagility-preview/",
"Project": "migrationSource1",
Expand All @@ -15,12 +15,11 @@
"LanguageMaps": {
"AreaPath": "Area",
"IterationPath": "Iteration"

}
}
],
"Target": [
{
},
"Target": {
"TfsTeamProject": {
"EndpointType": "TfsTeamProject",
"Collection": "https://dev.azure.com/nkdagility-preview/",
"Project": "migrationTest5",
Expand All @@ -34,7 +33,7 @@
"IterationPath": "Iteration"
}
}
],
},
"CommonTools": {
"WorkItemTypeMappingTool": {
"Enabled": true,
Expand Down Expand Up @@ -119,7 +118,7 @@
},
"Processors": [
{
"ProcessorType": "WorkItemMigrationProcessor",
"ProcessorType": "TfsWorkItemMigrationProcessor",
"Enabled": true,
"UpdateCreatedDate": true,
"UpdateCreatedBy": true,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions docs/Reference/Generated/MigrationTools.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<ItemGroup>
<PackageReference Include="Ben.Demystifier" Version="0.4.1" />
<PackageReference Include="DotNet.Glob" Version="3.1.3" />
<PackageReference Include="Microsoft.TeamFoundation.DistributedTask.Common.Contracts" Version="19.225.1" />
<PackageReference Include="Microsoft.TeamFoundation.DistributedTask.WebApi" Version="19.225.1" />
<PackageReference Include="Microsoft.TeamFoundationServer.ExtendedClient" Version="19.225.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public struct TfsNodeStructureToolSettings
public class TfsNodeStructureTool : Tool<TfsNodeStructureToolOptions>
{
private readonly Dictionary<string, NodeInfo> _pathToKnownNodeMap = new Dictionary<string, NodeInfo>();
private string[] _nodeBasePaths;

private ICommonStructureService4 _sourceCommonStructureService;

Expand Down Expand Up @@ -417,9 +416,7 @@ private static string GetUserFriendlyPath(string systemNodePath)

private void MigrateAllNodeStructures()
{
_nodeBasePaths = Options.NodeBasePaths;

Log.LogDebug("NodeStructureEnricher.MigrateAllNodeStructures({nodeBasePaths}, {areaMaps}, {iterationMaps})", _nodeBasePaths, Options.AreaMaps, Options.IterationMaps);
Log.LogDebug("NodeStructureEnricher.MigrateAllNodeStructures({nodeBasePaths}, {areaMaps}, {iterationMaps})", Options.Filters, Options.AreaMaps, Options.IterationMaps);
//////////////////////////////////////////////////
ProcessCommonStructure(_sourceLanguageMaps.AreaPath, _targetLanguageMaps.AreaPath, _targetProjectName, TfsNodeStructureType.Area);
//////////////////////////////////////////////////
Expand Down Expand Up @@ -500,14 +497,14 @@ private void ProcessCommonStructure(string treeTypeSource, string localizedTreeT
/// <returns>true/false</returns>
private bool ShouldCreateNode(string userFriendlyPath)
{
if (_nodeBasePaths == null || _nodeBasePaths.Length == 0)
if (Options.Filters == null || Options.Filters.Length == 0)
{
return true;
}

var invertedPath = "!" + userFriendlyPath;
var exclusionPatterns = _nodeBasePaths.Where(oneBasePath => oneBasePath.StartsWith("!", StringComparison.InvariantCulture));
if (_nodeBasePaths.Any(oneBasePath => userFriendlyPath.StartsWith(oneBasePath)) &&
var exclusionPatterns = Options.Filters.Where(oneBasePath => oneBasePath.StartsWith("!", StringComparison.InvariantCulture));
if (Options.Filters.Any(oneBasePath => userFriendlyPath.StartsWith(oneBasePath)) &&
!exclusionPatterns.Any(oneBasePath => invertedPath.StartsWith(oneBasePath)))
{
return true;
Expand All @@ -525,7 +522,7 @@ private bool ShouldCreateNode(string userFriendlyPath)
/// <exception cref="NotImplementedException"></exception>
private bool CheckIsParentOfSelectedBasePath(string userFriendlyPath)
{
return _nodeBasePaths != null ? _nodeBasePaths.Where(onePath => !onePath.StartsWith("!"))
return Options.Filters != null ? Options.Filters.Where(onePath => !onePath.StartsWith("!"))
.Any(onePath => onePath.StartsWith(userFriendlyPath)) : false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public sealed class TfsNodeStructureToolOptions : ToolOptions, ITfsNodeStructure


/// <summary>
/// The root paths of the Ares / Iterations you want migrate. See [NodeBasePath Configuration](#nodebasepath-configuration)
/// Using the Glob format you can specify a list of nodes that you want to match. This can be used to filter the main migration of current nodes. note: This does not negate the nees for all nodes in the history of a work item in scope for the migration MUST exist for the system to run, and this will be validated before the migration.
/// </summary>
/// <default>["/"]</default>
public string[] NodeBasePaths { get; set; }
public string[] Filters { get; set; }

/// <summary>
/// Remapping rules for area paths, implemented with regular expressions. The rules apply with a higher priority than the `PrefixProjectToNodes`,
Expand All @@ -43,7 +43,7 @@ public sealed class TfsNodeStructureToolOptions : ToolOptions, ITfsNodeStructure

public interface ITfsNodeStructureToolOptions
{
public string[] NodeBasePaths { get; set; }
public string[] Filters { get; set; }
public Dictionary<string, string> AreaMaps { get; set; }
public Dictionary<string, string> IterationMaps { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions src/MigrationTools.Host/MigrationToolHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public static IHostBuilder CreateDefaultBuilder(string[] args, Action<IConfigura
break;
case MigrationConfigSchema.v160:
// This code Converts the new config format to the v1 and v2 runtme format.
options.Source = configuration.GetSection("MigrationTools:Source")?.GetMigrationToolsOption<IMigrationClientConfig>("EndpointType");
options.Target = configuration.GetSection("MigrationTools:Target")?.GetMigrationToolsOption<IMigrationClientConfig>("EndpointType");
options.Source = configuration.GetSection("MigrationTools:Source:TfsTeamProject")?.GetMigrationToolsOption<IMigrationClientConfig>("EndpointType");
options.Target = configuration.GetSection("MigrationTools:Target:TfsTeamProject")?.GetMigrationToolsOption<IMigrationClientConfig>("EndpointType");
break;
default:
logger.LogCritical("The config file {ConfigFile} is not of the correct format. Use '{ExecutableName}.exe init' to create a new configuration file and port over your old configuration.", configFile, Assembly.GetEntryAssembly().GetName().Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Configure(ProcessorContainerOptions options)
// Bind enrichers for each processor
var enrichersSection = _configuration.GetSection($"MigrationTools:Processors:{options.Processors.IndexOf(processor)}:Enrichers");
var enrichers = enrichersSection?.ToMigrationToolsList(child => child.GetMigrationToolsOption<IProcessorEnricher>("EnricherType"));
if (processor.Enrichers != null)
if (processor.Enrichers == null)
{
processor.Enrichers = new List<IProcessorEnricher>();
}
Expand Down

0 comments on commit d7b8c38

Please sign in to comment.