Created
November 21, 2014 19:41
-
-
Save fancyremarker/c46ea88a876efcd9be1c to your computer and use it in GitHub Desktop.
Sync all an org's repos with Slack notifications, specifying individual events to subscribe to
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 | |
# Usage: ruby slack-notifications-sync.rb aptible event [event event ...] | |
# Supported events: | |
# * commit_comment | |
# * create | |
# * delete | |
# * deployment | |
# * deployment_status | |
# * download | |
# * follow | |
# * fork | |
# * fork_apply | |
# * gist | |
# * gollum | |
# * issue_comment | |
# * issues | |
# * member | |
# * public | |
# * pull_request | |
# * pull_request_review_comment | |
# * push | |
# * release | |
# * status | |
# * team_add | |
# * watch | |
require 'octokit' | |
org_login = ARGV[0] | |
events = ARGV[1..-1] | |
print 'Username: ' | |
username = $stdin.gets.chomp | |
print 'Password: ' | |
password = $stdin.gets.chomp | |
print 'Hook URL: ' | |
hook_url = $stdin.gets.chomp | |
Octokit.configure do |c| | |
c.login = username | |
c.password = password | |
end | |
Octokit.auto_paginate = true | |
Octokit.org_repos(org_login).each do |repo| | |
existing_hooks = Octokit.hooks(repo.full_name) | |
slack_hook = existing_hooks.find { |h| h.config[:url] =~ /hooks.slack.com/ } | |
next if slack_hook && | |
slack_hook.config[:url] == hook_url && | |
slack_hook.events.sort == events.sort | |
# Remove existing hook since it doesn't match | |
if slack_hook | |
puts "Removing misconfigured hook on #{repo.full_name}..." | |
Octokit.remove_hook(repo.full_name, slack_hook.id) | |
end | |
# Create new hook | |
puts "Adding hook on #{repo.full_name}..." | |
Octokit.create_hook( | |
repo.full_name, | |
'web', | |
{ url: hook_url, content_type: 'json' }, | |
{ events: events, active: true } | |
) | |
end |
Hi @aruzmeister, how do you mean? Do you have a fork that I can look at? What error are you seeing?
Hi @aruzmeister, you also need content_type: 'json'
, as well as the second hash argument:
{ events: events, active: true }
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note to self: