Skip to content

Instantly share code, notes, and snippets.

@hinke
Created August 11, 2011 11:00
Show Gist options
  • Save hinke/1139381 to your computer and use it in GitHub Desktop.
Save hinke/1139381 to your computer and use it in GitHub Desktop.
A capistrano extension for sending deploy messages to yammer
Capistrano::Configuration.instance(:must_exist).load do
require 'httparty'
before "deploy", "yammer:notify_deploy_start"
after "deploy", "yammer:notify_deploy_success"
after "deploy:rollback", "yammer:notify_deploy_fail"
namespace :yammer do
desc "Notify a Yammer account that a deploy just started"
task :notify_deploy_start do
Yammer.new(application, branch, exists?(:stage) ? stage : nil).notify("Started deploying")
end
desc "Notify a Yammer account that a deploy just finished"
task :notify_deploy_success do
Yammer.new(application, branch, exists?(:stage) ? stage : nil).notify("Successfully deployed", " YAY!")
end
desc "Notify a Yammer account that a deploy just failed"
task :notify_deploy_fail do
Yammer.new(application, branch, exists?(:stage) ? stage : nil).notify("Failed to deploy", ", OH NO!")
end
end
class Yammer
include HTTParty
base_uri 'https://www.yammer.com'
def initialize(application, branch, stage)
@app = application
@branch = branch
@stage = stage
@consumer_key = "x"
@consumer_secret = "x"
@oauth_token = "x"
@oauth_token_secret = "x"
@oauth_verifier = "x"
@oauth_signature = "#{@consumer_secret}%26#{@oauth_token_secret}"
@auth_header = "OAuth oauth_consumer_key=#{@consumer_key},oauth_token=#{@oauth_token},oauth_signature_method=PLAINTEXT,oauth_timestamp=1297382941014,oauth_nonce=545746008,oauth_verifier=#{@oauth_verifier},oauth_signature=#{@oauth_signature}"
end
def notify(pre, post = "")
message = "#{pre} #{@app} (#{@branch})"
message += " to #{@stage}" unless @stage.blank?
message += "#{post}" unless post.blank?
options = {:query => {:body => message}, :headers => {"Authorization" => @auth_header}}
self.class.post("/api/v1/messages.json", options)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment