Skip to content

Instantly share code, notes, and snippets.

@djanowski
Created January 16, 2009 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djanowski/47947 to your computer and use it in GitHub Desktop.
Save djanowski/47947 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
# Usage:
#
# $ build.rb http://yoururl.com/your_project/push
#
# $ echo "HEAD -1 refs/heads/master" | build.rb http://yoururl.com/your_project/push
#
# or you can hard-code the URL in the following line instead
# of passing it as an argument.
url = ARGV.pop
#######################################################################
## ##
## == DON'T EDIT ANYTHING BELOW UNLESS YOU KNOW WHAT YOU'RE DOING == ##
## ##
#######################################################################
require 'net/http'
require 'uri'
old_head, new_head, ref = $stdin.gets.split unless $stdin.tty?
old_head = old_head ? "^#{old_head}" : "-1"
new_head ||= "HEAD"
ref ||= "refs/heads/master"
revisions = `git rev-list --pretty=oneline #{new_head} #{old_head} | awk '{print $1}'`.split("\n")
revisions.map! {|r| %Q({"id":"#{r}"}) }.join(",")
payload = %Q({"ref":"#{ref}", "commits":[#{revisions}]})
puts Net::HTTP.post_form(URI.parse(url), {
:payload => payload
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment