From 60ce2b381196986e2e1509a176a5b9a3f27ea16d Mon Sep 17 00:00:00 2001 From: Alexander Hjelm Date: Tue, 3 Oct 2023 22:01:23 +0200 Subject: [PATCH] Correct revision time for revisions with only one removed link --- src/WorkItemMigrator/JiraExport/JiraMapper.cs | 23 ++++++++++++++++++- .../RevisionUtils/LinkMapperUtils.cs | 2 +- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/WorkItemMigrator/JiraExport/JiraMapper.cs b/src/WorkItemMigrator/JiraExport/JiraMapper.cs index 901d469f..f38b1556 100644 --- a/src/WorkItemMigrator/JiraExport/JiraMapper.cs +++ b/src/WorkItemMigrator/JiraExport/JiraMapper.cs @@ -338,11 +338,13 @@ internal WiRevision MapRevision(JiraRevision r) List 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, @@ -361,6 +363,25 @@ protected override string MapUser(string sourceUser) return base.MapUser(email); } + protected DateTime CorrectTime(JiraRevision r, List attachments, List fields, List 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 InitializeTypeMappings() { HashSet types = new HashSet(); diff --git a/src/WorkItemMigrator/JiraExport/RevisionUtils/LinkMapperUtils.cs b/src/WorkItemMigrator/JiraExport/RevisionUtils/LinkMapperUtils.cs index 1ef9521a..9bb4894a 100644 --- a/src/WorkItemMigrator/JiraExport/RevisionUtils/LinkMapperUtils.cs +++ b/src/WorkItemMigrator/JiraExport/RevisionUtils/LinkMapperUtils.cs @@ -89,7 +89,7 @@ public static void AddRemoveSingleLink(JiraRevision r, List links, strin Change = changeType, SourceOriginId = r.ParentItem.Key, TargetOriginId = linkedItemKey, - WiType = linkType, + WiType = linkType }; links.Add(link);