Skip to content

Instantly share code, notes, and snippets.

@smichaelsen
Last active December 17, 2015 19:58
Show Gist options
  • Save smichaelsen/5663725 to your computer and use it in GitHub Desktop.
Save smichaelsen/5663725 to your computer and use it in GitHub Desktop.

This script is intented to be used as git post-commit hook. It uses sightsnap (https://github.com/monkeydom/sightsnap) and is based on an example script (https://github.com/monkeydom/sightsnap/blob/develop/examples/lolsnapcommit-hook.rb).

  • When committing it shoots a photo of you and provides some commit meta data as text on that image.
  • It prepares an URL (see lines 8 and 57) which it expects that image to be found on and attaches it as git note to the commit. I do that in Markdown syntax because I hope Github will render git notes as Markdown in the future.
  • Github will show the image url allong with the commit
  • A local folder action (Automator.app) uploads all snapshot images to my server
  • When pushing your changes to the origin (Github) remember to also push the git notes: git push origin refs/notes/*

Example: https://github.com/smichaelsen/typo3-opauth/commit/9d7f6c9b6973282a68760157dc1f64d728088deb example

#!/usr/bin/env ruby
# to install simply copy to somewhere in your path where this script will stay
# and either make sure sightsnap is in your path e.g. /usr/bin or you supply the
# full path here instead of the shorthand
sightsnap = "sightsnap"
http_path = 'http://t3seo.de/commitsnaps'
# then run lolsnapcommit-hook.rb --install to install the hook in a repository when inside the repo
# you can run lolsnapcommit-hook.rb to test it for the most recent commit
# or run lolsnapcommit-hook.rb --remove to remove the hook again
# or run lolsnapcommit-hook.rb --show to show the lolsnap-directory
# git parameters to use
commit = %x[git rev-parse --verify HEAD].strip
short_commit = commit[0..12]
top_level_dir = %x[git rev-parse --show-toplevel].strip
repo_name = File.basename(top_level_dir)
revision_number = %x[git rev-list HEAD | wc -l;].strip
commit_message = %x[git log -n 1 HEAD --format=format:%s%n%b].strip
branch_name = %x[git rev-parse --abbrev-ref HEAD].strip
base_snap_path = File.expand_path "~/Library/Application Support/lolsnap/"
# install and remove
commit_hook_path = File.join(top_level_dir, '.git/hooks/post-commit')
ARGV.each {|arg|
if (arg == "--install") then
here = File.expand_path(__FILE__)
%x[echo '#!/bin/sh\n#{here}' > '#{commit_hook_path}' && chmod a+x '#{commit_hook_path}']
print "installed lolsnap post-commit hook\n"
exit (0)
elsif (arg == "--remove") then
%x[mv '#{commit_hook_path}' '#{commit_hook_path}.lolsnap.old']
print "removed lolsnap post-commit hook\n"
exit (0)
elsif (arg == "--show") then
%x[open '#{base_snap_path}/#{repo_name}']
exit(0)
end
}
# single character escaping
class String
def escape_single
self.gsub("'","'\\\\''")
end
end
# settings
title = "%s %s:%10s" % [repo_name, branch_name, short_commit]
font = "Impact"
font_size = 40
filename = "/%s_%s.jpg" % [repo_name, short_commit]
%x[git notes add -m '![#{short_commit}](#{http_path}#{filename})']
#print title, "\n"
#print commit_message, "\n"
snap_path = File.join(base_snap_path, filename)
%x[#{sightsnap} -p -T '#{title.escape_single}' -C '#{commit_message.escape_single}' -j 0.6 -f '#{font}' -s '#{font_size}' -x 800 '#{snap_path.escape_single}']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment