Commit 6967871f authored by James Lopez's avatar James Lopez

fogbugz importer, also refactored migration again to make it easier to add new importers

parent 8da04f6b
...@@ -12,11 +12,14 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration ...@@ -12,11 +12,14 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
def up def up
say("Encrypting and migrating project import credentials...") say("Encrypting and migrating project import credentials...")
say("Projects and Github projects with a wrong URL") say("Projects and Github projects with a wrong URL. Also, migrating Gitlab projects credentials.")
in_transaction { process_projects_with_wrong_url } in_transaction { process_projects_with_wrong_url }
say("Migrating bitbucket credentials...") say("Migrating bitbucket credentials...")
in_transaction { process_bitbucket_projects } in_transaction { process_project(import_type: 'bitbucket') }
say("Migrating fogbugz credentials...")
in_transaction { process_project(import_type: 'fogbugz') }
end end
def process_projects_with_wrong_url def process_projects_with_wrong_url
...@@ -28,12 +31,16 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration ...@@ -28,12 +31,16 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
end end
end end
def process_bitbucket_projects def process_project(import_type: )
bitbucket_projects_with_wrong_import_url.each do |bitbucket_data| unencrypted_import_data(import_type: import_type).each do |data|
data_hash = YAML::load(bitbucket_data['data']) if bitbucket_data['data'] replace_data_credentials(data)
if defined?(data_hash) && data_hash && data_hash['bb_session'] end
update_import_data_for_bitbucket(data_hash, bitbucket_data['id'])
end end
def replace_data_credentials(data)
data_hash = YAML::load(data['data']) if data['data']
if defined?(data_hash) && data_hash
update_with_encrypted_data(data_hash, data['id'])
end end
end end
...@@ -56,7 +63,7 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration ...@@ -56,7 +63,7 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
end end
end end
def update_import_data_for_bitbucket(data_hash, import_data_id) def update_with_encrypted_data(data_hash, import_data_id)
fake_import_data = FakeProjectImportData.new fake_import_data = FakeProjectImportData.new
fake_import_data.credentials = data_hash fake_import_data.credentials = data_hash
execute(update_import_data_sql(import_data_id, fake_import_data)) execute(update_import_data_sql(import_data_id, fake_import_data))
...@@ -79,9 +86,9 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration ...@@ -79,9 +86,9 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
select_all("SELECT p.id, p.import_url FROM projects p WHERE p.import_url IS NOT NULL AND (p.import_url LIKE '%//%:%@%' OR p.import_url LIKE 'https___#{"_"*40}@github.com%')") select_all("SELECT p.id, p.import_url FROM projects p WHERE p.import_url IS NOT NULL AND (p.import_url LIKE '%//%:%@%' OR p.import_url LIKE 'https___#{"_"*40}@github.com%')")
end end
# All bitbucket imports # All imports with data for import_type
def bitbucket_projects_with_wrong_import_url def unencrypted_import_data(import_type: )
select_all("SELECT i.id, p.import_url, i.data FROM projects p INNER JOIN project_import_data i ON p.id = i.project_id WHERE p.import_url IS NOT NULL AND p.import_type = 'bitbucket' ") select_all("SELECT i.id, p.import_url, i.data FROM projects p INNER JOIN project_import_data i ON p.id = i.project_id WHERE p.import_url IS NOT NULL AND p.import_type = '#{import_type}' ")
end end
def project_import_data(project_id) def project_import_data(project_id)
......
...@@ -8,9 +8,12 @@ module Gitlab ...@@ -8,9 +8,12 @@ module Gitlab
import_data = project.import_data.try(:data) import_data = project.import_data.try(:data)
repo_data = import_data['repo'] if import_data repo_data = import_data['repo'] if import_data
if import_data_credentials && import_data_credentials['repo']
@repo = FogbugzImport::Repository.new(repo_data) @repo = FogbugzImport::Repository.new(repo_data)
@known_labels = Set.new @known_labels = Set.new
else
raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"
end
end end
def execute def execute
...@@ -30,6 +33,10 @@ module Gitlab ...@@ -30,6 +33,10 @@ module Gitlab
private private
def import_data_credentials
@import_data_credentials ||= project.import_data.credentials if project.import_data
end
def user_map def user_map
@user_map ||= begin @user_map ||= begin
user_map = Hash.new user_map = Hash.new
......
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
).execute ).execute
project.create_import_data( project.create_import_data(
data: { credentials: {
'repo' => repo.raw_data, 'repo' => repo.raw_data,
'user_map' => user_map, 'user_map' => user_map,
'fb_session' => fb_session 'fb_session' => fb_session
......
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