Skip to content
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

update iteration-path if different from source #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Common/Config/ConfigJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public class ConfigJson
[DefaultValue(false)]
public bool SkipWorkItemsWithMissingAreaPath { get; set; }

[JsonProperty(PropertyName = "update-work-items-with-different-iteration-path", DefaultValueHandling = DefaultValueHandling.Populate)]
[DefaultValue(false)]
public bool UpdateWorkItemsWithDifferentIterationPath { get; set; }

[JsonProperty(PropertyName = "skip-work-items-with-missing-iteration-path", DefaultValueHandling = DefaultValueHandling.Populate)]
[DefaultValue(false)]
public bool SkipWorkItemsWithMissingIterationPath { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Common.Config;
using Logging;
using Microsoft.Extensions.Logging;
using System;

namespace Common.Migration
{
Expand Down Expand Up @@ -30,6 +31,11 @@ public override void PrepareBatchContext(IBatchMigrationContext batchContext, IL
var workItemMigrationState = workItemsAndStateToMigrate.Where(w => w.SourceId == sourceWorkItem.Id.Value).FirstOrDefault();
if (workItemMigrationState != null && workItemMigrationState.TargetId.HasValue)
{
if(batchContext.WorkItemMigrationState
.Where(a => a.SourceId == sourceWorkItem.Id && a.Requirement.HasFlag(WorkItemMigrationState.RequirementForExisting.UpdateChangedDate)).Count() == 1) {
Logger.LogInformation($"Updating ChangedDate on work item with source id {sourceWorkItem.Id}");
sourceWorkItem.Fields["System.ChangedDate"] = DateTime.Now;
}
batchContext.TargetIdToSourceWorkItemMapping.Add(workItemMigrationState.TargetId.Value, sourceWorkItem);
}
else
Expand Down
1 change: 1 addition & 0 deletions Common/Validation/IValidationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public interface IValidationContext : IContext
ISet<string> RequestedFields { get; }

ConcurrentDictionary<int, int> SourceWorkItemRevision { get; set; }
ConcurrentDictionary<int, string> SourceWorkItemIterationPath { get; set; }

ConcurrentDictionary<string, WorkItemField> SourceFields { get; set; }

Expand Down
13 changes: 10 additions & 3 deletions Common/Validation/Target/ValidateTargetWorkItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,16 @@ private void ProcessUpdatedSourceWorkItem(WorkItem targetWorkItem, WorkItemMigra
else if (IsPhase2UpdateRequired(workItemMigrationState, targetWorkItem))
{
workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.UpdatePhase2;
}
else
{
} else if (ValidationContext.Config.UpdateWorkItemsWithDifferentIterationPath == true &&
!ValidationContext.SourceWorkItemIterationPath[(int)sourceId].Equals(targetWorkItem.Fields["System.IterationPath"])
) {
workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.None;
this.sourceWorkItemIdsThatHaveBeenUpdated.Add(sourceId);
workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.UpdatePhase1;
workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.UpdatePhase2;
workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.UpdateChangedDate;
Logger.LogInformation($"Work item with id {workItemMigrationState.SourceId} has different iteration path than target. Will update target (id {targetWorkItem.Id})");
} else {
workItemMigrationState.Requirement |= WorkItemMigrationState.RequirementForExisting.None;
}
}
Expand Down
4 changes: 3 additions & 1 deletion Common/Validation/ValidationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ public class ValidationContext : BaseContext, IValidationContext

public ConcurrentDictionary<int, int> SourceWorkItemRevision { get; set; } = new ConcurrentDictionary<int, int>();

public ConcurrentDictionary<string, WorkItemField> SourceFields { get; set; } = new ConcurrentDictionary<string, WorkItemField>(StringComparer.OrdinalIgnoreCase);
public ConcurrentDictionary<int, String> SourceWorkItemIterationPath { get; set; } = new ConcurrentDictionary<int, string>();

public ConcurrentDictionary<string, WorkItemField> SourceFields { get; set; } = new ConcurrentDictionary<string, WorkItemField>(StringComparer.OrdinalIgnoreCase);

public ConcurrentDictionary<string, WorkItemField> TargetFields { get; set; } = new ConcurrentDictionary<string, WorkItemField>(StringComparer.OrdinalIgnoreCase);

public ConcurrentDictionary<string, ISet<string>> SourceTypesAndFields { get; } = new ConcurrentDictionary<string, ISet<string>>(StringComparer.OrdinalIgnoreCase);
Expand Down
3 changes: 3 additions & 0 deletions Common/Validation/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ await context.WorkItemIdsUris.Keys.Batch(Constants.BatchSize).ForEachAsync(conte
foreach (var workItem in workItems)
{
await validator.Validate(context, workItem);

// Track iteration paths for sourcework items
context.SourceWorkItemIterationPath[(int)workItem.Id] = workItem.Fields["System.IterationPath"].ToString();
}
}

Expand Down
2 changes: 1 addition & 1 deletion Common/WorkItemMigrationState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class WorkItemMigrationState
public enum State { Create, Existing, Error }

[Flags]
public enum RequirementForExisting { None, UpdatePhase1, UpdatePhase2 }
public enum RequirementForExisting { None, UpdatePhase1, UpdatePhase2, UpdateChangedDate=4 }
[Flags]
public enum MigrationCompletionStatus { None, Phase1, Phase2, Phase3 }
public RevAndPhaseStatus RevAndPhaseStatus { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions WiMigrator/migration-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

#### ```skip-work-items-with-missing-iteration-path``` when true, will skip the work item if the iteration path does not exist in the target account when false, will migrate the work item and set the iteration path to the project name when the iteration path does not exist on the target account.

#### ```update-work-items-with-different-iteration-path``` when true, will update the iteration-path on the target work item if it's different than the source

#### ```default-area-path``` when the area path doesn't exist on the target project, the migrator will use this area path instead of defaulting to the root. note: if skip-work-items-with-missing-area-path is true, this setting is ignored.

#### ```default-iteration-path``` when the iteration path doesn't exist on the target project, the migrator will use this iteration path instead of defaulting to the root. note: if skip-work-items-with-missing-iteration-path is true, this setting is ignored.
Expand Down
1 change: 1 addition & 0 deletions WiMigrator/sample-configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"target-post-move-tag": "6F078B6C-2A96-453B-A7C3-EACE6E63BB97",
"skip-work-items-with-type-missing-fields": false,
"skip-work-items-with-missing-area-path": false,
"update-work-items-with-different-iteration-path": false,
"skip-work-items-with-missing-iteration-path": false,
"default-area-path": "contoso-project\\missing area path",
"default-iteration-path": "contoso-project\\missing iteration path",
Expand Down