Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First hack

  • Loading branch information...
commit e2776350cb35f1212a21f6861bb1a767d071663e 0 parents
@ultraninja ultraninja authored
2  .gitignore
@@ -0,0 +1,2 @@
+.bundle
+config.rb
3  Gemfile
@@ -0,0 +1,3 @@
+source "http://rubygems.org/"
+
+gem "nokogiri"
10 Gemfile.lock
@@ -0,0 +1,10 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ nokogiri (1.4.3.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ nokogiri
7 config-example.rb
@@ -0,0 +1,7 @@
+@user = "superuser"
+@token = "tokenofdeath"
+@repo = "superorg/hacks"
+@urls = [
+ "http://someci.example.org/",
+ "http://someirc.example.org/"
+]
55 github_post_receive_hook.rb
@@ -0,0 +1,55 @@
+#!/usr/bin/env ruby
+
+require 'net/http'
+require 'net/https'
+
+require 'nokogiri'
+require 'ruby-debug'
+
+require 'config'
+
+raise "No user specified" if @user.nil? || @user.empty?
+raise "No token specified" if @token.nil? || @token.empty?
+raise "No repo specified" if @repo.nil? || @repo.empty?
+raise "No urls specified" if @urls.nil? || @urls.empty?
+
+auth = {:login => @user, :token => @token}
+
+def fetch(uri, req)
+ server = Net::HTTP.new uri.host, uri.port
+ server.use_ssl = uri.scheme == 'https'
+ server.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ server.start {|http| http.request(req) }
+end
+
+admin_page = "https://github.com/#{@repo}/edit"
+uri = URI.parse(admin_page)
+req = Net::HTTP::Get.new(uri.path)
+req.set_form_data(auth, '&')
+
+res = fetch(uri, req)
+
+doc = Nokogiri::HTML(res.body)
+form = doc.at("form[action='/#{@repo}/edit/postreceive_urls']")
+urls = form.search("input[name='urls[]']").map {|x| x["value"]}.compact
+
+puts "Current: "
+puts urls
+
+urls += @urls
+urls.uniq!
+
+puts "New: "
+puts urls
+
+
+uri = URI.parse "#{admin_page}/postreceive_urls"
+req = Net::HTTP::Post.new(uri.path)
+data = auth.to_a
+urls.each do |url|
+ data << ["urls[]", url]
+end
+
+req.set_form_data(data, '&')
+
+fetch(uri, req)
Please sign in to comment.
Something went wrong with that request. Please try again.