-
Notifications
You must be signed in to change notification settings - Fork 69
Added AreaPath and IterationPath migration with tests #85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
7f1047a
810345e
8979194
830f05a
be79f00
6c7def0
05d3c94
105de2c
d6af915
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,14 @@ public class ConfigJson | |
| [DefaultValue(true)] | ||
| public bool SkipExisting { get; set; } | ||
|
|
||
| [JsonProperty(PropertyName = "move-area-paths", DefaultValueHandling = DefaultValueHandling.Populate)] | ||
| [DefaultValue(true)] | ||
| public bool MoveAreaPaths { get; set; } | ||
|
|
||
| [JsonProperty(PropertyName = "move-iterations", DefaultValueHandling = DefaultValueHandling.Populate)] | ||
| [DefaultValue(true)] | ||
|
||
| public bool MoveIterations{ get; set; } | ||
|
|
||
| [JsonProperty(PropertyName = "move-history", DefaultValueHandling = DefaultValueHandling.Populate)] | ||
| [DefaultValue(false)] | ||
| public bool MoveHistory { get; set; } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -348,6 +348,36 @@ public static async Task ReadSourceWorkItems(IMigrationContext migrationContext, | |
| batchContext.SourceWorkItems = await WorkItemTrackingHelpers.GetWorkItemsAsync(migrationContext.SourceClient.WorkItemTrackingHttpClient, workItemIds, expand: expand); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Populates batchContext.WorkItems | ||
| /// </summary> | ||
| /// <param name="migrationContext"></param> | ||
| /// <param name="workItemIds"></param> | ||
| /// <param name="batchContext"></param> | ||
| /// <param name="expand"></param> | ||
| /// <returns></returns> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mind updating the comment block? |
||
| public static async Task ReadSourceNodes(IMigrationContext migrationContext, string projectId) | ||
| { | ||
| var nodes = await WorkItemTrackingHelpers.GetClassificationNodes(migrationContext.SourceClient.WorkItemTrackingHttpClient, projectId); | ||
| migrationContext.SourceAreaAndIterationTree = new AreaAndIterationPathTree(nodes); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Populates batchContext.WorkItems | ||
| /// </summary> | ||
| /// <param name="migrationContext"></param> | ||
| /// <param name="workItemIds"></param> | ||
| /// <param name="batchContext"></param> | ||
| /// <param name="expand"></param> | ||
| /// <returns></returns> | ||
| public static async Task ReadTargetNodes(IMigrationContext migrationContext, string projectId) | ||
| { | ||
| var nodes = await WorkItemTrackingHelpers.GetClassificationNodes(migrationContext.TargetClient.WorkItemTrackingHttpClient, projectId); | ||
| migrationContext.TargetAreaAndIterationTree = new AreaAndIterationPathTree(nodes); | ||
| migrationContext.TargetAreaPaths = migrationContext.TargetAreaAndIterationTree.AreaPathList; | ||
| migrationContext.TargetIterationPaths = migrationContext.TargetAreaAndIterationTree.IterationPathList; | ||
| } | ||
|
|
||
| public static int GetTargetId(int sourceId, IEnumerable<WorkItemMigrationState> workItemMigrationStates) | ||
| { | ||
| return workItemMigrationStates.First(a => a.SourceId == sourceId).TargetId.Value; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models; | ||
| using Common.Config; | ||
| using Logging; | ||
| using Microsoft.TeamFoundation.TestManagement.WebApi; | ||
|
||
|
|
||
| namespace Common.Migration | ||
| { | ||
|
|
||
| public class ClassificationNodesPreProcessor : IPhase1PreProcessor | ||
| { | ||
| static ILogger Logger { get; } = MigratorLogging.CreateLogger<ClassificationNodesPreProcessor>(); | ||
| private IMigrationContext context; | ||
|
|
||
| public string Name => "Classification Nodes (Area Paths/Iterations)"; | ||
|
|
||
| public bool IsEnabled(ConfigJson config) | ||
| { | ||
| return true; | ||
|
||
| } | ||
|
|
||
| public async Task Prepare(IMigrationContext context) | ||
| { | ||
| this.context = context; | ||
| } | ||
|
|
||
| public async Task Process(IBatchMigrationContext batchContext) | ||
| { | ||
| int modificationCount = 0; | ||
| if (context.Config.MoveAreaPaths || context.Config.MoveIterations) | ||
| { | ||
| await Task.WhenAll( | ||
| Migrator.ReadSourceNodes(context, context.Config.SourceConnection.Project), | ||
| Migrator.ReadTargetNodes(context, context.Config.TargetConnection.Project)); | ||
| } | ||
|
|
||
| #region Process area paths .. | ||
| if (context.Config.MoveAreaPaths) | ||
| { | ||
| modificationCount = await ProcessAreaPaths(batchContext, modificationCount); | ||
| } | ||
| #endregion | ||
|
|
||
| #region Process iterations .. | ||
| if (context.Config.MoveIterations) | ||
| { | ||
| modificationCount = await ProcessIterationPaths(batchContext, modificationCount); | ||
| } | ||
| #endregion | ||
|
|
||
| if (modificationCount > 0) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not a fan of the pattern of passing an int and then assigning it in the return. Either make it an out or just have two variables. |
||
| { | ||
| await Migrator.ReadTargetNodes(context, context.Config.TargetConnection.Project); | ||
| } | ||
| } | ||
|
|
||
| public async Task<int> ProcessIterationPaths(IBatchMigrationContext batchContext, int modificationCount) | ||
| { | ||
| Logger.LogInformation(LogDestination.All, $"Identified {context.SourceAreaAndIterationTree.IterationPathList.Count} iterations in source project."); | ||
|
|
||
| foreach (var iterationPath in context.SourceAreaAndIterationTree.IterationPathList) | ||
| { | ||
| string iterationPathInTarget = iterationPath.Replace(context.Config.SourceConnection.Project, context.Config.TargetConnection.Project); | ||
|
|
||
| // If the iteration path is not found in the work items we're currently processing then just ignore it. | ||
| if (!batchContext.SourceWorkItems.Any(w => w.Fields.ContainsKey("System.IterationPath") && w.Fields["System.IterationPath"].ToString().ToLower().Equals(iterationPath.ToLower()))) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of all the tolowers, why not just do a stringcomparison.ignorecase |
||
| continue; | ||
|
|
||
| if (context.TargetAreaAndIterationTree.IterationPathListLookup.ContainsKey(iterationPathInTarget)) | ||
| { | ||
| Logger.LogInformation(LogDestination.All, $"[Exists] {iterationPathInTarget}."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mind including a little more detail, like "[Iteration path exists] |
||
| } | ||
| else | ||
| { | ||
| var sourceIterationNode = context.SourceAreaAndIterationTree.IterationPathListLookup[iterationPath]; | ||
| modificationCount += 1; | ||
| await CreateIterationPath(iterationPath, sourceIterationNode); | ||
|
|
||
| Logger.LogSuccess(LogDestination.All, $"[Created] {iterationPathInTarget}."); | ||
| } | ||
| } | ||
|
|
||
| Logger.LogInformation(LogDestination.All, $"Iterations synchronized."); | ||
| return modificationCount; | ||
| } | ||
|
|
||
| public async virtual Task CreateIterationPath(string iterationPath, WorkItemClassificationNode sourceIterationNode) | ||
| { | ||
| await WorkItemTrackingHelpers.CreateIterationAsync( | ||
| context.TargetClient.WorkItemTrackingHttpClient, | ||
| context.Config.TargetConnection.Project, | ||
| iterationPath, | ||
| sourceIterationNode.Attributes == null ? null : (DateTime?)sourceIterationNode.Attributes?["startDate"], | ||
| sourceIterationNode.Attributes == null ? null : (DateTime?)sourceIterationNode.Attributes["finishDate"]); | ||
| } | ||
|
|
||
| public async Task<int> ProcessAreaPaths(IBatchMigrationContext batchContext, int modificationCount) | ||
| { | ||
| Logger.LogInformation(LogDestination.All, $"Identified {context.SourceAreaAndIterationTree.AreaPathListLookup.Count} area paths in source project."); | ||
|
|
||
| foreach (var ap in context.SourceAreaAndIterationTree.AreaPathList) | ||
|
||
| { | ||
| string areaPathInTarget = ap.Replace(context.Config.SourceConnection.Project, context.Config.TargetConnection.Project); | ||
|
||
|
|
||
| // If the area path is not found in the work items we're currently processing then just ignore it. | ||
| if (!batchContext.SourceWorkItems.Any(w => w.Fields.ContainsKey("System.AreaPath") && w.Fields["System.AreaPath"].ToString().ToLower().Equals(ap.ToLower()))) | ||
| { | ||
| continue; | ||
| } | ||
| else if (context.TargetAreaAndIterationTree.AreaPathList.Any(a => a.ToLower() == areaPathInTarget.ToLower())) | ||
| { | ||
| Logger.LogInformation(LogDestination.All, $"[Exists] {areaPathInTarget}."); | ||
| } | ||
| else | ||
| { | ||
| modificationCount += 1; | ||
| await CreateAreaPath(areaPathInTarget); | ||
| Logger.LogSuccess(LogDestination.All, $"[Created] {areaPathInTarget}."); | ||
| } | ||
| } | ||
|
|
||
| Logger.LogInformation(LogDestination.All, $"Area paths synchronized."); | ||
| return modificationCount; | ||
| } | ||
|
|
||
| public async virtual Task CreateAreaPath(string areaPathInTarget) | ||
| { | ||
| await WorkItemTrackingHelpers.CreateAreaPathAsync(context.TargetClient.WorkItemTrackingHttpClient, context.Config.TargetConnection.Project, areaPathInTarget); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using System.Collections.Generic; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Diagnostics; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
|
|
@@ -25,6 +26,7 @@ public abstract class BaseWorkItemsProcessor : IPhase1Processor | |
|
|
||
| public abstract BaseWitBatchRequestGenerator GetWitBatchRequestGenerator(IMigrationContext context, IBatchMigrationContext batchContext); | ||
|
|
||
|
|
||
|
||
| public async Task Process(IMigrationContext context) | ||
| { | ||
| var workItemsAndStateToMigrate = this.GetWorkItemsAndStateToMigrate(context); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using System; | ||
| using System.Linq; | ||
|
||
| using System.Threading.Tasks; | ||
| using Logging; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd default this to false