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
b9380cdf
Commit
b9380cdf
authored
Jun 09, 2020
by
Illya Klymov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address reviewer comments
- make tests more precise - remove owner_name from serializing
parent
ad362640
Changes
15
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
88 additions
and
71 deletions
+88
-71
app/controllers/import/bitbucket_controller.rb
app/controllers/import/bitbucket_controller.rb
+1
-3
app/controllers/import/bitbucket_server_controller.rb
app/controllers/import/bitbucket_server_controller.rb
+16
-12
app/controllers/import/fogbugz_controller.rb
app/controllers/import/fogbugz_controller.rb
+1
-3
app/serializers/import/base_provider_repo_entity.rb
app/serializers/import/base_provider_repo_entity.rb
+0
-1
app/serializers/import/bitbucket_provider_repo_entity.rb
app/serializers/import/bitbucket_provider_repo_entity.rb
+0
-4
app/serializers/import/bitbucket_server_provider_repo_entity.rb
...rializers/import/bitbucket_server_provider_repo_entity.rb
+0
-4
app/serializers/import/fogbugz_provider_repo_entity.rb
app/serializers/import/fogbugz_provider_repo_entity.rb
+0
-4
app/serializers/import/githubish_provider_repo_entity.rb
app/serializers/import/githubish_provider_repo_entity.rb
+0
-4
spec/controllers/import/bitbucket_controller_spec.rb
spec/controllers/import/bitbucket_controller_spec.rb
+1
-1
spec/serializers/import/bitbucket_provider_repo_entity_spec.rb
...serializers/import/bitbucket_provider_repo_entity_spec.rb
+16
-7
spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb
...zers/import/bitbucket_server_provider_repo_entity_spec.rb
+17
-8
spec/serializers/import/fogbugz_provider_repo_entity_spec.rb
spec/serializers/import/fogbugz_provider_repo_entity_spec.rb
+14
-4
spec/serializers/import/githubish_provider_repo_entity_spec.rb
...serializers/import/githubish_provider_repo_entity_spec.rb
+13
-4
spec/serializers/import/provider_repo_serializer_spec.rb
spec/serializers/import/provider_repo_serializer_spec.rb
+1
-0
spec/support/shared_examples/serializers/import/import_entity_shared_examples.rb
...mples/serializers/import/import_entity_shared_examples.rb
+8
-12
No files found.
app/controllers/import/bitbucket_controller.rb
View file @
b9380cdf
...
@@ -24,9 +24,7 @@ class Import::BitbucketController < Import::BaseController
...
@@ -24,9 +24,7 @@ class Import::BitbucketController < Import::BaseController
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
status
def
status
if
Feature
.
enabled?
(
:new_import_ui
)
return
super
if
Feature
.
enabled?
(
:new_import_ui
)
return
super
end
bitbucket_client
=
Bitbucket
::
Client
.
new
(
credentials
)
bitbucket_client
=
Bitbucket
::
Client
.
new
(
credentials
)
repos
=
bitbucket_client
.
repos
(
filter:
sanitized_filter_param
)
repos
=
bitbucket_client
.
repos
(
filter:
sanitized_filter_param
)
...
...
app/controllers/import/bitbucket_server_controller.rb
View file @
b9380cdf
...
@@ -9,6 +9,8 @@ class Import::BitbucketServerController < Import::BaseController
...
@@ -9,6 +9,8 @@ class Import::BitbucketServerController < Import::BaseController
before_action
:bitbucket_auth
,
except:
[
:new
,
:configure
]
before_action
:bitbucket_auth
,
except:
[
:new
,
:configure
]
before_action
:validate_import_params
,
only:
[
:create
]
before_action
:validate_import_params
,
only:
[
:create
]
rescue_from
BitbucketServer
::
Connection
::
ConnectionError
,
with: :bitbucket_connection_error
# As a basic sanity check to prevent URL injection, restrict project
# As a basic sanity check to prevent URL injection, restrict project
# repository input and repository slugs to allowed characters. For Bitbucket:
# repository input and repository slugs to allowed characters. For Bitbucket:
#
#
...
@@ -61,14 +63,7 @@ class Import::BitbucketServerController < Import::BaseController
...
@@ -61,14 +63,7 @@ class Import::BitbucketServerController < Import::BaseController
# rubocop: disable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
def
status
def
status
if
Feature
.
enabled?
(
:new_import_ui
)
return
super
if
Feature
.
enabled?
(
:new_import_ui
)
begin
return
super
rescue
BitbucketServer
::
Connection
::
ConnectionError
=>
error
render
json:
{
error:
_
(
"Unable to connect to server: %{error}"
)
%
{
error:
error
}
},
status: :unprocessable_entity
return
end
end
@collection
=
client
.
repos
(
page_offset:
page_offset
,
limit:
limit_per_page
,
filter:
sanitized_filter_param
)
@collection
=
client
.
repos
(
page_offset:
page_offset
,
limit:
limit_per_page
,
filter:
sanitized_filter_param
)
@repos
,
@incompatible_repos
=
@collection
.
partition
{
|
repo
|
repo
.
valid?
}
@repos
,
@incompatible_repos
=
@collection
.
partition
{
|
repo
|
repo
.
valid?
}
...
@@ -78,10 +73,6 @@ class Import::BitbucketServerController < Import::BaseController
...
@@ -78,10 +73,6 @@ class Import::BitbucketServerController < Import::BaseController
already_added_projects_names
=
@already_added_projects
.
pluck
(
:import_source
)
already_added_projects_names
=
@already_added_projects
.
pluck
(
:import_source
)
@repos
.
reject!
{
|
repo
|
already_added_projects_names
.
include?
(
repo
.
browse_url
)
}
@repos
.
reject!
{
|
repo
|
already_added_projects_names
.
include?
(
repo
.
browse_url
)
}
rescue
BitbucketServer
::
Connection
::
ConnectionError
=>
error
flash
[
:alert
]
=
_
(
"Unable to connect to server: %{error}"
)
%
{
error:
error
}
clear_session_data
redirect_to
new_import_bitbucket_server_path
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
...
@@ -200,4 +191,17 @@ class Import::BitbucketServerController < Import::BaseController
...
@@ -200,4 +191,17 @@ class Import::BitbucketServerController < Import::BaseController
def
sanitized_filter_param
def
sanitized_filter_param
sanitize
(
params
[
:filter
])
sanitize
(
params
[
:filter
])
end
end
def
bitbucket_connection_error
(
error
)
respond_to
do
|
format
|
format
.
json
do
render
json:
{
error:
_
(
"Unable to connect to server: %{error}"
)
%
{
error:
error
}
},
status: :unprocessable_entity
end
format
.
html
do
flash
[
:alert
]
=
_
(
"Unable to connect to server: %{error}"
)
%
{
error:
error
}
clear_session_data
redirect_to
new_import_bitbucket_server_path
end
end
end
end
end
app/controllers/import/fogbugz_controller.rb
View file @
b9380cdf
...
@@ -50,9 +50,7 @@ class Import::FogbugzController < Import::BaseController
...
@@ -50,9 +50,7 @@ class Import::FogbugzController < Import::BaseController
return
redirect_to
new_import_fogbugz_path
return
redirect_to
new_import_fogbugz_path
end
end
if
Feature
.
enabled?
(
:new_import_ui
)
return
super
if
Feature
.
enabled?
(
:new_import_ui
)
return
super
end
@repos
=
client
.
repos
@repos
=
client
.
repos
...
...
app/serializers/import/base_provider_repo_entity.rb
View file @
b9380cdf
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
class
Import::BaseProviderRepoEntity
<
Grape
::
Entity
class
Import::BaseProviderRepoEntity
<
Grape
::
Entity
expose
:id
expose
:id
expose
:full_name
expose
:full_name
expose
:owner_name
expose
:sanitized_name
expose
:sanitized_name
expose
:provider_link
expose
:provider_link
end
end
app/serializers/import/bitbucket_provider_repo_entity.rb
View file @
b9380cdf
...
@@ -7,10 +7,6 @@ class Import::BitbucketProviderRepoEntity < Import::BaseProviderRepoEntity
...
@@ -7,10 +7,6 @@ class Import::BitbucketProviderRepoEntity < Import::BaseProviderRepoEntity
repo
.
full_name
repo
.
full_name
end
end
expose
:owner_name
,
override:
true
do
|
repo
|
repo
.
owner
end
expose
:sanitized_name
,
override:
true
do
|
repo
|
expose
:sanitized_name
,
override:
true
do
|
repo
|
repo
.
name
.
gsub
(
/[^\s\w.-]/
,
''
)
repo
.
name
.
gsub
(
/[^\s\w.-]/
,
''
)
end
end
...
...
app/serializers/import/bitbucket_server_provider_repo_entity.rb
View file @
b9380cdf
# frozen_string_literal: true
# frozen_string_literal: true
class
Import::BitbucketServerProviderRepoEntity
<
Import
::
BitbucketProviderRepoEntity
class
Import::BitbucketServerProviderRepoEntity
<
Import
::
BitbucketProviderRepoEntity
expose
:owner_name
,
override:
true
do
''
end
expose
:provider_link
,
override:
true
do
|
repo
,
options
|
expose
:provider_link
,
override:
true
do
|
repo
,
options
|
repo
.
browse_url
repo
.
browse_url
end
end
...
...
app/serializers/import/fogbugz_provider_repo_entity.rb
View file @
b9380cdf
...
@@ -7,10 +7,6 @@ class Import::FogbugzProviderRepoEntity < Import::BaseProviderRepoEntity
...
@@ -7,10 +7,6 @@ class Import::FogbugzProviderRepoEntity < Import::BaseProviderRepoEntity
repo
.
name
repo
.
name
end
end
expose
:owner_name
,
override:
true
do
''
end
expose
:sanitized_name
,
override:
true
do
|
repo
|
expose
:sanitized_name
,
override:
true
do
|
repo
|
repo
.
safe_name
repo
.
safe_name
end
end
...
...
app/serializers/import/githubish_provider_repo_entity.rb
View file @
b9380cdf
...
@@ -3,10 +3,6 @@
...
@@ -3,10 +3,6 @@
class
Import::GithubishProviderRepoEntity
<
Import
::
BaseProviderRepoEntity
class
Import::GithubishProviderRepoEntity
<
Import
::
BaseProviderRepoEntity
include
ImportHelper
include
ImportHelper
expose
:owner_name
,
override:
true
do
|
provider_repo
,
options
|
owner_name
(
provider_repo
,
options
[
:provider
])
end
expose
:sanitized_name
,
override:
true
do
|
provider_repo
|
expose
:sanitized_name
,
override:
true
do
|
provider_repo
|
sanitize_project_name
(
provider_repo
[
:name
])
sanitize_project_name
(
provider_repo
[
:name
])
end
end
...
...
spec/controllers/import/bitbucket_controller_spec.rb
View file @
b9380cdf
...
@@ -56,7 +56,7 @@ RSpec.describe Import::BitbucketController do
...
@@ -56,7 +56,7 @@ RSpec.describe Import::BitbucketController do
describe
"GET status"
do
describe
"GET status"
do
before
do
before
do
@repo
=
double
(
name:
'vim'
,
slug:
'vim'
,
owner:
'asd'
,
full_name:
'asd/vim'
,
clone_url:
"http://test.host/demo/url.git"
,
"valid?"
=>
true
)
@repo
=
double
(
name:
'vim'
,
slug:
'vim'
,
owner:
'asd'
,
full_name:
'asd/vim'
,
clone_url:
'http://test.host/demo/url.git'
,
'valid?'
=>
true
)
assign_session_tokens
assign_session_tokens
stub_feature_flags
(
new_import_ui:
false
)
stub_feature_flags
(
new_import_ui:
false
)
end
end
...
...
spec/serializers/import/bitbucket_provider_repo_entity_spec.rb
View file @
b9380cdf
...
@@ -5,13 +5,13 @@ require 'spec_helper'
...
@@ -5,13 +5,13 @@ require 'spec_helper'
describe
Import
::
BitbucketProviderRepoEntity
do
describe
Import
::
BitbucketProviderRepoEntity
do
let
(
:repo_data
)
do
let
(
:repo_data
)
do
{
{
"name"
=>
"repo_name"
,
'name'
=>
'repo_name'
,
"full_name"
=>
"owner/repo_name"
,
'full_name'
=>
'owner/repo_name'
,
"links"
=>
{
'links'
=>
{
"clone"
=>
[
'clone'
=>
[
{
{
"href"
=>
"https://bitbucket.org/owner/repo_name"
,
'href'
=>
'https://bitbucket.org/owner/repo_name'
,
"name"
=>
"https"
'name'
=>
'https'
}
}
]
]
}
}
...
@@ -21,5 +21,14 @@ describe Import::BitbucketProviderRepoEntity do
...
@@ -21,5 +21,14 @@ describe Import::BitbucketProviderRepoEntity do
subject
{
described_class
.
new
(
repo
).
as_json
}
subject
{
described_class
.
new
(
repo
).
as_json
}
it_behaves_like
'exposes required fields for import entity'
it_behaves_like
'exposes required fields for import entity'
do
let
(
:expected_values
)
do
{
id:
'owner/repo_name'
,
full_name:
'owner/repo_name'
,
sanitized_name:
'repo_name'
,
provider_link:
'https://bitbucket.org/owner/repo_name'
}
end
end
end
end
spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb
View file @
b9380cdf
...
@@ -5,15 +5,15 @@ require 'spec_helper'
...
@@ -5,15 +5,15 @@ require 'spec_helper'
describe
Import
::
BitbucketServerProviderRepoEntity
do
describe
Import
::
BitbucketServerProviderRepoEntity
do
let
(
:repo_data
)
do
let
(
:repo_data
)
do
{
{
"name"
=>
"demo"
,
'name'
=>
'test'
,
"project"
=>
{
'project'
=>
{
"name"
=>
"demo"
'name'
=>
'demo'
},
},
"links"
=>
{
'links'
=>
{
"self"
=>
[
'self'
=>
[
{
{
"href"
=>
"http://local.bitbucket.server/demo/demo.git"
,
'href'
=>
'http://local.bitbucket.server/demo/test.git'
,
"name"
=>
"http"
'name'
=>
'http'
}
}
]
]
}
}
...
@@ -23,5 +23,14 @@ describe Import::BitbucketServerProviderRepoEntity do
...
@@ -23,5 +23,14 @@ describe Import::BitbucketServerProviderRepoEntity do
subject
{
described_class
.
new
(
repo
).
as_json
}
subject
{
described_class
.
new
(
repo
).
as_json
}
it_behaves_like
'exposes required fields for import entity'
it_behaves_like
'exposes required fields for import entity'
do
let
(
:expected_values
)
do
{
id:
'demo/test'
,
full_name:
'demo/test'
,
sanitized_name:
'test'
,
provider_link:
'http://local.bitbucket.server/demo/test.git'
}
end
end
end
end
spec/serializers/import/fogbugz_provider_repo_entity_spec.rb
View file @
b9380cdf
...
@@ -3,15 +3,25 @@
...
@@ -3,15 +3,25 @@
require
'spec_helper'
require
'spec_helper'
describe
Import
::
FogbugzProviderRepoEntity
do
describe
Import
::
FogbugzProviderRepoEntity
do
let
(
:provider_url
)
{
'https://demo.fogbugz.com/'
}
let
(
:repo_data
)
do
let
(
:repo_data
)
do
{
{
"ixProject"
=>
"foo"
,
'ixProject'
=>
'foo'
,
"sProject"
=>
"demo"
'sProject'
=>
'demo'
}
}
end
end
let
(
:repo
)
{
Gitlab
::
FogbugzImport
::
Repository
.
new
(
repo_data
)
}
let
(
:repo
)
{
Gitlab
::
FogbugzImport
::
Repository
.
new
(
repo_data
)
}
subject
{
described_class
.
new
(
repo
).
as_json
}
subject
{
described_class
.
represent
(
repo
,
{
provider_url:
provider_url
}
).
as_json
}
it_behaves_like
'exposes required fields for import entity'
it_behaves_like
'exposes required fields for import entity'
do
let
(
:expected_values
)
do
{
id:
'foo'
,
full_name:
'demo'
,
sanitized_name:
'demo'
,
provider_link:
'https://demo.fogbugz.com/demo'
}
end
end
end
end
spec/serializers/import/githubish_provider_repo_entity_spec.rb
View file @
b9380cdf
...
@@ -3,16 +3,25 @@
...
@@ -3,16 +3,25 @@
require
'spec_helper'
require
'spec_helper'
describe
Import
::
GithubishProviderRepoEntity
do
describe
Import
::
GithubishProviderRepoEntity
do
let
(
:provider_url
)
{
'https://github.com/'
}
let
(
:repo
)
do
let
(
:repo
)
do
{
{
id:
1
,
id:
1
,
full_name:
'full/name'
,
full_name:
'full/name'
,
name:
'name'
,
name:
'name'
owner:
{
login:
'owner'
}
}
}
end
end
subject
{
described_class
.
new
(
repo
).
as_json
}
subject
{
described_class
.
represent
(
repo
,
{
provider_url:
provider_url
}
).
as_json
}
it_behaves_like
'exposes required fields for import entity'
it_behaves_like
'exposes required fields for import entity'
do
let
(
:expected_values
)
do
{
id:
1
,
full_name:
'full/name'
,
sanitized_name:
'name'
,
provider_link:
'https://github.com/full/name'
}
end
end
end
end
spec/serializers/import/provider_repo_serializer_spec.rb
View file @
b9380cdf
# frozen_string_literal: true
# frozen_string_literal: true
require
'spec_helper'
require
'spec_helper'
describe
Import
::
ProviderRepoSerializer
do
describe
Import
::
ProviderRepoSerializer
do
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
...
...
spec/support/shared_examples/serializers/import/import_entity_shared_examples.rb
View file @
b9380cdf
...
@@ -2,24 +2,20 @@
...
@@ -2,24 +2,20 @@
RSpec
.
shared_examples
'exposes required fields for import entity'
do
RSpec
.
shared_examples
'exposes required fields for import entity'
do
describe
'exposes required fields'
do
describe
'exposes required fields'
do
it
'exposes id'
do
it
'
correctly
exposes id'
do
expect
(
subject
).
to
include
(
:id
)
expect
(
subject
[
:id
]).
to
eql
(
expected_values
[
:id
]
)
end
end
it
'exposes full name'
do
it
'
correctly
exposes full name'
do
expect
(
subject
).
to
include
(
:full_name
)
expect
(
subject
[
:full_name
]).
to
eql
(
expected_values
[
:full_name
]
)
end
end
it
'
exposes owner
name'
do
it
'
correctly exposes sanitized
name'
do
expect
(
subject
).
to
include
(
:owner_name
)
expect
(
subject
[
:sanitized_name
]).
to
eql
(
expected_values
[
:sanitized_name
]
)
end
end
it
'exposes sanitized name'
do
it
'correctly exposes provider link'
do
expect
(
subject
).
to
include
(
:sanitized_name
)
expect
(
subject
[
:provider_link
]).
to
eql
(
expected_values
[
:provider_link
])
end
it
'exposes provider link'
do
expect
(
subject
).
to
include
(
:provider_link
)
end
end
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