require "todos_export/version" require 'todos_export/github_issues' require "highline/import" require 'octokit' HighLine.track_eof = false module TodosExport class Main attr_accessor :target, :files, :exportables def initialize(target) self.target = target self.exportables = [] end def find_files if File.file?(self.target) self.files = [self.target] elsif File.directory?(self.target) self.files = Dir.glob(File.join(self.target, "**", "*.rb")) else abort "#{target} does not exist." end return self.files end def find_exportables self.find_files self.files.each do |file| File.open(file) do |f| f.each_with_index do |line, number| search = line.scan(/(?:#)(?:| )(TODO|FIXME|BUG):?(.*)$/i) if !search.empty? self.exportables << { :type => search[0][0].upcase, :content => search[0][1].strip, :file => file.gsub(/^(.\/|\/)/, ''), :line => number + 1 } end end end end end def exportable_todos self.exportables.select { |x| x[:type] == 'TODO' } end def exportable_fixmes self.exportables.select { |x| x[:type] == 'FIXME' } end def exportable_bugs self.exportables.select { |x| x[:type] == 'BUG' } end def execute self.find_exportables say("Found #{self.exportable_todos.size} TODO's, " \ "#{self.exportable_fixmes.size} FIXME's and " \ "#{self.exportable_bugs.size} BUG's" \ " in #{self.exportables.map { |x| x[:file] }.uniq.size } of #{exportables.map { |x| x[:file] }.size } files searched.") say("\n") choose do |menu| menu.prompt = "Export to: " menu.choice('Github Issues') { TodosExport::GithubIssues.new(self).run } end end end end