Skip to content

Instantly share code, notes, and snippets.

@joelmoss
Forked from mperham/gist:1831203
Created February 15, 2012 21:56
Show Gist options
  • Save joelmoss/1839263 to your computer and use it in GitHub Desktop.
Save joelmoss/1839263 to your computer and use it in GitHub Desktop.
Campfire deploy announcements
# Put this at the bottom of your config/deploy.rb
# Requires config file at .campfire.yml or ~/.campfire.yml or ../.campfire.yml
# with your API token from your Campfire "My Info" page:
#
# token: lkjsadfsaduoi1u31oui3eh1kj2h
# roomid: 123456
# subdomain: acmeco
class Room
attr_accessor :config
def initialize(cfg)
@config = cfg
end
def say(msg, type=:Paste)
url = "https://#{config['subdomain']}.campfirenow.com/room/#{config['roomid']}"
message = "<message><type>#{type}Message</type><body>#{msg}</body></message>"
`curl -i -u #{config['token']}:X -H 'Content-Type: application/xml' -d '#{message}' #{url}/speak.xml`
end
def paste(msg)
say msg
end
def text(msg)
say msg, :Text
end
end
namespace :deploy do
task :campfire do
yml1, yml2, yml3 = ".campfire.yml", "../.campfire.yml", "~/.campfire.yml"
yml1, yml2, yml3 = File.expand_path(yml1), File.expand_path(yml2), File.expand_path(yml3)
if File.exist?(yml1)
config = YAML.load_file(yml1)
elsif File.exist?(yml2)
config = YAML.load_file(yml2)
elsif File.exist?(yml3)
config = YAML.load_file(yml3)
else
puts "Missing .campfire.yml or ../.campfire.yml or ~/.campfire.yml with your API token, can't announce deploys."
end
ROOM = Room.new(config) if respond_to?(:config)
end
task :pre_announce do
deploy.campfire
ROOM.text "is deploying '#{application}' to #{stage}" if respond_to?(:ROOM)
end
task :post_announce do
ROOM.text "finished deploying '#{application}' to #{stage}" if respond_to?(:ROOM)
end
end
before "deploy", "deploy:pre_announce"
after "deploy", "deploy:post_announce"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment