YouTrack Standalone 2018.2 Help

Import from Trac

Follow the instructions on this page to import tickets from Trac with a Python import script. This procedure requires the following steps:

  1. Set up your local environment.

  2. (Optional) Customize the mapping between the fields in your Trac database and the issue attributes in YouTrack.

  3. Import your issues.

Import Details

If the Trac database contains references to entities that do not already exist in YouTrack, they are created. The user account that you use to run the import should have permission to create projects, issues, users, and possibly more. We recommend that you use an account with a System Admin role to execute the import script.

New entities are created as follows:

Entity

Description

Projects

The Python script lets you import all issues from a source project at once. If the project does not already exist, a new project is created.
  • The project name and ID are assigned based on the values from the Trac database.

  • The user who executes the import script is set as the project lead.

Users

Several issue attributes like reporterName and Assignee store references to user accounts. For each account that does not match the login or email for an existing user in YouTrack, a new user account is created. There are two types of users in Trac:
  • Registered users with a login and a password. These users are imported to YouTrack with their original name and email.

  • Unregistered users who specified a name and an email address or a name only when creating or adding a comment the ticket. These users are imported only when an email address is provided. Users without email addresses are imported as guest.

    There is an option in the mapping file that lets you import all unregistered users as guest instead of creating new accounts in YouTrack.

All new user accounts are assigned randomly-generated passwords. To log in to YouTrack, imported users must click the Reset password link on the login page and create a new password.

Custom Fields

If the import data contains a field that does not exist in YouTrack, the custom field is created and added to the target project.
  • The field name and type are set according to the definitions in your mapping file.

  • The properties for the custom field are set as follows: autoAttached=true, isPrivate=false, defaultVisibility=false.

Field Values

If the source file contains new values for an existing field, they are added to the current set of values.

Tags

Keywords in Track are imported as tags.

Work Items

Trac offers plugins that support time tracking. The import script automatically detects and imports time tracking values from supported plugins. These values are added to imported issues as work items.

Set Up Your Environment

Import to YouTrack is supported with Python import scripts. These scripts are built on top of the YouTrack REST API. You won't actually need to do any programming in Python, but you do need to install Python and the package that contains the import scripts.

To set up your environment:

  1. Download and install Python. The Python Client Library is compatible with Python 2.7+. Python 3 releases are not supported. You can choose whichever installation directory you prefer.

    The latest versions of macOS, CentOS, Red Hat Enterprise Linux (RHEL), and Ubuntu come with Python 2.7 out of the box. If you're working with any of these operating systems, continue with the next step.

  2. Install the package that contains the import scripts. Open the command-line interface that is supported by your operating system and enter the following command:
    pip install youtrack-scripts
    • The import scripts are installed in your local environment.

    • The youtrack package that contains the Python client library for the YouTrack REST API is installed automatically as a dependency.

    If you prefer not to install the packages globally, you can install them for your user account only with the command:
    pip install --user youtrack-scripts

Customize the Mapping Definitions

The next step is to map the fields in your Trac database to attributes in YouTrack. You can use the trac2youtrack script to generate a sample mapping file.

You only need to customize the mapping file if you have customized the issue attributes in Trac. To use the default mapping definitions, skip this procedure and import your data.

To generate a mapping file:

  1. Open the command-line interface that is supported by your operating system.

  2. If necessary, change the current directory to the installation directory for Python. For example (Windows):

    cd C:\Python27

  3. Enter the following command:
    trac2youtrack -g -m mapping.json
    • The -g option tells the script to generate the mapping file.

    • The -m option overrides the default path and filename for the mapping file. If you don't pass this option, the file is generated in the current directory as mapping.json. If you want to specify another location and/or filename, specify a value for the parameter with the full path of the target directory and/or desired name.

    • If the command is executed successfully, a message with the location of the generated file is printed in the command-line interface.

To customize the mapping definitions:

  1. Open the generated mapping file.

  2. Update the mapping to ensure that all of the data that you want to import from the Trac database is mapped to the desired values in YouTrack. If the file contains one or more fields that you don't want to import, you can remove the references from the mapping file. For a description of the default mappings, see Default Mapping.

  3. Set values for the parameters that manage user import:
    • default_email — Assigns a default email address to users who are imported without an email.

    • accept_non_authorised_users — If True, unregistered users are imported to YouTrack. If False, unregistered users are imported as guest.

  4. If used, specify the time tracking plugin that is enabled in Trac. The default parameter in the mapping file is set to support_time_tracking = "auto", which detects and imports time tracking values from supported plugins automatically. You can also specify the plugin from which data is imported:

    Value

    Description

    trachours

    Imports data from the TracHoursPlugin.

    timingandestimationplugin

    Imports data from the TimingAndEstimationPlugin.

  5. Save your changes and close the mapping file.

Import Your Data

The last step is to run the command that imports your data from Trac.

