Skip to content

Instantly share code, notes, and snippets.

@Fiyorden
Created April 29, 2015 21:27
Show Gist options
  • Save Fiyorden/156f4d477a59811d100b to your computer and use it in GitHub Desktop.
Save Fiyorden/156f4d477a59811d100b to your computer and use it in GitHub Desktop.
Capistrano 3 - Hipchat usage
require 'hipchat'
set :hipchat_user, "Capistrano"
set :hipchat_token, "mettre le token"
set :hipchat_client, HipChat::Client.new(fetch(:hipchat_token))
set :hipchat_room_name, "Nom de la salle" # If you pass an array such as ["room_a", "room_b"] you can send announcements to multiple rooms.
# Optional
set :hipchat_announce, false # notify users
set :hipchat_message_format, 'html' # Sets the deployment message format, see https://www.hipchat.com/docs/api/method/rooms/message
set :hipchat_options, {
:api_version => "v2" # Set "v2" to send messages with API v2
}
namespace :hipchat do
desc 'Test HipChat API connection'
task :ping do
fetch(:hipchat_client)[fetch(:hipchat_room_name)].send(fetch(:hipchat_user), "Test 1, 2... Test! (#{fetch(:stage)})", :notify => fetch(:hipchat_announce), :color => 'purple')
end
desc 'Notify the start of deployement'
task :notify_deploy_started do
fetch(:hipchat_client)[fetch(:hipchat_room_name)].send(fetch(:hipchat_user), "#{human} a commencer à déployer sur #{fetch(:server_name)} dans l'environnent #{fetch(:stage)}.", :notify => fetch(:hipchat_announce), :color => 'gray')
end
task :notify_deploy_finished do
fetch(:hipchat_client)[fetch(:hipchat_room_name)].send(fetch(:hipchat_user), "#{human} a fini de déployer sur #{fetch(:server_name)} dans l'environnent #{fetch(:stage)}.", :notify => fetch(:hipchat_announce), :color => 'green')
end
task :notify_deploy_reverted do
fetch(:hipchat_client)[fetch(:hipchat_room_name)].send(fetch(:hipchat_user), "une erreur est survenue dans le déploiement sur #{fetch(:server_name)} dans l'environnent #{fetch(:stage)}.", :notify => fetch(:hipchat_announce), :color => 'red')
end
def human
user = ENV['HIPCHAT_USER'] || fetch(:hipchat_human)
user = user || if (u = %x{git config user.name}.strip) != ''
u
elsif (u = ENV['USER']) != ''
u
else
'Someone'
end
user
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment