Created
December 17, 2019 20:01
-
-
Save aaronmallen/8f019916a6f841807790571d0c679dee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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