From ced56641bfc42c8380af1760fae93ba37bf2e785 Mon Sep 17 00:00:00 2001
From: James Lopez <james@jameslopez.es>
Date: Mon, 21 Mar 2016 18:09:47 +0100
Subject: [PATCH] refactored code based on feedback

---
 app/models/project.rb    | 10 ++++++++--
 lib/gitlab/import_url.rb |  6 +++---
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/app/models/project.rb b/app/models/project.rb
index 242ad19b115..a1aa1d5fdbc 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -406,8 +406,7 @@ class Project < ActiveRecord::Base
 
   def import_url=(value)
     import_url = Gitlab::ImportUrl.new(value)
-    # deletes any existing import_data
-    create_import_data(credentials: import_url.credentials)
+    create_or_update_import_data(import_url.credentials)
     super(import_url.sanitized_url)
   end
 
@@ -420,6 +419,13 @@ class Project < ActiveRecord::Base
     end
   end
 
+  def create_or_update_import_data(credentials)
+    project_import_data = import_data || ProjectImportData.new
+    project_import_data.credentials = credentials
+    project_import_data.project_id = id
+    project_import_data.save
+  end
+
   def import?
     external_import? || forked?
   end
diff --git a/lib/gitlab/import_url.rb b/lib/gitlab/import_url.rb
index adcbcc43d24..5b18d67ddc3 100644
--- a/lib/gitlab/import_url.rb
+++ b/lib/gitlab/import_url.rb
@@ -20,10 +20,10 @@ module Gitlab
     private
 
     def generate_full_url
-      return @url unless @credentials
+      return @url unless credentials
       @full_url = @url.dup
-      @full_url.user = @credentials[:user]
-      @full_url.password = @credentials[:password]
+      @full_url.user = credentials[:user]
+      @full_url.password = credentials[:password]
       @full_url
     end
 
-- 
GitLab