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

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

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