Skip to content

Instantly share code, notes, and snippets.

@aaronmallen
Created December 17, 2019 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronmallen/8f019916a6f841807790571d0c679dee to your computer and use it in GitHub Desktop.
Save aaronmallen/8f019916a6f841807790571d0c679dee to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
system('gem install thor') unless require('thor')
require 'rubygems'
require 'yaml'
require 'fileutils'
require 'thor'
class RandReviewer < Thor
attr_accessor :names
CONFIG_FILE = File.join(ENV['HOME'], '.config', 'rand_reviewers.yml').freeze
def initialize(args = [], local_options = {}, config = {})
super
@names = load_config
end
desc 'add <NAMES>', 'Add a reviewer to the reviewer list'
long_desc <<-LONGDESC
Adds a name to the list of possible reviewers.
Takes a list of space seperated names as an argument.
LONGDESC
def add(*add_names)
self.names = names.concat(add_names).uniq
save_config
end
desc 'remove <NAMES>', 'Remove a review from the reviewer list'
long_desc <<-LONGDESC
Removes a name from the list of possible reviewers.
Takes a list of space seperated names as an argument.
LONGDESC
def remove(*del_names)
del_names.each { |n| names.delete(n) }
save_config
end
desc 'list', 'List all possible reviewers'
long_desc <<-LONGDESC
Lists all possible reviewers
LONGDESC
def list
say names.join(' ')
end
desc 'pick', 'Pick a random reviewer'
long_desc <<-LONGDESC
Picks a random name from the list of reviewers.
LONGDESC
def pick
say names.sample
end
private
def prep_config_file
return if File.exist?(CONFIG_FILE)
FileUtils.mkdir_p(File.dirname(CONFIG_FILE))
File.open(CONFIG_FILE, 'w') do |f|
f.write [].to_yaml
f.close
end
end
def load_config
prep_config_file
YAML.load_file(CONFIG_FILE)
end
def save_config
File.open(CONFIG_FILE, 'w') do |f|
f.write names.sort.uniq.to_yaml
f.close
end
end
end
RandReviewer.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment