public
Rubygem
Description: Git based distributed ticketing system, including a command line client and web viewer
Clone URL: git://github.com/schacon/ticgit.git
Search Repo:
ticgit / examples / post-commit
100755 29 lines (22 sloc) 0.847 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/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