This repository has been archived by the owner on Jan 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathimport.rb
154 lines (141 loc) · 3.89 KB
/
import.rb
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# vim: set expandtab ts=2 sw=2:
require 'simp/metadata'
require 'yaml'
$UPSTREAMREPO = 'https://github.com/simp/simp-core.git'
$DATAREPO = 'git@github.com:simp/simp-metadata.git'
begin
Dir.mkdir('scratch')
Dir.mkdir('scratch/data')
rescue
end
Dir.chdir('scratch') do
if Dir.exist?('upstream')
Dir.chdir('upstream') do
`git fetch origin`
end
else
`git clone #{$UPSTREAMREPO} upstream`
end
Dir.chdir('data') do
if Dir.exist?('simp-metadata/')
Dir.chdir('simp-metadata') do
`git pull origin`
end
else
`git clone #{$DATAREPO} simp-metadata`
end
begin
Dir.mkdir('data/releases')
rescue
end
end
end
repo = ENV.fetch('EXTRAREPO', nil)
repos = if repo.nil?
[$DATAREPO]
else
[$DATAREPO, repo]
end
metadata = Simp::Metadata::Engine.new('scratch', repos)
# binding.pry
data = {}
data['components'] = {}
data['releases'] = {}
components = data['components']
component_by_url = {}
class Puppetfile
def initialize
@repos = {}
@moduledir = '/'
end
attr_reader :repos
def mod(name, params = {})
@repos[name] = params.merge('destination' => @moduledir)
end
def forge(url)
puts url
end
def moduledir(name)
@moduledir = "/#{name}"
end
end
def parse_git(url)
case url
when /^https:/
https_url = url.split('/')
host = https_url[2]
path = https_url.drop(3).join('/').gsub('.git', '')
type = 'https'
when /^git@/
git_url = url.split(':')
host = git_url[0].gsub('git@', '')
path = git_url[1].gsub('.git', '')
type = 'ssh'
when /^git:/
git_url = url.split('/')
host = git_url[2]
path = git_url.drop(3).join('/').gsub('.git', '')
type = 'ssh'
end
{ 'host' => host, 'path' => path, 'type' => type }
end
repo_url = {}
Dir.chdir('scratch/upstream') do
branches = "master\n6.0.0-Alpha-Release\n" + `git tag -l`
branches.split("\n").each do |branch|
begin
pfile = Puppetfile.new
`git checkout #{branch}`
if File.exist?('Puppetfile.stable')
release = {}
pfile.instance_eval(File.read('Puppetfile.stable').delete('}'))
pfile.repos.each do |key, value|
ret = {}
ret['type'] = 'git'
ret['authoritative'] = true
gitinfo = parse_git(value[:git])
ret['primary_source'] = gitinfo.dup.delete_if { |key, _value| key == 'type' }
object = {
'ref' => value[:ref],
'type' => gitinfo['type'],
'path' => value['destination']
}
if component_by_url.key?(ret['primary_source'])
release[component_by_url[ret['primary_source']]] = object
else
['', '-1', '-2', '-3', '-4', '-5', '-6'].each do |opt|
nkey = key + opt
ret['mirrors'] = { 'gitlab' => { 'host' => 'gitlab.com', 'path' => 'simp/' + nkey } }
if components.key?(nkey)
if components[nkey]['type'] != ret['type'] && components[nkey]['primary_source'] != ret['primary_source']
next
else
release[nkey] = object
break
end
else
components[nkey] = ret
component_by_url[ret['primary_source']] = nkey
release[nkey] = object
break
end
end
end
end
end
data['releases'][branch] = release
# rescue
end
end
end
comp = { 'components' => components }
File.open('scratch/data/simp-metadata/v1/components.yaml', 'w') { |f| f.write comp.to_yaml }
data['releases'].each do |key, value|
release = { 'releases' => { key => value } }
File.open("scratch/data/simp-metadata/v1/releases/#{key}.yaml", 'w') { |f| f.write release.to_yaml }
end
Dir.chdir('scratch/data') do
`git add -A`
`git commit -m "Auto Update by rubygem-simp-metadata"`
# `git push origin`
end