Commit 26628fb9 authored by Valery Sizov's avatar Valery Sizov

BB importer: Fixed bug with putting expired token to a project.clone_url

parent 076cdd20
...@@ -49,6 +49,9 @@ class Import::BitbucketController < Import::BaseController ...@@ -49,6 +49,9 @@ class Import::BitbucketController < Import::BaseController
namespace = find_or_create_namespace(@target_namespace, current_user) namespace = find_or_create_namespace(@target_namespace, current_user)
if current_user.can?(:create_projects, namespace) 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 @project = Gitlab::BitbucketImport::ProjectCreator.new(repo, @project_name, namespace, current_user, credentials).execute
else else
render 'unauthorized' render 'unauthorized'
......
module Bitbucket module Bitbucket
class Client class Client
attr_reader :connection
def initialize(options = {}) def initialize(options = {})
@connection = Connection.new(options) @connection = Connection.new(options)
end end
...@@ -48,8 +50,6 @@ module Bitbucket ...@@ -48,8 +50,6 @@ module Bitbucket
private private
attr_reader :connection
def get_collection(path, type) def get_collection(path, type)
paginator = Paginator.new(connection, path, type) paginator = Paginator.new(connection, path, type)
Collection.new(paginator) Collection.new(paginator)
......
...@@ -4,6 +4,8 @@ module Bitbucket ...@@ -4,6 +4,8 @@ module Bitbucket
DEFAULT_BASE_URI = 'https://api.bitbucket.org/' DEFAULT_BASE_URI = 'https://api.bitbucket.org/'
DEFAULT_QUERY = {} DEFAULT_QUERY = {}
attr_reader :expires_at, :expires_in, :refresh_token, :token
def initialize(options = {}) def initialize(options = {})
@api_version = options.fetch(:api_version, DEFAULT_API_VERSION) @api_version = options.fetch(:api_version, DEFAULT_API_VERSION)
@base_uri = options.fetch(:base_uri, DEFAULT_BASE_URI) @base_uri = options.fetch(:base_uri, DEFAULT_BASE_URI)
...@@ -38,8 +40,6 @@ module Bitbucket ...@@ -38,8 +40,6 @@ module Bitbucket
private private
attr_reader :expires_at, :expires_in, :refresh_token, :token
def client def client
@client ||= OAuth2::Client.new(provider.app_id, provider.app_secret, options) @client ||= OAuth2::Client.new(provider.app_id, provider.app_secret, options)
end end
......
...@@ -21,7 +21,7 @@ module Gitlab ...@@ -21,7 +21,7 @@ module Gitlab
visibility_level: repo.visibility_level, visibility_level: repo.visibility_level,
import_type: 'bitbucket', import_type: 'bitbucket',
import_source: repo.full_name, 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 } import_data: { credentials: session_data }
).execute ).execute
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment