summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-11-11 16:22:51 +0100
committerDouwe Maan <douwe@gitlab.com>2015-11-18 12:00:56 +0100
commit841a7c6897b23957286056498cc3f05ec4330d15 (patch)
treedba78089ddaa57ce67ac251a1565b17d54fa79b3 /app
parent531177757eef772cc7ce5dd3898c3e6803187ed6 (diff)
downloadgitlab-ce-841a7c6897b23957286056498cc3f05ec4330d15.tar.gz
Store and show reason why import failed.
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb10
-rw-r--r--app/views/projects/imports/new.html.haml12
-rw-r--r--app/workers/repository_fork_worker.rb14
-rw-r--r--app/workers/repository_import_worker.rb67
4 files changed, 61 insertions, 42 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index a099a67cf63..c2ff103759a 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -310,15 +310,17 @@ class Project < ActiveRecord::Base
def add_import_job
if forked?
- unless RepositoryForkWorker.perform_async(id, forked_from_project.path_with_namespace, self.namespace.path)
- import_fail
- end
+ RepositoryForkWorker.perform_async(self.id, forked_from_project.path_with_namespace, self.namespace.path)
else
- RepositoryImportWorker.perform_async(id)
+ RepositoryImportWorker.perform_async(self.id)
end
end
def clear_import_data
+ update(import_error: nil)
+
+ ProjectCacheWorker.perform_async(self.id)
+
self.import_data.destroy if self.import_data
end
diff --git a/app/views/projects/imports/new.html.haml b/app/views/projects/imports/new.html.haml
index 92a87690c54..f7b4416d87e 100644
--- a/app/views/projects/imports/new.html.haml
+++ b/app/views/projects/imports/new.html.haml
@@ -1,12 +1,16 @@
- page_title "Import repository"
%h3.page-title
- - if @project.import_failed?
- Import failed. Retry?
- - else
- Import repository
+ Import repository
%hr
+- if @project.import_failed?
+ .alert.alert-danger
+ %p The repository could not be imported.
+ %pre.prepend-top-10
+ :preserve
+ #{@project.import_error.try(:strip)}
+
= form_for @project, url: namespace_project_import_path(@project.namespace, @project), method: :post, html: { class: 'form-horizontal' } do |f|
.form-group.import-url-data
= f.label :import_url, class: 'control-label' do
diff --git a/app/workers/repository_fork_worker.rb b/app/workers/repository_fork_worker.rb
index acd1c43f06b..2f991c52339 100644
--- a/app/workers/repository_fork_worker.rb
+++ b/app/workers/repository_fork_worker.rb
@@ -13,22 +13,20 @@ class RepositoryForkWorker
end
result = gitlab_shell.fork_repository(source_path, target_path)
-
unless result
logger.error("Unable to fork project #{project_id} for repository #{source_path} -> #{target_path}")
+ project.update(import_error: "The project could not be forked.")
project.import_fail
- project.save
return
end
- if project.valid_repo?
- ProjectCacheWorker.perform_async(project.id)
- project.import_finish
- else
- project.import_fail
+ unless project.valid_repo?
logger.error("Project #{id} had an invalid repository after fork")
+ project.update(import_error: "The forked repository is invalid.")
+ project.import_fail
+ return
end
- project.save
+ project.import_finish
end
end
diff --git a/app/workers/repository_import_worker.rb b/app/workers/repository_import_worker.rb
index ea2808045eb..5be2245df28 100644
--- a/app/workers/repository_import_worker.rb
+++ b/app/workers/repository_import_worker.rb
@@ -7,37 +7,52 @@ class RepositoryImportWorker
def perform(project_id)
project = Project.find(project_id)
- unless project.import_url == Project::UNKNOWN_IMPORT_URL
- import_result = gitlab_shell.send(:import_repository,
- project.path_with_namespace,
- project.import_url)
- return project.import_fail unless import_result
- else
+ if project.import_url == Project::UNKNOWN_IMPORT_URL
+ # In this case, we only want to import issues, not a repository.
unless project.create_repository
- return project.import_fail
+ project.update(import_error: "The repository could not be created.")
+ project.import_fail
+ return
+ end
+ else
+ begin
+ import_result = gitlab_shell.import_repository(project.path_with_namespace, project.import_url)
+ rescue Gitlab::Shell::Error => e
+ project.update(import_error: e.message)
+ project.import_fail
+ return
end
end
- 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
- return project.import_fail unless data_import_result
-
- Gitlab::BitbucketImport::KeyDeleter.new(project).execute if project.import_type == 'bitbucket'
+ 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
project.import_finish
- project.save
- ProjectCacheWorker.perform_async(project.id)
+
+ # Explicitly update mirror so that upstream remote is created and fetched
+ project.update_mirror
end
end