To import your data:

  1. Open the command-line interface that is supported by your operating system.

  2. If necessary, change the current directory to the installation directory for Python. For example (Windows):

    cd C:\Python27

  3. Enter the following command:
    trac2youtrack -m mapping.json -t token -u login -p password target_url project_ID project_name path_to_trac_environment
    Replace the command-line parameters with values as described here:

    Parameter

    Description

    mapping.json

    Use with the -m option to specify the full path and filename of your custom mapping file. If you don't pass this option, the default mapping file is used instead.

    token

    When used with the -t option, a permanent token that is used to authenticate your administrator account in YouTrack. This is the preferred method of authentication. If you use this option, skip the -u and -p options. To learn how to generate a permanent token, see Create a Permanent Token.

    Alternatively, you can use the -T option and specify the full path and filename for a file that contains a permanent token.

    login

    When used with the -u option, the login for a YouTrack administrator account. You must also specify a value for the -p option.

    password

    When used with the -p option, the password for the YouTrack administrator account.

    target_url

    The base URL of the target YouTrack server. For YouTrack InCloud instances, your base URL includes the trailing /youtrack. For example: https://company.myjetbrains.com/youtrack

    project_ID

    The ID of the target project in YouTrack.

    project_name

    The name of the target project in YouTrack.

    path_to_trac_environment

    The path to the source project in Trac.

    • The command executes the Python import script.

    • If successful, the following line is printed in the command-line interface for each issue:

      Issue [ <issue ID> ] imported successfully

  4. Check the project that you imported issues into and verify that the data is presented properly. If you are not satisfied with the results and want to re-import the data:
    • Delete all of the issues that were created during import. If you imported issues into a new project, simply delete the project.

    • Edit your mapping file.

    • Run the import script again.

Default Mapping

The Python Client Library includes a default mapping file for importing issues from Trac to YouTrack. The file is saved as defaultTrac.py in the youtrackutils/tracLib subfolder of the repository.

The import script references the default mapping file. If you create a custom mapping file, use the -m option in your import script and specify the full path and filename of your file as described in the previous section.

Ticket Type

Tickets in Trac use the default types defect, enhancement, and task. The default mapping file contains a types dictionary that maps these values to corresponding values for the Type field in YouTrack.

types = { "defect" : "Bug", "enhancement" : "Feature", "task" : "Task", }

Pay attention to the following guidelines when you edit this section of the mapping file:

  • The left side of the mapping references the value for the Type field in Trac. If you have added custom values to this field, add a new definition for each value to the dictionary.

  • The right side of the mapping references the corresponding values for the Type field in YouTrack. If you specify a value for the Type field that does not already exist, it is added to the field during import.

Ticket Priority

Similar to the mapping for the Type field, this dictionary maps values for the Priority field in Trac to the field with the same name in YouTrack. Follow the same guidelines as for issue type to customize this section of the mapping file. The mapping for default issue priority is as follows:

priorities = { "trivial" : "Minor", #Minor "minor" : "Normal", #Normal "major" : "Major", #Major "critical" : "Critical", #Critical "blocker" : "Show-stopper" #Show-stopper }

Ticket Resolution and Status

Values for both the Resolution and Status field in Trac are mapped to values for the State field in YouTrack. The default mapping for these values is as follows:

resolutions = { "duplicate" : "Duplicate", "fixed" : "Fixed", "wontfix" : "Won't fix", "worksforme" : "Can't Reproduce", "invalid" : "Can't Reproduce" # : "To be discussed } states = { "accepted" : "Submitted", "new" : "Open", "reopened" : "Reopened", "assigned" : "Submitted", "closed" : None }

Ticket Fields

The field_names dictionary maps field names in Trac to custom fields in YouTrack. You can update the mappings in this section to import data to specific custom fields. The default mapping file only contains definitions for fields that do not match existing fields in YouTrack:

field_names = { "Resolution" : "State", "Status" : "State", "Owner" : "Assignee", "Version" : "Fix versions", "Component" : "Subsystem", "Test_five" : "YT Select" }

Pay attention to the following guidelines when you edit the custom field mapping:

  • The left side of the mapping references the field name in Track.

  • The right side of the mapping references the name of the custom field in YouTrack.

  • If you do not specify a mapping for a field in Trac that does not match a target field in YouTrack, a custom field is created with the same name as in Trac.

    For example, older versions of Trac include a field for Severity. The default mapping file defines the field type but does not map the field to a target field in YouTrack. The field and its values are imported as a new Severity field.

Custom Field Types

The field_types dictionary maps data types in Trac to custom field types in YouTrack. If you have added fields to the mapping for custom fields, add a corresponding entry to this dictionary to define how the data is stored in YouTrack. The default mapping file contains definitions for the following field types:

field_types = { "Priority" : "enum[1]", "Type" : "enum[1]", "State" : "state[1]", "Fix versions" : "version[*]", "Affected versions" : "version[*]", "Assignee" : "user[1]", "Severity" : "enum[1]", "YT Select" : "enum[*]", "Subsystem" : "ownedField[1]" }

Pay attention to the following guidelines when you edit the field type mapping:

  • The left side of the mapping references the name of the custom field in YouTrack. These values must exactly match the custom field name in the field_names dictionary.

  • The right side of the mapping references the field type in YouTrack. For a list of valid types, refer to the Administration REST API.

  • If the target field already exists in YouTrack, you do not need to include it here.

  • You cannot change the data type of an existing field. For example, if the existing Assignee field stores single values (user[1]), you cannot use user[*] in the mapping file and import multiple assignees. You must first update this property for the Assignee field in the YouTrack user interface, then import the data.

Last modified: 7 March 2019