Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#save_the_beers(args) ⇒ Object



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
51
52
53
54
55
56
57
# File 'lib/enable_beer.rb', line 5

def save_the_beers(args)

  if args.length != 1
  	puts "USAGE: ./enable_beer <GH USERNAME>"
    exit
  end

  begin
    require 'io/console'
  rescue LoadError
  end

  if STDIN.respond_to?(:noecho)
    def get_password(prompt="Password: ")
      print prompt
      STDIN.noecho(&:gets).chomp
    end
  else
    def get_password(prompt="Password: ")
      `read -s -p "#{prompt}" password; echo $password`.chomp
    end
  end

  pwd = Dir.pwd
  `ln -f -s ~/Dropbox #{pwd}/dropbox`
  `mkdir -p #{pwd}/dropbox/gh_rescued_beers`
  `mkdir -p #{pwd}/sources`

  user = args[0]

  pass = get_password("Enter your GH password here for #{user}: ")
  github = Github.new login: user, password: pass

  puts "Listing repos with #BACKUP in the description"
  a = github.repos.list(:sources)

  puts "-> Repos marked #BACKUP in the description"
  puts "-------"

  marked = a.select { | r | r.description.match('#BACKUP') }
  marked.each do |repo|
  	puts "-> #{repo.full_name} - #{repo.description}"
  end

  marked.each do |repo|
  	puts "Cloning...."
  	`git clone #{repo.ssh_url} #{pwd}/sources/#{repo.name}`
  	`cd #{pwd}/sources && tar czvf #{repo.name}.tgz #{repo.name}`
  end
  `cp #{pwd}/sources/*.tgz #{pwd}/dropbox/gh_rescued_beers`

  puts "Add #BACKUP in the description to back it up.."
end