BigW Consortium Gitlab

Commit b53ed848 by James Lopez

adapted current services stuff to use new project import, plus fixes a few…

adapted current services stuff to use new project import, plus fixes a few issues, updated routes, etc...
parent 1d4243f5
......@@ -12,20 +12,21 @@ class Import::GitlabProjectsController < Import::BaseController
return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." })
end
@project = Gitlab::ImportExport::ProjectCreator.new(Namespace.find(project_params[:namespace_id]),
@project = Gitlab::ImportExport::ProjectCreator.new(project_params[:namespace_id],
current_user,
File.expand_path(params[:file].path),
project_params[:path]).execute
flash[:notice] = "The project import has been started."
if @project.saved?
redirect_to(
project_path(@project),
notice: "Project '#{@project.name}' is being imported."
)
else
render 'new'
redirect_to(
new_project_path,
alert: "Project could not be exported: #{@project.errors.full_messages.join(', ')}"
)
end
end
......
......@@ -451,7 +451,7 @@ class Project < ActiveRecord::Base
end
def import?
external_import? || forked?
external_import? || forked? || gitlab_project_import?
end
def no_import?
......
......@@ -14,22 +14,26 @@ module Projects
]
def execute
if unknown_url?
# In this case, we only want to import issues, not a repository.
create_repository
else
import_repository
end
add_repository_to_project unless project.gitlab_project_import?
import_data
success
rescue Error => e
rescue => e
error(e.message)
end
private
def add_repository_to_project
if unknown_url?
# In this case, we only want to import issues, not a repository.
create_repository
else
import_repository
end
end
def create_repository
unless project.create_repository
raise Error, 'The repository could not be created.'
......@@ -38,7 +42,7 @@ module Projects
def import_repository
begin
gitlab_shell.import_repository(project.path_with_namespace, project.import_url) unless @project.gitlab_project_import?
gitlab_shell.import_repository(project.path_with_namespace, project.import_url)
rescue Gitlab::Shell::Error => e
raise Error, "Error importing repository #{project.import_url} into #{project.path_with_namespace} - #{e.message}"
end
......@@ -47,7 +51,7 @@ module Projects
def import_data
return unless has_importer?
project.repository.before_import
project.repository.before_import unless project.gitlab_project_import?
unless importer.execute
raise Error, 'The remote data could not be imported.'
......@@ -59,7 +63,7 @@ module Projects
end
def importer
return Gitlab::ImportExport::Importer if @project.gitlab_project_import?
return Gitlab::ImportExport::Importer.new(project) if @project.gitlab_project_import?
class_name = "Gitlab::#{project.import_type.camelize}Import::Importer"
class_name.constantize.new(project)
......
......@@ -455,7 +455,7 @@ Rails.application.routes.draw do
post :toggle_star
post :markdown_preview
post :export
post :download_export
get :download_export
get :autocomplete_sources
get :activity
end
......
......@@ -2,24 +2,22 @@ module Gitlab
module ImportExport
class Importer
def self.execute(*args)
new(*args).execute
end
def initialize(project)
@archive_file = project.import_source
@current_user = project.creator
@shared = Gitlab::ImportExport::Shared.new(relative_path: path_with_namespace(@project.path))
@project = project
@shared = Gitlab::ImportExport::Shared.new(relative_path: path_with_namespace)
end
def execute
Gitlab::ImportExport::FileImporter.import(archive_file: @archive_file,
shared: @shared)
if check_version! && [project_tree, repo_restorer, wiki_restorer, uploads_restorer].all?(&:restore)
project_tree.project
project_tree.restored_project
else
project_tree.project.destroy if project_tree.project
nil
project_tree.restored_project.destroy if project_tree.restored_project
raise Projects::ImportService::Error.new, @shared.errors.join(', ')
end
end
......@@ -38,22 +36,22 @@ module Gitlab
def repo_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: repo_path,
shared: @shared,
project: project_tree.project)
project: project_tree.restored_project)
end
def wiki_restorer
Gitlab::ImportExport::RepoRestorer.new(path_to_bundle: wiki_repo_path,
shared: @shared,
project: ProjectWiki.new(project_tree.project),
project: ProjectWiki.new(project_tree.restored_project),
wiki: true)
end
def uploads_restorer
Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.project, shared: @shared)
Gitlab::ImportExport::UploadsRestorer.new(project: project_tree.restored_project, shared: @shared)
end
def path_with_namespace(project_path)
File.join(@namespace.path, project_path)
def path_with_namespace
File.join(@project.namespace.path, @project.path)
end
def repo_path
......@@ -63,18 +61,6 @@ module Gitlab
def wiki_repo_path
File.join(@shared.export_path, 'project.wiki.bundle')
end
def attributes_for_todo
{ user_id: @current_user.id,
project_id: project_tree.project.id,
target_type: 'Project',
target: project_tree.project,
action: Todo::IMPORTED,
author_id: @current_user.id,
state: :pending,
target_id: project_tree.project.id
}
end
end
end
end
......@@ -11,10 +11,10 @@ module Gitlab
def execute
::Projects::CreateService.new(
current_user,
@current_user,
name: @project_path,
path: @project_path,
namespace_id: namespace_id,
namespace_id: @namespace_id,
import_type: "gitlab_project",
import_source: @file
).execute
......
......@@ -19,7 +19,7 @@ module Gitlab
false
end
def project
def restored_project
@restored_project ||= restore_project
end
......@@ -28,7 +28,7 @@ module Gitlab
def members_mapper
@members_mapper ||= Gitlab::ImportExport::MembersMapper.new(exported_members: @project_members,
user: @user,
project: project)
project: restored_project)
end
# Loops through the tree of models defined in import_export.yml and
......@@ -45,7 +45,7 @@ module Gitlab
relation_key = relation.is_a?(Hash) ? relation.keys.first : relation
relation_hash = create_relation(relation_key, @tree_hash[relation_key.to_s])
saved << project.update_attribute(relation_key, relation_hash)
saved << restored_project.update_attribute(relation_key, relation_hash)
end
saved.all?
end
......@@ -57,6 +57,8 @@ module Gitlab
end
def restore_project
return @project unless @tree_hash
project_params = @tree_hash.reject { |_key, value| value.is_a?(Array) }
@project.update(project_params)
@project
......@@ -91,7 +93,7 @@ module Gitlab
def create_relation(relation, relation_hash_list)
relation_array = [relation_hash_list].flatten.map do |relation_hash|
Gitlab::ImportExport::RelationFactory.create(relation_sym: relation.to_sym,
relation_hash: relation_hash.merge('project_id' => project.id),
relation_hash: relation_hash.merge('project_id' => restored_project.id),
members_mapper: members_mapper,
user: @user)
end
......
......@@ -2,8 +2,8 @@ module Gitlab
module ImportExport
class VersionChecker
def self.restore(*args)
new(*args).check
def self.check!(*args)
new(*args).check!
end
def initialize(shared:)
......
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