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
Hide 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,22 +33,22 @@ module BitbucketServer
check_errors!
(
response
)
response
response
.
parsed_response
end
private
def
check_errors!
(
response
)
if
response
.
code
!
=
200
error
=
if
response
.
parsed_response
&&
response
.
parsed_response
.
is_a?
(
Hash
)
sanitize
(
response
.
parsed_response
.
dig
(
'errors'
,
0
,
'message'
)
)
end
message
=
"Error
#{
response
.
code
}
"
message
+=
":
#{
error
}
"
if
error
raise
ConnectionError
,
message
end
return
if
response
.
code
=
=
200
details
=
if
response
.
parsed_response
&&
response
.
parsed_response
.
is_a?
(
Hash
)
sanitize
(
response
.
parsed_response
.
dig
(
'errors'
,
0
,
'message'
))
end
message
=
"Error
#{
response
.
code
}
"
message
+=
":
#{
details
}
"
if
details
raise
ConnectionError
,
message
end
def
auth
...
...
lib/gitlab/bitbucket_server_import/importer.rb
View file @
ec4109d4
...
...
@@ -90,12 +90,11 @@ module Gitlab
shas
.
each
do
|
branch_name
,
sha
|
next
if
sha_exists?
(
sha
)
response
=
client
.
create_branch
(
project_key
,
repository_slug
,
branch_name
,
sha
)
if
response
.
success?
begin
client
.
create_branch
(
project_key
,
repository_slug
,
branch_name
,
sha
)
branches_created
<<
branch_name
els
e
Rails
.
logger
.
warn
(
"BitbucketServerImporter: Unable to recreate branch for SHA
#{
sha
}
:
#{
response
.
cod
e
}
"
)
rescue
BitbucketServer
::
Connection
::
ConnectionError
=>
e
Rails
.
logger
.
warn
(
"BitbucketServerImporter: Unable to recreate branch for SHA
#{
sha
}
:
#{
e
}
"
)
end
end
end
...
...
spec/lib/bitbucket_server/connection_spec.rb
View file @
ec4109d4
...
...
@@ -4,12 +4,11 @@ describe BitbucketServer::Connection do
let
(
:options
)
{
{
base_uri:
'https://test:7990'
,
user:
'bitbucket'
,
password:
'mypassword'
}
}
let
(
:payload
)
{
{
'test'
=>
1
}
}
let
(
:headers
)
{
{
"Content-Type"
=>
"application/json"
}
}
let
(
:url
)
{
'https://test:7990/rest/api/1.0/test?something=1'
}
subject
{
described_class
.
new
(
options
)
}
describe
'#get'
do
let
(
:url
)
{
'https://test:7990/rest/api/1.0/test?something=1'
}
it
'returns JSON body'
do
WebMock
.
stub_request
(
:get
,
url
).
to_return
(
body:
payload
.
to_json
,
status:
200
,
headers:
headers
)
...
...
@@ -24,5 +23,16 @@ describe BitbucketServer::Connection do
end
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
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