10_merge_requests.rb 1.9 KB
Newer Older
1 2
require './spec/support/sidekiq'

3
Gitlab::Seeder.quiet do
4 5 6
  # Limit the number of merge requests per project to avoid long seeds
  MAX_NUM_MERGE_REQUESTS = 10

7
  Project.non_archived.with_merge_requests_enabled.reject(&:empty_repo?).each do |project|
8
    branches = project.repository.branch_names.sample(MAX_NUM_MERGE_REQUESTS * 2)
D
Dmitriy Zaporozhets 已提交
9 10 11 12 13 14 15 16 17

    branches.each do |branch_name|
      break if branches.size < 2
      source_branch = branches.pop
      target_branch = branches.pop

      params = {
        source_branch: source_branch,
        target_branch: target_branch,
R
Robert Speicher 已提交
18 19
        title: FFaker::Lorem.sentence(6),
        description: FFaker::Lorem.sentences(3).join(" "),
D
Dmitriy Zaporozhets 已提交
20 21
        milestone: project.milestones.sample,
        assignee: project.team.users.sample
D
Dmitriy Zaporozhets 已提交
22 23
      }

24 25 26 27
      # Only create MRs with users that are allowed to create MRs
      developer = project.team.developers.sample
      break unless developer

S
Shinya Maeda 已提交
28 29
      Sidekiq::Worker.skipping_transaction_check do
        MergeRequests::CreateService.new(project, developer, params).execute
30 31 32
      rescue Repository::AmbiguousRefError
        # Ignore pipelines creation errors for now, we can doing that after
        # https://gitlab.com/gitlab-org/gitlab-ce/issues/55966. will be resolved.
S
Shinya Maeda 已提交
33
      end
D
Dmitriy Zaporozhets 已提交
34
      print '.'
35
    end
36
  end
37

38
  project = Project.find_by_full_path('gitlab-org/gitlab-test')
39

40 41
  next if project.empty_repo? # We don't have repository on CI

42 43 44 45 46
  params = {
    source_branch: 'feature',
    target_branch: 'master',
    title: 'Can be automatically merged'
  }
S
Shinya Maeda 已提交
47 48 49
  Sidekiq::Worker.skipping_transaction_check do
    MergeRequests::CreateService.new(project, User.admins.first, params).execute
  end
50 51 52 53 54 55 56
  print '.'

  params = {
    source_branch: 'feature_conflict',
    target_branch: 'feature',
    title: 'Cannot be automatically merged'
  }
S
Shinya Maeda 已提交
57 58 59
  Sidekiq::Worker.skipping_transaction_check do
    MergeRequests::CreateService.new(project, User.admins.first, params).execute
  end
60
  print '.'
R
randx 已提交
61
end