Skip to content

Commit ab40864

Browse files
authored
Merge pull request #956 from voxpupuli/add-openvox-script
Add a script to modify metadata.json across all modules
2 parents 2cf9dc0 + 840f352 commit ab40864

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

bin/add_openvox_to_metadata_json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'yaml'
4+
require 'json'
5+
6+
def clone_or_update(repo)
7+
if Dir.exist?(repo)
8+
system("cd #{repo}; git pull; cd ..")
9+
else
10+
system("git clone [email protected]:voxpupuli/#{repo}.git")
11+
end
12+
end
13+
14+
15+
clone_or_update('modulesync_config')
16+
17+
yd = YAML.load_file('modulesync_config/managed_modules.yml')
18+
yd.each do |module_|
19+
clone_or_update(module_)
20+
filepath = "#{module_}/metadata.json"
21+
if !File.exist?(filepath)
22+
puts "#{filepath} doesn't exist, skipping"
23+
next
24+
end
25+
# load whole metadata.json file
26+
metadata = JSON.load_file(filepath)
27+
28+
# extract the `puppet` requirements
29+
puppet = metadata['requirements'].detect{|requirement| requirement['name'] == 'puppet'}
30+
31+
# generate `openvox` requirements with same versions as `puppet`
32+
openvox = {'name'=>'openvox', 'version_requirement'=>puppet['version_requirement']}
33+
34+
# write everything back to the file
35+
File.write(filepath, JSON.pretty_generate(metadata.merge({'requirements'=>[puppet, openvox]})) + "\n")
36+
end
37+
38+
# Once this runs, all the changes will exist, you'll then want to commit / make PRs with something like:
39+
# gh auth login
40+
# for x in $(ls -d puppet*); do
41+
# pushd $x
42+
# git switch -c add-openvox
43+
# git commit metadata.json -m "Add openvox to metadata.json"
44+
# git push origin add-openvox
45+
# gh repo set-default voxpupuli/$x
46+
# gh pr create --label enhancement --title 'metadata.json: Add OpenVox' --body ''
47+
# popd
48+
# done

0 commit comments

Comments
 (0)