Commit 8aafe685 authored by James Lopez's avatar James Lopez

first round of fixes and spec fixes

parent 3b78885e
......@@ -407,7 +407,7 @@ class Project < ActiveRecord::Base
end
def import_url
if import_data
if import_data && super
import_url = Gitlab::ImportUrl.new(super, credentials: import_data.credentials)
import_url.full_url
else
......@@ -417,7 +417,8 @@ class Project < ActiveRecord::Base
def create_or_update_import_data(credentials)
project_import_data = import_data || build_import_data
project_import_data.credentials = credentials
project_import_data.credentials ||= {}
project_import_data.credentials.merge!(credentials)
project_import_data.save
end
......
module Gitlab
module BitbucketImport
class Importer
attr_reader :project, :client
def initialize(project)
@project = project
if import_data_credentials && import_data_credentials['bb_session']
token = import_data_credentials['bb_session']['bitbucket_access_token']
token_secret = import_data_credentials['bb_session']['bitbucket_access_token_secret']
@client = Client.new(token, token_secret)
@formatter = Gitlab::ImportFormatter.new
else
raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"
end
end
class Importer < ImporterInit
def execute
import_issues if has_issues?
......@@ -27,10 +14,6 @@ module Gitlab
private
def import_data_credentials
@import_data_credentials ||= project.import_data.credentials if project.import_data
end
def gl_user_id(project, bitbucket_id)
if bitbucket_id
user = User.joins(:identities).find_by("identities.extern_uid = ? AND identities.provider = 'bitbucket'", bitbucket_id.to_s)
......
module Gitlab
module BitbucketImport
class ImporterInit
attr_reader :project, :client
def initialize(project)
@project = project
if import_data_credentials && import_data_credentials['bb_session']
token = import_data_credentials['bb_session']['bitbucket_access_token']
token_secret = import_data_credentials['bb_session']['bitbucket_access_token_secret']
@client = Client.new(token, token_secret)
@formatter = Gitlab::ImportFormatter.new
else
raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"
end
end
private
def import_data_credentials
@import_data_credentials ||= project.import_data.credentials if project.import_data
end
end
end
end
module Gitlab
module BitbucketImport
class KeyDeleter
attr_reader :project, :current_user, :client
def initialize(project)
@project = project
@current_user = project.creator
import_data = project.import_data.try(:data)
bb_session = import_data["bb_session"] if import_data
@client = Client.new(bb_session["bitbucket_access_token"],
bb_session["bitbucket_access_token_secret"])
end
class KeyDeleter < ImporterInit
attr_reader :current_user
def execute
return false unless BitbucketImport.public_key.present?
......
......@@ -22,8 +22,8 @@ module Gitlab
import_source: "#{repo["owner"]}/#{repo["slug"]}",
import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git",
).execute
project.create_import_data(credentials: { "bb_session" => session_data } )
import_data = project.import_data
import_data.credentials.merge!("bb_session" => session_data)
project
end
end
......
......@@ -34,9 +34,9 @@ describe Gitlab::BitbucketImport::Importer, lib: true do
let(:project_identifier) { 'namespace/repo' }
let(:data) do
{
bb_session: {
bitbucket_access_token: "123456",
bitbucket_access_token_secret: "secret"
'bb_session' => {
'bitbucket_access_token' => "123456",
'bitbucket_access_token_secret' => "secret"
}
}
end
......@@ -44,7 +44,7 @@ describe Gitlab::BitbucketImport::Importer, lib: true do
create(
:project,
import_source: project_identifier,
import_data: ProjectImportData.new(data: data)
import_data: ProjectImportData.new(credentials: data)
)
end
let(:importer) { Gitlab::BitbucketImport::Importer.new(project) }
......
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