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
37fbda6f
Commit
37fbda6f
authored
Aug 13, 2020
by
Illya Klymov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix use of project_name instead of project_key for import
Correctly generate key and slug for bitbucket server importer
parent
9e404d35
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
6 deletions
+27
-6
app/serializers/import/bitbucket_server_provider_repo_entity.rb
...rializers/import/bitbucket_server_provider_repo_entity.rb
+4
-0
changelogs/unreleased/xanf-fix-bitbucket-server-importer-key.yml
...ogs/unreleased/xanf-fix-bitbucket-server-importer-key.yml
+5
-0
spec/controllers/import/bitbucket_server_controller_spec.rb
spec/controllers/import/bitbucket_server_controller_spec.rb
+14
-4
spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb
...zers/import/bitbucket_server_provider_repo_entity_spec.rb
+4
-2
No files found.
app/serializers/import/bitbucket_server_provider_repo_entity.rb
View file @
37fbda6f
# frozen_string_literal: true
class
Import::BitbucketServerProviderRepoEntity
<
Import
::
BitbucketProviderRepoEntity
expose
:id
,
override:
true
do
|
repo
|
"
#{
repo
.
project_key
}
/
#{
repo
.
slug
}
"
end
expose
:provider_link
,
override:
true
do
|
repo
,
options
|
repo
.
browse_url
end
...
...
changelogs/unreleased/xanf-fix-bitbucket-server-importer-key.yml
0 → 100644
View file @
37fbda6f
---
title
:
Fix failing bitbucket server import when project slug differs from name
merge_request
:
39433
author
:
type
:
fixed
spec/controllers/import/bitbucket_server_controller_spec.rb
View file @
37fbda6f
...
...
@@ -33,15 +33,18 @@ RSpec.describe Import::BitbucketServerController do
describe
'POST create'
do
let
(
:project_name
)
{
"my-project_123"
}
# rubocop: disable CodeReuse/ActiveRecord
before
do
allow
(
controller
).
to
receive
(
:client
).
and_return
(
client
)
repo
=
double
(
name:
project_name
)
allow
(
client
).
to
receive
(
:repo
).
with
(
project_key
,
repo_slug
).
and_return
(
repo
)
assign_session_tokens
end
# rubocop: enable CodeReuse/ActiveRecord
let_it_be
(
:project
)
{
create
(
:project
)
}
# rubocop: disable CodeReuse/ActiveRecord
it
'returns the new project'
do
allow
(
Gitlab
::
BitbucketServerImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
project_key
,
repo_slug
,
anything
,
project_name
,
user
.
namespace
,
user
,
anything
)
...
...
@@ -51,10 +54,12 @@ RSpec.describe Import::BitbucketServerController do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
# rubocop: enable CodeReuse/ActiveRecord
context
'with project key with tildes'
do
let
(
:project_key
)
{
'~someuser_123'
}
# rubocop: disable CodeReuse/ActiveRecord
it
'successfully creates a project'
do
allow
(
Gitlab
::
BitbucketServerImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
project_key
,
repo_slug
,
anything
,
project_name
,
user
.
namespace
,
user
,
anything
)
...
...
@@ -64,6 +69,7 @@ RSpec.describe Import::BitbucketServerController do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
it
'returns an error when an invalid project key is used'
do
...
...
@@ -78,6 +84,7 @@ RSpec.describe Import::BitbucketServerController do
expect
(
response
).
to
have_gitlab_http_status
(
:unprocessable_entity
)
end
# rubocop: disable CodeReuse/ActiveRecord
it
'returns an error when the project cannot be found'
do
allow
(
client
).
to
receive
(
:repo
).
with
(
project_key
,
repo_slug
).
and_return
(
nil
)
...
...
@@ -85,7 +92,9 @@ RSpec.describe Import::BitbucketServerController do
expect
(
response
).
to
have_gitlab_http_status
(
:unprocessable_entity
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
it
'returns an error when the project cannot be saved'
do
allow
(
Gitlab
::
BitbucketServerImport
::
ProjectCreator
)
.
to
receive
(
:new
).
with
(
project_key
,
repo_slug
,
anything
,
project_name
,
user
.
namespace
,
user
,
anything
)
...
...
@@ -95,7 +104,9 @@ RSpec.describe Import::BitbucketServerController do
expect
(
response
).
to
have_gitlab_http_status
(
:unprocessable_entity
)
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: disable CodeReuse/ActiveRecord
it
"returns an error when the server can't be contacted"
do
allow
(
client
).
to
receive
(
:repo
).
with
(
project_key
,
repo_slug
).
and_raise
(
::
BitbucketServer
::
Connection
::
ConnectionError
)
...
...
@@ -103,6 +114,7 @@ RSpec.describe Import::BitbucketServerController do
expect
(
response
).
to
have_gitlab_http_status
(
:unprocessable_entity
)
end
# rubocop: enable CodeReuse/ActiveRecord
it_behaves_like
'project import rate limiter'
end
...
...
@@ -139,8 +151,6 @@ RSpec.describe Import::BitbucketServerController do
describe
'GET status'
do
render_views
let
(
:repos
)
{
instance_double
(
BitbucketServer
::
Collection
)
}
before
do
allow
(
controller
).
to
receive
(
:client
).
and_return
(
client
)
...
...
@@ -157,14 +167,14 @@ RSpec.describe Import::BitbucketServerController do
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
[
'incompatible_repos'
].
length
).
to
eq
(
1
)
expect
(
json_response
.
dig
(
"incompatible_repos"
,
0
,
"id"
)).
to
eq
(
@invalid_repo
.
full_name
)
expect
(
json_response
.
dig
(
"incompatible_repos"
,
0
,
"id"
)).
to
eq
(
"
#{
@invalid_repo
.
project_key
}
/
#{
@invalid_repo
.
slug
}
"
)
expect
(
json_response
[
'provider_repos'
].
length
).
to
eq
(
1
)
expect
(
json_response
.
dig
(
"provider_repos"
,
0
,
"id"
)).
to
eq
(
@repo
.
full_name
)
end
it_behaves_like
'import controller status'
do
let
(
:repo
)
{
@repo
}
let
(
:repo_id
)
{
@repo
.
full_name
}
let
(
:repo_id
)
{
"
#{
@repo
.
project_key
}
/
#{
@repo
.
slug
}
"
}
let
(
:import_source
)
{
@repo
.
browse_url
}
let
(
:provider_name
)
{
'bitbucket_server'
}
let
(
:client_repos_field
)
{
:repos
}
...
...
spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb
View file @
37fbda6f
...
...
@@ -6,8 +6,10 @@ RSpec.describe Import::BitbucketServerProviderRepoEntity do
let
(
:repo_data
)
do
{
'name'
=>
'test'
,
'slug'
=>
'TEST'
,
'project'
=>
{
'name'
=>
'demo'
'name'
=>
'demo'
,
'key'
=>
'DEM'
},
'links'
=>
{
'self'
=>
[
...
...
@@ -27,7 +29,7 @@ RSpec.describe Import::BitbucketServerProviderRepoEntity do
it_behaves_like
'exposes required fields for import entity'
do
let
(
:expected_values
)
do
{
id:
'
demo/test
'
,
id:
'
DEM/TEST
'
,
full_name:
'demo/test'
,
sanitized_name:
'test'
,
provider_link:
'http://local.bitbucket.server/demo/test.git'
...
...
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