Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/bitbucket_server/connection.rb23
-rw-r--r--spec/lib/bitbucket_server/client_spec.rb9
2 files changed, 25 insertions, 7 deletions
diff --git a/lib/bitbucket_server/connection.rb b/lib/bitbucket_server/connection.rb
index a43b4364cab..a3150cc38d5 100644
--- a/lib/bitbucket_server/connection.rb
+++ b/lib/bitbucket_server/connection.rb
@@ -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
diff --git a/spec/lib/bitbucket_server/client_spec.rb b/spec/lib/bitbucket_server/client_spec.rb
index d7931d6e4b5..f926ae963a4 100644
--- a/spec/lib/bitbucket_server/client_spec.rb
+++ b/spec/lib/bitbucket_server/client_spec.rb
@@ -1,7 +1,8 @@
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: '{}')