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
ec4109d4
Commit
ec4109d4
authored
Jul 12, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make Connection#post consistent with Connection#get and add specs
parent
15220291
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
18 deletions
+27
-18
lib/bitbucket_server/connection.rb
lib/bitbucket_server/connection.rb
+11
-11
lib/gitlab/bitbucket_server_import/importer.rb
lib/gitlab/bitbucket_server_import/importer.rb
+4
-5
spec/lib/bitbucket_server/connection_spec.rb
spec/lib/bitbucket_server/connection_spec.rb
+12
-2
No files found.
lib/bitbucket_server/connection.rb
View file @
ec4109d4
...
@@ -33,23 +33,23 @@ module BitbucketServer
...
@@ -33,23 +33,23 @@ module BitbucketServer
check_errors!
(
response
)
check_errors!
(
response
)
response
response
.
parsed_response
end
end
private
private
def
check_errors!
(
response
)
def
check_errors!
(
response
)
if
response
.
code
!=
200
return
if
response
.
code
==
200
error
=
details
=
if
response
.
parsed_response
&&
response
.
parsed_response
.
is_a?
(
Hash
)
if
response
.
parsed_response
&&
response
.
parsed_response
.
is_a?
(
Hash
)
sanitize
(
response
.
parsed_response
.
dig
(
'errors'
,
0
,
'message'
))
sanitize
(
response
.
parsed_response
.
dig
(
'errors'
,
0
,
'message'
))
end
end
message
=
"Error
#{
response
.
code
}
"
message
=
"Error
#{
response
.
code
}
"
message
+=
":
#{
error
}
"
if
error
message
+=
":
#{
details
}
"
if
details
raise
ConnectionError
,
message
raise
ConnectionError
,
message
end
end
end
def
auth
def
auth
@auth
||=
{
username:
username
,
password:
token
}
@auth
||=
{
username:
username
,
password:
token
}
...
...
lib/gitlab/bitbucket_server_import/importer.rb
View file @
ec4109d4
...
@@ -90,12 +90,11 @@ module Gitlab
...
@@ -90,12 +90,11 @@ module Gitlab
shas
.
each
do
|
branch_name
,
sha
|
shas
.
each
do
|
branch_name
,
sha
|
next
if
sha_exists?
(
sha
)
next
if
sha_exists?
(
sha
)
response
=
client
.
create_branch
(
project_key
,
repository_slug
,
branch_name
,
sha
)
begin
client
.
create_branch
(
project_key
,
repository_slug
,
branch_name
,
sha
)
if
response
.
success?
branches_created
<<
branch_name
branches_created
<<
branch_name
els
e
rescue
BitbucketServer
::
Connection
::
ConnectionError
=>
e
Rails
.
logger
.
warn
(
"BitbucketServerImporter: Unable to recreate branch for SHA
#{
sha
}
:
#{
response
.
cod
e
}
"
)
Rails
.
logger
.
warn
(
"BitbucketServerImporter: Unable to recreate branch for SHA
#{
sha
}
:
#{
e
}
"
)
end
end
end
end
end
end
...
...
spec/lib/bitbucket_server/connection_spec.rb
View file @
ec4109d4
...
@@ -4,12 +4,11 @@ describe BitbucketServer::Connection do
...
@@ -4,12 +4,11 @@ describe BitbucketServer::Connection do
let
(
:options
)
{
{
base_uri:
'https://test:7990'
,
user:
'bitbucket'
,
password:
'mypassword'
}
}
let
(
:options
)
{
{
base_uri:
'https://test:7990'
,
user:
'bitbucket'
,
password:
'mypassword'
}
}
let
(
:payload
)
{
{
'test'
=>
1
}
}
let
(
:payload
)
{
{
'test'
=>
1
}
}
let
(
:headers
)
{
{
"Content-Type"
=>
"application/json"
}
}
let
(
:headers
)
{
{
"Content-Type"
=>
"application/json"
}
}
let
(
:url
)
{
'https://test:7990/rest/api/1.0/test?something=1'
}
subject
{
described_class
.
new
(
options
)
}
subject
{
described_class
.
new
(
options
)
}
describe
'#get'
do
describe
'#get'
do
let
(
:url
)
{
'https://test:7990/rest/api/1.0/test?something=1'
}
it
'returns JSON body'
do
it
'returns JSON body'
do
WebMock
.
stub_request
(
:get
,
url
).
to_return
(
body:
payload
.
to_json
,
status:
200
,
headers:
headers
)
WebMock
.
stub_request
(
:get
,
url
).
to_return
(
body:
payload
.
to_json
,
status:
200
,
headers:
headers
)
...
@@ -24,5 +23,16 @@ describe BitbucketServer::Connection do
...
@@ -24,5 +23,16 @@ describe BitbucketServer::Connection do
end
end
describe
'#post'
do
describe
'#post'
do
it
'returns JSON body'
do
WebMock
.
stub_request
(
:post
,
url
).
to_return
(
body:
payload
.
to_json
,
status:
200
,
headers:
headers
)
expect
(
subject
.
post
(
url
,
payload
)).
to
eq
(
payload
)
end
it
'throws an exception if the response is not 200'
do
WebMock
.
stub_request
(
:post
,
url
).
to_return
(
body:
payload
.
to_json
,
status:
500
,
headers:
headers
)
expect
{
subject
.
post
(
url
,
payload
)
}.
to
raise_error
(
described_class
::
ConnectionError
)
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