2018-11-16 19:37:17 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-02 05:16:24 -04:00
|
|
|
module Gitlab
|
|
|
|
module ManifestImport
|
2018-07-06 09:21:22 -04:00
|
|
|
class ProjectCreator
|
|
|
|
attr_reader :repository, :destination, :current_user
|
2018-07-02 05:16:24 -04:00
|
|
|
|
2018-07-06 09:21:22 -04:00
|
|
|
def initialize(repository, destination, current_user)
|
2018-07-02 05:16:24 -04:00
|
|
|
@repository = repository
|
|
|
|
@destination = destination
|
2018-07-06 09:21:22 -04:00
|
|
|
@current_user = current_user
|
2018-07-02 05:16:24 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
group_full_path, _, project_path = repository[:path].rpartition('/')
|
2018-07-05 08:24:53 -04:00
|
|
|
group_full_path = File.join(destination.full_path, group_full_path) if destination
|
2018-07-09 07:59:07 -04:00
|
|
|
group = create_group_with_parents(group_full_path)
|
2018-07-02 05:16:24 -04:00
|
|
|
|
|
|
|
params = {
|
|
|
|
import_url: repository[:url],
|
2020-08-18 20:10:34 -04:00
|
|
|
import_source: repository[:url],
|
2018-07-02 05:16:24 -04:00
|
|
|
import_type: 'manifest',
|
|
|
|
namespace_id: group.id,
|
|
|
|
path: project_path,
|
|
|
|
name: project_path,
|
|
|
|
visibility_level: destination.visibility_level
|
|
|
|
}
|
|
|
|
|
2018-07-06 09:21:22 -04:00
|
|
|
Projects::CreateService.new(current_user, params).execute
|
2018-07-02 05:16:24 -04:00
|
|
|
end
|
|
|
|
|
2018-07-06 09:21:22 -04:00
|
|
|
private
|
|
|
|
|
2018-07-02 05:16:24 -04:00
|
|
|
def create_group_with_parents(full_path)
|
|
|
|
params = {
|
|
|
|
group_path: full_path,
|
|
|
|
visibility_level: destination.visibility_level
|
|
|
|
}
|
|
|
|
|
2018-07-06 09:21:22 -04:00
|
|
|
Groups::NestedCreateService.new(current_user, params).execute
|
2018-07-02 05:16:24 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|