Create a gist now

Instantly share code, notes, and snippets.

heroku plugin search
#! /usr/bin/env ruby
require_relative 'util'
include Util
auth_key = key_hash(ARGV.last)
puts "restarting all processes"
apps = curl('https://api.heroku.com/apps', auth_key)
apps.each do |app|
name = app['name']
cmd = "heroku ps:restart --app #{name}"
puts cmd
puts `#{cmd}`
end
#! /usr/bin/env ruby
require_relative 'util'
include Util
addon_name = ARGV.first
abort "usage: #{__FILE__} ADDON-NAME [API-KEY]" if addon_name.nil?
auth_key = key_hash(ARGV.last)
puts "searching for addon #{addon_name}"
apps = curl('https://api.heroku.com/apps', auth_key)
apps.each do |app|
name = app['name']
addons = curl("https://api.heroku.com/apps/#{name}/addons", auth_key)
addon_names = addons.map { |addon| addon["addon_service"]["name"] }
if addon_names.grep(/#{addon_name}/i).size > 0
puts "found #{name} -> #{addon_names}"
collaborators = curl("https://api.heroku.com/apps/#{name}/collaborators", auth_key)
emails = collaborators.map { |collaborator| collaborator['user']['email'] }
emails -= ["admins+deploy@shopify.com", "admins@shopify.com"]
puts "contact #{emails}"
end
end
#! /usr/bin/env ruby
require_relative 'util'
include Util
env_value = ARGV.first
abort "usage: #{__FILE__} VAR-VALUE [API-KEY]" if env_value.nil?
auth_key = key_hash(ARGV.last)
puts "searching for env-var-value #{env_value}"
apps = curl('https://api.heroku.com/apps', auth_key)
apps.each do |app|
name = app['name']
vars = curl("https://api.heroku.com/apps/#{name}/config-vars", auth_key)
if vars.any? { |key, value| key.match(env_value) || value.match(env_value) }
puts "#{name} contains value: #{vars}"
end
end
#! /usr/bin/env ruby
require_relative 'util'
include Util
auth_key = key_hash(ARGV.last)
puts "searching for idle dynos"
apps = curl('https://api.heroku.com/apps', auth_key)
apps.each do |app|
name = app['name']
dynos = curl("https://api.heroku.com/apps/#{name}/dynos", auth_key)
states = dynos.map { |dyno| dyno['state'] }
if states.include?('idle')
puts "#{name} has idle dynos"
collaborators = curl("https://api.heroku.com/apps/#{name}/collaborators", auth_key)
emails = collaborators.map { |collaborator| collaborator['user']['email'] }
emails -= ["admins+deploy@shopify.com", "admins@shopify.com"]
puts "contact #{emails}"
end
end
require 'json'
module Util
def key_hash(auth_token)
if auth_token.nil?
puts "fetching key from heroku config"
`(echo -n ":" ; heroku auth:token) | base64`.chomp
else
puts "using provided key"
`(echo -n ":" ; echo "#{auth_token}") | base64`.chomp
end
end
def curl(url, auth_key, method: 'GET')
response = `curl -sS -X #{method} #{url} -H "Accept: application/vnd.heroku+json; version=3" -H "Authorization: #{auth_key}"`.chomp
JSON.parse(response)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment