Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
842f7d67d291
Commit
402cc95c
authored
Nov 21, 2016
by
Stan Hu
Browse files
Fix Bitbucket importer spec to pass with 2.0 API
parent
8ad83b0912eb
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/bitbucket/page.rb
View file @
842f7d67
...
...
@@ -22,10 +22,10 @@ def parse_attrs(raw)
attrs
.
map
{
|
attr
|
{
attr
.
to_sym
=>
raw
[
attr
]
}
}.
reduce
(
&
:merge
)
end
def
parse_values
(
raw
,
representation
_class
)
def
parse_values
(
raw
,
bitbucket_rep
_class
)
return
[]
unless
raw
[
'values'
]
&&
raw
[
'values'
].
is_a?
(
Array
)
raw
[
'values'
].
map
{
|
hash
|
representation
_class
.
new
(
hash
)
}
raw
[
'values'
].
map
{
|
hash
|
bitbucket_rep
_class
.
new
(
hash
)
}
end
def
representation_class
(
type
)
...
...
lib/gitlab/bitbucket_import/importer.rb
View file @
842f7d67
...
...
@@ -62,13 +62,6 @@ def import_issues
)
end
end
project
.
issues
.
create!
(
description:
body
,
title:
issue
[
"title"
],
state:
%w(resolved invalid duplicate wontfix closed)
.
include?
(
issue
[
"status"
])
?
'closed'
:
'opened'
,
author_id:
gitlab_user_id
(
project
,
reporter
)
)
end
rescue
ActiveRecord
::
RecordInvalid
nil
...
...
spec/lib/gitlab/bitbucket_import/importer_spec.rb
View file @
842f7d67
...
...
@@ -23,10 +23,14 @@
statuses
.
map
.
with_index
do
|
status
,
index
|
issues
<<
{
local_
id:
index
,
stat
us
:
status
,
id:
index
,
stat
e
:
status
,
title:
"Issue
#{
index
}
"
,
content:
"Some content to issue
#{
index
}
"
content:
{
raw:
"Some content to issue
#{
index
}
"
,
markup:
"markdown"
,
html:
"Some content to issue
#{
index
}
"
}
}
end
...
...
@@ -37,8 +41,8 @@
let
(
:data
)
do
{
'bb_session'
=>
{
'bitbucket_
access_
token'
=>
"123456"
,
'bitbucket_
access_token_secret
'
=>
"secret"
'bitbucket_token'
=>
"123456"
,
'bitbucket_
refresh_token
'
=>
"secret"
}
}
end
...
...
@@ -53,7 +57,7 @@
let
(
:issues_statuses_sample_data
)
do
{
count:
sample_issues_statuses
.
count
,
iss
ues:
sample_issues_statuses
val
ues:
sample_issues_statuses
}
end
...
...
@@ -61,26 +65,40 @@
before
do
stub_request
(
:get
,
"https://bitbucket.org/api/1.0/repositories/
#{
project_identifier
}
"
).
to_return
(
status:
200
,
body:
{
has_issues:
true
}.
to_json
)
"https://api.bitbucket.org/2.0/repositories/
#{
project_identifier
}
"
).
to_return
(
status:
200
,
headers:
{
"Content-Type"
=>
"application/json"
},
body:
{
has_issues:
true
,
full_name:
project_identifier
}.
to_json
)
stub_request
(
:get
,
"https://bitbucket.org/api/1.0/repositories/
#{
project_identifier
}
/issues?limit=50&sort=utc_created_on&start=0"
).
to_return
(
status:
200
,
body:
issues_statuses_sample_data
.
to_json
)
"https://api.bitbucket.org/2.0/repositories/
#{
project_identifier
}
/issues?pagelen=50&sort=created_on"
).
to_return
(
status:
200
,
headers:
{
"Content-Type"
=>
"application/json"
},
body:
issues_statuses_sample_data
.
to_json
)
sample_issues_statuses
.
each_with_index
do
|
issue
,
index
|
stub_request
(
:get
,
"https://bitbucket.org/
api/1
.0/repositories/
#{
project_identifier
}
/issues/
#{
issue
[
:
local_
id
]
}
/comments"
"https://
api.
bitbucket.org/
2
.0/repositories/
#{
project_identifier
}
/issues/
#{
issue
[
:id
]
}
/comments
?pagelen=50&sort=created_on
"
).
to_return
(
status:
200
,
body:
[{
author_info:
{
username:
"username"
},
utc_created_on:
index
}].
to_json
headers:
{
"Content-Type"
=>
"application/json"
},
body:
{
author_info:
{
username:
"username"
},
utc_created_on:
index
}.
to_json
)
end
stub_request
(
:get
,
"https://api.bitbucket.org/2.0/repositories/
#{
project_identifier
}
/pullrequests?pagelen=50&sort=created_on&state=ALL"
).
to_return
(
status:
200
,
headers:
{
"Content-Type"
=>
"application/json"
},
body:
{}.
to_json
)
end
it
'map statuses to open or closed'
do
# HACK: Bitbucket::Representation.const_get('Issue') seems to return Issue without this
Bitbucket
::
Representation
::
Issue
importer
.
execute
expect
(
project
.
issues
.
where
(
state:
"closed"
).
size
).
to
eq
(
5
)
...
...
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