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 images in custom rendered fields #918

Merged
merged 1 commit into from
Nov 28, 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
28 changes: 28 additions & 0 deletions src/WorkItemMigrator/WorkItemImport/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,34 @@ public bool ImportRevision(WiRevision rev, WorkItem wi, Settings settings)
{
Logger.Log(ex, $"Failed to correct description for '{wi.Id}', rev '{rev}'.");
}

// Correct other HTMl fields than description
foreach (var field in settings.FieldMap.Fields)
{
if (
field.Mapper == "MapRendered"
&& (field.For == "All" || field.For.Split(',').Contains(wi.Fields[WiFieldReference.WorkItemType]))
&& (field.NotFor == null || !field.NotFor.Split(',').Contains(wi.Fields[WiFieldReference.WorkItemType]))
&& wi.Fields.ContainsKey(field.Target)
&& field.Target != WiFieldReference.Description
)
{
try
{
_witClientUtils.CorrectRenderedField(
wi,
_context.GetItem(rev.ParentOriginId),
rev,
field.Target,
_context.Journal.IsAttachmentMigrated
);
}
catch (Exception ex)
{
Logger.Log(ex, $"Failed to correct description for '{wi.Id}', rev '{rev}'.");
}
}
}
}

// rev with a commit won't have meaningful information, skip saving fields
Expand Down
3 changes: 2 additions & 1 deletion src/WorkItemMigrator/WorkItemImport/ImportCommandLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ private bool ExecuteMigration(CommandOption token, CommandOption url, CommandOpt
IgnoreFailedLinks = config.IgnoreFailedLinks,
ProcessTemplate = config.ProcessTemplate,
IncludeLinkComments = config.IncludeLinkComments,
IncludeCommits = config.IncludeCommits
IncludeCommits = config.IncludeCommits,
FieldMap = config.FieldMap
};

// initialize Azure DevOps/TFS connection. Creates/fetches project, fills area and iteration caches.
Expand Down
5 changes: 4 additions & 1 deletion src/WorkItemMigrator/WorkItemImport/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace WorkItemImport
using Migration.Common.Config;

namespace WorkItemImport
{
public class Settings
{
Expand All @@ -18,5 +20,6 @@ public Settings(string account, string project, string pat)
public string ProcessTemplate { get; internal set; }
public bool IncludeLinkComments { get; internal set; }
public bool IncludeCommits { get; internal set; }
public FieldMap FieldMap { get; internal set; }
}
}
33 changes: 33 additions & 0 deletions src/WorkItemMigrator/WorkItemImport/WitClient/WitClientUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,39 @@ public bool CorrectDescription(WorkItem wi, WiItem wiItem, WiRevision rev, IsAtt
return descUpdated;
}

public bool CorrectRenderedField(WorkItem wi, WiItem wiItem, WiRevision rev, string fieldRef, IsAttachmentMigratedDelegate<string, string, bool> isAttachmentMigratedDelegate)
{
if (wi == null)
{
throw new ArgumentException(nameof(wi));
}

if (wiItem == null)
{
throw new ArgumentException(nameof(wiItem));
}

if (rev == null)
{
throw new ArgumentException(nameof(rev));
}

string fieldValue = wi.Fields[fieldRef].ToString();
if (string.IsNullOrWhiteSpace(fieldValue))
return false;

bool updated = false;

CorrectImagePath(wi, wiItem, rev, ref fieldValue, ref updated, isAttachmentMigratedDelegate);

if (updated)
{
wi.Fields[fieldRef] = fieldValue;
}

return updated;
}

public bool CorrectAcceptanceCriteria(WorkItem wi, WiItem wiItem, WiRevision rev, IsAttachmentMigratedDelegate<string, string, bool> isAttachmentMigratedDelegate)
{
if (wi == null)
Expand Down
Loading