Skip to content

Instantly share code, notes, and snippets.

@nerf
Created October 8, 2014 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerf/6e13502cc599fd15f55e to your computer and use it in GitHub Desktop.
Save nerf/6e13502cc599fd15f55e to your computer and use it in GitHub Desktop.
hipchat notifications for shell commands
#!/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.")
@nerf
Copy link
Author

nerf commented Oct 8, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment