Skip to content

Commit

Permalink
Correct revision time for revisions with only one removed link
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Hjelm committed Oct 3, 2023
1 parent 735e7b1 commit 60ce2b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/WorkItemMigrator/JiraExport/JiraMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,13 @@ internal WiRevision MapRevision(JiraRevision r)
List<WiLink> links = MapLinks(r);
var commit = MapCommit(r);

DateTime rTime = CorrectTime(r, attachments, fields, links);

return new WiRevision()
{
ParentOriginId = r.ParentItem.Key,
Index = r.Index,
Time = r.Time,
Time = rTime,
Author = MapUser(r.Author),
Attachments = attachments,
Fields = fields,
Expand All @@ -361,6 +363,25 @@ protected override string MapUser(string sourceUser)
return base.MapUser(email);
}

protected DateTime CorrectTime(JiraRevision r, List<WiAttachment> attachments, List<WiField> fields, List<WiLink> links)
{
var rTime = r.Time;

// If the only change is to remove a link, remove 1 second to ensure that Link Removals happen before
// the corresponding Link Additions, since this can be a problem in the raw jira data
if (
fields.Count == 0
&& attachments.Count == 0
&& links.Count == 1
&& links[0].Change == ReferenceChangeType.Removed
)
{
rTime = rTime.AddSeconds(-1);
}

return rTime;
}

private HashSet<string> InitializeTypeMappings()
{
HashSet<string> types = new HashSet<string>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,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 60ce2b3

Please sign in to comment.