diff options
author | James Lopez <james@jameslopez.es> | 2016-04-07 16:00:20 +0300 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-04-07 16:00:20 +0300 |
commit | 15044e7d857138b31199b796f02a81f0c29c643f (patch) | |
tree | a366d69c9f3a0679f14ebfeeb45cf0d249db2411 | |
parent | e8b7e37c6de2c541510ff804730e3d9946857b9e (diff) |
refactored a few things based on MR feedback
-rw-r--r-- | app/models/project.rb | 13 | ||||
-rw-r--r-- | db/schema.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/project_creator.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/fogbugz_import/importer.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/fogbugz_import/project_creator.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/google_code_import/project_creator.rb | 4 |
6 files changed, 25 insertions, 22 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 7b1188420ef..17b971b9d30 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 5d87dbfe41f..53d12aa35dd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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 diff --git a/lib/gitlab/bitbucket_import/project_creator.rb b/lib/gitlab/bitbucket_import/project_creator.rb index 109010cb962..65b62b2b816 100644 --- a/lib/gitlab/bitbucket_import/project_creator.rb +++ b/lib/gitlab/bitbucket_import/project_creator.rb @@ -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 diff --git a/lib/gitlab/fogbugz_import/importer.rb b/lib/gitlab/fogbugz_import/importer.rb index 42f9b6eab84..501d5a95547 100644 --- a/lib/gitlab/fogbugz_import/importer.rb +++ b/lib/gitlab/fogbugz_import/importer.rb @@ -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 diff --git a/lib/gitlab/fogbugz_import/project_creator.rb b/lib/gitlab/fogbugz_import/project_creator.rb index e9fac8968e6..c000b300468 100644 --- a/lib/gitlab/fogbugz_import/project_creator.rb +++ b/lib/gitlab/fogbugz_import/project_creator.rb @@ -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 diff --git a/lib/gitlab/google_code_import/project_creator.rb b/lib/gitlab/google_code_import/project_creator.rb index 49d6013af28..d2e20afbb1e 100644 --- a/lib/gitlab/google_code_import/project_creator.rb +++ b/lib/gitlab/google_code_import/project_creator.rb @@ -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 |