hipchat 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.textile +10 -5
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/hipchat.gemspec +6 -6
- data/lib/hipchat.rb +8 -7
- data/lib/hipchat/capistrano.rb +29 -5
- data/lib/hipchat/chef.rb +1 -1
- data/lib/hipchat/rails3_tasks.rb +13 -6
- data/spec/hipchat_spec.rb +5 -17
- metadata +27 -12
data/LICENSE
CHANGED
data/README.textile
CHANGED
@@ -13,6 +13,9 @@ client['my room'].send('username', 'I quit!', :notify => true)
|
|
13
13
|
# Color it red. or "yellow", "green", "purple", "random" (default "yellow")
|
14
14
|
client['my room'].send('username', 'Build failed!', :color => 'red')
|
15
15
|
|
16
|
+
# Have your message rendered as text in HipChat (see https://www.hipchat.com/docs/api/method/rooms/message)
|
17
|
+
client['my room'].send('username', '@coworker Build faild!', :message_format => 'text')
|
18
|
+
|
16
19
|
h2. Capistrano
|
17
20
|
|
18
21
|
bc.. require 'hipchat/capistrano'
|
@@ -20,6 +23,9 @@ bc.. require 'hipchat/capistrano'
|
|
20
23
|
set :hipchat_token, "<your token>"
|
21
24
|
set :hipchat_room_name, "Your room"
|
22
25
|
set :hipchat_announce, false # notify users
|
26
|
+
set :hipchat_color, 'green' #finished deployment message color
|
27
|
+
set :hipchat_failed_color, 'red' #cancelled deployment message color
|
28
|
+
set :hipchat_message_format, 'text' # Sets the deployment message format, see https://www.hipchat.com/docs/api/method/rooms/message
|
23
29
|
|
24
30
|
h3. Who did it?
|
25
31
|
|
@@ -34,7 +40,7 @@ h2. Rails 3 Rake Task
|
|
34
40
|
|
35
41
|
Send a message using a rake task:
|
36
42
|
|
37
|
-
bc
|
43
|
+
bc. rake hipchat:send["hello world"]
|
38
44
|
|
39
45
|
Options like the room, API token, user name and notification flag can be set in YAML.
|
40
46
|
|
@@ -52,15 +58,14 @@ Use a "deploy hook":http://bit.ly/qnbIkP to send messages from Engine Yard's Clo
|
|
52
58
|
RAILS_ROOT/deploy/after_restart.rb:
|
53
59
|
|
54
60
|
bc.. on_app_master do
|
55
|
-
message = "Deploying revision #{
|
56
|
-
message += " to #{@configuration[:environment]}"
|
61
|
+
message = "Deploying revision #{revision[0...6]} to #{node[:environment][:name]}"
|
57
62
|
message += " (with migrations)" if migrate?
|
58
63
|
message += "."
|
59
64
|
|
60
65
|
# Send a message via rake task assuming a hipchat.yml in your config like above
|
61
|
-
run "cd #{release_path} && rake hipchat:send MESSAGE='#{message}'"
|
66
|
+
run "cd #{release_path} && bundle exec rake hipchat:send MESSAGE='#{message}'"
|
62
67
|
end
|
63
68
|
|
64
69
|
h2. Copyright
|
65
70
|
|
66
|
-
Copyright (c)
|
71
|
+
Copyright (c) 2012 Atlassian. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -7,9 +7,9 @@ begin
|
|
7
7
|
gem.name = "hipchat"
|
8
8
|
gem.summary = %Q{Ruby library to interact with HipChat}
|
9
9
|
gem.description = %Q{Ruby library to interact with HipChat}
|
10
|
-
gem.email = "
|
11
|
-
gem.homepage = "
|
12
|
-
gem.authors = ["
|
10
|
+
gem.email = "support@hipchat.com"
|
11
|
+
gem.homepage = "https://github.com/hipchat/hipchat-rb"
|
12
|
+
gem.authors = ["HipChat/Atlassian"]
|
13
13
|
gem.add_dependency "httparty"
|
14
14
|
gem.add_development_dependency "rspec", "~> 2.0"
|
15
15
|
gem.add_development_dependency "rr", "~> 1.0"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
data/hipchat.gemspec
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "hipchat"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["
|
12
|
-
s.date = "
|
11
|
+
s.authors = ["HipChat/Atlassian"]
|
12
|
+
s.date = "2012-10-12"
|
13
13
|
s.description = "Ruby library to interact with HipChat"
|
14
|
-
s.email = "
|
14
|
+
s.email = "support@hipchat.com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.textile"
|
@@ -32,9 +32,9 @@ Gem::Specification.new do |s|
|
|
32
32
|
"spec/spec.opts",
|
33
33
|
"spec/spec_helper.rb"
|
34
34
|
]
|
35
|
-
s.homepage = "
|
35
|
+
s.homepage = "https://github.com/hipchat/hipchat-rb"
|
36
36
|
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = "1.8.
|
37
|
+
s.rubygems_version = "1.8.24"
|
38
38
|
s.summary = "Ruby library to interact with HipChat"
|
39
39
|
|
40
40
|
if s.respond_to? :specification_version then
|
data/lib/hipchat.rb
CHANGED
@@ -47,7 +47,7 @@ module HipChat
|
|
47
47
|
# send 'nickname', 'some message'
|
48
48
|
#
|
49
49
|
# # Notify users and color the message red
|
50
|
-
# send 'nickname', 'some message', :notify => true, :color => 'red'
|
50
|
+
# send 'nickname', 'some message', :notify => true, :color => 'red'
|
51
51
|
#
|
52
52
|
# # Notify users (deprecated)
|
53
53
|
# send 'nickname', 'some message', true
|
@@ -58,7 +58,7 @@ module HipChat
|
|
58
58
|
# (default "yellow")
|
59
59
|
# +notify+:: true or false
|
60
60
|
# (default false)
|
61
|
-
def send(from, message, options_or_notify =
|
61
|
+
def send(from, message, options_or_notify = {})
|
62
62
|
options = if options_or_notify == true or options_or_notify == false
|
63
63
|
warn "DEPRECATED: Specify notify flag as an option (e.g., :notify => true)"
|
64
64
|
{ :notify => options_or_notify }
|
@@ -71,11 +71,12 @@ module HipChat
|
|
71
71
|
response = self.class.post('/message',
|
72
72
|
:query => { :auth_token => @token },
|
73
73
|
:body => {
|
74
|
-
:room_id
|
75
|
-
:from
|
76
|
-
:message
|
77
|
-
:
|
78
|
-
:
|
74
|
+
:room_id => room_id,
|
75
|
+
:from => from,
|
76
|
+
:message => message,
|
77
|
+
:message_format => options[:message_format] || 'html',
|
78
|
+
:color => options[:color],
|
79
|
+
:notify => options[:notify] ? 1 : 0
|
79
80
|
}
|
80
81
|
)
|
81
82
|
|
data/lib/hipchat/capistrano.rb
CHANGED
@@ -20,22 +20,30 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
20
20
|
task :notify_deploy_started do
|
21
21
|
if hipchat_send_notification
|
22
22
|
on_rollback do
|
23
|
+
send_options.merge!(:color => failed_message_color)
|
23
24
|
hipchat_client[hipchat_room_name].
|
24
|
-
send(deploy_user, "#{human} cancelled deployment of #{deployment_name} to #{env}.",
|
25
|
+
send(deploy_user, "#{human} cancelled deployment of #{deployment_name} to #{env}.", send_options)
|
25
26
|
end
|
26
27
|
|
27
28
|
message = "#{human} is deploying #{deployment_name} to #{env}"
|
28
29
|
message << " (with migrations)" if hipchat_with_migrations
|
29
30
|
message << "."
|
30
31
|
|
31
|
-
hipchat_client[hipchat_room_name].
|
32
|
-
send(deploy_user, message, hipchat_announce)
|
32
|
+
hipchat_client[hipchat_room_name].send(deploy_user, message, send_options)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
task :notify_deploy_finished do
|
37
37
|
hipchat_client[hipchat_room_name].
|
38
|
-
send(deploy_user, "#{human} finished deploying #{deployment_name} to #{env}.",
|
38
|
+
send(deploy_user, "#{human} finished deploying #{deployment_name} to #{env}.", send_options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def send_options
|
42
|
+
return @send_options if defined?(@send_options)
|
43
|
+
@send_options = message_color ? {:color => message_color} : {}
|
44
|
+
@send_options = message_format ? {:message_format => message_format } : {}
|
45
|
+
@send_options.merge!(:notify => message_notification)
|
46
|
+
@send_options
|
39
47
|
end
|
40
48
|
|
41
49
|
def deployment_name
|
@@ -45,7 +53,23 @@ Capistrano::Configuration.instance(:must_exist).load do
|
|
45
53
|
application
|
46
54
|
end
|
47
55
|
end
|
48
|
-
|
56
|
+
|
57
|
+
def message_color
|
58
|
+
fetch(:hipchat_color, nil)
|
59
|
+
end
|
60
|
+
|
61
|
+
def failed_message_color
|
62
|
+
fetch(:hipchat_failed_color, "red")
|
63
|
+
end
|
64
|
+
|
65
|
+
def message_notification
|
66
|
+
fetch(:hipchat_announce, false)
|
67
|
+
end
|
68
|
+
|
69
|
+
def message_format
|
70
|
+
fetch(:hipchat_message_format, "html")
|
71
|
+
end
|
72
|
+
|
49
73
|
def deploy_user
|
50
74
|
fetch(:hipchat_deploy_user, "Deploy")
|
51
75
|
end
|
data/lib/hipchat/chef.rb
CHANGED
@@ -25,7 +25,7 @@ module HipChat
|
|
25
25
|
msg = "Failure on #{node.name}: #{run_status.formatted_exception}"
|
26
26
|
|
27
27
|
client = HipChat::Client.new(@api_token)
|
28
|
-
client[@room_name].send('Chef', msg, @notify_users)
|
28
|
+
client[@room_name].send('Chef', msg, :notify => @notify_users)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
data/lib/hipchat/rails3_tasks.rb
CHANGED
@@ -7,16 +7,23 @@ namespace :hipchat do
|
|
7
7
|
config_file = Rails.root.join 'config', 'hipchat.yml'
|
8
8
|
|
9
9
|
options = {
|
10
|
-
:message
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
10
|
+
:message => ENV['MESSAGE'],
|
11
|
+
:message_format => ENV['MESSAGE_FORMAT'],
|
12
|
+
:user => ENV['HIPCHAT_USER'],
|
13
|
+
:notify => ENV['NOTIFY'],
|
14
|
+
:room => ENV['ROOM'],
|
15
|
+
:token => ENV['TOKEN']
|
16
|
+
}.reject { |k, v| v.blank? }
|
17
|
+
|
18
|
+
system_options = {
|
19
|
+
:user => ENV['USER']
|
15
20
|
}.reject { |k, v| v.blank? }
|
16
21
|
|
17
22
|
if File.exists? config_file
|
18
23
|
options.reverse_merge! YAML.load_file(config_file).symbolize_keys
|
19
24
|
end
|
25
|
+
|
26
|
+
options.reverse_merge! system_options
|
20
27
|
|
21
28
|
options[:notify] = options[:notify].to_s != 'false'
|
22
29
|
|
@@ -27,6 +34,6 @@ namespace :hipchat do
|
|
27
34
|
|
28
35
|
client = HipChat::Client.new(options[:token])
|
29
36
|
|
30
|
-
client[options[:room]].send(options[:user], options[:message], options[:notify])
|
37
|
+
client[options[:room]].send(options[:user], options[:message], :notify => options[:notify])
|
31
38
|
end
|
32
39
|
end
|
data/spec/hipchat_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe HipChat do
|
|
4
4
|
subject { HipChat::Client.new("blah") }
|
5
5
|
|
6
6
|
let(:room) { subject["Hipchat"] }
|
7
|
-
|
7
|
+
|
8
8
|
# Helper for mocking room message post requests
|
9
9
|
def mock_successful_send(from, message, options={})
|
10
10
|
options = {:color => 'yellow', :notify => 0}.merge(options)
|
@@ -16,40 +16,28 @@ describe HipChat do
|
|
16
16
|
:color => options[:color],
|
17
17
|
:notify => options[:notify]}) {
|
18
18
|
OpenStruct.new(:code => 200)
|
19
|
-
}
|
19
|
+
}
|
20
20
|
end
|
21
21
|
|
22
22
|
describe "sends a message to a room" do
|
23
23
|
it "successfully without custom options" do
|
24
24
|
mock_successful_send 'Dude', 'Hello world'
|
25
|
-
|
26
|
-
room.send("Dude", "Hello world").should be_true
|
27
|
-
end
|
28
|
-
|
29
|
-
it "successfully with notifications on as boolean" do
|
30
|
-
mock_successful_send 'Dude', 'Hello world', :notify => 1
|
31
25
|
|
32
|
-
room.send("Dude", "Hello world"
|
26
|
+
room.send("Dude", "Hello world").should be_true
|
33
27
|
end
|
34
|
-
|
35
|
-
it "successfully with notifications off as boolean" do
|
36
|
-
mock_successful_send 'Dude', 'Hello world', :notify => 0
|
37
28
|
|
38
|
-
room.send("Dude", "Hello world", false).should be_true
|
39
|
-
end
|
40
|
-
|
41
29
|
it "successfully with notifications on as option" do
|
42
30
|
mock_successful_send 'Dude', 'Hello world', :notify => 1
|
43
31
|
|
44
32
|
room.send("Dude", "Hello world", :notify => true).should be_true
|
45
33
|
end
|
46
|
-
|
34
|
+
|
47
35
|
it "successfully with custom color" do
|
48
36
|
mock_successful_send 'Dude', 'Hello world', :color => 'red'
|
49
37
|
|
50
38
|
room.send("Dude", "Hello world", :color => 'red').should be_true
|
51
39
|
end
|
52
|
-
|
40
|
+
|
53
41
|
it "but fails when the room doesn't exist" do
|
54
42
|
mock(HipChat::Room).post(anything, anything) {
|
55
43
|
OpenStruct.new(:code => 404)
|
metadata
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hipchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
|
-
-
|
8
|
+
- HipChat/Atlassian
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-10-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rspec
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ~>
|
@@ -32,10 +37,15 @@ dependencies:
|
|
32
37
|
version: '2.0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rr
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
51
|
- - ~>
|
@@ -43,9 +53,14 @@ dependencies:
|
|
43
53
|
version: '1.0'
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
47
62
|
description: Ruby library to interact with HipChat
|
48
|
-
email:
|
63
|
+
email: support@hipchat.com
|
49
64
|
executables: []
|
50
65
|
extensions: []
|
51
66
|
extra_rdoc_files:
|
@@ -66,7 +81,7 @@ files:
|
|
66
81
|
- spec/hipchat_spec.rb
|
67
82
|
- spec/spec.opts
|
68
83
|
- spec/spec_helper.rb
|
69
|
-
homepage:
|
84
|
+
homepage: https://github.com/hipchat/hipchat-rb
|
70
85
|
licenses: []
|
71
86
|
post_install_message:
|
72
87
|
rdoc_options: []
|
@@ -86,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
101
|
version: '0'
|
87
102
|
requirements: []
|
88
103
|
rubyforge_project:
|
89
|
-
rubygems_version: 1.8.
|
104
|
+
rubygems_version: 1.8.24
|
90
105
|
signing_key:
|
91
106
|
specification_version: 3
|
92
107
|
summary: Ruby library to interact with HipChat
|