Skip to content

Instantly share code, notes, and snippets.

@miketheman
Last active October 11, 2015 01:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketheman/3784158 to your computer and use it in GitHub Desktop.
Save miketheman/3784158 to your computer and use it in GitHub Desktop.
API-based addition of hooks to your repos
require 'octokit'
# I don't have to put my secrets in this file
require_relative 'auth'
ORGNAME = '<insert your organization or repo name here>'
client = Octokit::Client.new(:login => LOGIN, :password => PASSWORD)
repo = "#{ORGNAME}/<insert your repo name here>"
# Hooks:
# This could probably be a YAML file or such.
[
{ :name => "web",
:config => {
:insecure_ssl => "1",
:url => "http://jenkins.external.jenkins.url.mydomain.com/github-webhook/"
}
},
{ :name => "irc",
:config => {
:branch_regexes => "",
:message_without_join => "1",
:nick => "",
:notice => "1",
:password => "",
:port => "6667",
:room => "#<insert the name of your IRC room here>",
:server => "irc.freenode.net"
}
},
{ :name => "pivotaltracker",
:config => {
:branch => "",
:endpoint => "",
:token => "<some secret api key goes here>"
}
}
].each do |hook|
client.create_hook(repo, hook[:name], hook[:config])
puts "#{hook[:name]} created on #{repo}"
end
# The secretest secrets
LOGIN = 'miketheman'
PASSWORD = 'you didn't really think I'd put it here, right?'
gem "octokit", "~> 1.24.0"

What to do:

  1. Install the dependencies: bundle install (alternatively gem install octokit
  2. Create an auth.rb file with your secrets
  3. Create the addhooks.rb file, and modify where necessary - ORGNAME, and set up any hooks as an array with the hash of the hook to modify
  4. Execute: ruby addhooks.rb
  5. Profit!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment