1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# frozen_string_literal: true
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',
notifications: 'Notifications',
current_user_todos: "Current user todos",
award_emoji: 'Award emoji',
linked_items: 'Linked items'
}.freeze
WIDGETS_FOR_TYPE = {
issue: [
:assignees,
:labels,
:description,
:hierarchy,
:start_and_due_date,
:milestone,
:notes,
:iteration,
:weight,
:health_status,
:notifications,
:current_user_todos,
:award_emoji,
:linked_items
],
incident: [
:assignees,
:description,
:hierarchy,
:notes,
:notifications,
:current_user_todos,
:award_emoji,
:linked_items
],
test_case: [
:description,
:notes,
:notifications,
:current_user_todos,
:award_emoji,
:linked_items
],
requirement: [
:description,
:notes,
:status,
:requirement_legacy,
:test_reports,
:notifications,
:current_user_todos,
:award_emoji,
:linked_items
],
task: [
:assignees,
:labels,
:description,
:hierarchy,
:start_and_due_date,
:milestone,
:notes,
:iteration,
:weight,
:notifications,
:current_user_todos,
:award_emoji,
:linked_items
],
objective: [
:assignees,
:labels,
:description,
:hierarchy,
:milestone,
:notes,
:health_status,
:progress,
:notifications,
:current_user_todos,
:award_emoji,
:linked_items
],
key_result: [
:assignees,
:labels,
:description,
:hierarchy,
:start_and_due_date,
:notes,
:health_status,
:progress,
:notifications,
:current_user_todos,
:award_emoji,
:linked_items
],
epic: [
:assignees,
:description,
:hierarchy,
:labels,
:notes,
:start_and_due_date,
:health_status,
:status,
:notifications,
:award_emoji,
:linked_items
],
ticket: [
:assignees,
:labels,
:description,
:hierarchy,
:start_and_due_date,
:milestone,
:notes,
:iteration,
:weight,
:health_status,
:notifications,
:current_user_todos,
:award_emoji
]
}.freeze
def self.upsert_types
current_time = Time.current
base_types = ::WorkItems::Type::BASE_TYPES.map do |type, attributes|
attributes.slice(:name, :icon_name)
.merge(created_at: current_time, updated_at: current_time, base_type: type)
end
::WorkItems::Type.upsert_all(
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
end
end
|