diff options
author | James Lopez <james@jameslopez.es> | 2016-04-07 15:08:38 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-04-07 15:08:38 +0200 |
commit | a1a1d1f7de71f46787f12f1efa23346a2a6b1c29 (patch) | |
tree | 3b68596379b7e025c7964b27461c6baec7bedd8d | |
parent | 15044e7d857138b31199b796f02a81f0c29c643f (diff) | |
download | gitlab-ce-a1a1d1f7de71f46787f12f1efa23346a2a6b1c29.tar.gz |
refactored create_or_update_import_data
-rw-r--r-- | app/models/project.rb | 23 | ||||
-rw-r--r-- | lib/gitlab/bitbucket_import/project_creator.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/fogbugz_import/project_creator.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/google_code_import/project_creator.rb | 2 |
4 files changed, 10 insertions, 19 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 17b971b9d30..273b04c6323 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -404,7 +404,7 @@ class Project < ActiveRecord::Base def import_url=(value) import_url = Gitlab::ImportUrl.new(value) - create_or_update_import_data(import_url.credentials) + create_or_update_import_data(credentials: import_url.credentials) super(import_url.sanitized_url) end @@ -417,26 +417,17 @@ class Project < ActiveRecord::Base end end - def create_or_update_import_data(credentials) + def create_or_update_import_data(data: nil, credentials: nil) 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 + project_import_data.data = data if data + if credentials + project_import_data.credentials ||= {} + project_import_data.credentials = project_import_data.credentials.merge(credentials) + 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/lib/gitlab/bitbucket_import/project_creator.rb b/lib/gitlab/bitbucket_import/project_creator.rb index 65b62b2b816..941f818b847 100644 --- a/lib/gitlab/bitbucket_import/project_creator.rb +++ b/lib/gitlab/bitbucket_import/project_creator.rb @@ -23,7 +23,7 @@ module Gitlab import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git", ).execute - project.update_import_data(credentials: { bb_session: session_data }) + project.create_or_update_import_data(credentials: { bb_session: session_data }) project end diff --git a/lib/gitlab/fogbugz_import/project_creator.rb b/lib/gitlab/fogbugz_import/project_creator.rb index c000b300468..3840765db87 100644 --- a/lib/gitlab/fogbugz_import/project_creator.rb +++ b/lib/gitlab/fogbugz_import/project_creator.rb @@ -24,7 +24,7 @@ module Gitlab import_url: Project::UNKNOWN_IMPORT_URL ).execute - project.update_import_data(data: { 'repo' => repo.raw_data, 'user_map' => user_map }, credentials: { fb_session: fb_session }) + project.create_or_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 d2e20afbb1e..0abb7a64c17 100644 --- a/lib/gitlab/google_code_import/project_creator.rb +++ b/lib/gitlab/google_code_import/project_creator.rb @@ -24,7 +24,7 @@ module Gitlab import_url: repo.import_url ).execute - project.update_import_data(data: { 'repo' => repo.raw_data, 'user_map' => user_map }) + project.create_or_update_import_data(data: { 'repo' => repo.raw_data, 'user_map' => user_map }) project end |