Commit 06b36c00 authored by James Lopez's avatar James Lopez
Browse files

some refactoring in the migration. Also fixed github import issue and updated spec

parent 1c54dd8f9413
......@@ -23,11 +23,16 @@ def regex_extractor
end
def up
projects_with_wrong_import_url.each do |project|
sanitizer = ImportUrlSanitizer.new(project.import_urls)
project.update_columns(import_url: sanitizer.sanitized_url)
if project.import_data
project.import_data.update_columns(credentials: sanitizer.credentials)
projects_with_wrong_import_url.each do |project_id|
project = Project.find(project_id["id"])
sanitizer = ImportUrlSanitizer.new(project.import_url)
ActiveRecord::Base.transaction do
project.update_columns(import_url: sanitizer.sanitized_url)
if project.import_data
project.import_data.credentials = sanitizer.credentials
project.save!
end
end
end
end
......
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160222153918) do
ActiveRecord::Schema.define(version: 20160302152808) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -658,6 +658,8 @@
create_table "project_import_data", force: :cascade do |t|
t.integer "project_id"
t.text "data"
t.text "encrypted_credentials"
t.text "encrypted_credentials_iv"
end
create_table "projects", force: :cascade do |t|
......
......@@ -20,13 +20,21 @@ def execute
visibility_level: repo.private ? Gitlab::VisibilityLevel::PRIVATE : Gitlab::VisibilityLevel::PUBLIC,
import_type: "github",
import_source: repo.full_name,
import_url: repo.clone_url.sub("https://", "https://#{@session_data[:github_access_token]}@"),
import_url: repo.clone_url,
wiki_enabled: !repo.has_wiki? # If repo has wiki we'll import it later
).execute
project.create_import_data(data: { "github_session" => session_data } )
create_import_data(project)
project
end
private
def create_import_data(project)
project.create_import_data(
credentials: session_data.delete(:github_access_token),
data: { "github_session" => session_data })
end
end
end
end
......@@ -26,7 +26,8 @@
project_creator = Gitlab::GithubImport::ProjectCreator.new(repo, namespace, user, access_params)
project = project_creator.execute
expect(project.import_url).to eq("https://asdffg@gitlab.com/asd/vim.git")
expect(project.import_url).to eq("https://gitlab.com/asd/vim.git")
expect(project.import_data.credentials).to eq("asdffg")
expect(project.visibility_level).to eq(Gitlab::VisibilityLevel::PRIVATE)
end
end
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