summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-11-15 13:33:52 +0000
committerYorick Peterse <yorickpeterse@gmail.com>2017-11-15 13:33:52 +0000
commita4072db0198896242886d22c644ed91c1016aa8d (patch)
tree5d02ddbc23be5adfdad040bf3f25569d3788fee7
parent81e94ce1761b48b73be2a8d71938dfe934921e35 (diff)
parent8da236611b5182a1105111904027ae3e74ed1682 (diff)
downloadgitlab-ce-40186-the-ee_compat_check-job-sometimes-fail-on-the-git-apply-3way-step-for-forks.tar.gz
Merge branch 'dm-import-service-polymorphism' into 'master'40186-the-ee_compat_check-job-sometimes-fail-on-the-git-apply-3way-step-for-forks
Prefer polymorphism over specific type checks in Import service See merge request gitlab-org/gitlab-ce!15397
-rw-r--r--app/models/project.rb4
-rw-r--r--app/services/projects/import_service.rb22
-rw-r--r--lib/gitlab/github_import/parallel_importer.rb4
-rw-r--r--lib/gitlab/import_export/importer.rb4
4 files changed, 19 insertions, 15 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 853f6bc504a..894ded2a9f6 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -704,10 +704,6 @@ class Project < ActiveRecord::Base
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
diff --git a/app/services/projects/import_service.rb b/app/services/projects/import_service.rb
index c950da44aba..c3b11341b4d 100644
--- a/app/services/projects/import_service.rb
+++ b/app/services/projects/import_service.rb
@@ -11,13 +11,11 @@ module Projects
# 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 @@ module Projects
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 @@ module Projects
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 @@ module Projects
end
def importer_class
- Gitlab::ImportSources.importer(project.import_type)
+ @importer_class ||= Gitlab::ImportSources.importer(project.import_type)
end
def has_importer?
diff --git a/lib/gitlab/github_import/parallel_importer.rb b/lib/gitlab/github_import/parallel_importer.rb
index 81739834b41..6da11e6ef08 100644
--- a/lib/gitlab/github_import/parallel_importer.rb
+++ b/lib/gitlab/github_import/parallel_importer.rb
@@ -11,6 +11,10 @@ module Gitlab
true
end
+ def self.imports_repository?
+ true
+ end
+
def initialize(project)
@project = project
end
diff --git a/lib/gitlab/import_export/importer.rb b/lib/gitlab/import_export/importer.rb
index fbdd74788bc..c14646b0611 100644
--- a/lib/gitlab/import_export/importer.rb
+++ b/lib/gitlab/import_export/importer.rb
@@ -1,6 +1,10 @@
module Gitlab
module ImportExport
class Importer
+ def self.imports_repository?
+ true
+ end
+
def initialize(project)
@archive_file = project.import_source
@current_user = project.creator