Skip to content

Commit

Permalink
Fix error on Embeded Link for Work item that does not exist. (#2278)
Browse files Browse the repository at this point in the history
♻️ (MigrationTools): refactor GetWorkItem method to include stopOnError
parameter

The GetWorkItem method now includes an optional stopOnError parameter,
which defaults to true. This change allows for more flexible error
handling by enabling the caller to decide whether the application should
exit on error or continue execution. This is particularly useful for
scenarios where non-critical errors should not halt the entire migration
process. Additionally, updated the corresponding tests and interfaces to
accommodate this new parameter.
  • Loading branch information
MrHinsh authored Aug 12, 2024
2 parents e3c4db3 + 3d6545d commit 268f5e9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
20 changes: 10 additions & 10 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 @@ -91,7 +91,7 @@ public override int Enrich(WorkItemData sourceWorkItem, WorkItemData targetWorkI
{
var workItemId = workItemLinkMatch.Groups["id"].Value;
Log.LogDebug("{LogTypeName}: Source work item {workItemId} mention link traced on field {fieldName} on target work item {targetWorkItemId}.", LogTypeName, workItemId, field.Name, targetWorkItem.Id);
var sourceLinkWi = Engine.Source.WorkItems.GetWorkItem(workItemId);
var sourceLinkWi = Engine.Source.WorkItems.GetWorkItem(workItemId, false);
if (sourceLinkWi != null)
{
var linkWI = Engine.Target.WorkItems.FindReflectedWorkItemByReflectedWorkItemId(sourceLinkWi);
Expand All @@ -113,7 +113,9 @@ public override int Enrich(WorkItemData sourceWorkItem, WorkItemData targetWorkI
}
else
{
Log.LogInformation("{LogTypeName}: [SKIP] Source work item {workItemId} mention link on field {fieldName} on target work item {targetWorkItemId} was not found on the source collection.", LogTypeName, workItemId, field.Name, targetWorkItem.Id);
var replaceValue = value;
field.Value = field.Value.ToString().Replace(anchorTagMatch.Value, replaceValue);
Log.LogInformation("{LogTypeName}: [SKIP] Source work item {workItemId} mention link on field {fieldName} was not found on the source collection.", LogTypeName, workItemId, field.Name, targetWorkItem.Id);
}
}
else if ((href.StartsWith("mailto:") || href.StartsWith("#")) && value.StartsWith("@"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ public override WorkItemData GetRevision(WorkItemData workItem, int revision)
throw new NotImplementedException("GetRevision in combination with WorkItemData is buggy");
}

public override WorkItemData GetWorkItem(string id)
public override WorkItemData GetWorkItem(string id, bool stopOnError = true)
{
return GetWorkItem(int.Parse(id));
return GetWorkItem(int.Parse(id), stopOnError);
}

public override WorkItemData GetWorkItem(int id)
public override WorkItemData GetWorkItem(int id, bool stopOnError = true)
{
if (id == 0)
{
Expand Down Expand Up @@ -175,7 +175,10 @@ public override WorkItemData GetWorkItem(int id)
{ "Time",timer.ElapsedMilliseconds }
});
Log.Error(ex, "Unable to GetWorkItem with id[{id}]", id);
Environment.Exit(-1);
if (stopOnError)
{
Environment.Exit(-1);
}
} finally
{
timer.Stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public ProjectData GetProject()
throw new System.NotImplementedException();
}

public WorkItemData GetWorkItem(string id)
public WorkItemData GetWorkItem(string id, bool stopOnError = true)
{
throw new System.NotImplementedException();
}
Expand All @@ -127,7 +127,7 @@ public List<WorkItemData> FilterWorkItemsThatAlreadyExist(List<WorkItemData> sou
throw new System.NotImplementedException();
}

public WorkItemData GetWorkItem(int id)
public WorkItemData GetWorkItem(int id, bool stopOnError = true)
{
throw new System.NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public interface IWorkItemMigrationClient

List<WorkItemData> GetWorkItems();

WorkItemData GetWorkItem(string id);
WorkItemData GetWorkItem(string id, bool stopOnError = true);

WorkItemData GetWorkItem(int id);
WorkItemData GetWorkItem(int id, bool stopOnError = true);

List<int> GetWorkItemIds(string WIQLQuery);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using MigrationTools._EngineV1.Configuration;
using MigrationTools._EngineV1.DataContracts;
Expand Down Expand Up @@ -44,9 +44,9 @@ public void Configure(IMigrationClient migrationClient, bool bypassRules = true)

public abstract WorkItemData GetRevision(WorkItemData workItem, int revision);

public abstract WorkItemData GetWorkItem(string id);
public abstract WorkItemData GetWorkItem(string id, bool stopOnError = true);

public abstract WorkItemData GetWorkItem(int id);
public abstract WorkItemData GetWorkItem(int id, bool stopOnError = true);

public abstract List<WorkItemData> GetWorkItems();

Expand Down

0 comments on commit 268f5e9

Please sign in to comment.