Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-03 21:48:09 +0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2017-04-03 21:50:22 +0300
commit6143642a5ff2bbc63736b4b05d9583e72527fd5e (patch)
tree5d7818ad8d53e9bcc3cbcc0894872a2a0647f522 /app/services/projects
parent35fe9c660cc5309e244ce1bde5f65b4e7ec73e4e (diff)
Refactoring Projects::ImportService
Diffstat (limited to 'app/services/projects')
-rw-r--r--app/services/projects/import_service.rb50
1 files changed, 22 insertions, 28 deletions
diff --git a/app/services/projects/import_service.rb b/app/services/projects/import_service.rb
index 794cc1556a4..45ad47c8f44 100644
--- a/app/services/projects/import_service.rb
+++ b/app/services/projects/import_service.rb
@@ -11,7 +11,7 @@ module Projects
success
rescue => e
- error(e.message)
+ error("Error importing repository #{project.import_url} into #{project.path_with_namespace} - #{e.message}")
end
private
@@ -21,11 +21,7 @@ module Projects
# In this case, we only want to import issues, not a repository.
create_repository
elsif !project.repository_exists?
- if project.github_import? || project.gitea_import?
- fetch_repository
- else
- import_repository
- end
+ import_repository
end
end
@@ -36,42 +32,40 @@ module Projects
end
def import_repository
+ raise Error, 'Blocked import URL.' if Gitlab::UrlBlocker.blocked_url?(project.import_url)
+
begin
- raise Error, "Blocked import URL." if Gitlab::UrlBlocker.blocked_url?(project.import_url)
- gitlab_shell.import_repository(project.repository_storage_path, project.path_with_namespace, project.import_url)
- rescue => e
+ if project.github_import? || project.gitea_import?
+ fetch_repository
+ else
+ clone_repository
+ end
+ rescue Gitlab::Shell::Error => e
# Expire cache to prevent scenarios such as:
# 1. First import failed, but the repo was imported successfully, so +exists?+ returns true
# 2. Retried import, repo is broken or not imported but +exists?+ still returns true
- project.repository.before_import if project.repository_exists?
+ project.repository.expire_content_cache if project.repository_exists?
- raise Error, "Error importing repository #{project.import_url} into #{project.path_with_namespace} - #{e.message}"
+ raise Error, e.message
end
end
- def fetch_repository
- begin
- raise Error, 'Blocked import URL.' if Gitlab::UrlBlocker.blocked_url?(project.import_url)
-
- project.create_repository
- project.repository.add_remote(project.import_type, project.import_url)
- project.repository.set_remote_as_mirror (project.import_type)
- project.repository.fetch_remote(project.import_type, forced: true)
- project.repository.remove_remote(project.import_type)
- rescue => e
- # Expire cache to prevent scenarios such as:
- # 1. First import failed, but the repo was imported successfully, so +exists?+ returns true
- # 2. Retried import, repo is broken or not imported but +exists?+ still returns true
- project.repository.before_import if project.repository_exists?
+ def clone_repository
+ gitlab_shell.import_repository(project.repository_storage_path, project.path_with_namespace, project.import_url)
+ end
- raise Error, "Error importing repository #{project.import_url} into #{project.path_with_namespace} - #{e.message}"
- end
+ def fetch_repository
+ project.create_repository
+ project.repository.add_remote(project.import_type, project.import_url)
+ project.repository.set_remote_as_mirror (project.import_type)
+ project.repository.fetch_remote(project.import_type, forced: true)
+ project.repository.remove_remote(project.import_type)
end
def import_data
return unless has_importer?
- project.repository.before_import unless project.gitlab_project_import?
+ project.repository.expire_content_cache unless project.gitlab_project_import?
unless importer.execute
raise Error, 'The remote data could not be imported.'