Created
March 23, 2010 20:41
-
-
Save mathias/341627 to your computer and use it in GitHub Desktop.
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/env ruby | |
## post-receive | |
## | |
## Description: | |
## This should live in a gitosis repo's .git/hooks directory and be set executable | |
## It is run every time someone sucessfully does a "git push" to the server | |
## Then it POSTs to a server, ideally creating a Drupal node with the details of the git push. | |
require 'net/http' | |
require 'uri' | |
# CONSTANTS | |
$refname = ARGV[0] | |
$oldrev = ARGV[1] | |
$newrev = ARGV[2] | |
$user = ENV['USER'] | |
# .htaccess: | |
$USER = "" | |
$PASS = "" | |
# URL to POST | |
#postURL = URI.parse('http://example.com/drupal_create_case.php') | |
$postURL = URI.parse('http://localhost:9393/') | |
$regex = /^\d+$/ | |
def post_form(rev) | |
message = `git cat-file commit #{rev} | sed '1,/^$/d'` | |
caseNumber = message.split("\n").last | |
request = Net::HTTP::Post.new($postURL.path); | |
request.basic_auth $USER, $PASS | |
request.set_form_data({"caseNumber" => caseNumber, "rev" => rev, "message" => message}) | |
res = Net::HTTP.new($postURL).start {|http| http.request(request) } | |
end | |
# Check message format. | |
def check_message_format | |
missed_revs = `git rev-list #{$oldrev}..#{$newrev} --`.split("\n") | |
missed_revs.each do |rev| | |
message = `git cat-file commit #{rev} | sed '1,/^$/d'` | |
# Check to make sure we're referencing a case number | |
caseNumber = message.split("\n").last | |
if $regex.match(caseNumber) | |
# POST a new node to Drupal | |
# puts "Last line is a case number" | |
post_form(rev) | |
end | |
end | |
end | |
check_message_format |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment