Created
May 28, 2009 13:33
-
-
Save jmeridth/119297 to your computer and use it in GitHub Desktop.
integrity ci githook post-receive
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 | |
require 'rubygems' | |
require 'net/http' | |
require 'net/https' | |
require 'json' | |
# EDIT POST_RECEIVE_URL | |
POST_RECEIVE_URL = 'https://my.domain.com/application_name/push' | |
old_head, new_head, ref = STDIN.gets.split | |
#puts "old_head: #{old_head}" | |
#puts "new_head: #{new_head}" | |
#puts "ref: #{ref}" | |
revision_text = `git-rev-list --pretty=format:'Author: %an <%ae>%nDate: %cd%n%s%n' #{new_head} ^#{old_head}` | |
revisions = [] | |
revision_text.split(/\n\n/).each { |commit| | |
s = commit.split(/\n/) | |
s[0] =~ /commit (\w+)/ | |
sha1 = $1 | |
s[1] =~ /Author: (.*) <(.+?)>/ | |
author_name, author_email = $1, $2 | |
s[2] =~ /Date: +(.+?) -0/ | |
timestamp = $1 | |
message = s[3].strip | |
revisions << { | |
'id' => sha1, | |
'author' => { | |
'email' => author_email, | |
'name' => author_name, | |
}, | |
'message' => message, | |
'timestamp' => timestamp, | |
} | |
} | |
if revisions.empty? | |
exit 0 | |
end | |
payload = { | |
'payload' => { | |
"ref" => ref, | |
"commits" => revisions, | |
}.to_json | |
} | |
if pid = fork | |
Process.detach pid | |
else | |
uri = URI.parse(POST_RECEIVE_URL) | |
post_req = Net::HTTP::Post.new(uri.path) | |
post_req.basic_auth '53cr3t', 'p@55w0rd' | |
post_req.set_form_data(payload, ';') | |
req = Net::HTTP.new(uri.host, uri.port) | |
req.use_ssl = true | |
req.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
req.start {|http| http.request(post_req)} | |
end | |
puts "Running Integrity CI build for application_name application" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment