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:
authorStan Hu <stanhu@gmail.com>2018-06-25 23:06:10 +0300
committerStan Hu <stanhu@gmail.com>2018-06-25 23:06:10 +0300
commitebd8e4333a263138abf2113dd315a97352851cbe (patch)
tree4e4975eab778d490c20c9252785761a1d78fae26 /lib/bitbucket_server/connection.rb
parent2bac2918b2d6f12d94f739f4b6865b9e9221c642 (diff)
WIP: Add support for Bitbucket Server imports
Diffstat (limited to 'lib/bitbucket_server/connection.rb')
-rw-r--r--lib/bitbucket_server/connection.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/bitbucket_server/connection.rb b/lib/bitbucket_server/connection.rb
new file mode 100644
index 00000000000..64f12527a8d
--- /dev/null
+++ b/lib/bitbucket_server/connection.rb
@@ -0,0 +1,35 @@
+module BitbucketServer
+ class Connection
+ DEFAULT_API_VERSION = '1.0'.freeze
+
+ attr_reader :api_version, :base_uri, :username, :token
+
+ def initialize(options = {})
+ @api_version = options.fetch(:api_version, DEFAULT_API_VERSION)
+ @base_uri = options[:base_uri]
+ @username = options[:username]
+ @token = options[:personal_access_token]
+ end
+
+ def get(path, extra_query = {})
+ auth = { username: username, password: token }
+ response = Gitlab::HTTP.get(build_url(path),
+ basic_auth: auth,
+ params: extra_query)
+ ## Handle failure
+ response.parsed_response
+ end
+
+ private
+
+ def build_url(path)
+ return path if path.starts_with?(root_url)
+
+ "#{root_url}#{path}"
+ end
+
+ def root_url
+ "#{base_uri}/rest/api/#{api_version}"
+ end
+ end
+end