Skip to content

Instantly share code, notes, and snippets.

@foca
Created November 17, 2008 03:57
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save foca/e431699c726fd17fb06a to your computer and use it in GitHub Desktop.
Generic Integrity post-receive-hook for non-github repos
#!/usr/local/bin/ruby
# Replace the following by the url given to you in your project's edit page
POST_RECEIVE_URL = 'http://localhost:4567/my_fancy_project/push'
#######################################################################
## ##
## == 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
revisions = `git-rev-list --pretty=oneline #{new_head} ^#{old_head} | awk '{print $1}'`.split("\n")
revisions.map! {|r| %Q({"id":"#{r}"}) }.join(",")
Net::HTTP.post_form(URI.parse(POST_RECEIVE_URL), {
:payload => %Q({"ref":"#{ref}", "commits":[#{revisions}]})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment