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
Boxiang Sun
gitlab-ce
Commits
11dd390c
Commit
11dd390c
authored
Jul 15, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for pull request comments
parent
57c9a893
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
14 deletions
+41
-14
lib/gitlab/bitbucket_server_import/importer.rb
lib/gitlab/bitbucket_server_import/importer.rb
+9
-6
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
+32
-8
No files found.
lib/gitlab/bitbucket_server_import/importer.rb
View file @
11dd390c
...
...
@@ -55,7 +55,10 @@ module Gitlab
return
users
[
email
]
if
users
.
key?
(
email
)
users
[
email
]
=
User
.
find_by_any_email
(
email
)
user
=
User
.
find_by_any_email
(
email
)
users
[
email
]
=
user
&
.
id
if
user
user
&
.
id
end
def
repo
...
...
@@ -163,7 +166,7 @@ module Gitlab
target_branch_sha
=
pull_request
.
target_branch_sha
source_branch_sha
=
project
.
repository
.
commit
(
source_branch_sha
)
&
.
sha
||
source_branch_sha
target_branch_sha
=
project
.
repository
.
commit
(
target_branch_sha
)
&
.
sha
||
target_branch_sha
author
=
gitlab_user_id
(
project
,
pull_request
.
author_email
)
||
User
.
ghost
author
_id
=
gitlab_user_id
(
project
,
pull_request
.
author_email
)
||
User
.
ghost
.
id
project
.
merge_requests
.
find_by
(
iid:
pull_request
.
iid
)
&
.
destroy
...
...
@@ -178,7 +181,7 @@ module Gitlab
target_branch:
Gitlab
::
Git
.
ref_name
(
pull_request
.
target_branch_name
),
target_branch_sha:
target_branch_sha
,
state:
pull_request
.
state
,
author_id:
author
.
id
,
author_id:
author
_
id
,
assignee_id:
nil
,
created_at:
pull_request
.
created_at
,
updated_at:
pull_request
.
updated_at
...
...
@@ -204,11 +207,11 @@ module Gitlab
def
import_merge_event
(
merge_request
,
merge_event
)
committer
=
merge_event
.
committer_email
user
=
find_user_id
(
committer
)
if
committer
user
||=
User
.
ghost
user
_id
=
find_user_id
(
committer
)
if
committer
user
_id
||=
User
.
ghost
.
id
timestamp
=
merge_event
.
merge_timestamp
metric
=
MergeRequest
::
Metrics
.
find_or_initialize_by
(
merge_request:
merge_request
)
metric
.
update
_attributes
(
merged_by:
user
,
merged_at:
timestamp
)
metric
.
update
(
merged_by_id:
user_id
,
merged_at:
timestamp
)
end
def
import_inline_comments
(
inline_comments
,
pull_request
,
merge_request
)
...
...
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
View file @
11dd390c
...
...
@@ -56,25 +56,36 @@ describe Gitlab::BitbucketServerImport::Importer do
updated_at:
Time
.
now
,
merged?:
true
)
expect
(
subject
.
client
).
to
receive
(
:pull_requests
).
and_return
([
pull_request
])
allow
(
subject
.
client
).
to
receive
(
:pull_requests
).
and_return
([
pull_request
])
@merge_event
=
instance_double
(
BitbucketServer
::
Representation
::
Activity
,
comment?:
false
,
merge_event?:
true
,
committer_email:
project
.
owner
.
email
,
merge_timestamp:
Time
.
now
)
merge_timestamp:
Time
.
now
.
utc
.
change
(
usec:
0
)
)
@inline_comment
=
instance_double
(
BitbucketServer
::
Representation
::
Activity
,
comment?:
true
,
inline_comment?:
true
,
merge_event?:
false
)
@pr_note
=
instance_double
(
BitbucketServer
::
Representation
::
Comment
,
note:
'Hello world'
,
author_email:
'unknown@gmail.com'
,
comments:
[],
created_at:
Time
.
now
.
utc
.
change
(
usec:
0
),
updated_at:
Time
.
now
.
utc
.
change
(
usec:
0
))
@pr_comment
=
instance_double
(
BitbucketServer
::
Representation
::
Activity
,
comment?:
true
,
merge_event?:
false
)
inline_comment?:
false
,
merge_event?:
false
,
comment:
@pr_note
)
end
it
'
handle
s merge event'
do
it
'
import
s merge event'
do
expect
(
subject
.
client
).
to
receive
(
:activities
).
and_return
([
@merge_event
])
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
...
...
@@ -84,19 +95,32 @@ describe Gitlab::BitbucketServerImport::Importer do
expect
(
merge_request
.
metrics
.
merged_at
).
to
eq
(
@merge_event
.
merge_timestamp
)
end
context
'handles comments'
do
it
'imports comments'
do
expect
(
subject
.
client
).
to
receive
(
:activities
).
and_return
([
@pr_comment
])
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
.
note
).
to
eq
(
@pr_note
.
note
)
expect
(
note
.
author
).
to
eq
(
project
.
owner
)
expect
(
note
.
created_at
).
to
eq
(
@pr_note
.
created_at
)
expect
(
note
.
updated_at
).
to
eq
(
@pr_note
.
created_at
)
end
contex
t
'handles diff comments'
do
i
t
'handles diff comments'
do
end
contex
t
'falls back to comments if diff comments'
do
i
t
'falls back to comments if diff comments'
do
end
contex
t
'restores branches of inaccessible SHAs'
do
i
t
'restores branches of inaccessible SHAs'
do
end
end
describe
'#delete_temp_branches'
do
it
'deletes branches'
do
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