summaryrefslogtreecommitdiff
path: root/db/fixtures/development/20_nested_groups.rb
blob: 2bc78e120a5ad32725fc0122d8567853b81b03ec (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
require './spec/support/sidekiq'

def create_group_with_parents(user, full_path)
  parent_path = nil
  group = nil

  until full_path.blank?
    path, _, full_path = full_path.partition('/')

    if parent_path
      parent = Group.find_by_full_path(parent_path)

      parent_path += '/'
      parent_path += path

      group = Groups::CreateService.new(user, path: path, parent_id: parent.id).execute
    else
      parent_path = path

      group = Group.find_by_full_path(parent_path) ||
        Groups::CreateService.new(user, path: path).execute
    end
  end

  group
end

Sidekiq::Testing.inline! do
  Gitlab::Seeder.quiet do
    flag = 'SEED_NESTED_GROUPS'

    if ENV[flag]
      project_urls = [
        'https://android.googlesource.com/platform/hardware/broadcom/libbt.git',
        'https://android.googlesource.com/platform/hardware/broadcom/wlan.git',
        'https://android.googlesource.com/platform/hardware/bsp/bootloader/intel/edison-u-boot.git',
        'https://android.googlesource.com/platform/hardware/bsp/broadcom.git',
        'https://android.googlesource.com/platform/hardware/bsp/freescale.git',
        'https://android.googlesource.com/platform/hardware/bsp/imagination.git',
        'https://android.googlesource.com/platform/hardware/bsp/intel.git',
        'https://android.googlesource.com/platform/hardware/bsp/kernel/common/v4.1.git',
        'https://android.googlesource.com/platform/hardware/bsp/kernel/common/v4.4.git'
      ]

      user = User.admins.first

      project_urls.each_with_index do |url, i|
        full_path = url.sub('https://android.googlesource.com/', '')
        full_path = full_path.sub(/\.git\z/, '')
        full_path, _, project_path = full_path.rpartition('/')
        group = Group.find_by_full_path(full_path) || create_group_with_parents(user, full_path)

        params = {
          import_url: url,
          namespace_id: group.id,
          path: project_path,
          name: project_path,
          description: FFaker::Lorem.sentence,
          visibility_level: Gitlab::VisibilityLevel.values.sample
        }

        project = Projects::CreateService.new(user, params).execute
        project.send(:_run_after_commit_queue)

        if project.valid?
          print '.'
        else
          print 'F'
        end
      end
    else
      puts "Skipped. Use the `#{flag}` environment variable to enable."
    end
  end
end