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
Léo-Paul Géneau
gitlab-ce
Commits
3f715bb4
Commit
3f715bb4
authored
Jul 26, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate server errors and add specs
parent
079b490a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
16 deletions
+106
-16
app/controllers/import/bitbucket_server_controller.rb
app/controllers/import/bitbucket_server_controller.rb
+2
-12
lib/bitbucket_server/client.rb
lib/bitbucket_server/client.rb
+17
-3
spec/controllers/import/bitbucket_server_controller_spec.rb
spec/controllers/import/bitbucket_server_controller_spec.rb
+1
-1
spec/lib/bitbucket_server/client_spec.rb
spec/lib/bitbucket_server/client_spec.rb
+86
-0
No files found.
app/controllers/import/bitbucket_server_controller.rb
View file @
3f715bb4
...
...
@@ -15,16 +15,6 @@ class Import::BitbucketServerController < Import::BaseController
# (https://community.atlassian.com/t5/Answers-Developer-Questions/stash-repository-names/qaq-p/499054)
VALID_BITBUCKET_CHARS
=
/\A[a-zA-z0-9\-_\.\s]+\z/
SERVER_ERRORS
=
[
SocketError
,
OpenSSL
::
SSL
::
SSLError
,
Errno
::
ECONNRESET
,
Errno
::
ECONNREFUSED
,
Errno
::
EHOSTUNREACH
,
Net
::
OpenTimeout
,
Net
::
ReadTimeout
,
Gitlab
::
HTTP
::
BlockedUrlError
,
BitbucketServer
::
Connection
::
ConnectionError
].
freeze
def
new
end
...
...
@@ -52,7 +42,7 @@ class Import::BitbucketServerController < Import::BaseController
else
render
json:
{
errors:
'This namespace has already been taken! Please choose another one.'
},
status: :unprocessable_entity
end
rescue
*
SERVER_ERRORS
=>
e
rescue
BitbucketServer
::
Client
::
ServerError
=>
e
render
json:
{
errors:
"Unable to connect to server:
#{
e
}
"
},
status: :unprocessable_entity
end
...
...
@@ -73,7 +63,7 @@ class Import::BitbucketServerController < Import::BaseController
already_added_projects_names
=
@already_added_projects
.
pluck
(
:import_source
)
@repos
.
to_a
.
reject!
{
|
repo
|
already_added_projects_names
.
include?
(
repo
.
browse_url
)
}
rescue
*
SERVER_ERRORS
=>
e
rescue
BitbucketServer
::
Connection
::
ConnectionError
,
BitbucketServer
::
Client
::
ServerError
=>
e
flash
[
:alert
]
=
"Unable to connect to server:
#{
e
}
"
clear_session_data
redirect_to
new_import_bitbucket_server_path
...
...
lib/bitbucket_server/client.rb
View file @
3f715bb4
...
...
@@ -4,6 +4,18 @@ module BitbucketServer
class
Client
attr_reader
:connection
ServerError
=
Class
.
new
(
StandardError
)
SERVER_ERRORS
=
[
SocketError
,
OpenSSL
::
SSL
::
SSLError
,
Errno
::
ECONNRESET
,
Errno
::
ECONNREFUSED
,
Errno
::
EHOSTUNREACH
,
Net
::
OpenTimeout
,
Net
::
ReadTimeout
,
Gitlab
::
HTTP
::
BlockedUrlError
,
BitbucketServer
::
Connection
::
ConnectionError
].
freeze
def
initialize
(
options
=
{})
@connection
=
Connection
.
new
(
options
)
end
...
...
@@ -13,8 +25,8 @@ module BitbucketServer
get_collection
(
path
,
:pull_request
)
end
def
activities
(
project_key
,
repo
,
pull_request
)
path
=
"/projects/
#{
project_key
}
/repos/
#{
repo
}
/pull-requests/
#{
pull_request
}
/activities"
def
activities
(
project_key
,
repo
,
pull_request
_id
)
path
=
"/projects/
#{
project_key
}
/repos/
#{
repo
}
/pull-requests/
#{
pull_request
_id
}
/activities"
get_collection
(
path
,
:activity
)
end
...
...
@@ -50,8 +62,10 @@ module BitbucketServer
private
def
get_collection
(
path
,
type
)
paginator
=
BitbucketServer
::
Paginator
.
new
(
connection
,
path
,
type
)
paginator
=
BitbucketServer
::
Paginator
.
new
(
connection
,
Addressable
::
URI
.
escape
(
path
)
,
type
)
BitbucketServer
::
Collection
.
new
(
paginator
)
rescue
*
SERVER_ERRORS
=>
e
raise
ServerError
,
e
end
end
end
spec/controllers/import/bitbucket_server_controller_spec.rb
View file @
3f715bb4
...
...
@@ -78,7 +78,7 @@ describe Import::BitbucketServerController do
end
it
"returns an error when the server can't be contacted"
do
expect
(
client
).
to
receive
(
:repo
).
with
(
project_key
,
repo_slug
).
and_raise
(
Errno
::
ECONNREFUSED
)
expect
(
client
).
to
receive
(
:repo
).
with
(
project_key
,
repo_slug
).
and_raise
(
BitbucketServer
::
Client
::
ServerError
)
post
:create
,
project:
project_key
,
repository:
repo_slug
,
format: :json
...
...
spec/lib/bitbucket_server/client_spec.rb
0 → 100644
View file @
3f715bb4
require
'spec_helper'
describe
BitbucketServer
::
Client
do
let
(
:options
)
{
{
base_uri:
'https://test:7990'
,
user:
'bitbucket'
,
password:
'mypassword'
}
}
let
(
:project
)
{
'SOME-PROJECT'
}
let
(
:repo_slug
)
{
'my-repo'
}
subject
{
described_class
.
new
(
options
)
}
describe
'#pull_requests'
do
let
(
:path
)
{
"/projects/
#{
project
}
/repos/
#{
repo_slug
}
/pull-requests?state=ALL"
}
it
'requests a collection'
do
expect
(
BitbucketServer
::
Paginator
).
to
receive
(
:new
).
with
(
anything
,
path
,
:pull_request
)
subject
.
pull_requests
(
project
,
repo_slug
)
end
it
'throws an exception when connection fails'
do
allow
(
BitbucketServer
::
Collection
).
to
receive
(
:new
).
and_raise
(
OpenSSL
::
SSL
::
SSLError
)
expect
{
subject
.
pull_requests
(
project
,
repo_slug
)
}.
to
raise_error
(
described_class
::
ServerError
)
end
end
describe
'#activities'
do
let
(
:path
)
{
"/projects/
#{
project
}
/repos/
#{
repo_slug
}
/pull-requests/1/activities"
}
it
'requests a collection'
do
expect
(
BitbucketServer
::
Paginator
).
to
receive
(
:new
).
with
(
anything
,
path
,
:activity
)
subject
.
activities
(
project
,
repo_slug
,
1
)
end
end
describe
'#repo'
do
let
(
:path
)
{
"/projects/
#{
project
}
/repos/
#{
repo_slug
}
"
}
let
(
:url
)
{
"https://test:7990/rest/api/1.0/projects/SOME-PROJECT/repos/my-repo"
}
it
'requests a specific repository'
do
stub_request
(
:get
,
url
)
subject
.
repo
(
project
,
repo_slug
)
expect
(
WebMock
).
to
have_requested
(
:get
,
url
)
end
end
describe
'#repos'
do
let
(
:path
)
{
"/repos"
}
it
'requests a collection'
do
expect
(
BitbucketServer
::
Paginator
).
to
receive
(
:new
).
with
(
anything
,
path
,
:repo
)
subject
.
repos
end
end
describe
'#create_branch'
do
let
(
:branch
)
{
'test-branch'
}
let
(
:sha
)
{
'12345678'
}
let
(
:url
)
{
'https://test:7990/rest/api/1.0/projects/SOME-PROJECT/repos/my-repo/branches'
}
it
'requests Bitbucket to create a branch'
do
stub_request
(
:post
,
url
)
subject
.
create_branch
(
project
,
repo_slug
,
branch
,
sha
)
expect
(
WebMock
).
to
have_requested
(
:post
,
url
)
end
end
describe
'#delete_branch'
do
let
(
:branch
)
{
'test-branch'
}
let
(
:sha
)
{
'12345678'
}
let
(
:url
)
{
'https://test:7990/rest/branch-utils/1.0/projects/SOME-PROJECT/repos/my-repo/branches'
}
it
'requests Bitbucket to create a branch'
do
stub_request
(
:delete
,
url
)
subject
.
delete_branch
(
project
,
repo_slug
,
branch
,
sha
)
expect
(
WebMock
).
to
have_requested
(
:delete
,
url
)
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