module TodosExport class GithubIssues attr_accessor :main def initialize(main) @main = main end def run authenticate select_repo process_exportables end def authenticate say("\n") choose do |menu| menu.prompt = "Choose authentication method: " menu.choice('Username / Password') do say("\n") username = ask("Github Username:") password = ask("Github Password:") { |q| q.echo = false } @client = ::Octokit::Client.new(:login => username, :password => password) end menu.choice('Personal Access Token (https://github.com/settings/applications)') do say("\n") token = ask("Github token:") @client = ::Octokit::Client.new(:oauth_token => token) end end end def select_repo say("\n") choose do |menu| menu.prompt = "Choose a repository to add issues to:" @client.repos.each do |repo| menu.choice(repo.full_name) { @repo = repo.full_name } end end end def process_exportables say("\n") self.main.exportables.each do |ex| say("Create a new Issue") say("==================") say("<%= color('Name:', :green) %>\n#{ex[:content]}") say("<%= color('Description:', :green) %>\n#{ex[:content]}\n\nhttps://github.com/#{@repo}/blob/master/#{ex[:file]}#L#{ex[:line]}") say("<%= color('Tags:', :green) %>\n'#{ex[:type].downcase}'") say("\n") create = agree("Create this issue? [y]es, [n]o") if create if @client.create_issue( @repo, ex[:content], "#{ex[:content]}\n\nhttps://github.com/#{@repo}/blob/master/#{ex[:file]}#L#{ex[:line]}", { :labels => ex[:type].downcase }) say("\n<%= color('Created!', :green) %>\n\n") else say("\n<%= color('Not created!', :red) %>\n\n") end end end end end end