Created
March 11, 2010 19:05
-
-
Save netzpirat/329522 to your computer and use it in GitHub Desktop.
Tweet a message on successful multistage capistrano deployment
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
require 'open-uri' | |
require 'net/http' | |
namespace :tweet do | |
desc 'Posts deployment information to twitter' | |
task :notify do | |
begin | |
File.open(File.expand_path('~/.twitter')) do |file| | |
@username = file.readline.gsub!(/\n+/, '') | |
@password = file.readline.gsub!(/\n+/, '') | |
end | |
revision = capture("cat #{current_path}/REVISION").chomp | |
link = "https://github.com/screenconcept/#{ application }/tree/#{ revision }" | |
url = URI.parse('http://twitter.com/statuses/update.xml') | |
request = Net::HTTP::Post.new(url.path) | |
request.basic_auth @username, @password | |
request.set_form_data 'status' => "#{ stage.to_s.upcase }: Deployed #{ application }: #{ link }" | |
response = Net::HTTP.new(url.host, url.port).start { |http| http.request(request) } | |
if response.code.to_i == 200 | |
logger.info "Tweet, tweet, tweet..." | |
else | |
logger.important "Deploy tweet failed with #{ response.code }: #{ response.message }!" | |
end | |
rescue Errno::ENOENT | |
logger.important "Please configure your twitter account settings to automatically tweet deploys!" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment