Last active
December 15, 2015 03:49
-
-
Save obfusk/5197581 to your computer and use it in GitHub Desktop.
list github repos and gists (w/ desc, home, branches)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'io/console' | |
require 'json' | |
require 'open-uri' | |
# -- | |
pag = ->(data; l, n, r) { | |
(l = data.meta['link']) && | |
(n = l.split(',').grep(/rel="next"/).first) && | |
(r = l.match(%r{<(https://[^>]*)>})) && r[1] | |
} | |
jcat = ->(pages) { pages.map { |x| JSON.load x } .flatten 1 } | |
paginate = ->(url, f) { | |
pages = [] | |
while url; pages << data = f[url]; url = pag[data]; end | |
pages | |
} | |
prompt = ->(prompt) { | |
STDERR.print prompt; STDERR.flush | |
line = STDIN.noecho { |i| i.gets }; STDERR.puts | |
line and line.chomp | |
} | |
# -- | |
verbose = if ARGV.first == '-v' then ARGV.shift; true else false end | |
ARGV.each do |user| | |
if user.include? '@' | |
au, user = user.split '@'; au = user if au.empty? | |
ap = prompt["password for #{user}: "] | |
opts = { http_basic_authentication: [au, ap] } | |
else | |
opts = {} | |
end | |
url = "https://api.github.com/users/#{user}/gists" | |
rs = jcat[paginate[url, ->(u) { open u, opts }]] | |
puts "#{user}[#{rs.size}]/" | |
rs.each do |repo| | |
puts " #{ repo['id'] }" | |
if verbose | |
puts " desc: #{ repo['description'] }" | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'io/console' | |
require 'json' | |
require 'open-uri' | |
# -- | |
pag = ->(data; l, n, r) { | |
(l = data.meta['link']) && | |
(n = l.split(',').grep(/rel="next"/).first) && | |
(r = l.match(%r{<(https://[^>]*)>})) && r[1] | |
} | |
jcat = ->(pages) { pages.map { |x| JSON.load x } .flatten 1 } | |
paginate = ->(url, f) { | |
pages = [] | |
while url; pages << data = f[url]; url = pag[data]; end | |
pages | |
} | |
prompt = ->(prompt) { | |
STDERR.print prompt; STDERR.flush | |
line = STDIN.noecho { |i| i.gets }; STDERR.puts | |
line and line.chomp | |
} | |
# -- | |
verbose = if ARGV.first == '-v' then ARGV.shift; true else false end | |
ARGV.each do |user| | |
if user.include? '@' | |
au, user = user.split '@'; au = user if au.empty? | |
ap = prompt["password for #{user}: "] | |
opts = { http_basic_authentication: [au, ap] } | |
else | |
opts = {} | |
end | |
url = "https://api.github.com/users/#{user}/repos" | |
rs = jcat[paginate[url, ->(u) { open u, opts }]] | |
puts "#{user}[#{rs.size}]/" | |
rs.each do |repo| | |
puts " #{ repo['name'] }" | |
if verbose | |
puts " desc: #{ repo['description'] }" | |
puts " home: #{ repo['homepage'] }" | |
puts " branches:" | |
system "git ls-remote #{ repo['clone_url'] }" + | |
" | grep -v HEAD | sed 's!^! !'" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment