Commit a1a1d1f7 authored by James Lopez's avatar James Lopez

refactored create_or_update_import_data

parent 15044e7d
...@@ -404,7 +404,7 @@ class Project < ActiveRecord::Base ...@@ -404,7 +404,7 @@ class Project < ActiveRecord::Base
def import_url=(value) def import_url=(value)
import_url = Gitlab::ImportUrl.new(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) super(import_url.sanitized_url)
end end
...@@ -417,26 +417,17 @@ class Project < ActiveRecord::Base ...@@ -417,26 +417,17 @@ class Project < ActiveRecord::Base
end end
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 = import_data || build_import_data
project_import_data.data = data if data
if credentials
project_import_data.credentials ||= {} project_import_data.credentials ||= {}
project_import_data.credentials = project_import_data.credentials.merge(credentials) project_import_data.credentials = project_import_data.credentials.merge(credentials)
project_import_data.save
end 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 project_import_data.save
end 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? def import?
external_import? || forked? external_import? || forked?
end end
......
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git", import_url: "ssh://git@bitbucket.org/#{repo["owner"]}/#{repo["slug"]}.git",
).execute ).execute
project.update_import_data(credentials: { bb_session: session_data }) project.create_or_update_import_data(credentials: { bb_session: session_data })
project project
end end
......
...@@ -24,7 +24,7 @@ module Gitlab ...@@ -24,7 +24,7 @@ module Gitlab
import_url: Project::UNKNOWN_IMPORT_URL import_url: Project::UNKNOWN_IMPORT_URL
).execute ).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 project
end end
......
...@@ -24,7 +24,7 @@ module Gitlab ...@@ -24,7 +24,7 @@ module Gitlab
import_url: repo.import_url import_url: repo.import_url
).execute ).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 project
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