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
15220291
Commit
15220291
authored
Jul 12, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add spec for BitbucketServer::Connection
parent
f85712fb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
35 additions
and
9 deletions
+35
-9
app/controllers/import/bitbucket_server_controller.rb
app/controllers/import/bitbucket_server_controller.rb
+1
-1
lib/bitbucket_server/client.rb
lib/bitbucket_server/client.rb
+0
-1
lib/bitbucket_server/connection.rb
lib/bitbucket_server/connection.rb
+6
-2
lib/bitbucket_server/error/unauthorized.rb
lib/bitbucket_server/error/unauthorized.rb
+0
-5
spec/lib/bitbucket_server/connection_spec.rb
spec/lib/bitbucket_server/connection_spec.rb
+28
-0
No files found.
app/controllers/import/bitbucket_server_controller.rb
View file @
15220291
...
...
@@ -21,7 +21,7 @@ class Import::BitbucketServerController < Import::BaseController
Net
::
OpenTimeout
,
Net
::
ReadTimeout
,
Gitlab
::
HTTP
::
BlockedUrlError
,
BitbucketServer
::
Error
::
Unauthorized
].
freeze
BitbucketServer
::
Connection
::
ConnectionError
].
freeze
def
new
end
...
...
lib/bitbucket_server/client.rb
View file @
15220291
...
...
@@ -18,7 +18,6 @@ module BitbucketServer
def
repo
(
project
,
repo_name
)
parsed_response
=
connection
.
get
(
"/projects/
#{
project
}
/repos/
#{
repo_name
}
"
)
# XXXX TODO Handle failure
BitbucketServer
::
Representation
::
Repo
.
new
(
parsed_response
)
end
...
...
lib/bitbucket_server/connection.rb
View file @
15220291
...
...
@@ -6,6 +6,8 @@ module BitbucketServer
attr_reader
:api_version
,
:base_uri
,
:username
,
:token
ConnectionError
=
Class
.
new
(
StandardError
)
def
initialize
(
options
=
{})
@api_version
=
options
.
fetch
(
:api_version
,
DEFAULT_API_VERSION
)
@base_uri
=
options
[
:base_uri
]
...
...
@@ -19,6 +21,7 @@ module BitbucketServer
query:
extra_query
)
check_errors!
(
response
)
response
.
parsed_response
end
...
...
@@ -29,6 +32,7 @@ module BitbucketServer
body:
body
)
check_errors!
(
response
)
response
end
...
...
@@ -37,13 +41,13 @@ module BitbucketServer
def
check_errors!
(
response
)
if
response
.
code
!=
200
error
=
if
response
.
parsed_response
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
::
BitbucketServer
::
Error
::
Unauthorized
,
message
raise
ConnectionError
,
message
end
end
...
...
lib/bitbucket_server/error/unauthorized.rb
deleted
100644 → 0
View file @
f85712fb
module
BitbucketServer
module
Error
Unauthorized
=
Class
.
new
(
StandardError
)
end
end
spec/lib/bitbucket_server/connection_spec.rb
0 → 100644
View file @
15220291
require
'spec_helper'
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"
}
}
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
)
expect
(
subject
.
get
(
url
,
{
something:
1
})).
to
eq
(
payload
)
end
it
'throws an exception if the response is not 200'
do
WebMock
.
stub_request
(
:get
,
url
).
to_return
(
body:
payload
.
to_json
,
status:
500
,
headers:
headers
)
expect
{
subject
.
get
(
url
)
}.
to
raise_error
(
described_class
::
ConnectionError
)
end
end
describe
'#post'
do
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