Arthur Chang

Entrepreneur, Software Engineer, and Photographer
Mar 17

Campfire and Git pushes

Previously when using Campfire, we used a library called Marshmallow, that joins a room and says what commit happened in an SVN repository.  Since moving over to a Git repository, we needed a new bot that would come and tell us what was happening.

I turned to an unofficial Campfire API called Tinder, and wrote a little bit of code to join a single room that has guest access turned on, to say what was just committed to the repository.

The code joins a room, looks for commits in Git, and "speaks".  It runs post-update, so put this in the /git/repo.git/hooks/post-update file.  Don't forget to chmod 770 the post-update file so it can be executed.  This hook is basically what is run when you do a push to the repository.

#!/usr/bin/env ruby

require 'rubygems'
require 'tinder' #require the tinder gem

# room: the subdomain you use for subdomain.campfirenow.com
# path: path to your repository you want to track
# hash: the guest hash, should be about 5 characters long.  you need to turn on guest access in campfire manually first.
# msg: a nice commit message, check the manual for git-log for some flags
#          %an is the author name, %ar is time since the commit, %s is the message, %H is the commit hash
config = {
  :room => 'SUBDOMAIN',
  :path => '/git/repo/path/repo.git',
    :hash => 'GUEST_HASH',
  :msg  => 'Commit by %an (%ar): \"%s\"%nChangeset: http://trac.yoursite.com/changeset/%H'
}

# create new campfire instance with the room
campfire = Tinder::Campfire.new(config[:room])
# get the guest room
room = campfire.find_room_by_guest_hash(config[:hash], 'gitbot')

# get all the commits
commits = `cd #{config[:path]} && git log -#{ARGV.size} --pretty=format:"#{config[:msg]}"`

# say something for each commit
commits.each_line do |commit|
  room.speak "#{commit}"
end

I added some comments above explaining what was going on.  You might also be curious about the msg hash.  The changeset link is going to a modified version of Trac, which I've installed a Git Plugin, so Trac uses our Git repository instead of our SVN repository.  There's probably better tracking systems out there, but we're just reusing what we had before.

About Arthur Chang

Life
I live in the San Francisco Bay Area and love to surround myself with friends and family. I'm a technology geek with an obsessive startup mentality, a photography nerd, and love to play sports (basketball, tennis, and more).

Startups
I am an entrepreneur with a background in software engineering. Most notably, I founded a company in 2009, Fanvibe.com, backed by investors including Y Combinator, which was acquired in 2011 by beRecruited.com. I am now the Lead of Product and Engineering (fancy title) of beRecruited.

Hacks
I graduated from UC Santa Barbara's College of Engineering with a B.S. in Computer Science in 2005. I've been developing and designing products in web and mobile platforms with large corporations and many of my own startups. I'm obsessed with disruptive apps, cutting edge tech, social game mechanics, social network development, software security, and all things code.

Photography
Photography is one of my biggest passions. Historically, it has been a hobby of capturing stories within still images. I photograph weddings, engagements, travel destinations, landscapes, various events, and many good cause events as a volunteer.

I shoot with a iPhone 4S and various Nikon SLR gear. I'm available to shoot events, weddings, and engagements. I am also always happy to volunteer my time to photograph good cause events.


TwitterFacebookmetaweblog

Search Blog

Get Updates

Tags

Archive

2012 (8)
2011 (20)
2010 (41)
2009 (83)
2008 (2)