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

Add support for the new Parent field #926

Merged
merged 1 commit into from
Dec 6, 2023
Merged
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
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
Loading