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
Jérome Perrin
gitlab-ce
Commits
7985b522
Commit
7985b522
authored
Dec 16, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BB importer: Adressed more review comments
parent
445e83eb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
15 deletions
+23
-15
changelogs/unreleased/bitbucket-oauth2.yml
changelogs/unreleased/bitbucket-oauth2.yml
+4
-0
lib/gitlab/bitbucket_import/importer.rb
lib/gitlab/bitbucket_import/importer.rb
+19
-15
No files found.
changelogs/unreleased/bitbucket-oauth2.yml
0 → 100644
View file @
7985b522
---
title
:
Refactor Bitbucket importer to use BitBucket API Version
2
merge_request
:
author
:
lib/gitlab/bitbucket_import/importer.rb
View file @
7985b522
...
@@ -6,7 +6,7 @@ module Gitlab
...
@@ -6,7 +6,7 @@ module Gitlab
{
title:
'proposal'
,
color:
'#69D100'
},
{
title:
'proposal'
,
color:
'#69D100'
},
{
title:
'task'
,
color:
'#7F8C8D'
}].
freeze
{
title:
'task'
,
color:
'#7F8C8D'
}].
freeze
attr_reader
:project
,
:client
,
:errors
attr_reader
:project
,
:client
,
:errors
,
:users
def
initialize
(
project
)
def
initialize
(
project
)
@project
=
project
@project
=
project
...
@@ -14,6 +14,7 @@ module Gitlab
...
@@ -14,6 +14,7 @@ module Gitlab
@formatter
=
Gitlab
::
ImportFormatter
.
new
@formatter
=
Gitlab
::
ImportFormatter
.
new
@labels
=
{}
@labels
=
{}
@errors
=
[]
@errors
=
[]
@users
=
{}
end
end
def
execute
def
execute
...
@@ -36,17 +37,18 @@ module Gitlab
...
@@ -36,17 +37,18 @@ module Gitlab
end
end
def
gitlab_user_id
(
project
,
username
)
def
gitlab_user_id
(
project
,
username
)
user
=
find_user
(
username
)
find_user_id
(
username
)
||
project
.
creator_id
user
.
try
(
:id
)
||
project
.
creator_id
end
end
def
find_user
(
username
)
def
find_user
_id
(
username
)
return
nil
unless
username
return
nil
unless
username
User
.
joins
(
:identities
).
find_by
(
"identities.extern_uid = ? AND identities.provider = 'bitbucket'"
,
username
)
end
def
existing_gitlab_user?
(
username
)
return
users
[
username
]
if
users
.
key?
(
username
)
username
&&
find_user
(
username
)
users
[
username
]
=
User
.
select
(
:id
)
.
joins
(
:identities
)
.
find_by
(
"identities.extern_uid = ? AND identities.provider = 'bitbucket'"
,
username
)
.
try
(
:id
)
end
end
def
repo
def
repo
...
@@ -58,16 +60,18 @@ module Gitlab
...
@@ -58,16 +60,18 @@ module Gitlab
create_labels
create_labels
gitlab_issue
=
nil
client
.
issues
(
repo
).
each
do
|
issue
|
client
.
issues
(
repo
).
each
do
|
issue
|
begin
begin
description
=
''
description
=
''
description
+=
@formatter
.
author_line
(
issue
.
author
)
unless
existing_gitlab_user?
(
issue
.
author
)
description
+=
@formatter
.
author_line
(
issue
.
author
)
unless
find_user_id
(
issue
.
author
)
description
+=
issue
.
description
description
+=
issue
.
description
label_name
=
issue
.
kind
label_name
=
issue
.
kind
milestone
=
issue
.
milestone
?
project
.
milestones
.
find_or_create_by
(
title:
issue
.
milestone
)
:
nil
milestone
=
issue
.
milestone
?
project
.
milestones
.
find_or_create_by
(
title:
issue
.
milestone
)
:
nil
issue
=
project
.
issues
.
create!
(
gitlab_
issue
=
project
.
issues
.
create!
(
iid:
issue
.
iid
,
iid:
issue
.
iid
,
title:
issue
.
title
,
title:
issue
.
title
,
description:
description
,
description:
description
,
...
@@ -81,9 +85,9 @@ module Gitlab
...
@@ -81,9 +85,9 @@ module Gitlab
errors
<<
{
type: :issue
,
iid:
issue
.
iid
,
errors:
e
.
message
}
errors
<<
{
type: :issue
,
iid:
issue
.
iid
,
errors:
e
.
message
}
end
end
issue
.
labels
<<
@labels
[
label_name
]
gitlab_
issue
.
labels
<<
@labels
[
label_name
]
if
issue
.
persisted?
if
gitlab_
issue
.
persisted?
client
.
issue_comments
(
repo
,
issue
.
iid
).
each
do
|
comment
|
client
.
issue_comments
(
repo
,
issue
.
iid
).
each
do
|
comment
|
# The note can be blank for issue service messages like "Changed title: ..."
# The note can be blank for issue service messages like "Changed title: ..."
# We would like to import those comments as well but there is no any
# We would like to import those comments as well but there is no any
...
@@ -93,11 +97,11 @@ module Gitlab
...
@@ -93,11 +97,11 @@ module Gitlab
next
unless
comment
.
note
.
present?
next
unless
comment
.
note
.
present?
note
=
''
note
=
''
note
+=
@formatter
.
author_line
(
comment
.
author
)
unless
existing_gitlab_user?
(
comment
.
author
)
note
+=
@formatter
.
author_line
(
comment
.
author
)
unless
find_user_id
(
comment
.
author
)
note
+=
comment
.
note
note
+=
comment
.
note
begin
begin
issue
.
notes
.
create!
(
gitlab_
issue
.
notes
.
create!
(
project:
project
,
project:
project
,
note:
note
,
note:
note
,
author_id:
gitlab_user_id
(
project
,
comment
.
author
),
author_id:
gitlab_user_id
(
project
,
comment
.
author
),
...
@@ -124,7 +128,7 @@ module Gitlab
...
@@ -124,7 +128,7 @@ module Gitlab
pull_requests
.
each
do
|
pull_request
|
pull_requests
.
each
do
|
pull_request
|
begin
begin
description
=
''
description
=
''
description
+=
@formatter
.
author_line
(
pull_request
.
author
)
unless
existing_gitlab_user?
(
pull_request
.
author
)
description
+=
@formatter
.
author_line
(
pull_request
.
author
)
unless
find_user_id
(
pull_request
.
author
)
description
+=
pull_request
.
description
description
+=
pull_request
.
description
merge_request
=
project
.
merge_requests
.
create
(
merge_request
=
project
.
merge_requests
.
create
(
...
...
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