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
Léo-Paul Géneau
gitlab-ce
Commits
da02df04
Commit
da02df04
authored
Jul 17, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup and test threaded discussions
parent
78f23d3c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
41 deletions
+51
-41
lib/gitlab/bitbucket_server_import/importer.rb
lib/gitlab/bitbucket_server_import/importer.rb
+11
-16
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
+40
-25
No files found.
lib/gitlab/bitbucket_server_import/importer.rb
View file @
da02df04
...
@@ -83,7 +83,7 @@ module Gitlab
...
@@ -83,7 +83,7 @@ module Gitlab
end
end
created_branches
=
restore_branch_shas
(
shas_to_restore
)
created_branches
=
restore_branch_shas
(
shas_to_restore
)
@temp_branches
<<
created_branches
@temp_branches
+=
created_branches
import_repository
unless
created_branches
.
empty?
import_repository
unless
created_branches
.
empty?
end
end
...
@@ -200,7 +200,7 @@ module Gitlab
...
@@ -200,7 +200,7 @@ module Gitlab
inline_comments
,
pr_comments
=
comments
.
partition
(
&
:inline_comment?
)
inline_comments
,
pr_comments
=
comments
.
partition
(
&
:inline_comment?
)
import_inline_comments
(
inline_comments
.
map
(
&
:comment
),
pull_request
,
merge_request
)
import_inline_comments
(
inline_comments
.
map
(
&
:comment
),
merge_request
)
import_standalone_pr_comments
(
pr_comments
.
map
(
&
:comment
),
merge_request
)
import_standalone_pr_comments
(
pr_comments
.
map
(
&
:comment
),
merge_request
)
end
end
...
@@ -213,32 +213,27 @@ module Gitlab
...
@@ -213,32 +213,27 @@ module Gitlab
metric
.
update
(
merged_by_id:
user_id
,
merged_at:
timestamp
)
metric
.
update
(
merged_by_id:
user_id
,
merged_at:
timestamp
)
end
end
def
import_inline_comments
(
inline_comments
,
pull_request
,
merge_request
)
def
import_inline_comments
(
inline_comments
,
merge_request
)
inline_comments
.
each
do
|
comment
|
inline_comments
.
each
do
|
comment
|
parent
=
build_diff_note
(
merge_request
,
comment
)
position
=
build_position
(
merge_request
,
comment
)
parent
=
build_diff_note
(
merge_request
,
comment
,
position
)
next
unless
parent
&
.
persisted?
next
unless
parent
&
.
persisted?
discussion_id
=
parent
.
discussion_id
comment
.
comments
.
each
do
|
reply
|
comment
.
comments
.
each
do
|
reply
|
begin
build_diff_note
(
merge_request
,
reply
,
position
,
discussion_id
)
attributes
=
pull_request_comment_attributes
(
reply
)
attributes
.
merge!
(
position:
build_position
(
merge_request
,
comment
),
discussion_id:
parent
.
discussion_id
,
type:
'DiffNote'
)
merge_request
.
notes
.
create!
(
attributes
)
rescue
StandardError
=>
e
errors
<<
{
type: :pull_request
,
id:
comment
.
id
,
errors:
e
.
message
}
end
end
end
end
end
end
end
def
build_diff_note
(
merge_request
,
comment
)
def
build_diff_note
(
merge_request
,
comment
,
position
,
discussion_id
=
nil
)
attributes
=
pull_request_comment_attributes
(
comment
)
attributes
=
pull_request_comment_attributes
(
comment
)
attributes
.
merge!
(
attributes
.
merge!
(
position:
build_position
(
merge_request
,
comment
)
,
position:
position
,
type:
'DiffNote'
)
type:
'DiffNote'
)
attributes
[
:discussion_id
]
=
discussion_id
if
discussion_id
merge_request
.
notes
.
create!
(
attributes
)
merge_request
.
notes
.
create!
(
attributes
)
rescue
StandardError
=>
e
rescue
StandardError
=>
e
...
...
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
View file @
da02df04
...
@@ -4,6 +4,7 @@ describe Gitlab::BitbucketServerImport::Importer do
...
@@ -4,6 +4,7 @@ describe Gitlab::BitbucketServerImport::Importer do
include
ImportSpecHelper
include
ImportSpecHelper
let
(
:project
)
{
create
(
:project
,
:repository
,
import_url:
'http://my-bitbucket'
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
import_url:
'http://my-bitbucket'
)
}
let
(
:now
)
{
Time
.
now
.
utc
.
change
(
usec:
0
)
}
subject
{
described_class
.
new
(
project
)
}
subject
{
described_class
.
new
(
project
)
}
...
@@ -63,15 +64,15 @@ describe Gitlab::BitbucketServerImport::Importer do
...
@@ -63,15 +64,15 @@ describe Gitlab::BitbucketServerImport::Importer do
comment?:
false
,
comment?:
false
,
merge_event?:
true
,
merge_event?:
true
,
committer_email:
project
.
owner
.
email
,
committer_email:
project
.
owner
.
email
,
merge_timestamp:
Time
.
now
.
utc
.
change
(
usec:
0
)
)
merge_timestamp:
now
)
@pr_note
=
instance_double
(
@pr_note
=
instance_double
(
BitbucketServer
::
Representation
::
Comment
,
BitbucketServer
::
Representation
::
Comment
,
note:
'Hello world'
,
note:
'Hello world'
,
author_email:
'unknown@gmail.com'
,
author_email:
'unknown@gmail.com'
,
comments:
[],
comments:
[],
created_at:
Time
.
now
.
utc
.
change
(
usec:
0
)
,
created_at:
now
,
updated_at:
Time
.
now
.
utc
.
change
(
usec:
0
)
)
updated_at:
now
)
@pr_comment
=
instance_double
(
@pr_comment
=
instance_double
(
BitbucketServer
::
Representation
::
Activity
,
BitbucketServer
::
Representation
::
Activity
,
comment?:
true
,
comment?:
true
,
...
@@ -104,10 +105,15 @@ describe Gitlab::BitbucketServerImport::Importer do
...
@@ -104,10 +105,15 @@ describe Gitlab::BitbucketServerImport::Importer do
expect
(
note
.
updated_at
).
to
eq
(
@pr_note
.
created_at
)
expect
(
note
.
updated_at
).
to
eq
(
@pr_note
.
created_at
)
end
end
it
'imports threaded comments'
do
it
'imports threaded discussions'
do
end
reply
=
instance_double
(
BitbucketServer
::
Representation
::
PullRequestComment
,
author_email:
'someuser@gitlab.com'
,
note:
'I agree'
,
created_at:
now
,
updated_at:
now
)
it
'imports diff comments'
do
# https://gitlab.com/gitlab-org/gitlab-test/compare/c1acaa58bbcbc3eafe538cb8274ba387047b69f8...5937ac0a7beb003549fc5fd26fc247ad
# https://gitlab.com/gitlab-org/gitlab-test/compare/c1acaa58bbcbc3eafe538cb8274ba387047b69f8...5937ac0a7beb003549fc5fd26fc247ad
inline_note
=
instance_double
(
inline_note
=
instance_double
(
BitbucketServer
::
Representation
::
PullRequestComment
,
BitbucketServer
::
Representation
::
PullRequestComment
,
...
@@ -119,9 +125,9 @@ describe Gitlab::BitbucketServerImport::Importer do
...
@@ -119,9 +125,9 @@ describe Gitlab::BitbucketServerImport::Importer do
new_pos:
4
,
new_pos:
4
,
note:
'Hello world'
,
note:
'Hello world'
,
author_email:
'unknown@gmail.com'
,
author_email:
'unknown@gmail.com'
,
comments:
[],
comments:
[
reply
],
created_at:
Time
.
now
.
utc
.
change
(
usec:
0
)
,
created_at:
now
,
updated_at:
Time
.
now
.
utc
.
change
(
usec:
0
)
)
updated_at:
now
)
inline_comment
=
instance_double
(
inline_comment
=
instance_double
(
BitbucketServer
::
Representation
::
Activity
,
BitbucketServer
::
Representation
::
Activity
,
...
@@ -135,22 +141,31 @@ describe Gitlab::BitbucketServerImport::Importer do
...
@@ -135,22 +141,31 @@ 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
.
notes
.
count
).
to
eq
(
1
)
expect
(
merge_request
.
notes
.
count
).
to
eq
(
2
)
note
=
merge_request
.
notes
.
first
expect
(
merge_request
.
notes
.
map
(
&
:discussion_id
).
uniq
.
count
).
to
eq
(
1
)
expect
(
note
.
type
).
to
eq
(
'DiffNote'
)
notes
=
merge_request
.
notes
.
order
(
:id
).
to_a
expect
(
note
.
note
).
to
eq
(
inline_note
.
note
)
start_note
=
notes
.
first
expect
(
note
.
created_at
).
to
eq
(
inline_note
.
created_at
)
expect
(
start_note
.
type
).
to
eq
(
'DiffNote'
)
expect
(
note
.
updated_at
).
to
eq
(
inline_note
.
updated_at
)
expect
(
start_note
.
note
).
to
eq
(
inline_note
.
note
)
expect
(
start_note
.
created_at
).
to
eq
(
inline_note
.
created_at
)
expect
(
note
.
position
.
base_sha
).
to
eq
(
inline_note
.
from_sha
)
expect
(
start_note
.
updated_at
).
to
eq
(
inline_note
.
updated_at
)
expect
(
note
.
position
.
start_sha
).
to
eq
(
inline_note
.
from_sha
)
expect
(
start_note
.
position
.
base_sha
).
to
eq
(
inline_note
.
from_sha
)
expect
(
note
.
position
.
head_sha
).
to
eq
(
inline_note
.
to_sha
)
expect
(
start_note
.
position
.
start_sha
).
to
eq
(
inline_note
.
from_sha
)
expect
(
note
.
position
.
old_line
).
to
be_nil
expect
(
start_note
.
position
.
head_sha
).
to
eq
(
inline_note
.
to_sha
)
expect
(
note
.
position
.
new_line
).
to
eq
(
inline_note
.
new_pos
)
expect
(
start_note
.
position
.
old_line
).
to
be_nil
end
expect
(
start_note
.
position
.
new_line
).
to
eq
(
inline_note
.
new_pos
)
it
'falls back to comments if diff comments'
do
reply_note
=
notes
.
last
expect
(
reply_note
.
note
).
to
eq
(
reply
.
note
)
expect
(
reply_note
.
author
).
to
eq
(
project
.
owner
)
expect
(
reply_note
.
created_at
).
to
eq
(
reply
.
created_at
)
expect
(
reply_note
.
updated_at
).
to
eq
(
reply
.
created_at
)
expect
(
reply_note
.
position
.
base_sha
).
to
eq
(
inline_note
.
from_sha
)
expect
(
reply_note
.
position
.
start_sha
).
to
eq
(
inline_note
.
from_sha
)
expect
(
reply_note
.
position
.
head_sha
).
to
eq
(
inline_note
.
to_sha
)
expect
(
reply_note
.
position
.
old_line
).
to
be_nil
expect
(
reply_note
.
position
.
new_line
).
to
eq
(
inline_note
.
new_pos
)
end
end
it
'restores branches of inaccessible SHAs'
do
it
'restores branches of inaccessible SHAs'
do
...
...
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