Read about our upcoming Code of Conduct on this issue

Commit 8da23661 authored by Douwe Maan's avatar Douwe Maan
Browse files

Prefer polymorphism over specific type checks in Import service

parent b6921cfdb809
......@@ -704,10 +704,6 @@ def gitea_import?
import_type == 'gitea'
end
def github_import?
import_type == 'github'
end
def check_limit
unless creator.can_create_project? || namespace.kind == 'group'
projects_limit = creator.projects_limit
......
......@@ -11,13 +11,11 @@ class ImportService < BaseService
# supported by an importer class (`Gitlab::GithubImport::ParallelImporter`
# for example).
def async?
return false unless has_importer?
!!importer_class.try(:async?)
has_importer? && !!importer_class.try(:async?)
end
def execute
add_repository_to_project unless project.gitlab_project_import?
add_repository_to_project
import_data
......@@ -29,6 +27,14 @@ def execute
private
def add_repository_to_project
if project.external_import? && !unknown_url?
raise Error, 'Blocked import URL.' if Gitlab::UrlBlocker.blocked_url?(project.import_url)
end
# We should skip the repository for a GitHub import or GitLab project import,
# because these importers fetch the project repositories for us.
return if has_importer? && importer_class.try(:imports_repository?)
if unknown_url?
# In this case, we only want to import issues, not a repository.
create_repository
......@@ -44,12 +50,6 @@ def create_repository
end
def import_repository
raise Error, 'Blocked import URL.' if Gitlab::UrlBlocker.blocked_url?(project.import_url)
# We should return early for a GitHub import because the new GitHub
# importer fetch the project repositories for us.
return if project.github_import?
begin
if project.gitea_import?
fetch_repository
......@@ -88,7 +88,7 @@ def import_data
end
def importer_class
Gitlab::ImportSources.importer(project.import_type)
@importer_class ||= Gitlab::ImportSources.importer(project.import_type)
end
def has_importer?
......
......@@ -11,6 +11,10 @@ def self.async?
true
end
def self.imports_repository?
true
end
def initialize(project)
@project = project
end
......
module Gitlab
module ImportExport
class Importer
def self.imports_repository?
true
end
def initialize(project)
@archive_file = project.import_source
@current_user = project.creator
......
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