Created
October 8, 2014 12:31
-
-
Save nerf/6e13502cc599fd15f55e to your computer and use it in GitHub Desktop.
hipchat notifications for shell commands
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
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'uri' | |
require 'open3' | |
TOKEN = 'YOUR_TOKEN' | |
ROOM = 'ROOM_ID' | |
FROM='YOU_NAME' | |
COLOR='green' | |
def send_notification(message) | |
encoded_message = URI.encode(message) | |
url = "https://api.hipchat.com/v1/rooms/message?auth_token=#{TOKEN}&room_id=#{ROOM}&from=#{FROM}&color=#{COLOR}&message=#{encoded_message}" | |
status = Net::HTTP.get(URI.parse(url)) | |
puts "Notification status: #{status}" | |
end | |
command = ARGV.join(' ') | |
send_notification("Starting #{command}...") | |
Open3.pipeline(command) | |
send_notification("#{command} finished.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save this file to bin directory and set execution flag like so
chmod u+x path/to/bin/hipchat_notify
.Then prefix your commands like this:
hipchat_notify cap production deploy