140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/ra10ke/dependencies.rb', line 140
def define_task_print_git_conversion(*_args)
desc 'Convert and print forge modules to git format'
task :print_git_conversion do
require 'ra10ke/git_repo'
require 'r10k/puppetfile'
require 'puppet_forge'
PuppetForge.user_agent = "ra10ke/#{Ra10ke::VERSION}"
puppetfile = get_puppetfile
puppetfile.load!
PuppetForge.host = puppetfile.forge if puppetfile.forge =~ /^http/
ignore_modules = []
ignore_modules = File.readlines('.r10kignore').each { |l| l.chomp! } if File.exist?('.r10kignore')
forge_mods = puppetfile.modules.find_all do |mod|
mod.instance_of?(R10K::Module::Forge) && mod.v3_module.homepage_url?
end
threads = forge_mods.map do |mod|
Thread.new do
source_url = mod.v3_module.attributes.dig(:current_release, :metadata, :source) || mod.v3_module.homepage_url
source_url = source_url.gsub('git://', 'https://')
source_url = source_url.gsub(/\Agit@(.*):(.*)/) do
"https://#{::Regexp.last_match(1)}/#{::Regexp.last_match(2)}"
end
repo = ::Ra10ke::GitRepo.new(source_url)
ref = repo.get_ref_like(mod.expected_version)
ref_name = ref ? ref[:name] : "bad url or tag #{mod.expected_version} is missing"
<<~EOF
mod '#{mod.name}',
:git => '#{source_url}',
:ref => '#{ref_name}'
EOF
end
end
output = threads.map { |th| th.join.value }
puts output
end
end
|