Skip to content

Instantly share code, notes, and snippets.

@garethr
Created July 11, 2010 17:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethr/471711 to your computer and use it in GitHub Desktop.
Save garethr/471711 to your computer and use it in GitHub Desktop.
pre-receive git hook for integrity continuous integration server
#!/usr/bin/env ruby
require 'rubygems'
require 'grit'
require 'nokogiri'
require 'open-uri'
# This is a pre-receive git hook designed to be part of a continuous
# deployment workflow using the Integrity continuous integration server
INTEGRITY = 'http://localhost:9292'
PROJECT = 'site'
# 1. Check if the build is currently broken
# 2. If it's broken check if the commit messages starts with
# [BUILD] and if so trigger a build
# 3. If it's broken and all messages don't have the prefix
# then stop the push
# 4. If the build is fine then let everything through
doc = Nokogiri::HTML(open("#{INTEGRITY}/#{PROJECT}"))
doc.css('div#last_build h1').each do |heading|
content = heading.content.split
@status = content[-1]
end
if @status == "failed"
puts "Build currently broken, to force use the [BUILD] commit message prefix"
old_rev, new_rev, ref_name = STDIN.gets.split
repo = Grit::Repo.new(".")
commits = repo.commits_between(old_rev, new_rev)
commits.reverse.each do |c|
short, long = c.message.split(/\n+/, 2)
if short.slice(0..7) != "[BUILD]
puts "Cancelling push"
exit 1
end
end
end
@daroay
Copy link

daroay commented Jan 27, 2014

typo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment