-
-
Save cswilliams/78979 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
# Originally posted on http://pastie.org/pastes/298043 (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: | |
[lighthouse] | |
token = your_lh_api_token | |
account = your_lh_account | |
project = your_lh_project_id | |
# Credits | |
Original guide: http://github.com/guides/integrating-git-commit-messages-in-lighthouse/ | |
Original script: http://pastie.org/178549 | |
Author: http://github.com/vjt | |
# 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: | |
#!/bin/bash | |
git lh "$@" && git push --all |
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
#!/bin/sh | |
git lh "$@" && git push --all |
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 '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 | |
if revs.size.zero? | |
puts "Already up-to-date." | |
exit 1 | |
end | |
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 | |
<changeset> | |
<title>#{CGI.escapeHTML("%s committed new changes to %s" % [author, GITHUB_REPOSITORY])}</title> | |
<body> | |
#{CGI.escapeHTML(log)}\n | |
#{"http://github.com/%s/%s/commit/%s" % [ GITHUB_ACCOUNT, GITHUB_REPOSITORY, revision ]}\n | |
#{CGI.escapeHTML(diffstat)} | |
</body> | |
<changes type="yaml">#{CGI.escapeHTML(changes)}</changes> | |
<revision>#{CGI.escapeHTML(revision)}</revision> | |
<changed-at type="datetime">#{CGI.escapeHTML(date.split('(').first.strip)}</changed-at> | |
</changeset> | |
EOF | |
request = Net::HTTP::Post.new("/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}.lighthouseapp.com").request(request) | |
puts " Pushed rev #{revision} (#{log}). response: #{response.message}" | |
sleep 0.3 | |
end |
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
# 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-lh-push.sh $GIT/git-lh-push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment