Permalink
Browse files

added an example post-commit hook file

  • Loading branch information...
1 parent 74b835f commit 6e453f523fa1da50ecb04431101112b3611c6a4d @yob yob committed with schacon May 12, 2008
Showing with 28 additions and 0 deletions.
  1. +28 −0 examples/post-commit
View
28 examples/post-commit
@@ -0,0 +1,28 @@
+#!/usr/bin/env ruby
+
+require 'tempfile'
+
+commit_log = `git log -1`.chomp
+m, commit_id = * commit_log.match(/commit\W*([A-Fa-f0-9]+)/)
+
+Tempfile.open('ticgit_comment') do |tmp|
+ tmp.write commit_log
+ actions = {}
+
+ # comment on any tickets this commit references
+ commit_log.scan(/\(\W*[Rr]efs?\W*:*\W*\#([a-fA-F0-9]+)\W*\)/).each do |ticked_id|
+ actions[ticket_id] = :ref
+ end
+
+ # close any tickets this commit solves
+ # overwrite any refs, as the commit log will still
+ # be added to the ticket as a comment, but will also be closed
+ commit_log.scan(/\(\W*[Cc]loses\W*:*\W*\#([a-fA-F0-9]+)\W*\)/).each do |ticket_id|
+ actions[ticket_id] = :close
+ end
+
+ actions.each do |ticket_id, action|
+ `ti comment #{ticket_id} --file #{tmp.path}` if action
+ `ti state #{ticket_id} resolved` if action == :close
+ end
+end

0 comments on commit 6e453f5

Please sign in to comment.