forked from hiromi-mi/esolang-box
-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.rb
84 lines (75 loc) · 2.42 KB
/
push.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
require 'httpclient'
require 'yaml'
require 'json'
require 'erb'
VERSION = '2.3.0'
$erb = ERB.new(File.read(File.join(__dir__, 'box_readme.md.erb')))
$boxes = YAML::load_file(File.join(__dir__, 'boxes.yml'))
$hello_files = {}
$hello_outs = {}
$hello_contents = {}
spec_file = File.read(File.join(__dir__, 'spec', 'boxes_spec.rb'))
current_lang = nil
spec_file.lines do |line|
if match = line.match(/describe\s+'(.+?)'/i)
current_lang, = match.captures
end
if match = line.match(/'(hello\..+?)'/i)
hello_file, = match.captures
$hello_files[current_lang] = hello_file
hello_content = File.read(File.join(__dir__, 'spec', 'assets', hello_file))
if hello_content.valid_encoding? && hello_content.chars.size <= 250
$hello_contents[current_lang] = hello_content
end
end
if match = line.match(/hello.+eql\((['"].+?['"])\)/i)
hello_out, = match.captures
$hello_outs[current_lang] = YAML.load(%Q(---\n#{hello_out}\n)).rstrip
end
end
def do_count(lang, parent = nil)
count = 0
lang.each do |key, value|
unless key.start_with? '_'
unless value['_disabled'] || value['_name'].nil? || value['_link'].nil?
count += 1
end
count += do_count value, key
end
end
count
end
$language_count = do_count $boxes
def iterate(lang, parent = nil)
lang.each do |key, value|
unless key.start_with? '_'
unless value['_disabled'] || value['_name'].nil? || value['_link'].nil?
name = value['_name']
link = value['_link']
slug = key
hello_file = $hello_files[key]
hello_content = $hello_contents[key]
hello_out = $hello_outs[key]
disasm = value['_disasm'] == true
language_count = $language_count
readme = $erb.result(binding)
client = HTTPClient.new
client.debug_dev = $stderr
# To get token:
# curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/
res = client.patch("https://hub.docker.com/v2/repositories/esolang/#{slug}/",
header: {
Authorization: "JWT #{ENV['TOKEN']}",
'Content-Type' => 'application/json',
},
body: JSON.generate({
description: "Easily execute #{name} programming language",
full_description: readme,
}),
)
end
iterate value, key
end
end
end
iterate $boxes