Skip to content

Instantly share code, notes, and snippets.

Created January 28, 2009 12:01
Show Gist options
  • Save vjt/53917 to your computer and use it in GitHub Desktop.
Save vjt/53917 to your computer and use it in GitHub Desktop.
lighthouse-github integration
# Originally posted on (22 October 2008)
This script is intended for those who wish to push changesets
to lighthouse at push time, and not with a post-commit hook.
Because there's no point in having a distributed SCM if every
commit you do istantaneously goes public to lighthouse.
So, this script adds a new "git lh" command that fetches all the
revs between the remote origin and the current HEAD, and pushes
all of them to lighthouse.
This means that you should first issue git lh and then git push.
# Installation
Put the source file alongside the git command, naming it "git-lh".
# Configuration
Add the following stanzas into your .git/config, in the repository you
want to manage:
token = your_lh_api_token
account = your_lh_account
project = your_lh_project_id
# Credits
Original guide:
Original script:
# Added goodies
A nice diffstat in lighthouse changeset messages ;-)
Don't want to issue two commands? Add this simple script, and name
it git-lh-push:
git lh "$@" && git push --all
git lh "$@" && git push --all
#!/usr/bin/env ruby
require 'yaml'
require 'cgi'
require 'net/http'
git = `which git`.strip
first = $ARGV.shift || 'origin/master'
last = $ARGV.shift || 'HEAD'
revs = `#{git} log --pretty=format:%H --no-merges #{first}..#{last}`.split(/\n/).reverse
puts "Already up-to-date."
exit 1
LIGHTHOUSE_TOKEN = `#{git} config --get lighthouse.token`.chomp
LIGHTHOUSE_ACCOUNT = `#{git} config --get lighthouse.account`.chomp
LIGHTHOUSE_PROJECT = `#{git} config --get lighthouse.project`.chomp
GITHUB_ACCOUNT, GITHUB_REPOSITORY = `#{git} remote -v`.scan(/(\w+)\/(\S+)\.git/).flatten
puts "* Pushing #{revs.size} revisions to lighthouse"
revs.each do |revision|
author = `#{git} show --pretty=format:"%an" #{revision} | sed q`.chomp
log = `#{git} show --pretty=format:"%s" #{revision} | sed q`.chomp
date = `#{git} show --pretty=format:"%aD" #{revision} | sed q`.chomp
diffstat = `#{git} diff --stat #{revision}^..#{revision}`.chomp.gsub(/\n/, '\& ')
changed = `#{git} diff-tree -r --name-status #{revision} | sed -n '$p'`
changes = changed.split("\n").inject([]) { |memo, line| memo << [$1, $2] if line.strip =~ /(\w)\s+(.*)/ }.to_yaml
xml = <<-EOF
<title>#{CGI.escapeHTML("%s committed new changes to %s" % [author, GITHUB_REPOSITORY])}</title>
<changes type="yaml">#{CGI.escapeHTML(changes)}</changes>
<changed-at type="datetime">#{CGI.escapeHTML(date.split('(').first.strip)}</changed-at>
request ="/projects/#{LIGHTHOUSE_PROJECT}/changesets.xml")
request.set_content_type "application/xml"
request.basic_auth LIGHTHOUSE_TOKEN, "x"
request.body = xml
response = Net::HTTP.start("#{LIGHTHOUSE_ACCOUNT}").request(request)
puts " Pushed rev #{revision} (#{log}). response: #{response.message}"
sleep 0.3
# Assuming you're on Ubuntu or OSX
GIT=$(dirname `which git`)
sudo install -m 755 git-lh.rb $GIT/git-lh
sudo install -m 755 $GIT/git-lh-push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment