Welcome to mirror list, hosted at ThFree Co, Russian Federation.

hierarchy_restrictions_importer.rb « work_items « database_importers « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4e3b685c06c83c6e95cabd6bca0cda7920bd9aa2 (plain)
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
# frozen_string_literal: true

module Gitlab
  module DatabaseImporters
    module WorkItems
      module HierarchyRestrictionsImporter
        def self.upsert_restrictions
          objective = find_or_create_type(::WorkItems::Type::TYPE_NAMES[:objective])
          key_result = find_or_create_type(::WorkItems::Type::TYPE_NAMES[:key_result])
          issue = find_or_create_type(::WorkItems::Type::TYPE_NAMES[:issue])
          task = find_or_create_type(::WorkItems::Type::TYPE_NAMES[:task])
          incident = find_or_create_type(::WorkItems::Type::TYPE_NAMES[:incident])
          epic = find_or_create_type(::WorkItems::Type::TYPE_NAMES[:epic])
          ticket = find_or_create_type(::WorkItems::Type::TYPE_NAMES[:ticket])

          restrictions = [
            {
              parent_type_id: objective.id,
              child_type_id: objective.id,
              maximum_depth: 9,
              cross_hierarchy_enabled: false
            },
            {
              parent_type_id: objective.id,
              child_type_id: key_result.id,
              maximum_depth: 1,
              cross_hierarchy_enabled: false
            },
            {
              parent_type_id: issue.id,
              child_type_id: task.id,
              maximum_depth: 1,
              cross_hierarchy_enabled: false
            },
            {
              parent_type_id: incident.id,
              child_type_id: task.id,
              maximum_depth: 1,
              cross_hierarchy_enabled: false
            },
            {
              parent_type_id: epic.id,
              child_type_id: epic.id,
              maximum_depth: 9,
              cross_hierarchy_enabled: true
            },
            {
              parent_type_id: epic.id,
              child_type_id: issue.id,
              maximum_depth: 1,
              cross_hierarchy_enabled: true
            },
            {
              parent_type_id: ticket.id,
              child_type_id: task.id,
              maximum_depth: 1,
              cross_hierarchy_enabled: false
            }
          ]

          ::WorkItems::HierarchyRestriction.upsert_all(
            filtered_restrictions(restrictions),
            unique_by: :index_work_item_hierarchy_restrictions_on_parent_and_child
          )
        end

        def self.find_or_create_type(name)
          type = ::WorkItems::Type.find_by_name_and_namespace_id(name, nil)
          return type if type

          Gitlab::DatabaseImporters::WorkItems::BaseTypeImporter.upsert_types
          ::WorkItems::Type.find_by_name_and_namespace_id(name, nil)
        end

        def self.filtered_restrictions(restrictions)
          missing_columns = restrictions.first.keys.select do |attribute|
            ::WorkItems::HierarchyRestriction.column_names.exclude?(attribute.to_s)
          end

          return restrictions if missing_columns.empty?

          restrictions.map { |restriction| restriction.except(*missing_columns) }
        end
      end
    end
  end
end