class TodosExport::GithubIssues

Attributes

main[RW]
remote_repo[RW]

Public Class Methods

new(main) click to toggle source
# File lib/todos_export/github_issues.rb, line 5
def initialize(main)
  @main = main
end

Public Instance Methods

authenticate() click to toggle source
# File lib/todos_export/github_issues.rb, line 15
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
github_line_url(file, line) click to toggle source
# File lib/todos_export/github_issues.rb, line 52
def github_line_url(file, line)
  sha = self.main.git_head_sha || 'master'
  "https://github.com/#{@remote_repo}/blob/#{sha}/#{file}#L#{line}"
end
process_exportables() click to toggle source
# File lib/todos_export/github_issues.rb, line 57
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\n#{self.github_line_url(ex[:file], ex[:line])}")
    say("<%= color('Tags:', :green) %>\n'#{ex[:type].downcase}'")
    say("\n")
    create = agree("Create this issue? [y]es, [n]o")
    if create && @client.create_issue(@remote_repo,
                                       ex[:content],
                                       "#{ex[:content]}\n\n#{self.github_line_url(ex[:file], ex[:line])}",
                                       { :labels => ex[:type].downcase }
                                     )
      say("\n<%= color('Created!', :green) %>\n\n")

      say("Delete the comment and save the file?" \
        "\n\nFile: #{ex[:file]}" \
        "\nLine: #{ex[:line]}" \
        "\nComment: #{ex[:original_content]}\n\n")
      delete = agree("[y]es, [n]")
      if delete
        self.main.delete_exportable(ex[:file], ex[:line])
        say("\n<%= color('Deleted the line', :green) %>\n\n")
      end
    else
      say("\n<%= color('Not created!', :red) %>\n\n")
    end
  end
end
run() click to toggle source
# File lib/todos_export/github_issues.rb, line 9
def run
  authenticate
  select_repo
  process_exportables
end
select_repo() click to toggle source
# File lib/todos_export/github_issues.rb, line 35
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) { @remote_repo = repo.full_name }
    end

    @client.organizations.each do |org|
      @client.org_repos(org['login']).each do |repo|
        menu.choice(repo.full_name) { @remote_repo = repo.full_name }
      end
    end
  end
end