Skip to content

Create parent links for imported epics

Nicolas Dular requested to merge nd/fix-parent-work-item-import into master

What does this MR do and why?

Create parent links for imported epics

When importing epics from groups where epics and sub-epics features where enabled to groups where these features are not enabled, we need to retain the relationship on the work item side on imports.

We store the parent_id on the epic record. For this reason we bypassed the license checks in the epic services and still created the sub-epic relationships.

This doesn't work on the work item side, so we need to explicitly create the work item parent link when importing epics.

Changelog: changed

Issue: #463557 (closed)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. gdk stop
  2. export GITLAB_SIMULATE_SAAS=1 (easiest to change group licenses)
  3. gdk start
  4. Select a group which is on a ultimate plan (you can change plans on admin -> groups -> select a plan)
  5. Create epics and sub-epics
  6. Export group (group settings -> general -> export)
  7. Download the exported gzip file (gdk:3000/rails/letter_opener is helpful here)
  8. Create a new group that is either on a free or premium tier and use the gzipped file you just downloaded

Then make sure it got exported correctly:

Switch to work item epics and go to the newly imported group's epics and check that the sub-epics are still there:

Feature.enable(:namespace_level_work_items)

If you imported to a free group, you can upgrade the group to premium or ultimate, or you can check in the console:

epics = Epic.where(group_id: IMPORTED_GROUP_ID)
epics.reduce([]) do |mismatches, epic|
   diff = Gitlab::EpicWorkItemSync::Diff.new(epic, epic.work_item, strict_equal: true)
   mismatches.concat(diff.attributes)
end
 
# => should only output `lock_version`

Note: When checking the epic_work_item_sync.log

The log will still say there are mismatches on parent_id (and lock_version which can be ignored). These mismatches are false positives and we need to investigate further. The reason for this mismatch report is that we create the WorkItems::ParentLink after Epics::CreateService & with it the Validation worker get executed.

Edited by Nicolas Dular

Merge request reports