Coder Social home page Coder Social logo

Comments (11)

Alexander-Hjelm avatar Alexander-Hjelm commented on June 19, 2024

However the tool seems to ignore the mappings (or at least I am not able to find the error) and I can see following entries in the log:
[I][15:13:38] Connecting to Jira...
[I][15:13:38] Retrieving Jira fields...
[I][15:13:38] Retrieving Jira link types...
[I][15:13:38] Export started. Selecting 1 items.
[I][15:13:38] Initializing Jira field mapping...
[W][15:13:42] Ignoring target mapping with key: 'System.History', because it is already configured.
[W][15:16:28] Ignoring target mapping with key: 'System.History', because it is already configured.
[W][15:16:32] Ignoring target mapping with key: 'System.History', because it is already configured.
[W][15:16:33] Ignoring target mapping with key: 'System.History', because it is already configured.

Migrating multiple source fields to the same target fields is not supported. I will mark this as a feature request.

:)

from jira-azuredevops-migrator.

masteragi avatar masteragi commented on June 19, 2024

OK, thank you. I need to think of a workaround here... Is a change required only on the export side or also on the import side?

from jira-azuredevops-migrator.

Alexander-Hjelm avatar Alexander-Hjelm commented on June 19, 2024

Pretty sure it would only be on the export side!

Sure! A temporary but rather annoying workaround would be to set the target field as a temporary token and then search-replace all such tokens with "System.History".

For example I could see you doing something like this:

      {
        "original-name": "Melder",
	"source": "customfield_10160",
        "target": "UniqueReplace1"
      },
      {
        "original-name": "Fehlerart",
	"source": "customfield_16324",
        "target": "UniqueReplace2"
      },
      {
        "original-name": "Fachbereich",
	"source": "customfield_10460",
        "target": "UniqueReplace3"
      },
      {
        "original-name": "Anforderungsart",
	"source": "customfield_16324",
        "target": "UniqueReplace4"
      },

Then after the Export, go inside an IDE like VS Code and do a folderwide search-replace in your folder (with regex enabled):

  • UniqueReplace\d+ -> System.History

Finally go ahead with the Import.

This should take care of it in theory, but I have never tried before, so I cannot say with 100% certainty. You are welcome to try though!

from jira-azuredevops-migrator.

masteragi avatar masteragi commented on June 19, 2024

First thing I tried is to add another History entry in the exported Jira json file, like this:

        {
          "ReferenceName": "System.History",
          "Value": "Value 1"
        },
	{
          "ReferenceName": "System.History",
          "Value": "Value 2"
        },

And after the import just "Value 2" gets written in the Azure DevOps work item.

It doesn't seem to be a big code-change on the export side so I might take a swing at it but I haven't checked the import side yet...

from jira-azuredevops-migrator.

Alexander-Hjelm avatar Alexander-Hjelm commented on June 19, 2024

Correct, each update would need to be in it's own separate revisions! It can only write to any single Work Item Field once in each revision.

from jira-azuredevops-migrator.

masteragi avatar masteragi commented on June 19, 2024

Correct, each update would need to be in it's own separate revisions! It can only write to any single Work Item Field once in each revision.

I see... In this case it is a bigger code-change, but I can only say for sure after I understand the code bahind revisions. 😄

from jira-azuredevops-migrator.

masteragi avatar masteragi commented on June 19, 2024

@Alexander-Hjelm
I am trying to make this work and have made following changes in the code to make this work:

Added the option to mapping configuration in the config.json file (additional "customFieldsList" with the list of my custom fields, mapped to "System.History" with the new "MapMultiple" mapper):

{
"source": "multiple",
"customFieldsList": [
	"Melder",
	"Fehlerart",
	"Fachbereich",
	"Anforderungsart"
],
"target": "System.History",
"mapper": "MapMultiple"
}

Then I added the "customFieldsList" as a property in the Field class:

[JsonProperty("customFieldsList")]
public List<string> CustomFieldsList { get; set; }

Added the handling of the "MapMultiple" mapper in JiraMapper::InitializeFieldMappings:

