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
57c9a893
Commit
57c9a893
authored
Jul 15, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix assorted bugs and write spec for importing merge event
parent
eb482bfa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
5 deletions
+67
-5
lib/gitlab/bitbucket_server_import/importer.rb
lib/gitlab/bitbucket_server_import/importer.rb
+5
-3
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
+62
-2
No files found.
lib/gitlab/bitbucket_server_import/importer.rb
View file @
57c9a893
...
@@ -163,6 +163,8 @@ module Gitlab
...
@@ -163,6 +163,8 @@ module Gitlab
target_branch_sha
=
pull_request
.
target_branch_sha
target_branch_sha
=
pull_request
.
target_branch_sha
source_branch_sha
=
project
.
repository
.
commit
(
source_branch_sha
)
&
.
sha
||
source_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
target_branch_sha
=
project
.
repository
.
commit
(
target_branch_sha
)
&
.
sha
||
target_branch_sha
author
=
gitlab_user_id
(
project
,
pull_request
.
author_email
)
||
User
.
ghost
project
.
merge_requests
.
find_by
(
iid:
pull_request
.
iid
)
&
.
destroy
project
.
merge_requests
.
find_by
(
iid:
pull_request
.
iid
)
&
.
destroy
attributes
=
{
attributes
=
{
...
@@ -176,7 +178,7 @@ module Gitlab
...
@@ -176,7 +178,7 @@ module Gitlab
target_branch:
Gitlab
::
Git
.
ref_name
(
pull_request
.
target_branch_name
),
target_branch:
Gitlab
::
Git
.
ref_name
(
pull_request
.
target_branch_name
),
target_branch_sha:
target_branch_sha
,
target_branch_sha:
target_branch_sha
,
state:
pull_request
.
state
,
state:
pull_request
.
state
,
author_id:
gitlab_user_id
(
project
,
pull_request
.
author_email
)
,
author_id:
author
.
id
,
assignee_id:
nil
,
assignee_id:
nil
,
created_at:
pull_request
.
created_at
,
created_at:
pull_request
.
created_at
,
updated_at:
pull_request
.
updated_at
updated_at:
pull_request
.
updated_at
...
@@ -202,8 +204,8 @@ module Gitlab
...
@@ -202,8 +204,8 @@ module Gitlab
def
import_merge_event
(
merge_request
,
merge_event
)
def
import_merge_event
(
merge_request
,
merge_event
)
committer
=
merge_event
.
committer_email
committer
=
merge_event
.
committer_email
user
=
User
.
ghost
user
=
find_user_id
(
committer
)
if
committer
user
||=
find_user_id
(
committer
)
if
committer
user
||=
User
.
ghost
timestamp
=
merge_event
.
merge_timestamp
timestamp
=
merge_event
.
merge_timestamp
metric
=
MergeRequest
::
Metrics
.
find_or_initialize_by
(
merge_request:
merge_request
)
metric
=
MergeRequest
::
Metrics
.
find_or_initialize_by
(
merge_request:
merge_request
)
metric
.
update_attributes
(
merged_by:
user
,
merged_at:
timestamp
)
metric
.
update_attributes
(
merged_by:
user
,
merged_at:
timestamp
)
...
...
spec/lib/gitlab/bitbucket_server_import/importer_spec.rb
View file @
57c9a893
...
@@ -3,7 +3,7 @@ require 'spec_helper'
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
Gitlab
::
BitbucketServerImport
::
Importer
do
describe
Gitlab
::
BitbucketServerImport
::
Importer
do
include
ImportSpecHelper
include
ImportSpecHelper
let
(
:project
)
{
create
(
:project
,
import_url:
'http://my-bitbucket'
)
}
set
(
:project
)
{
create
(
:project
,
:repository
,
import_url:
'http://my-bitbucket'
)
}
subject
{
described_class
.
new
(
project
)
}
subject
{
described_class
.
new
(
project
)
}
...
@@ -32,11 +32,71 @@ describe Gitlab::BitbucketServerImport::Importer do
...
@@ -32,11 +32,71 @@ describe Gitlab::BitbucketServerImport::Importer do
end
end
end
end
# XXX We don't handle pull requests across forks
describe
'#import_pull_requests'
do
describe
'#import_pull_requests'
do
before
do
allow
(
subject
).
to
receive
(
:import_repository
)
allow
(
subject
).
to
receive
(
:delete_temp_branches
)
allow
(
subject
).
to
receive
(
:restore_branches
)
sample
=
RepoHelpers
.
sample_compare
pull_request
=
instance_double
(
BitbucketServer
::
Representation
::
PullRequest
,
iid:
10
,
source_branch_sha:
sample
.
commits
.
last
,
source_branch_name:
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
sample
.
source_branch
,
target_branch_sha:
sample
.
commits
.
first
,
target_branch_name:
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
sample
.
target_branch
,
title:
'This is a title'
,
description:
'This is a test pull request'
,
state:
'merged'
,
author:
'Test Author'
,
author_email:
project
.
owner
.
email
,
created_at:
Time
.
now
,
updated_at:
Time
.
now
,
merged?:
true
)
expect
(
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
)
@inline_comment
=
instance_double
(
BitbucketServer
::
Representation
::
Activity
,
comment?:
true
,
merge_event?:
false
)
@pr_comment
=
instance_double
(
BitbucketServer
::
Representation
::
Activity
,
comment?:
true
,
merge_event?:
false
)
end
it
'handles merge event'
do
expect
(
subject
.
client
).
to
receive
(
:activities
).
and_return
([
@merge_event
])
expect
{
subject
.
execute
}.
to
change
{
MergeRequest
.
count
}.
by
(
1
)
merge_request
=
MergeRequest
.
first
expect
(
merge_request
.
metrics
.
merged_by
).
to
eq
(
project
.
owner
)
expect
(
merge_request
.
metrics
.
merged_at
).
to
eq
(
@merge_event
.
merge_timestamp
)
end
context
'handles comments'
do
end
context
'handles diff comments'
do
end
context
'falls back to comments if diff comments'
do
end
context
'restores branches of inaccessible SHAs'
do
end
end
end
describe
'#delete_temp_branches'
do
describe
'#delete_temp_branches'
do
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