HipChat Wrapper

A very basic wrapper for the HipChat HTTP API.

Build Status

Usage

client = HipChat::Client.new(api_token)
client['my room'].send('username', 'I talk')</code>

<code># Send notifications to users (default false)
client['my room'].send('username', 'I quit!', :notify => true)</code>

<code># Color it red. or "yellow", "green", "purple", "random" (default "yellow")
client['my room'].send('username', 'Build failed!', :color => 'red')</code>

<code># Have your message rendered as text in HipChat (see https://www.hipchat.com/docs/api/method/rooms/message)
client['my room'].send('username', '@coworker Build faild!', :message_format => 'text')</code>

<code># Update the topic of a room in HipChat (see https://www.hipchat.com/docs/api/method/rooms/topic)
client['my room'].topic('Free Ice Cream in the kitchen')</code>

<code># Change the from field for a topic update (default "API")
client['my room'].topic('Weekely sales: $10,000', :from => 'Sales Team')

Capistrano

require 'hipchat/capistrano'</code>

<code>set :hipchat_token, "<your token>"
set :hipchat_room_name, "Your room" # If you pass an array such as ["room_a", "room_b"] you can send announcements to multiple rooms.
set :hipchat_announce, false # notify users
set :hipchat_color, 'yellow' #normal message color
set :hipchat_success_color, 'green' #finished deployment message color
set :hipchat_failed_color, 'red' #cancelled deployment message color
set :hipchat_message_format, 'text' # Sets the deployment message format, see https://www.hipchat.com/docs/api/method/rooms/message

Who did it?

To determine the user that is currently running the deploy, the capistrano tasks will look for the following:

  1. The $HIPCHAT_USER environment variable
  2. The hipchat_human capistrano var.
  3. The git user.name var.
  4. The $USER environment variable.

Rails 3 Rake Task

Send a message using a rake task:

rake hipchat:send["hello world"]

Options like the room, API token, user name and notification flag can be set in YAML.

RAILS_ROOT/config/hipchat.yml:

token: "<your token>"
room: "Your room"
user: "Your name" # Default to `whoami`
notify: true # Defaults to false

Engine Yard

Use a deploy hook to send messages from Engine Yard’s Cloud platform.

RAILS_ROOT/deploy/after_restart.rb:

on_app_master do
  message  = "Deploying revision #{revision[0...6]} to #{node[:environment][:name]}"
  message += " (with migrations)" if migrate?
  message += "."</code>

<code>  # Send a message via rake task assuming a hipchat.yml in your config like above
  run "cd #{release_path} && bundle exec rake hipchat:send MESSAGE='#{message}'"
end

Copyright

Copyright © 2012 Atlassian. See LICENSE for details.