Skip to content

Commit 2c5de98

Browse files
jivkokoKostadinov Zhivko (BD PDL-BG1)
andauthored
Bugfix for exceptions when migrating revisions with changed type and the configuration is set to "SkipToFinalRevisedWorkItemType": true. Removed usage of "SkipToFinalRevisedWorkItemType" confuguration. Check for Work Item ID > 0 before updating added. (#1756 ) (#1761)
Co-authored-by: Kostadinov Zhivko (BD PDL-BG1) <[email protected]>
1 parent fe76296 commit 2c5de98

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ private WorkItemData ReplayRevisions(List<RevisionItem> revisionsToMigrate, Work
649649
//If work item hasn't been created yet, create a shell
650650
if (targetWorkItem == null)
651651
{
652-
var skipToFinalRevisedWorkItemType = _config.SkipToFinalRevisedWorkItemType;
653652
var finalDestType = revisionsToMigrate.Last().Type;
654653
var targetType = revisionsToMigrate.First().Type;
655654

@@ -658,16 +657,11 @@ private WorkItemData ReplayRevisions(List<RevisionItem> revisionsToMigrate, Work
658657
TraceWriteLine(LogEventLevel.Information, $"WorkItem has changed type at one of the revisions, from {targetType} to {finalDestType}");
659658
}
660659

661-
if (skipToFinalRevisedWorkItemType)
662-
{
663-
targetType = finalDestType;
664-
}
665-
666660
if (Engine.TypeDefinitionMaps.Items.ContainsKey(targetType))
667661
{
668662
targetType = Engine.TypeDefinitionMaps.Items[targetType].Map();
669663
}
670-
targetWorkItem = CreateWorkItem_Shell(Engine.Target.WorkItems.Project, sourceWorkItem, skipToFinalRevisedWorkItemType ? finalDestType : targetType);
664+
targetWorkItem = CreateWorkItem_Shell(Engine.Target.WorkItems.Project, sourceWorkItem, targetType);
671665
}
672666

673667
if (_config.AttachRevisionHistory)
@@ -691,16 +685,18 @@ private WorkItemData ReplayRevisions(List<RevisionItem> revisionsToMigrate, Work
691685
destType = Engine.TypeDefinitionMaps.Items[destType].Map();
692686
}
693687
bool typeChange = (destType != targetWorkItem.Type);
694-
695-
if (typeChange)
688+
689+
int workItemId = Int32.Parse(targetWorkItem.Id);
690+
691+
if (typeChange && workItemId > 0)
696692
{
697693
ValidatePatTokenRequirement();
698694
Uri collectionUri = Engine.Target.Config.AsTeamProjectConfig().Collection;
699695
string token = Engine.Target.Config.AsTeamProjectConfig().PersonalAccessToken;
700696
VssConnection connection = new VssConnection(collectionUri, new VssBasicCredential(string.Empty, token));
701697
WorkItemTrackingHttpClient workItemTrackingClient = connection.GetClient<WorkItemTrackingHttpClient>();
702698
JsonPatchDocument patchDocument = new JsonPatchDocument();
703-
DateTime changedDate = ((DateTime) currentRevisionWorkItem.Fields["System.ChangedDate"].Value).AddMilliseconds(-3);
699+
DateTime changedDate = ((DateTime)currentRevisionWorkItem.Fields["System.ChangedDate"].Value).AddMilliseconds(-3);
704700

705701
patchDocument.Add(
706702
new JsonPatchOperation()
@@ -734,9 +730,16 @@ private WorkItemData ReplayRevisions(List<RevisionItem> revisionsToMigrate, Work
734730
Value = changedDate
735731
}
736732
);
737-
int id = Int32.Parse(targetWorkItem.Id);
738-
var result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, id, bypassRules:true).Result;
739-
targetWorkItem = Engine.Target.WorkItems.GetWorkItem(id);
733+
patchDocument.Add(
734+
new JsonPatchOperation()
735+
{
736+
Operation = Operation.Add,
737+
Path = "/fields/System.ChangedBy",
738+
Value = currentRevisionWorkItem.Fields["System.ChangedBy"].Value.ToString()
739+
}
740+
);
741+
var result = workItemTrackingClient.UpdateWorkItemAsync(patchDocument, workItemId, bypassRules: true).Result;
742+
targetWorkItem = Engine.Target.WorkItems.GetWorkItem(workItemId);
740743
}
741744
PopulateWorkItem(currentRevisionWorkItem, targetWorkItem, destType);
742745

@@ -748,7 +751,8 @@ private WorkItemData ReplayRevisions(List<RevisionItem> revisionsToMigrate, Work
748751
if (f.AllowedValues.Count > 0)
749752
{
750753
targetWorkItem.ToWorkItem().Fields[f.Name].Value = f.AllowedValues[0];
751-
} else if (f.FieldDefinition.AllowedValues.Count > 0)
754+
}
755+
else if (f.FieldDefinition.AllowedValues.Count > 0)
752756
{
753757
targetWorkItem.ToWorkItem().Fields[f.Name].Value = f.FieldDefinition.AllowedValues[0];
754758
}

0 commit comments

Comments
 (0)