lib/capistrano-payload/capistrano_integration.rb in capistrano-payload-0.1.0 vs lib/capistrano-payload/capistrano_integration.rb in capistrano-payload-0.3.0

- old
+ new

@@ -1,21 +1,29 @@ require 'capistrano' +require 'capistrano/version' +require 'socket' module CapistranoPayload class CapistranoIntegration def self.load_into(capistrano_config) capistrano_config.load do _cset(:payload_url) { abort 'Payload URL required! set :payload_url' } - _cset(:payload_format) { :json } + _cset(:payload_message) { true } + _cset(:payload_format) { :json } + _cset(:payload_params) { Hash.new } _cset(:payload_data) { { + :version => Capistrano::Version.to_s.strip, :application => fetch(:application), - :deployer => ENV['USER'] || ENV['USERNAME'] || 'n/a', + :deployer => { + :user => ENV['USER'] || ENV['USERNAME'] || 'n/a', + :hostname => ENV['HOSTNAME'] || Socket.gethostname + }, :timestamp => Time.now, :source => { :branch => fetch(:branch), :revision => fetch(:real_revision), :repository => fetch(:repository) @@ -24,22 +32,28 @@ } namespace :payload do task :deploy, :roles => :app do logger.debug("Sending deployment notification to #{fetch(:payload_url)}") + message = payload_message == true ? Capistrano::CLI.ui.ask("Deployment message (none): ", nil) : '' begin - CapistranoPayload::Payload.new('deploy', payload_data).deliver(fetch(:payload_url)) + CapistranoPayload::Payload.new('deploy', message, payload_data, payload_format, payload_params).deliver(payload_url) rescue DeliveryError => err logger.debug("Payload delivery error: #{err.message}") + rescue ConfigurationError => err + logger.debug("Payload configuration error: #{err.message}") end end task :rollback, :roles => :app do logger.debug("Sending rollback notification to #{fetch(:payload_url)}") + message = payload_message == true ? Capistrano::CLI.ui.ask("Rollback message (none): ", nil) : '' begin - CapistranoPayload::Payload.new('rollback', payload_data).deliver(fetch(:payload_url)) + CapistranoPayload::Payload.new('rollback', message, payload_data, payload_format, payload_params).deliver(payload_url) rescue DeliveryError => err logger.debug("Payload delivery error: #{err.message}") + rescue ConfigurationError => err + logger.debug("Payload configuration error: #{err.message}") end end end after :deploy, 'payload:deploy' \ No newline at end of file