2020-01-01 13:55:28 +05:30
|
|
|
require './spec/support/sidekiq_middleware'
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
Gitlab::Seeder.quiet do
|
2016-06-02 11:05:42 +05:30
|
|
|
# Limit the number of merge requests per project to avoid long seeds
|
|
|
|
MAX_NUM_MERGE_REQUESTS = 10
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
projects = Project
|
|
|
|
.non_archived
|
|
|
|
.with_merge_requests_enabled
|
|
|
|
.not_mass_generated
|
|
|
|
.reject(&:empty_repo?)
|
|
|
|
|
|
|
|
projects.each do |project|
|
2016-06-02 11:05:42 +05:30
|
|
|
branches = project.repository.branch_names.sample(MAX_NUM_MERGE_REQUESTS * 2)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
branches.each do |branch_name|
|
|
|
|
break if branches.size < 2
|
|
|
|
source_branch = branches.pop
|
|
|
|
target_branch = branches.pop
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
label_ids = project.labels.pluck(:id).sample(3)
|
|
|
|
label_ids += project.group.labels.sample(3) if project.group
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
params = {
|
|
|
|
source_branch: source_branch,
|
|
|
|
target_branch: target_branch,
|
2015-09-11 14:41:01 +05:30
|
|
|
title: FFaker::Lorem.sentence(6),
|
|
|
|
description: FFaker::Lorem.sentences(3).join(" "),
|
2014-09-02 18:07:02 +05:30
|
|
|
milestone: project.milestones.sample,
|
2019-07-31 22:56:46 +05:30
|
|
|
assignees: [project.team.users.sample],
|
2019-07-07 11:18:12 +05:30
|
|
|
label_ids: label_ids
|
2014-09-02 18:07:02 +05:30
|
|
|
}
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
# Only create MRs with users that are allowed to create MRs
|
|
|
|
developer = project.team.developers.sample
|
|
|
|
break unless developer
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
Sidekiq::Worker.skipping_transaction_check do
|
|
|
|
MergeRequests::CreateService.new(project, developer, params).execute
|
2019-03-02 22:35:43 +05:30
|
|
|
rescue Repository::AmbiguousRefError
|
|
|
|
# Ignore pipelines creation errors for now, we can doing that after
|
2019-12-04 20:38:33 +05:30
|
|
|
# https://gitlab.com/gitlab-org/gitlab-foss/issues/55966. will be resolved.
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
print '.'
|
|
|
|
end
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
project = Project.find_by_full_path('gitlab-org/gitlab-test')
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
next if !project || project.empty_repo? # We don't have repository on CI
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
params = {
|
|
|
|
source_branch: 'feature',
|
|
|
|
target_branch: 'master',
|
|
|
|
title: 'Can be automatically merged'
|
|
|
|
}
|
2019-02-15 15:39:39 +05:30
|
|
|
Sidekiq::Worker.skipping_transaction_check do
|
|
|
|
MergeRequests::CreateService.new(project, User.admins.first, params).execute
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
print '.'
|
|
|
|
|
|
|
|
params = {
|
|
|
|
source_branch: 'feature_conflict',
|
|
|
|
target_branch: 'feature',
|
|
|
|
title: 'Cannot be automatically merged'
|
|
|
|
}
|
2019-02-15 15:39:39 +05:30
|
|
|
Sidekiq::Worker.skipping_transaction_check do
|
|
|
|
MergeRequests::CreateService.new(project, User.admins.first, params).execute
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
print '.'
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|