Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |