Skip to content

Commit

Permalink
Merge pull request #871 from solidify/bugfix/duplicate-epic-child-links
Browse files Browse the repository at this point in the history
Fix error where Epic Child links would not get deleted properly
  • Loading branch information
Alexander-Hjelm authored Oct 9, 2023
2 parents 3eef434 + 4f4489f commit e40f162
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
67 changes: 64 additions & 3 deletions src/WorkItemMigrator/JiraExport/JiraCommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ private bool ExecuteMigration(CommandOption user, CommandOption password, Comman

var issues = jiraProvider.EnumerateIssues(jiraSettings.JQL, skips, downloadOptions);

var createdWorkItems = new List<WiItem>();

foreach (var issue in issues)
{
if (issue == null)
Expand All @@ -130,11 +132,18 @@ private bool ExecuteMigration(CommandOption user, CommandOption password, Comman
WiItem wiItem = mapper.Map(issue);
if (wiItem != null)
{
localProvider.Save(wiItem);
exportedItemsCount++;
Logger.Log(LogLevel.Debug, $"Exported as type '{wiItem.Type}'.");
createdWorkItems.Add(wiItem);
}
}

FixRevisionDates(createdWorkItems);

foreach (var wiItem in createdWorkItems)
{
localProvider.Save(wiItem);
exportedItemsCount++;
Logger.Log(LogLevel.Debug, $"Exported as type '{wiItem.Type}'.");
}
}
catch (CommandParsingException e)
{
Expand All @@ -153,6 +162,58 @@ private bool ExecuteMigration(CommandOption user, CommandOption password, Comman
return succeeded;
}

private static void FixRevisionDates(List<WiItem> createdWorkItems)
{
var revisionsWithLinkChanges = new List<WiRevision>();
foreach (var wiItem in createdWorkItems)
{
revisionsWithLinkChanges.AddRange(wiItem.Revisions.Where(r => r.Links != null && r.Links.Count != 0));
}
bool anyRevisionTimeUpdated = true;
while (anyRevisionTimeUpdated)
{
anyRevisionTimeUpdated = false;
foreach (var rev1 in revisionsWithLinkChanges)
{
var rev1LinkSourceWiIds = rev1.Links.Select(l => l.SourceOriginId).ToList();
var revsWithOppositeLink = revisionsWithLinkChanges.Where(
r => r.Links.Any(l => rev1LinkSourceWiIds.Contains(l.TargetOriginId))
);
foreach (var rev2 in revsWithOppositeLink)
{
if (rev2 != rev1)
{
foreach (var link1 in rev1.Links)
{
foreach (var link2 in rev2.Links)
{
if (link1.SourceOriginId == link2.TargetOriginId || link1.TargetOriginId == link2.SourceOriginId)
{
if (link1.Change == ReferenceChangeType.Added && link2.Change == ReferenceChangeType.Removed
&& rev1.Time < rev2.Time && Math.Abs((rev1.Time - rev2.Time).TotalSeconds) < 2
&& link1.WiType == "System.LinkTypes.Hierarchy-Forward" && link2.WiType == "System.LinkTypes.Hierarchy-Reverse")
{
// rev1 should be moved back by 1 second
rev2.Time = rev2.Time.AddSeconds(-1);
anyRevisionTimeUpdated = true;
}
else if (link1.Change == ReferenceChangeType.Removed && link2.Change == ReferenceChangeType.Added
&& rev1.Time > rev2.Time && Math.Abs((rev1.Time - rev2.Time).TotalSeconds) < 2
&& link1.WiType == "System.LinkTypes.Hierarchy-Reverse" && link2.WiType == "System.LinkTypes.Hierarchy-Forward")
{
// rev2 should be moved back by 1 second
rev1.Time = rev1.Time.AddSeconds(-1);
anyRevisionTimeUpdated = true;
}
}
}
}
}
}
}
}
}

private static void InitSession(ConfigJson config, string continueOnCritical)
{
Logger.Init("jira-export", config.Workspace, config.LogLevel, continueOnCritical);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static void AddRemoveSingleLink(JiraRevision r, List<WiLink> links, strin
Change = changeType,
SourceOriginId = r.ParentItem.Key,
TargetOriginId = linkedItemKey,
WiType = linkType,
WiType = linkType
};

links.Add(link);
Expand Down

0 comments on commit e40f162

Please sign in to comment.