Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix up for Rails 4.0.0 and Capistrano 3.0.0 #5

Open
wants to merge 1 commit into from

4 participants

@DouglasSherk

This is probably not ideal, and I skimped out on some features that used to work, but it works at least.

@brianviveiros

Thanks Douglas! Any chance we can get this pull request accepted, or some other fix in place?

@braindev

Any update on this? I would love to have hipchat notifications w/ capistrano 3.

@DouglasSherk

I think this project is dead. If you want to continue it, feel free to use and contribute to my fork. I'm still using it and I know it works.

@shoe
Owner

@braindev @DouglasSherk I suggest submitting this pull request to the upstream repo: https://github.com/hipchat/hipchat-rb

@DouglasSherk

I can't. The upstream repo is entirely different. This isn't really a fork of it as much as it's a tool on top of an SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 31, 2013
  1. @DouglasSherk
This page is out of date. Refresh to see the latest.
View
96 lib/hipchat/capistrano.rb
@@ -1,95 +1,7 @@
require 'hipchat'
-Capistrano::Configuration.instance(:must_exist).load do
- set :hipchat_send_notification, false
- set :hipchat_with_migrations, false
-
- namespace :hipchat do
- task :set_client do
- set :hipchat_client, HipChat::Client.new(hipchat_token)
- end
-
- task :trigger_notification do
- set :hipchat_send_notification, true
- end
-
- task :configure_for_migrations do
- set :hipchat_with_migrations, true
- end
-
- task :notify_deploy_started do
- if hipchat_send_notification
- on_rollback do
- send_options.merge!(:color => failed_message_color)
- hipchat_client[hipchat_room_name].
- send(deploy_user, "#{human} cancelled deployment of #{deployment_name} to #{env}.", send_options)
- end
-
- message = "#{human} is deploying #{deployment_name} to #{env}"
- message << " (with migrations)" if hipchat_with_migrations
- message << "."
-
- hipchat_client[hipchat_room_name].send(deploy_user, message, send_options)
- end
- end
-
- task :notify_deploy_finished do
- hipchat_client[hipchat_room_name].
- send(deploy_user, "#{human} finished deploying #{deployment_name} to #{env}.", send_options)
- end
-
- def send_options
- return @send_options if defined?(@send_options)
- @send_options = message_color ? {:color => message_color} : {}
- @send_options.merge!(:notify => message_notification)
- @send_options
- end
-
- def deployment_name
- if branch
- "#{application}/#{branch}"
- else
- application
- end
- end
-
- def message_color
- fetch(:hipchat_color, nil)
- end
-
- def failed_message_color
- fetch(:hipchat_failed_color, "red")
- end
-
- def message_notification
- fetch(:hipchat_announce, false)
- end
-
- def deploy_user
- fetch(:hipchat_deploy_user, "Deploy")
- end
-
- def human
- ENV['HIPCHAT_USER'] ||
- fetch(:hipchat_human,
- if (u = %x{git config user.name}.strip) != ""
- u
- elsif (u = ENV['USER']) != ""
- u
- else
- "Someone"
- end)
- end
-
- def env
- fetch(:hipchat_env, fetch(:rack_env, fetch(:rails_env, "production")))
- end
- end
-
- before "hipchat:notify_deploy_started", "hipchat:set_client"
- before "deploy", "hipchat:trigger_notification"
- before "deploy:migrations", "hipchat:trigger_notification", "hipchat:configure_for_migrations"
- before "deploy:update_code", "hipchat:notify_deploy_started"
- after "deploy", "hipchat:notify_deploy_finished"
- after "deploy:migrations", "hipchat:notify_deploy_finished"
+if defined?(Capistrano::VERSION) && Gem::Version.new(Capistrano::VERSION).release >= Gem::Version.new('3.0.0')
+ load File.expand_path('../tasks/hipchat.rake', __FILE__)
+else
+ require_relative 'capistrano2'
end
View
93 lib/hipchat/capistrano2.rb
@@ -0,0 +1,93 @@
+Capistrano::Configuration.instance(:must_exist).load do
+ set :hipchat_send_notification, false
+ set :hipchat_with_migrations, false
+
+ namespace :hipchat do
+ task :set_client do
+ set :hipchat_client, HipChat::Client.new(hipchat_token)
+ end
+
+ task :trigger_notification do
+ set :hipchat_send_notification, true
+ end
+
+ task :configure_for_migrations do
+ set :hipchat_with_migrations, true
+ end
+
+ task :notify_deploy_started do
+ if hipchat_send_notification
+ on_rollback do
+ send_options.merge!(:color => failed_message_color)
+ hipchat_client[hipchat_room_name].
+ send(deploy_user, "#{human} cancelled deployment of #{deployment_name} to #{env}.", send_options)
+ end
+
+ message = "#{human} is deploying #{deployment_name} to #{env}"
+ message << " (with migrations)" if hipchat_with_migrations
+ message << "."
+
+ hipchat_client[hipchat_room_name].send(deploy_user, message, send_options)
+ end
+ end
+
+ task :notify_deploy_finished do
+ hipchat_client[hipchat_room_name].
+ send(deploy_user, "#{human} finished deploying #{deployment_name} to #{env}.", send_options)
+ end
+
+ def send_options
+ return @send_options if defined?(@send_options)
+ @send_options = message_color ? {:color => message_color} : {}
+ @send_options.merge!(:notify => message_notification)
+ @send_options
+ end
+
+ def deployment_name
+ if branch
+ "#{application}/#{branch}"
+ else
+ application
+ end
+ end
+
+ def message_color
+ fetch(:hipchat_color, nil)
+ end
+
+ def failed_message_color
+ fetch(:hipchat_failed_color, "red")
+ end
+
+ def message_notification
+ fetch(:hipchat_announce, false)
+ end
+
+ def deploy_user
+ fetch(:hipchat_deploy_user, "Deploy")
+ end
+
+ def human
+ ENV['HIPCHAT_USER'] ||
+ fetch(:hipchat_human,
+ if (u = %x{git config user.name}.strip) != ""
+ u
+ elsif (u = ENV['USER']) != ""
+ u
+ else
+ "Someone"
+ end)
+ end
+
+ def env
+ fetch(:hipchat_env, fetch(:rack_env, fetch(:rails_env, "production")))
+ end
+ end
+
+ before "hipchat:notify_deploy_started", "hipchat:set_client"
+ before "deploy", "hipchat:trigger_notification"
+ before "deploy:migrations", "hipchat:trigger_notification", "hipchat:configure_for_migrations"
+ before "deploy:update_code", "hipchat:notify_deploy_started"
+ after "deploy", "hipchat:notify_deploy_finished"
+ after "deploy:migrations", "hipchat:notify_deploy_finished"
+end
View
83 lib/hipchat/tasks/hipchat.rake
@@ -0,0 +1,83 @@
+namespace :hipchat do
+ set :hipchat_send_notification, false
+
+ task :notify_deploy_started do
+ if fetch(:hipchat_send_notification)
+ #on_rollback do
+ # send_options.merge!(:color => failed_message_color)
+ # @hipchat_client[fetch(:hipchat_room_name)].
+ # send(deploy_user, "#{human} cancelled deployment of #{deployment_name} to #{env}.", send_options)
+ #end
+
+ message = "#{human} is deploying #{deployment_name} to #{environment}"
+ message << "."
+
+ @hipchat_client[hipchat_room_name].send(deploy_user, message, send_options)
+ end
+ end
+
+ task :notify_deploy_finished do
+ @hipchat_client[hipchat_room_name].
+ send(deploy_user, "#{human} finished deploying #{deployment_name} to #{environment}.", send_options)
+ end
+
+ def send_options
+ return @send_options if defined?(@send_options)
+ @send_options = message_color ? {:color => message_color} : {}
+ @send_options.merge!(:notify => message_notification)
+ @send_options
+ end
+
+ def deployment_name
+ fetch(:application)
+ end
+
+ def message_color
+ fetch(:hipchat_color, nil)
+ end
+
+ #def failed_message_color
+ # fetch(:hipchat_failed_color, "red")
+ #end
+
+ def message_notification
+ fetch(:hipchat_announce, false)
+ end
+
+ def deploy_user
+ fetch(:hipchat_deploy_user, "Deploy")
+ end
+
+ def hipchat_room_name
+ fetch(:hipchat_room_name)
+ end
+
+ def human
+ ENV['HIPCHAT_USER'] ||
+ fetch(:hipchat_human,
+ if (u = %x{git config user.name}.strip) != ""
+ u
+ elsif (u = ENV['USER']) != ""
+ u
+ else
+ "Someone"
+ end)
+ end
+
+ def environment
+ fetch(:hipchat_env, fetch(:rack_env, fetch(:rails_env, "production")))
+ end
+
+ task :set_client do
+ @hipchat_client ||= HipChat::Client.new(fetch(:hipchat_token))
+ end
+
+ task :trigger_notification do
+ set :hipchat_send_notification, true
+ end
+
+ before "hipchat:notify_deploy_started", "hipchat:set_client"
+ before "deploy", "hipchat:trigger_notification"
+ before "deploy", "hipchat:notify_deploy_started"
+ after "deploy", "hipchat:notify_deploy_finished"
+end
Something went wrong with that request. Please try again.