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
d2fd6d23
Commit
d2fd6d23
authored
Jul 31, 2018
by
Stan Hu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deal with subpaths and trailing slashes properly
parent
77044043
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
7 deletions
+25
-7
lib/bitbucket_server/connection.rb
lib/bitbucket_server/connection.rb
+20
-3
spec/lib/bitbucket_server/client_spec.rb
spec/lib/bitbucket_server/client_spec.rb
+5
-4
No files found.
lib/bitbucket_server/connection.rb
View file @
d2fd6d23
...
...
@@ -5,6 +5,7 @@ module BitbucketServer
include
ActionView
::
Helpers
::
SanitizeHelper
DEFAULT_API_VERSION
=
'1.0'
SEPARATOR
=
'/'
attr_reader
:api_version
,
:base_uri
,
:username
,
:token
...
...
@@ -87,19 +88,35 @@ module BitbucketServer
def
build_url
(
path
)
return
path
if
path
.
starts_with?
(
root_url
)
URI
.
join
(
root_url
,
path
).
to_s
url_join_paths
(
root_url
,
path
)
end
def
root_url
URI
.
join
(
base_uri
,
"/rest/api/
#{
api_version
}
"
).
to_s
url_join_paths
(
base_uri
,
"/rest/api/
#{
api_version
}
"
)
end
def
delete_url
(
resource
,
path
)
if
resource
==
:branches
URI
.
join
(
base_uri
,
"/rest/branch-utils/
#{
api_version
}#{
path
}
"
).
to_s
url_join_paths
(
base_uri
,
"/rest/branch-utils/
#{
api_version
}#{
path
}
"
)
else
build_url
(
path
)
end
end
# URI.join is stupid in that slashes are important:
#
# # URI.join('http://example.com/subpath', 'hello')
# => http://example.com/hello
#
# We really want http://example.com/subpath/hello
#
def
url_join_paths
(
*
paths
)
paths
.
map
{
|
path
|
strip_slashes
(
path
)
}.
join
(
SEPARATOR
)
end
def
strip_slashes
(
path
)
path
=
path
[
1
..-
1
]
if
path
.
starts_with?
(
SEPARATOR
)
path
.
chomp
(
SEPARATOR
)
end
end
end
spec/lib/bitbucket_server/client_spec.rb
View file @
d2fd6d23
require
'spec_helper'
describe
BitbucketServer
::
Client
do
let
(
:options
)
{
{
base_uri:
'https://test:7990'
,
user:
'bitbucket'
,
password:
'mypassword'
}
}
let
(
:base_uri
)
{
'https://test:7990/stash/'
}
let
(
:options
)
{
{
base_uri:
base_uri
,
user:
'bitbucket'
,
password:
'mypassword'
}
}
let
(
:project
)
{
'SOME-PROJECT'
}
let
(
:repo_slug
)
{
'my-repo'
}
let
(
:headers
)
{
{
"Content-Type"
=>
"application/json"
}
}
...
...
@@ -36,7 +37,7 @@ describe BitbucketServer::Client do
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"
}
let
(
:url
)
{
"
#{
base_uri
}
rest/api/1.0/projects/SOME-PROJECT/repos/my-repo"
}
it
'requests a specific repository'
do
stub_request
(
:get
,
url
).
to_return
(
status:
200
,
headers:
headers
,
body:
'{}'
)
...
...
@@ -60,7 +61,7 @@ describe BitbucketServer::Client do
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'
}
let
(
:url
)
{
"
#{
base_uri
}
rest/api/1.0/projects/SOME-PROJECT/repos/my-repo/branches"
}
it
'requests Bitbucket to create a branch'
do
stub_request
(
:post
,
url
).
to_return
(
status:
204
,
headers:
headers
,
body:
'{}'
)
...
...
@@ -74,7 +75,7 @@ describe BitbucketServer::Client do
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'
}
let
(
:url
)
{
"
#{
base_uri
}
rest/branch-utils/1.0/projects/SOME-PROJECT/repos/my-repo/branches"
}
it
'requests Bitbucket to create a branch'
do
stub_request
(
:delete
,
url
).
to_return
(
status:
204
,
headers:
headers
,
body:
'{}'
)
...
...
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