2013-08-12 15:21:47 +00:00
|
|
|
class RepositoryImportWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
include Gitlab::ShellAdapter
|
|
|
|
|
|
|
|
sidekiq_options queue: :gitlab_shell
|
|
|
|
|
|
|
|
def perform(project_id)
|
|
|
|
project = Project.find(project_id)
|
2015-02-18 16:00:26 +00:00
|
|
|
|
2015-11-11 15:22:51 +00:00
|
|
|
if project.import_url == Project::UNKNOWN_IMPORT_URL
|
|
|
|
# In this case, we only want to import issues, not a repository.
|
2015-08-04 22:21:12 +00:00
|
|
|
unless project.create_repository
|
2015-11-11 15:22:51 +00:00
|
|
|
project.update(import_error: "The repository could not be created.")
|
|
|
|
project.import_fail
|
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2015-11-12 11:53:00 +00:00
|
|
|
gitlab_shell.import_repository(project.path_with_namespace, project.import_url)
|
2015-11-11 15:22:51 +00:00
|
|
|
rescue Gitlab::Shell::Error => e
|
|
|
|
project.update(import_error: e.message)
|
|
|
|
project.import_fail
|
|
|
|
return
|
2015-08-04 22:21:12 +00:00
|
|
|
end
|
|
|
|
end
|
2013-08-12 15:21:47 +00:00
|
|
|
|
2015-11-11 15:22:51 +00:00
|
|
|
data_import_result =
|
|
|
|
case project.import_type
|
|
|
|
when 'github'
|
|
|
|
Gitlab::GithubImport::Importer.new(project).execute
|
|
|
|
when 'gitlab'
|
|
|
|
Gitlab::GitlabImport::Importer.new(project).execute
|
|
|
|
when 'bitbucket'
|
|
|
|
Gitlab::BitbucketImport::Importer.new(project).execute
|
|
|
|
when 'google_code'
|
|
|
|
Gitlab::GoogleCodeImport::Importer.new(project).execute
|
|
|
|
when 'fogbugz'
|
|
|
|
Gitlab::FogbugzImport::Importer.new(project).execute
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
unless data_import_result
|
|
|
|
project.update(import_error: "The remote issue data could not be imported.")
|
|
|
|
project.import_fail
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if project.import_type == 'bitbucket'
|
|
|
|
Gitlab::BitbucketImport::KeyDeleter.new(project).execute
|
|
|
|
end
|
2015-08-07 07:06:20 +00:00
|
|
|
|
2015-02-18 16:00:26 +00:00
|
|
|
project.import_finish
|
2013-08-12 15:21:47 +00:00
|
|
|
end
|
2014-09-25 22:07:40 +00:00
|
|
|
end
|