/
delete-repos
executable file
·51 lines (40 loc) · 1.17 KB
/
delete-repos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env ruby
# Mass delete, just pass the names or full paths of the repos to delete
# and both the github and local repos/* repositories will be deleted.
#
##
# You might need to wait for a few hours between deleting and pushing
# since github has a bug where quickly deleting, creating, and pushing a
# repo with the same name will just result in a resurrection of the old
# repo with the old contents, not an empty one.
#
# Now you can use "FORCE=1 ./scraper 0999" to get around this. It doesn't
# update the script's description but usually that's not needed and it's
# better than waiting for github to fix this bug!
$:.unshift './lib'
require 'bundler'
Bundler.require
require 'github'
scripts = {}
ARGV.each do |name|
name =~ /^repos\/(.*)\.git\/?$/
name = $1 if $1
path = "repos/#{name}.git"
if test ?d, path
scripts[name] = path
else
puts "warning: can't find #{path}"
end
end
github = GitHub.new
scripts.each do |name,path|
github.delete name
end
scripts.each do |name,path|
begin
FileUtils.rm_rf path
puts "deleted #{path}"
rescue Exception => e
puts "could not delete #{path}: #{e}"
end
end