This repository has been archived by the owner on Apr 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
78 lines (62 loc) · 1.82 KB
/
Rakefile
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
require 'bundler/setup'
require 'fileutils'
task :update_scripts do
mkdir_p 'tmp'
rm_rf 'tmp/hubot-scripts'
`git clone git://github.com/github/hubot-scripts.git tmp/hubot-scripts`
end
task :read_scripts do
require './brain'
Dir.chdir('tmp/hubot-scripts')
Dir['src/scripts/*.coffee'].each do |script|
name = script.split('/').last
print "Adding #{name}..."
begin
file = File.new(script, 'r')
sections = {}
current_section = nil
# See Hubot's robot.coffee for how it approaches reading comments
while line = file.gets
break unless line[0] == "#"
cleaned_line = line[2..line.length]
if !cleaned_line.strip.empty? && cleaned_line.strip.downcase != "none"
if cleaned_line[0..1] != " "
# "Commands:" => "commands"
current_section = cleaned_line.strip.chomp(":").downcase
sections[current_section] ||= ""
else
sections[current_section] << cleaned_line.lstrip
end
end
end
dates = `git log --format=%aD #{script}`.split("\n")
sections['added_at'] = dates.last
sections['last_updated_at'] = dates.first
keys_values = sections.to_a.flatten
$redis.hmset("scripts:#{name}", *keys_values)
puts "OK"
rescue => error
puts "Error: #{error}"
ensure
file.close
end
end
$redis[:last_updated] = Time.now
puts "Scripts updated."
end
desc 'Retrieve and catalog the latest scripts'
task :catalog => [:update_scripts, :read_scripts]
desc 'Flush scripts'
task :flush do
require './brain'
$redis.keys('scripts:*').each do |key|
begin
print "Deleting #{key}..."
$redis.del(key)
puts "OK"
rescue => error
puts "Error: #{error}"
end
end
end
task :default => :catalog