case "MapMultiple":
    value = r => FieldMapperUtils.MapMultipleValues(r, item.CustomFieldsList, item.Target, _config, _jiraProvider);
    break;

Implemented the concatenation of custom field "name: value" pairs in the MapMultipleValues method:

public static (bool, object) MapMultipleValues(JiraRevision r, List<string> customFields, string targetItem, ConfigJson config, IJiraProvider jiraProvider)
{
    if (r == null)
        throw new ArgumentNullException(nameof(r));

    if (config == null)
        throw new ArgumentNullException(nameof(config));

    var mappedValues = string.Empty;
    var customFieldId = string.Empty;
    var customFieldValue = string.Empty;
    //go through the list of source fields
    foreach (var customFieldName in customFields)
    {
        //fetch the Jira Custom Field ID via the Jira Rest API
        customFieldId = jiraProvider.GetCustomId(customFieldName);
        //fetch the field value from the list of fields in the Jira Revision
        customFieldValue = r.GetFieldValue(customFieldId);

        //add an entry only if the custom Field has a value in the Jira Revision
        if (customFieldValue != null)
        {
            //add a breakpoint before every new key-value pair (except for the first one)
            mappedValues += (mappedValues != string.Empty) ? "</br>" : "";
            //put name and value together as "name: value"
            mappedValues += customFieldName + ": " + customFieldValue;
        }
    }

    return (true, mappedValues);
}

I've probably butchered the code a lot and left some loose ends unhandled but this is as far as I got so far to get multiple custom fields mapped to the System.History field.

What I am experiencing at the moment is that all the original Jira comments get overwritten by those same custom field values:
image

Before I go and lose a lot of time debugging the code, do you know where I got it wrong and where I might need to adjust the code (or maybe add some additional forks/checks)?

Thank you in advance for your support. 🙏

Cheers,
Marko

from jira-azuredevops-migrator.

Alexander-Hjelm avatar Alexander-Hjelm commented on June 19, 2024

My best guess is that it would be the JiraMapper blocking the old field mapping for System.History because it contains the same target property as your new field mapping. This will cause one to override the other. Currently only one field mapping is allowed per field per Work Item Type.

foreach (var wit in currentWorkItemTypes)
{
try
{
if (wit == "All" || wit == "Common")
{
commonFields.Add(item.Target, value);
}
else
{
// If we haven't mapped the Type then we probably want to ignore the field
if (typeFields.TryGetValue(wit, out FieldMapping<JiraRevision> fm))
{
fm.Add(item.Target, value);
}
else
{
Logger.Log(LogLevel.Warning, $"No target type '{wit}' is set, field {item.Source} cannot be mapped.");
}
}
}
catch (Exception)
{
Logger.Log(LogLevel.Warning, $"Ignoring target mapping with key: '{item.Target}', because it is already configured.");
}
}

from jira-azuredevops-migrator.

masteragi avatar masteragi commented on June 19, 2024

Thank you, @Alexander-Hjelm. Yes, that's what I first thought as well - that it is caused by the limitation of the Dictionary to hold one mapping for each key (target work item type). What would you recommend as the easiest workaround?

from jira-azuredevops-migrator.

Alexander-Hjelm avatar Alexander-Hjelm commented on June 19, 2024

I can think of a simple workaround which would be best implemented as a post-migration task. I would have mapped Comment to let's say "target": "System.History" and your new aggregated field to a unique token like "target": "System.History1". You can then do a folder-wide search replace in the workspace folder using e.g. an IDE or a script. You would replace all ocurences of System.History1" with "System.History". I think that this should adequately solve your problem, unless there are any instances where the the Jira Comment and your aggregated field are updated on the same revision, which I assume is not the case.

We would probably need to do a major redesign of the JiraMapper component if we want to properly support this scenario, plus think about all possible conflict scenarios. I am thus leaving this issue as a Feature Request for when we can commit to it! :)

from jira-azuredevops-migrator.

masteragi avatar masteragi commented on June 19, 2024

That's a good idea and easy to implement - as one additional line of code before the WiItem gets serialized to the JSON file. Will do that... Thank you so much!

from jira-azuredevops-migrator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.