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
|
# frozen_string_literal: true
require './spec/support/sidekiq_middleware'
class Gitlab::Seeder::ComposerPackages
def group
@group ||= Group.find_by(path: 'composer')
unless @group
@group = Group.create!(
name: 'Composer',
path: 'composer',
description: FFaker::Lorem.sentence
)
@group.add_owner(user)
@group.create_namespace_settings
end
@group
end
def user
@user ||= User.first
end
def create_real_project!(url)
project_path = url.split('/').last
project_path.gsub!(".git", "")
project = group.projects.find_by(name: project_path.titleize)
return project if project.present?
params = {
import_url: url,
namespace_id: group.id,
name: project_path.titleize,
description: FFaker::Lorem.sentence,
visibility_level: Gitlab::VisibilityLevel.values.sample,
skip_disk_validation: true
}
Sidekiq::Worker.skipping_transaction_check do
project = ::Projects::CreateService.new(user, params).execute
# Seed-Fu runs this entire fixture in a transaction, so the `after_commit`
# hook won't run until after the fixture is loaded. That is too late
# since the Sidekiq::Testing block has already exited. Force clearing
# the `after_commit` queue to ensure the job is run now.
project.send(:_run_after_commit_queue)
project.import_state.send(:_run_after_commit_queue)
# Expire repository cache after import to ensure
# valid_repo? call below returns a correct answer
project.repository.expire_all_method_caches
end
if project.valid? && project.valid_repo?
print '.'
return project
else
puts project.errors.full_messages
print 'F'
return nil
end
end
end
COMPOSER_PACKAGES = {
'https://github.com/php-fig/log.git' => [
{ branch: 'master' },
{ tag: 'v1.5.2' }
],
'https://github.com/ryssbowh/craft-themes.git' => [
{ tag: '1.0.2' }
],
'https://github.com/php-fig/http-message.git' => [
{ tag: '1.0.1' }
],
'https://github.com/doctrine/instantiator.git' => [
{ branch: '1.4.x' }
]
}.freeze
Gitlab::Seeder.quiet do
flag = 'SEED_COMPOSER'
unless ENV[flag]
puts "Use the `#{flag}` environment variable to seed composer packages"
next
end
Sidekiq::Testing.inline! do
COMPOSER_PACKAGES.each do |path, versions|
project = Gitlab::Seeder::ComposerPackages.new.create_real_project!(path)
versions.each do |version|
params = {}
if version[:branch]
params[:branch] = project.repository.find_branch(version[:branch])
elsif version[:tag]
params[:tag] = project.repository.find_tag(version[:tag])
end
if params[:branch].nil? && params[:tag].nil?
puts "version #{version.inspect} not found"
next
end
Sidekiq::Worker.skipping_transaction_check do
::Packages::Composer::CreatePackageService
.new(project, project.owner, params)
.execute
end
puts "version #{version.inspect} created!"
end
end
end
end
|