Skip to content

Instantly share code, notes, and snippets.

@nogweii
Created March 6, 2014 00:26
Show Gist options
  • Save nogweii/9379717 to your computer and use it in GitHub Desktop.
Save nogweii/9379717 to your computer and use it in GitHub Desktop.
A script to set up HipChat hooks on every repository in an organization
#!/usr/bin/ruby
# Script to set up HipChat on every repository in an Organization.
# Is idempotent -- doesn't make a hook if there already is a HipChat
# notification set up.
require 'octokit'
## Settings
# What organization should we set up?
@org_name = "github"
# OAuth Access Token for an user that can administrate hooks
@access_token = "123456789abcdef"
# HipChat APIv1 Notification or Admin token
@hipchat_token = "abcdef123456789"
########################################
# Step 1: Authenticate as an admin.
client = Octokit::Client.new access_token: @access_token
# Step 2: Get a list of all the repositories (public & private) in the org
repositories = client.org_repos(@org_name).map { |repo| repo.full_name }
repositories.each do |repo|
# Step 3: For a given repository, check if the hipchat hook has been set up
next if client.hooks(repo).any? { |hook| hook.name == "hipchat" }
puts "Creating HipChat hook for https://github.com/#{repo}"
# Step 4: Create the hipchat hook for the repo!
client.create_hook(repo, 'hipchat',
{
:auth_token => @hipchat_token,
:room => "Git",
:restrict_to_branch => "",
:color => "gray"
},{
:active => true,
:events => ["commit_comment", "download", "fork", "fork_apply", "gollum",
"issues", "issue_comment", "member", "public", "pull_request",
"pull_request_review_comment", "push", "watch"]
})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment