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

Fix error where Epic Child links would not get deleted properly #871

Merged
merged 5 commits into from
Oct 9, 2023
Merged
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
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
Loading