bin/shamebot in shamebot-1.0.0 vs bin/shamebot in shamebot-1.0.1
- old
+ new
@@ -14,24 +14,26 @@
Usage: shamebot [<options>]
Options:
EOS
opt :config, 'Path to configuration', type: :string, required: true, short: 'c'
+ opt :db, 'Path to shamings database', default: '/tmp/shamebot.db', short: 'b'
opt :debug, 'Enable debugging', default: false, short: 'd'
opt :port, 'Port to listen on', default: 4567, short: 'p'
opt :env, 'Sinatra environment', default: 'production', short: 'e'
- opt :bind, 'Interface to listen on', default: '0.0.0.0', short: 'b'
+ opt :bind, 'Interface to listen on', default: '0.0.0.0', short: 'i'
end
DEBUG = Opts[:debug]
CONFIG = JSON.parse File.read(Opts[:config])
+DB = File::exists?(Opts[:db]) ? JSON::parse(File.read(Opts[:db])) : {}
unless DEBUG
at_exit do
- puts "Writing back to '#{Opts[:config]}'"
- File.open(Opts[:config], 'w') do |f|
- f.puts JSON.pretty_generate(CONFIG)
+ puts "Writing back to '#{Opts[:db]}'"
+ File.open(Opts[:db], 'w') do |f|
+ f.puts JSON.pretty_generate(DB)
end
end
end
@@ -65,15 +67,13 @@
def random_template
TEMPLATES[rand(0...TEMPLATES.length)]
end
-CONFIG['shamings'] = CONFIG.has_key?('shamings') ? CONFIG['shamings'] : {}
-
# Part 2. Get connected to Hipchat and Gitlab
require 'hipchat'
require 'gitlab'
HIPCHAT = HipChat::Client.new CONFIG['hipchat']['auth_token']
@@ -148,15 +148,15 @@
# don't end up repeatedly shaming users for the same mistake. We also
# make sure the commits aren't too old.
new_bad_commits = []
bad_commits.each do |commit|
unless DEBUG
- next if CONFIG['shamings'].has_key? commit['id']
+ next if DB.has_key? commit['id']
commit_time = DateTime.strptime(commit['timestamp']).to_time
next unless commit_time >= last_half_hour
end
new_bad_commits << commit
- CONFIG['shamings'][commit['id']] = true
+ DB[commit['id']] = true
end
# Shame the user with a random template
commit_ids = new_bad_commits.map { |c| c['id'] }
commit_urls = new_bad_commits.map { |c| c['url'] }