class Deka::Cli
Attributes
base_hash[RW]
config[RW]
save_file[RW]
yaml[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/deka/cli.rb, line 12 def initialize(options = {}) @config = options[:config] || './deka.yml' @save_file = options[:save] || './.tracked_hash' @base_hash = File.exists?(save_file) && File.read(save_file).chomp @dry_run = options[:'dry-run'] end
run(options = {})
click to toggle source
# File lib/deka/cli.rb, line 8 def self.run(options = {}) new(options).run end
Public Instance Methods
client()
click to toggle source
# File lib/deka/cli.rb, line 34 def client @client ||= Octokit::Client.new(access_token: access_token) end
run()
click to toggle source
# File lib/deka/cli.rb, line 19 def run log = fetch_log all_hashes = log.each_line.map { |line| line.strip[0..39] } issue_hashes = all_hashes.take_while { |hash| hash != base_hash }.reverse issue_hashes.each do |issue_hash| create_issue(issuing_repo, issue_hash) end update_lastest_hash(issue_hashes.last) ensure delete_temp_repo end
Private Instance Methods
access_token()
click to toggle source
# File lib/deka/cli.rb, line 63 def access_token yaml['access_token'] end
create_issue(repo, hash)
click to toggle source
# File lib/deka/cli.rb, line 93 def create_issue(repo, hash) title = issue_title(hash) body = issue_body(hash) unless @dry_run client.create_issue(repo, title, body) end puts "created issue of #{hash}" end
delete_temp_repo()
click to toggle source
# File lib/deka/cli.rb, line 111 def delete_temp_repo if File.exist?(directory_name) FileUtils.rm_r directory_name end end
directory_name()
click to toggle source
# File lib/deka/cli.rb, line 67 def directory_name watching_repo.split('/')[1] end
fetch_log()
click to toggle source
# File lib/deka/cli.rb, line 84 def fetch_log system "git clone https://github.com/#{watching_repo}.git" log = '' FileUtils.cd directory_name do log = `git log --pretty=oneline #{watching_files}` end log end
issue_body(issue_hash)
click to toggle source
# File lib/deka/cli.rb, line 75 def issue_body(issue_hash) commit_url = "https://github.com/#{watching_repo}/commit/#{issue_hash}" if yaml['body'] yaml['body'] + "\n\n#{commit_url}" else "please respond \n\n#{commit_url}" end end
issue_title(issue_hash)
click to toggle source
# File lib/deka/cli.rb, line 71 def issue_title(issue_hash) "about #{issue_hash[0..6]}" end
issuing_repo()
click to toggle source
# File lib/deka/cli.rb, line 59 def issuing_repo yaml['issuing_repo'] end
update_lastest_hash(latest_hash)
click to toggle source
# File lib/deka/cli.rb, line 102 def update_lastest_hash(latest_hash) unless @dry_run File.open(save_file, 'w') do |file| file.write(latest_hash) end end puts "updated #{save_file} with #{latest_hash}" end
watching_files()
click to toggle source
# File lib/deka/cli.rb, line 51 def watching_files yaml['watching_files'] || 'README.md' end
watching_repo()
click to toggle source
# File lib/deka/cli.rb, line 55 def watching_repo yaml['watching_repo'] end