File: post-commit

package info (click to toggle)
ticgit 0.3.3-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 276 kB
  • ctags: 107
  • sloc: ruby: 1,256; makefile: 7
file content (28 lines) | stat: -rwxr-xr-x 847 bytes parent folder | download
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
#!/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