summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2018-06-20 10:27:40 +0200
committerJames Lopez <james@jameslopez.es>2018-06-20 10:27:40 +0200
commit4e9b094b29c225878dfe15a200dd60f0bc1fdd67 (patch)
tree266935a946713cfd356860773ad09b98e765d7a3 /lib
parent825c68e2ededed6f280ebd82c713cd932444d8ac (diff)
downloadgitlab-ce-4e9b094b29c225878dfe15a200dd60f0bc1fdd67.tar.gz
refactor finder
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/import_export/group_project_finder.rb22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/gitlab/import_export/group_project_finder.rb b/lib/gitlab/import_export/group_project_finder.rb
index b9ef43e4e51..cd239466a5c 100644
--- a/lib/gitlab/import_export/group_project_finder.rb
+++ b/lib/gitlab/import_export/group_project_finder.rb
@@ -2,18 +2,22 @@ module Gitlab
module ImportExport
class GroupProjectFinder
def self.find_or_new(*args)
- new(*args).find_or_new
+ Project.transaction do
+ new(*args).find_or_new
+ end
end
def self.find_or_create(*args)
- new(*args).find_or_create
+ Project.transaction do
+ new(*args).find_or_create
+ end
end
def initialize(klass, attributes)
@klass = klass
@attributes = attributes
- @group_id = @attributes['group_id']
- @project_id = @attributes['project_id']
+ @group = @attributes[:group]
+ @project = @attributes[:project]
end
def find_or_new
@@ -27,11 +31,11 @@ module Gitlab
private
def where_clause
- @attributes.except('group_id', 'project_id').map do |key, value|
- project_clause = table[key].eq(value).and(table[:project_id].eq(@project_id))
+ @attributes.except(:group, :project).map do |key, value|
+ project_clause = table[key].eq(value).and(table[:project_id].eq(@project.id))
- if @group_id
- project_clause.or(table[key].eq(value).and(table[:group_id].eq(@group_id)))
+ if @group
+ project_clause.or(table[key].eq(value).and(table[:group_id].eq(@group.id)))
else
project_clause
end
@@ -43,7 +47,7 @@ module Gitlab
end
def project_attributes
- @attributes.except('group_id').tap do |atts|
+ @attributes.except(:group).tap do |atts|
atts['type'] = 'ProjectLabel' if label?
end
end