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