Commit a4b6707e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor manifest import code

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 85b0240c
...@@ -47,7 +47,7 @@ class Import::ManifestController < Import::BaseController ...@@ -47,7 +47,7 @@ class Import::ManifestController < Import::BaseController
project[:id] == params[:repo_id].to_i project[:id] == params[:repo_id].to_i
end end
project = Gitlab::ManifestImport::Importer.new(repository, group, current_user).execute project = Gitlab::ManifestImport::ProjectCreator.new(repository, group, current_user).execute
if project.persisted? if project.persisted?
render json: ProjectSerializer.new.represent(project) render json: ProjectSerializer.new.represent(project)
......
...@@ -10,7 +10,7 @@ You can do it by following next steps: ...@@ -10,7 +10,7 @@ You can do it by following next steps:
1. Click on the **Manifest file** button 1. Click on the **Manifest file** button
1. Provide GitLab with a manifest xml file 1. Provide GitLab with a manifest xml file
1. Select a group you want to import to (you need to create a group first if you don't have one) 1. Select a group you want to import to (you need to create a group first if you don't have one)
1. Click **Import projects** 1. Click **Continue to the next step**
1. You will be redirected to the import status page with projects list based on manifest file 1. You will be redirected to the import status page with projects list based on manifest file
1. Check the list and click 'Import all repositories' to start import. 1. Check the list and click 'Import all repositories' to start import.
......
module Gitlab module Gitlab
module ManifestImport module ManifestImport
class Importer class ProjectCreator
attr_reader :repository, :destination, :user attr_reader :repository, :destination, :current_user
def initialize(repository, destination, user) def initialize(repository, destination, current_user)
@repository = repository @repository = repository
@destination = destination @destination = destination
@user = user @current_user = current_user
end end
def execute def execute
import_project
end
private
def import_project
group_full_path, _, project_path = repository[:path].rpartition('/') group_full_path, _, project_path = repository[:path].rpartition('/')
group_full_path = File.join(destination.full_path, group_full_path) if destination group_full_path = File.join(destination.full_path, group_full_path) if destination
group = Group.find_by_full_path(group_full_path) || group = Group.find_by_full_path(group_full_path) ||
...@@ -30,16 +24,18 @@ module Gitlab ...@@ -30,16 +24,18 @@ module Gitlab
visibility_level: destination.visibility_level visibility_level: destination.visibility_level
} }
Projects::CreateService.new(user, params).execute Projects::CreateService.new(current_user, params).execute
end end
private
def create_group_with_parents(full_path) def create_group_with_parents(full_path)
params = { params = {
group_path: full_path, group_path: full_path,
visibility_level: destination.visibility_level visibility_level: destination.visibility_level
} }
Groups::NestedCreateService.new(user, params).execute Groups::NestedCreateService.new(current_user, params).execute
end end
end end
end end
......
...@@ -50,7 +50,6 @@ describe Gitlab::ImportSources do ...@@ -50,7 +50,6 @@ describe Gitlab::ImportSources do
fogbugz fogbugz
gitlab_project gitlab_project
gitea gitea
manifest
) )
expect(described_class.importer_names).to eq(expected) expect(described_class.importer_names).to eq(expected)
...@@ -67,7 +66,7 @@ describe Gitlab::ImportSources do ...@@ -67,7 +66,7 @@ describe Gitlab::ImportSources do
'git' => nil, 'git' => nil,
'gitlab_project' => Gitlab::ImportExport::Importer, 'gitlab_project' => Gitlab::ImportExport::Importer,
'gitea' => Gitlab::LegacyGithubImport::Importer, 'gitea' => Gitlab::LegacyGithubImport::Importer,
'manifest' => Gitlab::ManifestImport::Importer 'manifest' => nil
} }
import_sources.each do |name, klass| import_sources.each do |name, klass|
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::ManifestImport::Importer, :postgresql do describe Gitlab::ManifestImport::ProjectCreator, :postgresql do
let(:group) { create(:group) } let(:group) { create(:group) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:repository) do let(:repository) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment