Skip to content

Instantly share code, notes, and snippets.

@stephenyeargin
Last active August 29, 2015 14:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenyeargin/d82c1da32f7456f3dc0a to your computer and use it in GitHub Desktop.
Save stephenyeargin/d82c1da32f7456f3dc0a to your computer and use it in GitHub Desktop.
Roll Slack Webhooks
require 'octokit'
# Config
GITHUB_API_TOKEN = '<a token>'
GITHUB_ORGANIZATION = '<an organization>'
###
client = Octokit::Client.new(
access_token: GITHUB_API_TOKEN
)
client.login
for repo in client.org_repos(GITHUB_ORGANIZATION)
next unless repo['permissions']['admin']
hooks = client.hooks(repo['full_name'])
for webhook in hooks
next unless /\.slack\.com/.match(webhook['config']['url'])
puts repo['full_name']
puts "DELETING: #{webhook['name']} | #{webhook['config']['url']}"
puts client.remove_hook(repo['full_name'], webhook['id']) ? 'Deleted!' : 'Failed.'
end
end
@kamarcum
Copy link

Ruby for/each hurt me, so I made this.

repos = client.org_reports(GITHUB_ORGANIZATION).select { |repo| repo['permissions']['admin'] }
repos.each do |repo|
  hooks = client.hooks(repo['full_name']).select { |hook| /\.slack\.com/.match(hook['config']['url']) }
  hooks.each do |hook|
    puts repo['full_name']
    puts "DELETING: #{hook['name']} | #{hook['config']['url']}"
    puts client.remove_hook(repo['full_name'], hook['id']) ? 'Deleted!' : 'Failed.'
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment