Last active
August 29, 2015 14:04
-
-
Save mikem/5fd52d21a1ec8736134f to your computer and use it in GitHub Desktop.
This file contains hidden or 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/env ruby | |
def parse_app app_text | |
app = {} | |
current_property = nil | |
lines = app_text.split("\n") | |
lines.each do |line| | |
next if line.start_with? '=== ' | |
if line =~ /^[A-Z]/ | |
components = line.split(':') | |
current_property = components.shift | |
if %w(Addons Collaborators).include? current_property | |
app[current_property] = [components.join(':').strip] | |
else | |
app[current_property] = components.join(':').strip | |
current_property = nil | |
end | |
elsif line.empty? | |
current_property = nil | |
else | |
app[current_property] << line.strip | |
end | |
end | |
app | |
end | |
all_apps = `heroku apps --all | grep -v ^= | grep -v '^$' | cut -d ' ' -f 1`.split("\n") | |
max_length = all_apps.map(&:length).max | |
puts "Found #{all_apps.length} apps" | |
report = {} | |
all_apps.each_with_index do |app_name, index| | |
print "\r" | |
print "Fetching data for " | |
print app_name + ' ' * (max_length - app_name.length) | |
print " [#{index + 1} of #{all_apps.length}]" | |
STDOUT.flush | |
app_text = `heroku apps:info -a #{app_name}` | |
app_name = app_text.split("\n").first.gsub(/^=== /, '') | |
report[app_name] = parse_app app_text | |
end | |
puts | |
puts | |
account_projects = {} | |
report.each do |project, description| | |
collaborators = description['Collaborators'] | |
next unless collaborators | |
collaborators.each do |email| | |
account_projects[email] ||= [] | |
account_projects[email] << project | |
end | |
end | |
account_projects.sort.each do |email, projects| | |
spacer = "\n#{' ' * (email.length + 2)}" | |
puts "#{email}: #{projects.join spacer}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment