Skip to content

Instantly share code, notes, and snippets.

@afeld
Created April 21, 2016 16:22
Show Gist options
  • Save afeld/7d0a063465322d874db368802f4bbfc6 to your computer and use it in GitHub Desktop.
Save afeld/7d0a063465322d874db368802f4bbfc6 to your computer and use it in GitHub Desktop.
get a list of all service hooks across an organization in GitHub
require 'octokit'
require 'set'
TOKEN = ENV['GITHUB_TOKEN'] || (raise "Please set GITHUB_TOKEN.")
ORG = ENV['ORG'] || (raise "Please set ORG as the organization name.")
Octokit.auto_paginate = true
client = Octokit::Client.new(access_token: TOKEN)
# default to an empty Set for each key
repos_per_service = Hash.new{ |hash, key| hash[key] = Set.new }
repos = client.organization_repositories(ORG)
repos.each do |repo|
hooks = client.hooks(repo.full_name)
hooks.each do |hook|
if hook.name == 'web'
uri = URI(hook.config.url)
hook_key = uri.host
else
# it's a "service"
# https://github.com/integrations
# https://developer.github.com/webhooks/#service-hooks
hook_key = hook.name
end
repos_per_service[hook_key] << repo
end
print '.'
end
puts ''
services = repos_per_service.keys
# note that some repositories may use the same service more than once
services.sort_by!{ |service| repos_per_service[service].length }.reverse!
services.each do |service|
repos = repos_per_service[service]
repo_names = repos.map(&:name).sort.join(',')
puts "#{service.ljust(35)} #{repo_names}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment