Skip to content

Instantly share code, notes, and snippets.

@galex
Created November 27, 2009 13:35
Show Gist options
  • Save galex/244018 to your computer and use it in GitHub Desktop.
Save galex/244018 to your computer and use it in GitHub Desktop.
File to put in each git-repository/hooks/ folder, for each project, to notifity Integrity to get this new build and test it.
#!/usr/bin/env ruby
# Replace the following by the url given to you in your project's edit page
POST_RECEIVE_URL = 'http://integrity.url.com/project_name/push'
# Set user and password if Integrity is protected with basic auth
USER = "***"
PASSWORD = "***"
#######################################################################
## ##
## == DON'T EDIT ANYTHING BELOW UNLESS YOU KNOW WHAT YOU'RE DOING == ##
## ##
#######################################################################
require 'net/http'
require 'uri'
require 'rubygems'
require 'git'
require 'daemons'
require 'logger'
require 'json'
before, after, ref = STDIN.gets.split
g = Git.open(Dir.pwd, :repository => Dir.pwd)
if before == '400'
commits = [g.gcommit(after)]
else
commits = g.log.between(before,after)
end
commit_list = commits.inject([]) do |list,commit|
path_list = {'modified'=>[],'new'=>[],'deleted'=>[]}
list << {
'id' => commit.sha,
'message' => commit.message,
'timestamp' => commit.date,
'added' => path_list['new'],
'removed' => path_list['deleted'],
'modified' => path_list['modified'],
'author' => {
'name' => commit.author.name,
'email' => commit.author.email
}
}
end
payload = {
'payload' => {
'before' => before,
'after' => after,
'ref' => ref,
'commits' => commit_list
}.to_json
}
Daemons.daemonize
url = URI.parse(POST_RECEIVE_URL)
req = Net::HTTP::Post.new(url.path)
req.basic_auth(USER, PASSWORD) unless (USER.empty? || PASSWORD.empty?)
req.set_form_data(payload,';')
res = Net::HTTP.new(url.host, url.port).start {|http|
http.read_timeout = 3600
http.request(req)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment