Skip to content

Commit

Permalink
Add 2 extra script for campfire
Browse files Browse the repository at this point in the history
git-svn-id: http://code.macournoyer.com/svn/scout/trunk@411 ab7993de-5426-0410-a80b-baa00616f331
  • Loading branch information
macournoyer committed Dec 18, 2007
1 parent be377d6 commit 50ae36c
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
70 changes: 70 additions & 0 deletions extra/campfire_notifier.rb
@@ -0,0 +1,70 @@
# Publish build status in a Campfire room.
# Requires the tinder gem: sudo gem install tinder.
#
# Adding the following lines to /path/to/builds/your_project/cruise_config.rb
# <pre><code>
# Project.configure do |project|
# ...
# project.campfire_notifier.account = 'mysubdomain'
# project.campfire_notifier.username = 'bot@mydomain.com'
# project.campfire_notifier.password = 'your_password'
# project.campfire_notifier.room = 'Main room'
# ...
# end
# </code></pre>
# Start the builder (./cruise build your_project)

require 'rubygems'
require 'tinder'

class CampfireNotifier
attr_accessor :account, :username, :password, :room

FIXED_MESSAGES = [
"%s, you fixed %s, I love you!",
"I think %s is the best hacker *EVER*, he fixed %s!",
"%s fixed %s build like a champ! Congrats!",
"Holy cow! %s fixed %s build again and again and again! *WOW!*"
]
BROKEN_MESSAGES = [
"%s broke %s build! Damn you!",
"Holy crap! %s broke %s build... again!",
"Why did you do this %s ? You broke %s build !",
"No! %s broke %s"
]

def initialize(project = nil)
@account = ''
@username = ''
@password = ''
@room = ''
end

def build_broken(build, previous_build)
send_message build, BROKEN_MESSAGES
end

def build_fixed(build, previous_build)
send_message build, FIXED_MESSAGES
end

private
def get_build_info(build)
changeset = ChangesetLogParser.new.parse_log(build.changeset.split("\n"))
author = changeset.last.committed_by
[author, build.project.name]
end

def send_message(build, messages)
campfire = Tinder::Campfire.new @account
campfire.login @username, @password
room = campfire.find_room_by_name @room

message = messages[rand(messages.size)] % get_build_info(build)

room.speak message
room.speak build.url
end
end

Project.plugin :campfire_notifier
41 changes: 41 additions & 0 deletions extra/campfire_post_commit_hook.rb
@@ -0,0 +1,41 @@
#!/usr/bin/ruby
# Commit hook to publish commits in Campfire room.
# Requires the tinder gem: sudo gem install tinder.
#
# Put this in your /svn/repo/path/hooks/post-commit
# /usr/bin/ruby /var/lib/svn/project/hooks/campfire_post_commit_hook.rb "$1" "$2"

CAMPFIRE = {
:subdomain => 'mysubdomain',
:email => 'admin@example.com',
:password => 'peanutketchup',
:room => 'Main Room'
}
CHANGESET_URL = 'http://trac.example.com/changeset/%s' # %s is the revision number
SVNLOOK = '/usr/bin/svnlook'

require 'rubygems'
require 'tinder'

campfire = Tinder::Campfire.new CAMPFIRE[:subdomain]
campfire.login CAMPFIRE[:email], CAMPFIRE[:password]
room = campfire.find_room_by_name CAMPFIRE[:room]

if ARGV.size > 1
revision = ARGV[1]
path = ARGV[0]

author = `#{SVNLOOK} author -r #{revision} #{path}`
paths = `#{SVNLOOK} changed -r #{revision} #{path}`
log = `#{SVNLOOK} log -r #{revision} #{path}`
message = [log, paths].join.strip
url = "#{author} commited #{CHANGESET_URL}/#{revision}"

room.speak url
room.paste message
else
room.speak ARGV[0]
end

room.leave
campfire.logout

0 comments on commit 50ae36c

Please sign in to comment.