diff options
Diffstat (limited to 'app/models/bulk_imports')
-rw-r--r-- | app/models/bulk_imports/entity.rb | 24 | ||||
-rw-r--r-- | app/models/bulk_imports/tracker.rb | 4 |
2 files changed, 26 insertions, 2 deletions
diff --git a/app/models/bulk_imports/entity.rb b/app/models/bulk_imports/entity.rb index 24f86b44841..ab5d248ff8c 100644 --- a/app/models/bulk_imports/entity.rb +++ b/app/models/bulk_imports/entity.rb @@ -78,6 +78,30 @@ class BulkImports::Entity < ApplicationRecord ERB::Util.url_encode(source_full_path) end + def pipelines + @pipelines ||= case source_type + when 'group_entity' + BulkImports::Groups::Stage.pipelines + when 'project_entity' + BulkImports::Projects::Stage.pipelines + end + end + + def pipeline_exists?(name) + pipelines.any? { |_, pipeline| pipeline.to_s == name.to_s } + end + + def create_pipeline_trackers! + self.class.transaction do + pipelines.each do |stage, pipeline| + trackers.create!( + stage: stage, + pipeline_name: pipeline + ) + end + end + end + private def validate_parent_is_a_group diff --git a/app/models/bulk_imports/tracker.rb b/app/models/bulk_imports/tracker.rb index 1b108d5c042..c185470b1c2 100644 --- a/app/models/bulk_imports/tracker.rb +++ b/app/models/bulk_imports/tracker.rb @@ -34,8 +34,8 @@ class BulkImports::Tracker < ApplicationRecord end def pipeline_class - unless BulkImports::Stage.pipeline_exists?(pipeline_name) - raise NameError, "'#{pipeline_name}' is not a valid BulkImport Pipeline" + unless entity.pipeline_exists?(pipeline_name) + raise BulkImports::Error, "'#{pipeline_name}' is not a valid BulkImport Pipeline" end pipeline_name.constantize |