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
470ece08
Commit
470ece08
authored
Oct 21, 2021
by
Glen P Miller
Committed by
Alex Pooley
Oct 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update BitBucket Server importer username mapping
parent
0407fa98
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
23 deletions
+63
-23
doc/user/project/import/bitbucket_server.md
doc/user/project/import/bitbucket_server.md
+1
-4
lib/gitlab/bitbucket_server_import/importer.rb
lib/gitlab/bitbucket_server_import/importer.rb
+7
-3
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
+55
-16
No files found.
doc/user/project/import/bitbucket_server.md
View file @
470ece08
...
@@ -78,10 +78,7 @@ the author's:
...
@@ -78,10 +78,7 @@ the author's:
-
`slug`
-
`slug`
-
`displayName`
-
`displayName`
If the user is not found by any of these properties, the search falls back to the author's
If the user is not found by any of these properties, the project creator is set as the author.
`email`
address.
Alternatively, if there is also no email address, the project creator is set as the author.
##### Enable or disable User assignment by username
##### Enable or disable User assignment by username
...
...
lib/gitlab/bitbucket_server_import/importer.rb
View file @
470ece08
...
@@ -461,11 +461,15 @@ module Gitlab
...
@@ -461,11 +461,15 @@ module Gitlab
end
end
def
uid
(
rep_object
)
def
uid
(
rep_object
)
find_user_id
(
by: :email
,
value:
rep_object
.
author_email
)
unless
Feature
.
enabled?
(
:bitbucket_server_user_mapping_by_username
)
# We want this explicit to only be username on the FF
# Otherwise, match email.
find_user_id
(
by: :username
,
value:
rep_object
.
author_username
)
||
# There should be no default fall-through on username. Fall-through to import user
if
Feature
.
enabled?
(
:bitbucket_server_user_mapping_by_username
)
find_user_id
(
by: :username
,
value:
rep_object
.
author_username
)
else
find_user_id
(
by: :email
,
value:
rep_object
.
author_email
)
find_user_id
(
by: :email
,
value:
rep_object
.
author_email
)
end
end
end
end
end
end
end
end
end
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
View file @
470ece08
...
@@ -142,7 +142,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
...
@@ -142,7 +142,7 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
merge_request
=
MergeRequest
.
first
merge_request
=
MergeRequest
.
first
expect
(
merge_request
.
author
).
to
eq
(
pull_request
_author
)
expect
(
merge_request
.
author
).
to
eq
(
expected
_author
)
end
end
end
end
...
@@ -151,27 +151,50 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
...
@@ -151,27 +151,50 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
stub_feature_flags
(
bitbucket_server_user_mapping_by_username:
false
)
stub_feature_flags
(
bitbucket_server_user_mapping_by_username:
false
)
end
end
context
'when email is not present'
do
before
do
allow
(
pull_request
).
to
receive
(
:author_email
).
and_return
(
nil
)
end
let
(
:expected_author
)
{
project_creator
}
include_examples
'imports pull requests'
end
context
'when email is present'
do
before
do
allow
(
pull_request
).
to
receive
(
:author_email
).
and_return
(
pull_request_author
.
email
)
end
let
(
:expected_author
)
{
pull_request_author
}
include_examples
'imports pull requests'
include_examples
'imports pull requests'
end
end
end
context
'when bitbucket_server_user_mapping_by_username feature flag is enabled'
do
context
'when bitbucket_server_user_mapping_by_username feature flag is enabled'
do
before
do
before
do
stub_feature_flags
(
bitbucket_server_user_mapping_by_username:
true
)
stub_feature_flags
(
bitbucket_server_user_mapping_by_username:
true
)
end
end
include_examples
'imports pull requests'
do
context
'when username is not present'
do
context
'when username is not present'
do
before
do
before
do
allow
(
pull_request
).
to
receive
(
:author_username
).
and_return
(
nil
)
allow
(
pull_request
).
to
receive
(
:author_username
).
and_return
(
nil
)
end
end
it
'maps by email'
do
let
(
:expected_author
)
{
project_creator
}
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
merge_request
=
MergeRequest
.
first
include_examples
'imports pull requests'
expect
(
merge_request
.
author
).
to
eq
(
pull_request_author
)
end
end
context
'when username is present'
do
before
do
allow
(
pull_request
).
to
receive
(
:author_username
).
and_return
(
pull_request_author
.
username
)
end
end
let
(
:expected_author
)
{
pull_request_author
}
include_examples
'imports pull requests'
end
end
end
end
...
@@ -228,7 +251,23 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
...
@@ -228,7 +251,23 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
allow
(
subject
.
client
).
to
receive
(
:activities
).
and_return
([
pr_comment
])
allow
(
subject
.
client
).
to
receive
(
:activities
).
and_return
([
pr_comment
])
end
end
it
'maps by email'
do
it
'defaults to import user'
do
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
merge_request
=
MergeRequest
.
first
expect
(
merge_request
.
notes
.
count
).
to
eq
(
1
)
note
=
merge_request
.
notes
.
first
expect
(
note
.
author
).
to
eq
(
project_creator
)
end
end
context
'when username is present'
do
before
do
allow
(
pr_note
).
to
receive
(
:author_username
).
and_return
(
note_author
.
username
)
allow
(
subject
.
client
).
to
receive
(
:activities
).
and_return
([
pr_comment
])
end
it
'maps by username'
do
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
merge_request
=
MergeRequest
.
first
merge_request
=
MergeRequest
.
first
...
@@ -384,13 +423,13 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
...
@@ -384,13 +423,13 @@ RSpec.describe Gitlab::BitbucketServerImport::Importer do
allow
(
inline_note
).
to
receive
(
:author_username
).
and_return
(
nil
)
allow
(
inline_note
).
to
receive
(
:author_username
).
and_return
(
nil
)
end
end
it
'
maps by email
'
do
it
'
defaults to import user
'
do
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
notes
=
MergeRequest
.
first
.
notes
.
order
(
:id
).
to_a
notes
=
MergeRequest
.
first
.
notes
.
order
(
:id
).
to_a
expect
(
notes
.
first
.
author
).
to
eq
(
inline_note_auth
or
)
expect
(
notes
.
first
.
author
).
to
eq
(
project_creat
or
)
expect
(
notes
.
last
.
author
).
to
eq
(
reply_auth
or
)
expect
(
notes
.
last
.
author
).
to
eq
(
project_creat
or
)
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