Skip to content

Commit

Permalink
Fix for null exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHinsh committed Mar 19, 2024
1 parent 88692cc commit b1399da
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 11 deletions.
13 changes: 8 additions & 5 deletions configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"Project": "migrationSource1",
"ReflectedWorkItemIDFieldName": "nkdScrum.ReflectedWorkItemId",
"AllowCrossProjectLinking": false,
"AuthenticationMode": "Prompt",
"AuthenticationMode": "AccessToken",
"PersonalAccessToken": "",
"PersonalAccessTokenVariableName": "",
"LanguageMaps": {
Expand All @@ -20,8 +20,8 @@
"Project": "migrationTest5",
"ReflectedWorkItemIDFieldName": "nkdScrum.ReflectedWorkItemId",
"AllowCrossProjectLinking": false,
"AuthenticationMode": "Prompt",
"PersonalAccessToken": "njp3kcec4nbev63fmbepvdpn35drawmonk5qf5yqsw77dgfwnjda",
"AuthenticationMode": "AccessToken",
"PersonalAccessToken": "",
"PersonalAccessTokenVariableName": "",
"LanguageMaps": {
"AreaPath": "Area",
Expand All @@ -34,12 +34,15 @@
"CommonEnrichersConfig": [
{
"$type": "TfsNodeStructureOptions",
"Enabled": false,
"NodeBasePaths": [],
"AreaMaps": {
"^migrationSource1([\\\\]?.*)$": "MigrationTest5$1",
"^nkdProducts([\\\\]?.*)$": "MigrationTest5$1",
"^Skypoint Cloud$": "MigrationTest5"
},
"IterationMaps": {
"^migrationSource1([\\\\]?.*)$": "MigrationTest5$1",
"^nkdProducts([\\\\]?.*)$": "MigrationTest5$1",
"^Skypoint Cloud\\\\Sprint 1$": "MigrationTest5\\Sprint 1"
},
Expand Down Expand Up @@ -98,7 +101,7 @@
"Enabled": true,
"UpdateCreatedDate": true,
"UpdateCreatedBy": true,
"WIQLQuery": "SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = @TeamProject AND [System.WorkItemType] NOT IN ('Program', 'Portfolio', 'Test Suite', 'Test Plan','Shared Steps','Shared Parameter','Feedback Request') ORDER BY [System.ChangedDate] desc",
"WIQLQuery": "SELECT [System.Id] FROM WorkItems WHERE [System.Id] =137 AND [System.TeamProject] = @TeamProject AND [System.WorkItemType] NOT IN ('Program', 'Portfolio', 'Test Suite', 'Test Plan','Shared Steps','Shared Parameter','Feedback Request') ORDER BY [System.ChangedDate] desc",
"LinkMigration": true,
"FixHtmlAttachmentLinks": false,
"SkipToFinalRevisedWorkItemType": false,
Expand All @@ -123,7 +126,7 @@
"Version": "15.0",
"workaroundForQuerySOAPBugEnabled": false,
"WorkItemTypeDefinition": {
"sourceWorkItemTypeName": "targetWorkItemTypeName"
"User Story": "Product Backlog Item"
},
"Endpoints": {
"InMemoryWorkItemEndpoints": [
Expand Down
25 changes: 25 additions & 0 deletions src/MigrationTools/ConfigException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Runtime.Serialization;

namespace MigrationTools
{
[Serializable]
internal class ConfigException : Exception
{
public ConfigException()
{
}

public ConfigException(string message) : base(message)
{
}

public ConfigException(string message, Exception innerException) : base(message, innerException)
{
}

protected ConfigException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Runtime.Serialization;

namespace VstsSyncMigrator.Engine
{
[Serializable]
internal class ConfigException : Exception
{
public ConfigException()
{
}

public ConfigException(string message) : base(message)
{
}

public ConfigException(string message, Exception innerException) : base(message, innerException)
{
}

protected ConfigException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,14 @@ protected override void InternalExecute()
embededImagesEnricher = Services.GetRequiredService<TfsEmbededImagesEnricher>();
gitRepositoryEnricher = Services.GetRequiredService<TfsGitRepositoryEnricher>();


_nodeStructureEnricher.ProcessorExecutionBegin(null);
if (_nodeStructureEnricher.Options.Enabled)
{
_nodeStructureEnricher.ProcessorExecutionBegin(null);
} else
{
Log.LogWarning("WorkItemMigrationContext::InternalExecute: nodeStructureEnricher is disabled! This may cause work item migration errors! ");
}


var stopwatch = Stopwatch.StartNew();
_itemsInError = new List<string>();
Expand Down Expand Up @@ -284,11 +290,21 @@ private void ValidateAllUsersExistOrAreMapped(List<WorkItemData> sourceWorkItems
private void ValidateAllNodesExistOrAreMapped(List<WorkItemData> sourceWorkItems)
{
contextLog.Information("Validating::Check that all Area & Iteration paths from Source have a valid mapping on Target");
List<NodeStructureItem> nodeStructureMissingItems = _nodeStructureEnricher.GetMissingRevisionNodes(sourceWorkItems);
if (_nodeStructureEnricher.ValidateTargetNodesExist(nodeStructureMissingItems))
if (!_nodeStructureEnricher.Options.Enabled && Engine.Target.Config.AsTeamProjectConfig().Project != Engine.Source.Config.AsTeamProjectConfig().Project)
{
throw new Exception("Missing Iterations in Target preventing progress, check log for list. To continue you MUST configure IterationMaps or AreaMaps that matches the missing paths..");
throw new ConfigException("Source and Target projects have different names, but NodeStructureEnricher is not enabled. Cant continue... please enable nodeStructureEnricher in the config and restart.");
}
if ( _nodeStructureEnricher.Options.Enabled)
{
List<NodeStructureItem> nodeStructureMissingItems = _nodeStructureEnricher.GetMissingRevisionNodes(sourceWorkItems);
if (_nodeStructureEnricher.ValidateTargetNodesExist(nodeStructureMissingItems))
{
throw new Exception("Missing Iterations in Target preventing progress, check log for list. To continue you MUST configure IterationMaps or AreaMaps that matches the missing paths..");
}
} else
{
contextLog.Error("nodeStructureEnricher is disabled! Please enable it in the config.");
}
}

private void ValidateAllWorkItemTypesHaveReflectedWorkItemIdField(List<WorkItemData> sourceWorkItems)
Expand Down Expand Up @@ -477,9 +493,14 @@ private void PopulateWorkItem(WorkItemData oldWorkItemData, WorkItemData newWork

if (_nodeStructureEnricher.Options.Enabled)
{

newWorkItem.AreaPath = _nodeStructureEnricher.GetNewNodeName(oldWorkItem.AreaPath, TfsNodeStructureType.Area);
newWorkItem.IterationPath = _nodeStructureEnricher.GetNewNodeName(oldWorkItem.IterationPath, TfsNodeStructureType.Iteration);
}
else
{
Log.LogWarning("WorkItemMigrationContext::PopulateWorkItem::nodeStructureEnricher::Disabled! This needs to be set to true!");
}

switch (destType)
{
Expand Down Expand Up @@ -544,7 +565,7 @@ private async Task ProcessWorkItemAsync(WorkItemData sourceWorkItem, int retryLi
{ "sourceWorkItemRev", sourceWorkItem.Rev },
{ "ReplayRevisions", _revisionManager.Options.ReplayRevisions }}
);
List<RevisionItem> revisionsToMigrate = _revisionManager.GetRevisionsToMigrate(sourceWorkItem.Revisions.Values.ToList(), targetWorkItem.Revisions.Values.ToList());
List<RevisionItem> revisionsToMigrate = _revisionManager.GetRevisionsToMigrate(sourceWorkItem.Revisions.Values.ToList(), targetWorkItem?.Revisions.Values.ToList());
if (targetWorkItem == null)
{
targetWorkItem = ReplayRevisions(revisionsToMigrate, sourceWorkItem, null);
Expand Down

0 comments on commit b1399da

Please sign in to comment.