Read about our upcoming Code of Conduct on this issue

Commit a1a1d1f7 authored by James Lopez's avatar James Lopez
Browse files

refactored create_or_update_import_data

parent e1fa96d1f16d
...@@ -404,7 +404,7 @@ def clear_import_data ...@@ -404,7 +404,7 @@ def clear_import_data
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 @@ def import_url ...@@ -417,26 +417,17 @@ def import_url
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.credentials ||= {} project_import_data.data = data if data
project_import_data.credentials = project_import_data.credentials.merge(credentials) if credentials
project_import_data.save project_import_data.credentials ||= {}
end 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 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 @@ def execute ...@@ -23,7 +23,7 @@ def execute
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 @@ def execute ...@@ -24,7 +24,7 @@ def execute
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 @@ def execute ...@@ -24,7 +24,7 @@ def execute
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