Commit cc4d04f9 authored by James Lopez's avatar James Lopez

added rest of importers, fixed specs and some issues with the migration

parent 6967871f
...@@ -12,7 +12,8 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration ...@@ -12,7 +12,8 @@ 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. 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 } in_transaction { process_projects_with_wrong_url }
say("Migrating bitbucket credentials...") say("Migrating bitbucket credentials...")
...@@ -20,6 +21,9 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration ...@@ -20,6 +21,9 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
say("Migrating fogbugz credentials...") say("Migrating fogbugz credentials...")
in_transaction { process_project(import_type: 'fogbugz') } in_transaction { process_project(import_type: 'fogbugz') }
say("Migrating google code credentials...")
in_transaction { process_project(import_type: 'google_code') }
end end
def process_projects_with_wrong_url def process_projects_with_wrong_url
...@@ -39,7 +43,7 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration ...@@ -39,7 +43,7 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
def replace_data_credentials(data) def replace_data_credentials(data)
data_hash = YAML::load(data['data']) if data['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']) update_with_encrypted_data(data_hash, data['id'])
end end
end end
...@@ -83,7 +87,7 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration ...@@ -83,7 +87,7 @@ class RemoveWrongImportUrlFromProjects < ActiveRecord::Migration
#Github projects with token, and any user:password@ based URL #Github projects with token, and any user:password@ based URL
def projects_with_wrong_import_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 end
# All imports with data for import_type # All imports with data for import_type
......
...@@ -417,9 +417,9 @@ ActiveRecord::Schema.define(version: 20160320204112) do ...@@ -417,9 +417,9 @@ ActiveRecord::Schema.define(version: 20160320204112) do
t.string "state" t.string "state"
t.integer "iid" t.integer "iid"
t.integer "updated_by_id" 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.datetime "deleted_at"
t.integer "moved_to_id"
end end
add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree
......
...@@ -6,12 +6,13 @@ module Gitlab ...@@ -6,12 +6,13 @@ module Gitlab
def initialize(project) def initialize(project)
@project = project @project = project
import_data = project.import_data.try(:data) if import_data_credentials && import_data_credentials['repo']
repo_data = import_data["repo"] if import_data @repo = GoogleCodeImport::Repository.new(import_data_credentials['repo'])
@repo = GoogleCodeImport::Repository.new(repo_data) @closed_statuses = []
@known_labels = Set.new
@closed_statuses = [] else
@known_labels = Set.new raise Projects::ImportService::Error, "Unable to find project import data credentials for project ID: #{@project.id}"
end
end end
def execute def execute
...@@ -28,6 +29,10 @@ module Gitlab ...@@ -28,6 +29,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 do |hash, user| user_map = Hash.new do |hash, user|
...@@ -35,8 +40,7 @@ module Gitlab ...@@ -35,8 +40,7 @@ module Gitlab
Client.mask_email(user).sub("...", "\\.\\.\\.") Client.mask_email(user).sub("...", "\\.\\.\\.")
end end
import_data = project.import_data.try(:data) stored_user_map = import_data_credentials["user_map"]
stored_user_map = import_data["user_map"] if import_data
user_map.update(stored_user_map) if stored_user_map user_map.update(stored_user_map) if stored_user_map
user_map user_map
......
...@@ -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
} }
......
...@@ -15,7 +15,7 @@ describe Gitlab::GoogleCodeImport::Importer, lib: true do ...@@ -15,7 +15,7 @@ describe Gitlab::GoogleCodeImport::Importer, lib: true do
subject { described_class.new(project) } subject { described_class.new(project) }
before do before do
project.create_import_data(data: import_data) project.create_import_data(credentials: import_data)
end end
describe "#execute" do describe "#execute" do
......
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