rboyd / git2yammer

a post-receive hook to relay git commits to yammer

git2yammer / git2yammer.rb
100644 28 lines (22 sloc) 0.586 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
#!/usr/bin/ruby
require 'rubygems'
require 'yammer4r'
require 'oauth/consumer'
 
 
yammer = Yammer::Client.new(:config => 'oauth.yml')
ref = ARGV[0]
git_dir = ARGV[1]
Dir.chdir(git_dir)
 
f = IO.popen("git cat-file commit #{ref}")
output = f.readlines
f.close
committer = ''
output.each do |line|
  results = line.scan(/committer .* <(.*)@/)
  if !results.empty?
    committer = results.flatten.shift
  end
end
 
message = output.pop
message.gsub!(/\n/, '')
 
repo = git_dir.scan(/.*\/(.*).git/).flatten.shift
yammer.message(:post, :body => "#{message} (committer: #{committer}) ##{repo}")