Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
8da23661
Commit
8da23661
authored
Nov 15, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prefer polymorphism over specific type checks in Import service
parent
148f4079
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
19 additions
and
15 deletions
+19
-15
app/models/project.rb
app/models/project.rb
+0
-4
app/services/projects/import_service.rb
app/services/projects/import_service.rb
+11
-11
lib/gitlab/github_import/parallel_importer.rb
lib/gitlab/github_import/parallel_importer.rb
+4
-0
lib/gitlab/import_export/importer.rb
lib/gitlab/import_export/importer.rb
+4
-0
No files found.
app/models/project.rb
View file @
8da23661
...
@@ -704,10 +704,6 @@ class Project < ActiveRecord::Base
...
@@ -704,10 +704,6 @@ class Project < ActiveRecord::Base
import_type
==
'gitea'
import_type
==
'gitea'
end
end
def
github_import?
import_type
==
'github'
end
def
check_limit
def
check_limit
unless
creator
.
can_create_project?
||
namespace
.
kind
==
'group'
unless
creator
.
can_create_project?
||
namespace
.
kind
==
'group'
projects_limit
=
creator
.
projects_limit
projects_limit
=
creator
.
projects_limit
...
...
app/services/projects/import_service.rb
View file @
8da23661
...
@@ -11,13 +11,11 @@ module Projects
...
@@ -11,13 +11,11 @@ module Projects
# supported by an importer class (`Gitlab::GithubImport::ParallelImporter`
# supported by an importer class (`Gitlab::GithubImport::ParallelImporter`
# for example).
# for example).
def
async?
def
async?
return
false
unless
has_importer?
has_importer?
&&
!!
importer_class
.
try
(
:async?
)
!!
importer_class
.
try
(
:async?
)
end
end
def
execute
def
execute
add_repository_to_project
unless
project
.
gitlab_project_import?
add_repository_to_project
import_data
import_data
...
@@ -29,6 +27,14 @@ module Projects
...
@@ -29,6 +27,14 @@ module Projects
private
private
def
add_repository_to_project
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?
if
unknown_url?
# In this case, we only want to import issues, not a repository.
# In this case, we only want to import issues, not a repository.
create_repository
create_repository
...
@@ -44,12 +50,6 @@ module Projects
...
@@ -44,12 +50,6 @@ module Projects
end
end
def
import_repository
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
begin
if
project
.
gitea_import?
if
project
.
gitea_import?
fetch_repository
fetch_repository
...
@@ -88,7 +88,7 @@ module Projects
...
@@ -88,7 +88,7 @@ module Projects
end
end
def
importer_class
def
importer_class
Gitlab
::
ImportSources
.
importer
(
project
.
import_type
)
@importer_class
||=
Gitlab
::
ImportSources
.
importer
(
project
.
import_type
)
end
end
def
has_importer?
def
has_importer?
...
...
lib/gitlab/github_import/parallel_importer.rb
View file @
8da23661
...
@@ -11,6 +11,10 @@ module Gitlab
...
@@ -11,6 +11,10 @@ module Gitlab
true
true
end
end
def
self
.
imports_repository?
true
end
def
initialize
(
project
)
def
initialize
(
project
)
@project
=
project
@project
=
project
end
end
...
...
lib/gitlab/import_export/importer.rb
View file @
8da23661
module
Gitlab
module
Gitlab
module
ImportExport
module
ImportExport
class
Importer
class
Importer
def
self
.
imports_repository?
true
end
def
initialize
(
project
)
def
initialize
(
project
)
@archive_file
=
project
.
import_source
@archive_file
=
project
.
import_source
@current_user
=
project
.
creator
@current_user
=
project
.
creator
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment