Skip to content

Instantly share code, notes, and snippets.

@harperreed
Forked from YenTheFirst/update_hooks.rb
Created January 13, 2012 21:58
Show Gist options
  • Save harperreed/1608924 to your computer and use it in GitHub Desktop.
Save harperreed/1608924 to your computer and use it in GitHub Desktop.
require 'github_v3_api'
g = g=GitHubV3API.new(ENV['GITHUB_OAUTH2_TOKEN'])
cfa = g.orgs.list.first
names = cfa.repos.map(&:name)
names.each do |name|
hooks = g.get("/repos/codeforamerica/#{name}/hooks")
scream_hook = hooks.find {|h| h["name"] == "web" && h["config"]["url"] =~ /6178/}
if scream_hook
unless scream_hook["config"]["url"] =~ /97.65.119.3/
puts "updating #{name}"
g.patch("/repos/codeforamerica/#{name}/hooks/#{scream_hook['id']}",{
"name"=>"web",
"config"=>scream_hook["config"].merge({"url"=>"97.65.119.3:6178/receive_commit"}),
})
end
else
puts "creating #{name}"
g.post("/repos/codeforamerica/#{name}/hooks",{
"name"=>"web",
"active"=>true,
"config"=>{
"url"=>"97.65.119.3:6178/receive_commit"
}
})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment