BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
317b0209
Commit
317b0209
authored
Aug 22, 2016
by
Douglas Barbosa Alexandre
Committed by
Stan Hu
Nov 21, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring Bitbucket importer to use the new OAuth2 client
parent
3c756b83
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
41 deletions
+33
-41
importer.rb
lib/gitlab/bitbucket_import/importer.rb
+33
-41
No files found.
lib/gitlab/bitbucket_import/importer.rb
View file @
317b0209
...
@@ -5,18 +5,14 @@ module Gitlab
...
@@ -5,18 +5,14 @@ module Gitlab
def
initialize
(
project
)
def
initialize
(
project
)
@project
=
project
@project
=
project
@client
=
Client
.
from_project
(
@project
)
@client
=
Bitbucket
::
Client
.
new
(
project
.
import_data
.
credentials
)
@formatter
=
Gitlab
::
ImportFormatter
.
new
@formatter
=
Gitlab
::
ImportFormatter
.
new
end
end
def
execute
def
execute
import_issues
if
has_issues?
import_issues
true
true
rescue
ActiveRecord
::
RecordInvalid
=>
e
raise
Projects
::
ImportService
::
Error
.
new
,
e
.
message
ensure
Gitlab
::
BitbucketImport
::
KeyDeleter
.
new
(
project
).
execute
end
end
private
private
...
@@ -30,44 +26,40 @@ module Gitlab
...
@@ -30,44 +26,40 @@ module Gitlab
end
end
end
end
def
identifier
def
repo
project
.
import_source
@repo
||=
client
.
repo
(
project
.
import_source
)
end
def
has_issues?
client
.
project
(
identifier
)[
"has_issues"
]
end
end
def
import_issues
def
import_issues
issues
=
client
.
issues
(
identifier
)
return
unless
repo
.
has_issues?
issues
.
each
do
|
issue
|
client
.
issues
(
repo
).
each
do
|
issue
|
body
=
''
description
=
@formatter
.
author_line
(
issue
.
author
)
reporter
=
nil
description
+=
issue
.
description
author
=
'Anonymous'
issue
=
project
.
issues
.
create
(
if
issue
[
"reported_by"
]
&&
issue
[
"reported_by"
][
"username"
]
iid:
issue
.
iid
,
reporter
=
issue
[
"reported_by"
][
"username"
]
title:
issue
.
title
,
author
=
reporter
description:
description
,
end
state:
issue
.
state
,
author_id:
gl_user_id
(
project
,
issue
.
author
),
body
=
@formatter
.
author_line
(
author
)
created_at:
issue
.
created_at
,
body
+=
issue
[
"content"
]
updated_at:
issue
.
updated_at
)
comments
=
client
.
issue_comments
(
identifier
,
issue
[
"local_id"
])
if
comments
.
any?
body
+=
@formatter
.
comments_header
end
comments
.
each
do
|
comment
|
author
=
'Anonymous'
if
comment
[
"author_info"
]
&&
comment
[
"author_info"
][
"username"
]
if
issue
.
persisted?
author
=
comment
[
"author_info"
][
"username"
]
client
.
issue_comments
(
repo
,
issue
.
iid
).
each
do
|
comment
|
note
=
@formatter
.
author_line
(
comment
.
author
)
note
+=
comment
.
note
issue
.
notes
.
create!
(
project:
project
,
note:
note
,
author_id:
gl_user_id
(
project
,
comment
.
author
),
created_at:
comment
.
created_at
,
updated_at:
comment
.
updated_at
)
end
end
body
+=
@formatter
.
comment
(
author
,
comment
[
"utc_created_on"
],
comment
[
"content"
])
end
end
project
.
issues
.
create!
(
project
.
issues
.
create!
(
...
@@ -77,8 +69,8 @@ module Gitlab
...
@@ -77,8 +69,8 @@ module Gitlab
author_id:
gitlab_user_id
(
project
,
reporter
)
author_id:
gitlab_user_id
(
project
,
reporter
)
)
)
end
end
rescue
ActiveRecord
::
RecordInvalid
=>
e
rescue
ActiveRecord
::
RecordInvalid
raise
Projects
::
ImportService
::
Error
,
e
.
message
nil
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