summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValery Sizov <valery@gitlab.com>2016-12-15 14:19:28 +0200
committerValery Sizov <valery@gitlab.com>2016-12-15 14:19:28 +0200
commit26628fb91a89bbe4998633eec00d2bd76cfb95c0 (patch)
tree561248da78a0d12ca64f528c94d5ee16d88cdb94
parent076cdd204459496d7cdd14b86838c2c2c7875cd4 (diff)
downloadgitlab-ce-26628fb91a89bbe4998633eec00d2bd76cfb95c0.tar.gz
BB importer: Fixed bug with putting expired token to a project.clone_url
-rw-r--r--app/controllers/import/bitbucket_controller.rb3
-rw-r--r--lib/bitbucket/client.rb4
-rw-r--r--lib/bitbucket/connection.rb4
-rw-r--r--lib/gitlab/bitbucket_import/project_creator.rb2
4 files changed, 8 insertions, 5 deletions
diff --git a/app/controllers/import/bitbucket_controller.rb b/app/controllers/import/bitbucket_controller.rb
index b9cc6556140..8e42cdf415f 100644
--- a/app/controllers/import/bitbucket_controller.rb
+++ b/app/controllers/import/bitbucket_controller.rb
@@ -49,6 +49,9 @@ class Import::BitbucketController < Import::BaseController
namespace = find_or_create_namespace(@target_namespace, current_user)
if current_user.can?(:create_projects, namespace)
+ # The token in a session can be expired, we need to get most recent one because
+ # Bitbucket::Connection class refreshes it.
+ session[:bitbucket_token] = bitbucket_client.connection.token
@project = Gitlab::BitbucketImport::ProjectCreator.new(repo, @project_name, namespace, current_user, credentials).execute
else
render 'unauthorized'
diff --git a/lib/bitbucket/client.rb b/lib/bitbucket/client.rb
index 5c2ef2a4509..f8ee7e0f9ae 100644
--- a/lib/bitbucket/client.rb
+++ b/lib/bitbucket/client.rb
@@ -1,5 +1,7 @@
module Bitbucket
class Client
+ attr_reader :connection
+
def initialize(options = {})
@connection = Connection.new(options)
end
@@ -48,8 +50,6 @@ module Bitbucket
private
- attr_reader :connection
-
def get_collection(path, type)
paginator = Paginator.new(connection, path, type)
Collection.new(paginator)
diff --git a/lib/bitbucket/connection.rb b/lib/bitbucket/connection.rb
index c150a20761e..7e55cf4deab 100644
--- a/lib/bitbucket/connection.rb
+++ b/lib/bitbucket/connection.rb
@@ -4,6 +4,8 @@ module Bitbucket
DEFAULT_BASE_URI = 'https://api.bitbucket.org/'
DEFAULT_QUERY = {}
+ attr_reader :expires_at, :expires_in, :refresh_token, :token
+
def initialize(options = {})
@api_version = options.fetch(:api_version, DEFAULT_API_VERSION)
@base_uri = options.fetch(:base_uri, DEFAULT_BASE_URI)
@@ -38,8 +40,6 @@ module Bitbucket
private
- attr_reader :expires_at, :expires_in, :refresh_token, :token
-
def client
@client ||= OAuth2::Client.new(provider.app_id, provider.app_secret, options)
end
diff --git a/lib/gitlab/bitbucket_import/project_creator.rb b/lib/gitlab/bitbucket_import/project_creator.rb
index b34be272af3..eb03882ab26 100644
--- a/lib/gitlab/bitbucket_import/project_creator.rb
+++ b/lib/gitlab/bitbucket_import/project_creator.rb
@@ -21,7 +21,7 @@ module Gitlab
visibility_level: repo.visibility_level,
import_type: 'bitbucket',
import_source: repo.full_name,
- import_url: repo.clone_url(@session_data[:token]),
+ import_url: repo.clone_url(session_data[:token]),
import_data: { credentials: session_data }
).execute
end