提交 15044e7d 编写于 作者: J James Lopez

refactored a few things based on MR feedback

上级 e8b7e37c
......@@ -424,6 +424,19 @@ class Project < ActiveRecord::Base
project_import_data.save
end
def create_or_update_import_data(credentials)
project_import_data = import_data || build_import_data
project_import_data.credentials ||= {}
project_import_data.credentials = project_import_data.credentials.merge(credentials)
project_import_data.save
end
def update_import_data(data: nil, credentials: nil)
import_data.data = data if data
import_data.credentials = import_data.credentials.merge(credentials) if credentials
import_data.save
end
def import?
external_import? || forked?
end
......
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160331223143) do
ActiveRecord::Schema.define(version: 20160320204112) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -44,6 +44,7 @@ ActiveRecord::Schema.define(version: 20160331223143) do
t.datetime "updated_at"
t.string "home_page_url"
t.integer "default_branch_protection", default: 2
t.boolean "twitter_sharing_enabled", default: true
t.text "restricted_visibility_levels"
t.boolean "version_check_enabled", default: true
t.integer "max_attachment_size", default: 10, null: false
......@@ -416,9 +417,9 @@ ActiveRecord::Schema.define(version: 20160331223143) do
t.string "state"
t.integer "iid"
t.integer "updated_by_id"
t.boolean "confidential", default: false
t.datetime "deleted_at"
t.integer "moved_to_id"
t.boolean "confidential", default: false
t.datetime "deleted_at"
end
add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree
......@@ -747,7 +748,6 @@ ActiveRecord::Schema.define(version: 20160331223143) do
add_index "projects", ["namespace_id"], name: "index_projects_on_namespace_id", using: :btree
add_index "projects", ["path"], name: "index_projects_on_path", using: :btree
add_index "projects", ["path"], name: "index_projects_on_path_trigram", using: :gin, opclasses: {"path"=>"gin_trgm_ops"}
add_index "projects", ["pending_delete"], name: "index_projects_on_pending_delete", using: :btree
add_index "projects", ["runners_token"], name: "index_projects_on_runners_token", using: :btree
add_index "projects", ["star_count"], name: "index_projects_on_star_count", using: :btree
add_index "projects", ["visibility_level"], name: "index_projects_on_visibility_level", using: :btree
......
......@@ -23,10 +23,7 @@ module Gitlab
import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git",
).execute
import_data = project.import_data
# merge! with a bang doesn't work here
import_data.credentials = import_data.credentials.merge(bb_session: session_data)
import_data.save
project.update_import_data(credentials: { bb_session: session_data })
project
end
......
......@@ -18,7 +18,7 @@ module Gitlab
def execute
return true unless repo.valid?
client = Gitlab::FogbugzImport::Client.new(token: import_data_credentials[:fb_session][:token], uri: import_data_credentials[:fb_session][:uri])
client = Gitlab::FogbugzImport::Client.new(token: fb_session[:token], uri: fb_session[:uri])
@cases = client.cases(@repo.id.to_i)
@categories = client.categories
......@@ -30,8 +30,8 @@ module Gitlab
private
def import_data_credentials
@import_data_credentials ||= project.import_data.credentials if project.import_data
def fb_session
@import_data_credentials ||= project.import_data.credentials[:fb_session] if project.import_data && project.import_data.credentials
end
def user_map
......@@ -240,8 +240,8 @@ module Gitlab
end
def build_attachment_url(rel_url)
uri = import_data_credentials[:fb_session][:uri]
token = import_data_credentials[:fb_session][:token]
uri = fb_session[:uri]
token = fb_session[:token]
"#{uri}/#{rel_url}&token=#{token}"
end
......
......@@ -24,12 +24,7 @@ module Gitlab
import_url: Project::UNKNOWN_IMPORT_URL
).execute
import_data = project.import_data
import_data.data = { 'repo' => repo.raw_data, 'user_map' => user_map }
# merge! with a bang doesn't work here
import_data.credentials = import_data.credentials.merge(fb_session: fb_session)
import_data.save
project.update_import_data(data: { 'repo' => repo.raw_data, 'user_map' => user_map }, credentials: { fb_session: fb_session })
project
end
......
......@@ -24,9 +24,7 @@ module Gitlab
import_url: repo.import_url
).execute
import_data = project.import_data
import_data.data = { 'repo' => repo.raw_data, 'user_map' => user_map }
import_data.save
project.update_import_data(data: { 'repo' => repo.raw_data, 'user_map' => user_map })
project
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册