Commit 4e9b094b authored by James Lopez's avatar James Lopez

refactor finder

parent 825c68e2
......@@ -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
......
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