Skip to content

Commit

Permalink
Add support for the new Parent field
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Hjelm committed Dec 5, 2023
1 parent 5fd3941 commit 105cdcd
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/WorkItemMigrator/JiraExport/RevisionUtils/LinkMapperUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,20 @@ public static void AddRemoveSingleLink(JiraRevision r, List<WiLink> links, strin

if (r.Fields.TryGetValue(field, out object value))
{
value = NumericCheckOnLinkTypeField(r, field, value);

var changeType = value == null ? ReferenceChangeType.Removed : ReferenceChangeType.Added;
var linkType = (from t in config.LinkMap.Links where t.Source == type select t.Target).FirstOrDefault();

// regardless if action is add or remove, as there can be only one, we remove previous epic link if it exists
if (r.Index != 0)
{
var prevLinkValue = r.ParentItem.Revisions[r.Index - 1].GetFieldValue(field);
var prevLinkValueUnchecked = NumericCheckOnLinkTypeField(r, field, prevLinkValue);
if(prevLinkValueUnchecked != null)
{
prevLinkValue = prevLinkValueUnchecked.ToString();
}
// if previous value is not null, add removal of previous link
if (!string.IsNullOrWhiteSpace(prevLinkValue))
{
Expand Down Expand Up @@ -94,6 +101,24 @@ public static void AddRemoveSingleLink(JiraRevision r, List<WiLink> links, strin
}
}

private static object NumericCheckOnLinkTypeField(JiraRevision r, string field, object value)
{
// 2023-12-05: For later versions pf Jira cloud, the parent link/epic link fields have been replaced by a single
// field named "Parent". This is represented by the ParentItem field and r.field["parent"] instead holds the numeric ID.
// Here we ensure that what we get is the issue key

if (value != null)
{
bool isNumeric = int.TryParse(value.ToString(), out int n);
if (isNumeric && field == "parent" && r.ParentItem != null && r.ParentItem.Parent != null)
{
value = r.ParentItem.Parent;
}
}

return value;
}

public static void AddSingleLink(JiraRevision r, List<WiLink> links, string field, string type, ConfigJson config)
{
if (String.IsNullOrWhiteSpace(field))
Expand Down

0 comments on commit 105cdcd

Please sign in to comment.