-
-
Save mileszs/4d81e30bbc4aac556dec to your computer and use it in GitHub Desktop.
post-receive hook for sending to your Integrity server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Git post-receive hook for pushing to Integrity | |
# 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' | |
require 'rubygems' | |
require 'daemons' | |
old_head, new_head, ref = STDIN.gets.split | |
# on solaris, ruby is choking on various shell commands, the quotes in format. | |
# maybe it's running sh? (though it seems to report bash)? | |
# the `bash -c ...` gets around it, anyhow: | |
revisions = %x{bash -c "git-rev-list --pretty=format:'%H %ai' #{new_head} ^#{old_head}"}.split("\n") | |
rev_list = revisions.inject([]) do |list,line| | |
if line[0..5] == 'commit' | |
list | |
else | |
list << %Q({"id":"#{line[0..40]}","timestamp":"#{line[41..66]}"}) | |
end | |
end | |
Daemons.daemonize | |
Net::HTTP.post_form(URI.parse(POST_RECEIVE_URL), { | |
:payload => %Q({"ref":"#{ref}", "commits":[#{rev_list.join(',')}]}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment