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