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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
8fc63d1f
Commit
8fc63d1f
authored
Dec 16, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve Gitlab::ImportSources
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
99ddd1dc
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
125 additions
and
43 deletions
+125
-43
app/controllers/import/github_controller.rb
app/controllers/import/github_controller.rb
+1
-1
app/services/projects/import_service.rb
app/services/projects/import_service.rb
+2
-30
lib/gitlab/import_sources.rb
lib/gitlab/import_sources.rb
+28
-12
spec/lib/gitlab/import_sources_spec.rb
spec/lib/gitlab/import_sources_spec.rb
+94
-0
No files found.
app/controllers/import/github_controller.rb
View file @
8fc63d1f
...
...
@@ -82,7 +82,7 @@ class Import::GithubController < Import::BaseController
def
provider_unauthorized
session
[
:access_token
]
=
nil
redirect_to
new_import_url
,
alert:
"Access denied to your
#{
Gitlab
::
ImportSources
.
options
.
key
(
provider
.
to_s
)
}
account."
alert:
"Access denied to your
#{
Gitlab
::
ImportSources
.
title
(
provider
.
to_s
)
}
account."
end
def
access_params
...
...
app/services/projects/import_service.rb
View file @
8fc63d1f
...
...
@@ -4,16 +4,6 @@ module Projects
class
Error
<
StandardError
;
end
ALLOWED_TYPES
=
[
'github'
,
'bitbucket'
,
'gitlab'
,
'google_code'
,
'fogbugz'
,
'gitlab_project'
,
'gitea'
]
def
execute
add_repository_to_project
unless
project
.
gitlab_project_import?
...
...
@@ -65,29 +55,11 @@ module Projects
end
def
has_importer?
ALLOWED_TYPES
.
include?
(
project
.
import_type
)
Gitlab
::
ImportSources
.
importer_names
.
include?
(
project
.
import_type
)
end
def
importer
return
Gitlab
::
ImportExport
::
Importer
.
new
(
project
)
if
@project
.
gitlab_project_import?
class_name
=
case
project
.
import_type
when
'github'
,
'gitea'
Gitlab
::
GithubImport
::
Importer
when
'bitbucket'
Gitlab
::
BitbucketImport
::
Importer
when
'gitlab'
Gitlab
::
GitlabImport
::
Importer
when
'google_code'
Gitlab
::
GoogleCodeImport
::
Importer
when
'fogbugz'
Gitlab
::
FogbugzImport
::
Importer
else
raise
'Unknown importer type!'
end
class_name
.
new
(
project
)
Gitlab
::
ImportSources
.
importer
(
project
.
import_type
).
new
(
project
)
end
def
unknown_url?
...
...
lib/gitlab/import_sources.rb
View file @
8fc63d1f
...
...
@@ -7,22 +7,38 @@ module Gitlab
module
ImportSources
extend
CurrentSettings
ImportSource
=
Struct
.
new
(
:name
,
:title
,
:importer
)
ImportTable
=
[
ImportSource
.
new
(
'github'
,
'GitHub'
,
Gitlab
::
GithubImport
::
Importer
),
ImportSource
.
new
(
'bitbucket'
,
'Bitbucket'
,
Gitlab
::
BitbucketImport
::
Importer
),
ImportSource
.
new
(
'gitlab'
,
'GitLab.com'
,
Gitlab
::
GitlabImport
::
Importer
),
ImportSource
.
new
(
'google_code'
,
'Google Code'
,
Gitlab
::
GoogleCodeImport
::
Importer
),
ImportSource
.
new
(
'fogbugz'
,
'FogBugz'
,
Gitlab
::
FogbugzImport
::
Importer
),
ImportSource
.
new
(
'git'
,
'Repo by URL'
,
nil
),
ImportSource
.
new
(
'gitlab_project'
,
'GitLab export'
,
Gitlab
::
ImportExport
::
Importer
),
ImportSource
.
new
(
'gitea'
,
'Gitea'
,
Gitlab
::
GithubImport
::
Importer
)
].
freeze
class
<<
self
def
options
@options
||=
Hash
[
ImportTable
.
map
{
|
importer
|
[
importer
.
title
,
importer
.
name
]
}]
end
def
values
options
.
values
@values
||=
ImportTable
.
map
(
&
:name
)
end
def
options
{
'GitHub'
=>
'github'
,
'Bitbucket'
=>
'bitbucket'
,
'GitLab.com'
=>
'gitlab'
,
'Google Code'
=>
'google_code'
,
'FogBugz'
=>
'fogbugz'
,
'Repo by URL'
=>
'git'
,
'GitLab export'
=>
'gitlab_project'
,
'Gitea'
=>
'gitea'
}
def
importer_names
@importer_names
||=
ImportTable
.
select
(
&
:importer
).
map
(
&
:name
)
end
def
importer
(
name
)
ImportTable
.
find
{
|
import_source
|
import_source
.
name
==
name
}.
importer
end
def
title
(
name
)
options
.
key
(
name
)
end
end
end
...
...
spec/lib/gitlab/import_sources_spec.rb
0 → 100644
View file @
8fc63d1f
require
'spec_helper'
describe
Gitlab
::
ImportSources
do
describe
'.options'
do
it
'returns a hash'
do
expected
=
{
'GitHub'
=>
'github'
,
'Bitbucket'
=>
'bitbucket'
,
'GitLab.com'
=>
'gitlab'
,
'Google Code'
=>
'google_code'
,
'FogBugz'
=>
'fogbugz'
,
'Repo by URL'
=>
'git'
,
'GitLab export'
=>
'gitlab_project'
,
'Gitea'
=>
'gitea'
}
expect
(
described_class
.
options
).
to
eq
(
expected
)
end
end
describe
'.values'
do
it
'returns an array'
do
expected
=
[
'github'
,
'bitbucket'
,
'gitlab'
,
'google_code'
,
'fogbugz'
,
'git'
,
'gitlab_project'
,
'gitea'
]
expect
(
described_class
.
values
).
to
eq
(
expected
)
end
end
describe
'.importer_names'
do
it
'returns an array of importer names'
do
expected
=
[
'github'
,
'bitbucket'
,
'gitlab'
,
'google_code'
,
'fogbugz'
,
'gitlab_project'
,
'gitea'
]
expect
(
described_class
.
importer_names
).
to
eq
(
expected
)
end
end
describe
'.importer'
do
import_sources
=
{
'github'
=>
Gitlab
::
GithubImport
::
Importer
,
'bitbucket'
=>
Gitlab
::
BitbucketImport
::
Importer
,
'gitlab'
=>
Gitlab
::
GitlabImport
::
Importer
,
'google_code'
=>
Gitlab
::
GoogleCodeImport
::
Importer
,
'fogbugz'
=>
Gitlab
::
FogbugzImport
::
Importer
,
'git'
=>
nil
,
'gitlab_project'
=>
Gitlab
::
ImportExport
::
Importer
,
'gitea'
=>
Gitlab
::
GithubImport
::
Importer
}
import_sources
.
each
do
|
name
,
klass
|
it
"returns
#{
klass
}
when given
#{
name
}
"
do
expect
(
described_class
.
importer
(
name
)).
to
eq
(
klass
)
end
end
end
describe
'.title'
do
import_sources
=
{
'github'
=>
'GitHub'
,
'bitbucket'
=>
'Bitbucket'
,
'gitlab'
=>
'GitLab.com'
,
'google_code'
=>
'Google Code'
,
'fogbugz'
=>
'FogBugz'
,
'git'
=>
'Repo by URL'
,
'gitlab_project'
=>
'GitLab export'
,
'gitea'
=>
'Gitea'
}
import_sources
.
each
do
|
name
,
title
|
it
"returns
#{
title
}
when given
#{
name
}
"
do
expect
(
described_class
.
title
(
name
)).
to
eq
(
title
)
end
end
end
end
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