Refactor manifest import code

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2018-07-06 16:21:22 +03:00
parent 85b0240c4b
commit a4b6707e63
6 changed files with 12 additions and 17 deletions

View file

@ -47,7 +47,7 @@ class Import::ManifestController < Import::BaseController
project[:id] == params[:repo_id].to_i
end
project = Gitlab::ManifestImport::Importer.new(repository, group, current_user).execute
project = Gitlab::ManifestImport::ProjectCreator.new(repository, group, current_user).execute
if project.persisted?
render json: ProjectSerializer.new.represent(project)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -10,7 +10,7 @@ You can do it by following next steps:
1. Click on the **Manifest file** button
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. 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. Check the list and click 'Import all repositories' to start import.

View file

@ -1,21 +1,15 @@
module Gitlab
module ManifestImport
class Importer
attr_reader :repository, :destination, :user
class ProjectCreator
attr_reader :repository, :destination, :current_user
def initialize(repository, destination, user)
def initialize(repository, destination, current_user)
@repository = repository
@destination = destination
@user = user
@current_user = current_user
end
def execute
import_project
end
private
def import_project
group_full_path, _, project_path = repository[:path].rpartition('/')
group_full_path = File.join(destination.full_path, group_full_path) if destination
group = Group.find_by_full_path(group_full_path) ||
@ -30,16 +24,18 @@ module Gitlab
visibility_level: destination.visibility_level
}
Projects::CreateService.new(user, params).execute
Projects::CreateService.new(current_user, params).execute
end
private
def create_group_with_parents(full_path)
params = {
group_path: full_path,
visibility_level: destination.visibility_level
}
Groups::NestedCreateService.new(user, params).execute
Groups::NestedCreateService.new(current_user, params).execute
end
end
end

View file

@ -50,7 +50,6 @@ describe Gitlab::ImportSources do
fogbugz
gitlab_project
gitea
manifest
)
expect(described_class.importer_names).to eq(expected)
@ -67,7 +66,7 @@ describe Gitlab::ImportSources do
'git' => nil,
'gitlab_project' => Gitlab::ImportExport::Importer,
'gitea' => Gitlab::LegacyGithubImport::Importer,
'manifest' => Gitlab::ManifestImport::Importer
'manifest' => nil
}
import_sources.each do |name, klass|

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe Gitlab::ManifestImport::Importer, :postgresql do
describe Gitlab::ManifestImport::ProjectCreator, :postgresql do
let(:group) { create(:group) }
let(:user) { create(:user) }
let(:repository) do