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
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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
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