Skip to content

Instantly share code, notes, and snippets.

@kowsik
Created March 22, 2012 19:42
Show Gist options
  • Save kowsik/2162781 to your computer and use it in GitHub Desktop.
Save kowsik/2162781 to your computer and use it in GitHub Desktop.
Quick script to go through a bunch of GitHub repos and add campfire notification to them. Turns out campfire notifications created in the past only have the 'push' event in them.
require 'rubygems'
require 'json/ext'
require 'restclient'
require 'pp'
# You'll need to define the following variables and of course change
# 'mudynamics' to your organization name
# user, password (for GitHub credentials)
# room, subdomain, token (your Campfire settings)
# Monkey patch RestClient::Resource to handle JSON parsing of the response
class RestClient::Resource
[ :get, :post, :put, :patch, :delete ].each do |verb|
define_method :"json_#{verb}" do |*args|
val = self.send verb, *args
JSON.parse val
end
end
end
gh = RestClient::Resource.new 'https://api.github.com', :user => user, \
:password => password
gh['/orgs/mudynamics/repos'].json_get.each do |repo|
next unless repo['name'] =~ /^blitz-/
repo_name = repo['name']
pp repo_name
hooks_url = "/repos/mudynamics/#{repo_name}/hooks"
hooks = gh[hooks_url].json_get
campfire = hooks.find { |h| h['name'] == 'campfire' }
# Add campfire notification if it doesn't exist
if not campfire
puts "=> adding campfire notification"
gh[hooks_url].json_post({
:name => 'campfire',
:active => true,
'events' => [ 'push', 'pull_request', 'issues' ],
:config => {
:room => room,
:subdomain => subdomain,
:token => token
}
}.to_json)
else
# Campfire notifications setup in the past only handle 'push' events.
# So patch that and add issues and pull_requests.
if not campfire['events'].find { |e| e == 'pull_request' }
puts "=> patching events"
gh[hooks_url + "/#{campfire['id']}"].patch({
:name => 'campfire',
:add_events => ['issues','pull_request']
}.to_json)
end
end
puts
end
@kowsik
Copy link
Author

kowsik commented Mar 22, 2012

According to @github support, the pull_request and issues events are new and are only configurable through the API. The UI support is not there yet. Hence this script.

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