diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /lib/gitlab/database_importers | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'lib/gitlab/database_importers')
-rw-r--r-- | lib/gitlab/database_importers/work_items/base_type_importer.rb | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/lib/gitlab/database_importers/work_items/base_type_importer.rb b/lib/gitlab/database_importers/work_items/base_type_importer.rb index 1e29ae7761b..9796a5905e3 100644 --- a/lib/gitlab/database_importers/work_items/base_type_importer.rb +++ b/lib/gitlab/database_importers/work_items/base_type_importer.rb @@ -4,6 +4,85 @@ module Gitlab module DatabaseImporters module WorkItems module BaseTypeImporter + WIDGET_NAMES = { + assignees: 'Assignees', + labels: 'Labels', + description: 'Description', + hierarchy: 'Hierarchy', + start_and_due_date: 'Start and due date', + milestone: 'Milestone', + notes: 'Notes', + iteration: 'Iteration', + weight: 'Weight', + health_status: 'Health status', + progress: 'Progress', + status: 'Status', + requirement_legacy: 'Requirement legacy', + test_reports: 'Test reports' + }.freeze + + WIDGETS_FOR_TYPE = { + issue: [ + :assignees, + :labels, + :description, + :hierarchy, + :start_and_due_date, + :milestone, + :notes, + :iteration, + :weight, + :health_status + ], + incident: [ + :description, + :hierarchy, + :notes + ], + test_case: [ + :description, + :notes + ], + requirement: [ + :description, + :notes, + :status, + :requirement_legacy, + :test_reports + ], + task: [ + :assignees, + :labels, + :description, + :hierarchy, + :start_and_due_date, + :milestone, + :notes, + :iteration, + :weight + ], + objective: [ + :assignees, + :labels, + :description, + :hierarchy, + :milestone, + :notes, + :health_status, + :progress + ], + key_result: [ + :assignees, + :labels, + :description, + :hierarchy, + :start_and_due_date, + :notes, + :health_status, + :progress + ] + }.freeze + def self.upsert_types current_time = Time.current @@ -16,6 +95,29 @@ module Gitlab base_types, unique_by: :idx_work_item_types_on_namespace_id_and_name_null_namespace ) + + upsert_widgets + end + + def self.upsert_widgets + type_ids_by_name = ::WorkItems::Type.default.pluck(:name, :id).to_h # rubocop: disable CodeReuse/ActiveRecord + + widgets = WIDGETS_FOR_TYPE.flat_map do |type_sym, widget_syms| + type_name = ::WorkItems::Type::TYPE_NAMES[type_sym] + + widget_syms.map do |widget_sym| + { + work_item_type_id: type_ids_by_name[type_name], + name: WIDGET_NAMES[widget_sym], + widget_type: ::WorkItems::WidgetDefinition.widget_types[widget_sym] + } + end + end + + ::WorkItems::WidgetDefinition.upsert_all( + widgets, + unique_by: :index_work_item_widget_definitions_on_default_witype_and_name + ) end end end |