diff --git a/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb b/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb index f3a4fc26be9fb6b2d5cbea5d6f7301d632af85c0..a55ab6a42b43c985079485d4afcb7cf693e293c2 100644 --- a/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb +++ b/db/migrate/20160302152808_remove_wrong_import_url_from_projects.rb @@ -12,7 +12,8 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration def up say("Encrypting and migrating project import credentials...") - say("Projects and Github projects with a wrong URL. Also, migrating Gitlab projects credentials.") + # This should cover Github, Gitlab, Bitbucket user:password, token@domain, and other similar URLs. + say("Projects and Github projects with a wrong URL. It also migrates Gitlab project credentials.") in_transaction { process_projects_with_wrong_url } say("Migrating bitbucket credentials...") @@ -20,6 +21,9 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration say("Migrating fogbugz credentials...") in_transaction { process_project(import_type: 'fogbugz') } + + say("Migrating google code credentials...") + in_transaction { process_project(import_type: 'google_code') } end def process_projects_with_wrong_url @@ -39,7 +43,7 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration def replace_data_credentials(data) data_hash = YAML::load(data['data']) if data['data'] - if defined?(data_hash) && data_hash + if defined?(data_hash) && !data_hash.blank? update_with_encrypted_data(data_hash, data['id']) end end @@ -83,7 +87,7 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration #Github projects with token, and any user:password@ based URL def projects_with_wrong_import_url - 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 '%//%@%'") end # All imports with data for import_type diff --git a/db/schema.rb b/db/schema.rb index 53d12aa35ddc479ad4c98caba7594e781910ecf4..75509c35b05a26a90a6703d5d2d6b0b056ca4a0a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -417,9 +417,9 @@ ActiveRecord::Schema.define(version: 20160320204112) do t.string "state" t.integer "iid" t.integer "updated_by_id" - t.integer "moved_to_id" - t.boolean "confidential", default: false + t.boolean "confidential", default: false t.datetime "deleted_at" + t.integer "moved_to_id" end add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree diff --git a/lib/gitlab/google_code_import/importer.rb b/lib/gitlab/google_code_import/importer.rb index 62da327931faff96264b4152325c321bc7f16281..6b0715d14921fe9a1c86b7663b3c999d3e87b8ee 100644 --- a/lib/gitlab/google_code_import/importer.rb +++ b/lib/gitlab/google_code_import/importer.rb @@ -6,12 +6,13 @@ module Gitlab def initialize(project) @project = project - import_data = project.import_data.try(:data) - repo_data = import_data["repo"] if import_data - @repo = GoogleCodeImport::Repository.new(repo_data) - - @closed_statuses = [] - @known_labels = Set.new + if import_data_credentials && import_data_credentials['repo'] + @repo = GoogleCodeImport::Repository.new(import_data_credentials['repo']) + @closed_statuses = [] + @known_labels = Set.new + else + raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}" + end end def execute @@ -28,6 +29,10 @@ module Gitlab private + def import_data_credentials + @import_data_credentials ||= project.import_data.credentials if project.import_data + end + def user_map @user_map ||= begin user_map = Hash.new do |hash, user| @@ -35,8 +40,7 @@ module Gitlab Client.mask_email(user).sub("...", "\\.\\.\\.") end - import_data = project.import_data.try(:data) - stored_user_map = import_data["user_map"] if import_data + stored_user_map = import_data_credentials["user_map"] user_map.update(stored_user_map) if stored_user_map user_map diff --git a/lib/gitlab/google_code_import/project_creator.rb b/lib/gitlab/google_code_import/project_creator.rb index 87821c2346094f94869b8144a2a6412c739618af..acd3a832d59c91a09d24851d045a0fac98456239 100644 --- a/lib/gitlab/google_code_import/project_creator.rb +++ b/lib/gitlab/google_code_import/project_creator.rb @@ -25,7 +25,7 @@ module Gitlab ).execute project.create_import_data( - data: { + credentials: { "repo" => repo.raw_data, "user_map" => user_map } diff --git a/spec/lib/gitlab/google_code_import/importer_spec.rb b/spec/lib/gitlab/google_code_import/importer_spec.rb index 647631271e0004725cf22834897ce7d15ccb6d39..6ecf3d7182f86408ac9c9fb69a8c80db5fea40dd 100644 --- a/spec/lib/gitlab/google_code_import/importer_spec.rb +++ b/spec/lib/gitlab/google_code_import/importer_spec.rb @@ -15,7 +15,7 @@ describe Gitlab::GoogleCodeImport::Importer, lib: true do subject { described_class.new(project) } before do - project.create_import_data(data: import_data) + project.create_import_data(credentials: import_data) end describe "#execute" do