Skip to content

API endpoint for re-import of named relation from project export file

James Nutt requested to merge jnutt/endpoint-for-relation-import into master

What does this MR do and why?

API endpoint for re-import of named relation from project export file

This MR adds the capability for a user to re-import a chosen relation (issues, milestones, merge requests or pipelines) from a project export archive via the GitLab API.

Related issue: #425798 (closed)

Changelog: added

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.

How to set up and validate locally

You can test this MR using the flightjs/Flight project that comes with the SDK seed.

  1. Enable file-based import in the Application Settings.
  2. Export the Flight project and store the tarball on your drive.
  3. Clear out some relations using your Rails console:
project = Project.find(7) # default Flight ID
project.merge_requests.find_by(iid: 3).destroy!
project.issues.find_by(iid: 38).destroy!
project.milestones.find_by(iid: 7).destroy!
project.ci_pipelines.find_by(iid: 29).destroy!

puts "MR: #{project.merge_requests.count} I: #{project.issues.count} MS: #{project.milestones.count} CI: #{project.ci_pipelines.count}"
# MR: 9 I: 37 MS: 8 CI: 33
  1. Verify that the relations are missing from the GitLab UI.
  2. Reimport them.
curl --request POST --header "PRIVATE-TOKEN: $GITLAB_DEV_TOKEN" \
  --form "path=flightjs/Flight" \
  --form "relation=merge_requests" \
  --form "file=@flight-export.tar.gz" \
  "http://gdk.test:3000/api/v4/projects/import-relation"
curl --request POST --header "PRIVATE-TOKEN: $GITLAB_DEV_TOKEN" \
  --form "path=flightjs/Flight" \
  --form "relation=issues" \
  --form "file=@flight-export.tar.gz" \
  "http://gdk.test:3000/api/v4/projects/import-relation"
curl --request POST --header "PRIVATE-TOKEN: $GITLAB_DEV_TOKEN" \
  --form "path=flightjs/Flight" \
  --form "relation=milestones" \
  --form "file=@flight-export.tar.gz" \
  "http://gdk.test:3000/api/v4/projects/import-relation"
curl --request POST --header "PRIVATE-TOKEN: $GITLAB_DEV_TOKEN" \
  --form "path=flightjs/Flight" \
  --form "relation=ci_pipelines" \
  --form "file=@flight-export.tar.gz" \
  "http://gdk.test:3000/api/v4/projects/import-relation"
  1. Verify that they have been successfully re-imported.

    puts "MR: #{project.merge_requests.count} I: #{project.issues.count} MS: #{project.milestones.count} CI: #{project.ci_pipelines.count}"
Edited by James Nutt

Merge request reports