Skip to content

Instantly share code, notes, and snippets.

@maxjacobson
Created March 14, 2016 03:25
Show Gist options
  • Select an option

  • Save maxjacobson/82ec12d405f6e02034ce to your computer and use it in GitHub Desktop.

Select an option

Save maxjacobson/82ec12d405f6e02034ce to your computer and use it in GitHub Desktop.
require 'github_api' # gem install github_api
require 'readline'
require 'fileutils'
FileUtils.touch("./safe")
username = Readline.readline("Enter your github username: ")
pw = Readline.readline("Enter your regular github password: ")
one_time_password = Readline.readline("Enter your one time password: ")
github = Github.new do |config|
config.basic_auth = "#{username}:#{pw}"
config.connection_options = {headers: {"X-GitHub-OTP" => one_time_password}}
end
safe_list = File.read("./safe").each_line.to_a.map(&:chomp)
github.repos.list(user: username).each_page do |page|
page.each do |repo|
name = repo.fetch('name')
next if safe_list.include?(name)
should_delete = Readline.readline("Delete #{name}? [yN]").downcase == 'y'
if should_delete
github.repos.delete(user: username, repo: name)
puts "deleted #{name}"
else
File.open("./safe", "a") { |f| f.puts name }
puts "not gonna delete #{name}... won't even ask you again"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment